blob: 1b53831135b985ccb1a28acc290a29cdac2811e9 [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
Sean Dague3c8973a2014-11-14 09:31:02 -050028GITDIR["django_openstack_auth"]=$DEST/django_openstack_auth
29
Sean Dagueb562e6a2012-11-19 16:00:01 -050030HORIZON_DIR=$DEST/horizon
31
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090032# local_settings.py is used to customize Dashboard settings.
33# The example file in Horizon repo is used by default.
34HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example}
35
Dean Troyer4237f592014-01-29 16:22:11 -060036# Tell Tempest this project is present
37TEMPEST_SERVICES+=,horizon
38
Dean Troyercc6b4432013-04-08 15:38:03 -050039
40# Functions
41# ---------
42
Eugene Nikanorovb663b332013-03-07 16:10:10 +040043# utility method of setting python option
Ian Wienandaee18c72014-02-21 15:35:08 +110044function _horizon_config_set {
Eugene Nikanorovb663b332013-03-07 16:10:10 +040045 local file=$1
46 local section=$2
47 local option=$3
48 local value=$4
49
Rob Crittendenc31fa402014-03-17 00:07:52 -040050 if [ -z "$section" ]; then
51 sed -e "/^$option/d" -i $local_settings
52 echo -e "\n$option=$value" >> $file
53 elif grep -q "^$section" $file; then
Dean Troyer1bbfcc72014-07-25 12:50:14 -050054 local line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
Eugene Nikanorovb663b332013-03-07 16:10:10 +040055 if [ -n "$line" ]; then
56 sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
57 else
Ravi Chunduru95c93e22013-07-16 04:18:47 -070058 sed -i -e "/^$section/a\ '$option': $value," $file
Eugene Nikanorovb663b332013-03-07 16:10:10 +040059 fi
60 else
61 echo -e "\n\n$section = {\n '$option': $value,\n}" >> $file
62 fi
63}
Sean Dagueb562e6a2012-11-19 16:00:01 -050064
Ian Wienandad43b392013-04-11 11:13:09 +100065
Dean Troyer1a6d4492013-06-03 16:47:36 -050066
Sean Dagueb562e6a2012-11-19 16:00:01 -050067# Entry Points
68# ------------
69
70# cleanup_horizon() - Remove residual data files, anything left over from previous
71# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110072function cleanup_horizon {
Dean Troyer1a6d4492013-06-03 16:47:36 -050073 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
74 # If ``/usr/bin/node`` points into ``$DEST``
75 # we installed it via ``install_nodejs``
76 if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then
77 sudo rm /usr/bin/node
78 fi
79 fi
Dean Troyer444a8d52014-06-06 16:36:52 -050080
81 local horizon_conf=$(apache_site_config_for horizon)
82 sudo rm -f $horizon_conf
Sean Dagueb562e6a2012-11-19 16:00:01 -050083}
84
85# configure_horizon() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +110086function configure_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -050087 setup_develop $HORIZON_DIR
Akihiro Motoki6518c0b2014-10-15 17:26:59 +090088
89 # Compile message catalogs.
90 # Horizon is installed as develop mode, so we can compile here.
91 # Message catalog compilation is handled by Django admin script,
92 # so compiling them after the installation avoids Django installation twice.
Sean Dague3c8973a2014-11-14 09:31:02 -050093 (cd $HORIZON_DIR; ./run_tests.sh -N --compilemessages)
Sean Dagueb562e6a2012-11-19 16:00:01 -050094}
95
96# init_horizon() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +110097function init_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -050098 # ``local_settings.py`` is used to override horizon default settings.
Dean Troyer1bbfcc72014-07-25 12:50:14 -050099 local local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +0900100 cp $HORIZON_SETTINGS $local_settings
Sean Dagueb562e6a2012-11-19 16:00:01 -0500101
Rob Crittendenc31fa402014-03-17 00:07:52 -0400102 _horizon_config_set $local_settings "" OPENSTACK_HOST \"${KEYSTONE_SERVICE_HOST}\"
Haiwei Xu98a18172014-06-04 19:15:11 +0900103 _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_URL "\"${KEYSTONE_SERVICE_PROTOCOL}://${KEYSTONE_SERVICE_HOST}:${KEYSTONE_SERVICE_PORT}/v2.0\""
Brant Knudson3951a942014-08-24 18:54:51 -0500104 if [[ -n "$KEYSTONE_TOKEN_HASH_ALGORITHM" ]]; then
105 _horizon_config_set $local_settings "" OPENSTACK_TOKEN_HASH_ALGORITHM \""$KEYSTONE_TOKEN_HASH_ALGORITHM"\"
106 fi
Rob Crittendenc31fa402014-03-17 00:07:52 -0400107
108 if [ -f $SSL_BUNDLE_FILE ]; then
109 _horizon_config_set $local_settings "" OPENSTACK_SSL_CACERT \"${SSL_BUNDLE_FILE}\"
110 fi
111
Sean Dagueb562e6a2012-11-19 16:00:01 -0500112 # Create an empty directory that apache uses as docroot
113 sudo mkdir -p $HORIZON_DIR/.blackhole
114
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000115 local horizon_conf=$(apache_site_config_for horizon)
JordanP1e4587e2013-05-08 22:19:59 +0200116
Sean Dagueb562e6a2012-11-19 16:00:01 -0500117 # Configure apache to run horizon
118 sudo sh -c "sed -e \"
119 s,%USER%,$APACHE_USER,g;
120 s,%GROUP%,$APACHE_GROUP,g;
121 s,%HORIZON_DIR%,$HORIZON_DIR,g;
122 s,%APACHE_NAME%,$APACHE_NAME,g;
123 s,%DEST%,$DEST,g;
zhang-hared98a5d02013-06-21 18:18:02 +0800124 \" $FILES/apache-horizon.template >$horizon_conf"
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200125
126 if is_ubuntu; then
127 disable_apache_site 000-default
128 sudo touch $horizon_conf
129 elif is_fedora; then
130 sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
131 elif is_suse; then
132 : # nothing to do
133 else
134 exit_distro_not_supported "horizon apache configuration"
135 fi
136 enable_apache_site horizon
137
138 # Remove old log files that could mess with how devstack detects whether Horizon
139 # has been successfully started (see start_horizon() and functions::screen_it())
Chris Dent2f27a0e2014-09-09 13:46:02 +0100140 # and run_process
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200141 sudo rm -f /var/log/$APACHE_NAME/horizon_*
142
Sean Dagueb562e6a2012-11-19 16:00:01 -0500143}
144
Zhenguo Niue385d1e2014-03-12 16:58:12 +0800145# install_django_openstack_auth() - Collect source and prepare
146function install_django_openstack_auth {
Sean Dague3c8973a2014-11-14 09:31:02 -0500147 if use_library_from_git "django_openstack_auth"; then
148 local dir=${GITDIR["django_openstack_auth"]}
149 git_clone_by_name "django_openstack_auth"
150 # Compile message catalogs before installation
151 _prepare_message_catalog_compilation
152 (cd $dir; python setup.py compile_catalog)
153 setup_dev_lib "django_openstack_auth"
154 fi
155 # if we aren't using this library from git, then we just let it
156 # get dragged in by the horizon setup.
Zhenguo Niue385d1e2014-03-12 16:58:12 +0800157}
158
Sean Dagueb562e6a2012-11-19 16:00:01 -0500159# install_horizon() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100160function install_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -0500161 # Apache installation, because we mark it NOPRIME
zhang-hared98a5d02013-06-21 18:18:02 +0800162 install_apache_wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500163
Sean Dagueb562e6a2012-11-19 16:00:01 -0500164 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
165}
166
167# start_horizon() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100168function start_horizon {
zhang-hared98a5d02013-06-21 18:18:02 +0800169 restart_apache_server
Chris Dent2f27a0e2014-09-09 13:46:02 +0100170 tail_log horizon /var/log/$APACHE_NAME/horizon_error.log
Sean Dagueb562e6a2012-11-19 16:00:01 -0500171}
172
173# stop_horizon() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100174function stop_horizon {
zhang-hared98a5d02013-06-21 18:18:02 +0800175 stop_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500176}
177
Akihiro Motoki6518c0b2014-10-15 17:26:59 +0900178# NOTE: It can be moved to common functions, but it is only used by compilation
179# of django_openstack_auth catalogs at the moment.
180function _prepare_message_catalog_compilation {
181 local babel_package=$(grep ^Babel $REQUIREMENTS_DIR/global-requirements.txt)
182 pip_install "$babel_package"
183}
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: