blob: a422529d06ff687b63dc5dd85d23c21fbbba14f6 [file] [log] [blame]
Sean Dagueb562e6a2012-11-19 16:00:01 -05001# lib/horizon
2# Functions to control the configuration and operation of the horizon service
Sean Dagueb562e6a2012-11-19 16:00:01 -05003
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# - ``functions`` file
7# - ``apache`` file
8# - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
Sean Dagueb562e6a2012-11-19 16:00:01 -05009
10# ``stack.sh`` calls the entry points in this order:
11#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010012# - install_horizon
13# - configure_horizon
14# - init_horizon
15# - start_horizon
16# - stop_horizon
17# - cleanup_horizon
Sean Dagueb562e6a2012-11-19 16:00:01 -050018
19# Save trace setting
20XTRACE=$(set +o | grep xtrace)
21set +o xtrace
22
23
24# Defaults
25# --------
26
Sean Dagueb562e6a2012-11-19 16:00:01 -050027# Set up default directories
28HORIZON_DIR=$DEST/horizon
Zhenguo Niue385d1e2014-03-12 16:58:12 +080029HORIZONAUTH_DIR=$DEST/django_openstack_auth
Sean Dagueb562e6a2012-11-19 16:00:01 -050030
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090031# local_settings.py is used to customize Dashboard settings.
32# The example file in Horizon repo is used by default.
33HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example}
34
Dean Troyer4237f592014-01-29 16:22:11 -060035# Tell Tempest this project is present
36TEMPEST_SERVICES+=,horizon
37
Dean Troyercc6b4432013-04-08 15:38:03 -050038
39# Functions
40# ---------
41
Eugene Nikanorovb663b332013-03-07 16:10:10 +040042# utility method of setting python option
Ian Wienandaee18c72014-02-21 15:35:08 +110043function _horizon_config_set {
Eugene Nikanorovb663b332013-03-07 16:10:10 +040044 local file=$1
45 local section=$2
46 local option=$3
47 local value=$4
48
Rob Crittendenc31fa402014-03-17 00:07:52 -040049 if [ -z "$section" ]; then
50 sed -e "/^$option/d" -i $local_settings
51 echo -e "\n$option=$value" >> $file
52 elif grep -q "^$section" $file; then
Dean Troyer1bbfcc72014-07-25 12:50:14 -050053 local line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
Eugene Nikanorovb663b332013-03-07 16:10:10 +040054 if [ -n "$line" ]; then
55 sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
56 else
Ravi Chunduru95c93e22013-07-16 04:18:47 -070057 sed -i -e "/^$section/a\ '$option': $value," $file
Eugene Nikanorovb663b332013-03-07 16:10:10 +040058 fi
59 else
60 echo -e "\n\n$section = {\n '$option': $value,\n}" >> $file
61 fi
62}
Sean Dagueb562e6a2012-11-19 16:00:01 -050063
Ian Wienandad43b392013-04-11 11:13:09 +100064
Dean Troyer1a6d4492013-06-03 16:47:36 -050065
Sean Dagueb562e6a2012-11-19 16:00:01 -050066# Entry Points
67# ------------
68
69# cleanup_horizon() - Remove residual data files, anything left over from previous
70# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110071function cleanup_horizon {
Dean Troyer1a6d4492013-06-03 16:47:36 -050072 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
73 # If ``/usr/bin/node`` points into ``$DEST``
74 # we installed it via ``install_nodejs``
75 if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then
76 sudo rm /usr/bin/node
77 fi
78 fi
Dean Troyer444a8d52014-06-06 16:36:52 -050079
80 local horizon_conf=$(apache_site_config_for horizon)
81 sudo rm -f $horizon_conf
Sean Dagueb562e6a2012-11-19 16:00:01 -050082}
83
84# configure_horizon() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +110085function configure_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -050086 setup_develop $HORIZON_DIR
87}
88
89# init_horizon() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +110090function init_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -050091 # ``local_settings.py`` is used to override horizon default settings.
Dean Troyer1bbfcc72014-07-25 12:50:14 -050092 local local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090093 cp $HORIZON_SETTINGS $local_settings
Sean Dagueb562e6a2012-11-19 16:00:01 -050094
Edgar Maganac973f122013-07-29 16:39:56 -070095 if is_service_enabled neutron; then
96 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_security_group $Q_USE_SECGROUP
97 fi
Eugene Nikanorovb663b332013-03-07 16:10:10 +040098 # enable loadbalancer dashboard in case service is enabled
99 if is_service_enabled q-lbaas; then
Nobuto MURATA73a39bf2013-07-11 16:26:02 +0900100 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_lb True
Eugene Nikanorovb663b332013-03-07 16:10:10 +0400101 fi
102
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700103 # enable firewall dashboard in case service is enabled
104 if is_service_enabled q-fwaas; then
105 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_firewall True
106 fi
107
Akihiro MOTOKIeaa9e1e2013-09-10 05:22:37 +0900108 # enable VPN dashboard in case service is enabled
109 if is_service_enabled q-vpn; then
110 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_vpn True
111 fi
112
Rob Crittendenc31fa402014-03-17 00:07:52 -0400113 _horizon_config_set $local_settings "" OPENSTACK_HOST \"${KEYSTONE_SERVICE_HOST}\"
Haiwei Xu98a18172014-06-04 19:15:11 +0900114 _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_URL "\"${KEYSTONE_SERVICE_PROTOCOL}://${KEYSTONE_SERVICE_HOST}:${KEYSTONE_SERVICE_PORT}/v2.0\""
Rob Crittendenc31fa402014-03-17 00:07:52 -0400115
116 if [ -f $SSL_BUNDLE_FILE ]; then
117 _horizon_config_set $local_settings "" OPENSTACK_SSL_CACERT \"${SSL_BUNDLE_FILE}\"
118 fi
119
Sean Dagueb562e6a2012-11-19 16:00:01 -0500120 # Create an empty directory that apache uses as docroot
121 sudo mkdir -p $HORIZON_DIR/.blackhole
122
Chris Buccella610af8c2013-11-05 12:56:34 +0000123 # Apache 2.4 uses mod_authz_host for access control now (instead of "Allow")
Dean Troyer1bbfcc72014-07-25 12:50:14 -0500124 local horizon_require=''
Chris Buccella610af8c2013-11-05 12:56:34 +0000125 if check_apache_version "2.4" ; then
Dean Troyer1bbfcc72014-07-25 12:50:14 -0500126 horizon_require='Require all granted'
Chris Buccella610af8c2013-11-05 12:56:34 +0000127 fi
128
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000129 local horizon_conf=$(apache_site_config_for horizon)
JordanP1e4587e2013-05-08 22:19:59 +0200130
Sean Dagueb562e6a2012-11-19 16:00:01 -0500131 # Configure apache to run horizon
132 sudo sh -c "sed -e \"
133 s,%USER%,$APACHE_USER,g;
134 s,%GROUP%,$APACHE_GROUP,g;
135 s,%HORIZON_DIR%,$HORIZON_DIR,g;
136 s,%APACHE_NAME%,$APACHE_NAME,g;
137 s,%DEST%,$DEST,g;
Dean Troyer1bbfcc72014-07-25 12:50:14 -0500138 s,%HORIZON_REQUIRE%,$horizon_require,g;
zhang-hared98a5d02013-06-21 18:18:02 +0800139 \" $FILES/apache-horizon.template >$horizon_conf"
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200140
141 if is_ubuntu; then
142 disable_apache_site 000-default
143 sudo touch $horizon_conf
144 elif is_fedora; then
145 sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
146 elif is_suse; then
147 : # nothing to do
148 else
149 exit_distro_not_supported "horizon apache configuration"
150 fi
151 enable_apache_site horizon
152
153 # Remove old log files that could mess with how devstack detects whether Horizon
154 # has been successfully started (see start_horizon() and functions::screen_it())
Chris Dent2f27a0e2014-09-09 13:46:02 +0100155 # and run_process
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200156 sudo rm -f /var/log/$APACHE_NAME/horizon_*
157
Sean Dagueb562e6a2012-11-19 16:00:01 -0500158}
159
Zhenguo Niue385d1e2014-03-12 16:58:12 +0800160# install_django_openstack_auth() - Collect source and prepare
161function install_django_openstack_auth {
162 git_clone $HORIZONAUTH_REPO $HORIZONAUTH_DIR $HORIZONAUTH_BRANCH
Sean Daguee8377142014-06-23 08:21:07 -0400163 setup_install $HORIZONAUTH_DIR
Zhenguo Niue385d1e2014-03-12 16:58:12 +0800164}
165
Sean Dagueb562e6a2012-11-19 16:00:01 -0500166# install_horizon() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100167function install_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -0500168 # Apache installation, because we mark it NOPRIME
zhang-hared98a5d02013-06-21 18:18:02 +0800169 install_apache_wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500170
Sean Dagueb562e6a2012-11-19 16:00:01 -0500171 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
172}
173
174# start_horizon() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100175function start_horizon {
zhang-hared98a5d02013-06-21 18:18:02 +0800176 restart_apache_server
Chris Dent2f27a0e2014-09-09 13:46:02 +0100177 tail_log horizon /var/log/$APACHE_NAME/horizon_error.log
Sean Dagueb562e6a2012-11-19 16:00:01 -0500178}
179
180# stop_horizon() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100181function stop_horizon {
zhang-hared98a5d02013-06-21 18:18:02 +0800182 stop_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500183}
184
Dean Troyer1a6d4492013-06-03 16:47:36 -0500185
Sean Dagueb562e6a2012-11-19 16:00:01 -0500186# Restore xtrace
187$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400188
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100189# Tell emacs to use shell-script-mode
190## Local variables:
191## mode: shell-script
192## End: