Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 1 | # lib/ironic |
| 2 | # Functions to control the configuration and operation of the **Ironic** service |
| 3 | |
| 4 | # Dependencies: |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 5 | # |
| 6 | # - ``functions`` file |
| 7 | # - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined |
| 8 | # - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined |
| 9 | # - ``SERVICE_HOST`` |
| 10 | # - ``KEYSTONE_TOKEN_FORMAT`` must be defined |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 11 | |
| 12 | # ``stack.sh`` calls the entry points in this order: |
| 13 | # |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 14 | # - install_ironic |
| 15 | # - install_ironicclient |
| 16 | # - init_ironic |
| 17 | # - start_ironic |
| 18 | # - stop_ironic |
| 19 | # - cleanup_ironic |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 20 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 21 | # Save trace and pipefail settings |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 22 | XTRACE=$(set +o | grep xtrace) |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 23 | PIPEFAIL=$(set +o | grep pipefail) |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 24 | set +o xtrace |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 25 | set +o pipefail |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 26 | |
| 27 | # Defaults |
| 28 | # -------- |
| 29 | |
| 30 | # Set up default directories |
| 31 | IRONIC_DIR=$DEST/ironic |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 32 | IRONIC_DATA_DIR=$DATA_DIR/ironic |
| 33 | IRONIC_STATE_PATH=/var/lib/ironic |
Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 34 | IRONICCLIENT_DIR=$DEST/python-ironicclient |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 35 | IRONIC_AUTH_CACHE_DIR=${IRONIC_AUTH_CACHE_DIR:-/var/cache/ironic} |
| 36 | IRONIC_CONF_DIR=${IRONIC_CONF_DIR:-/etc/ironic} |
| 37 | IRONIC_CONF_FILE=$IRONIC_CONF_DIR/ironic.conf |
| 38 | IRONIC_ROOTWRAP_CONF=$IRONIC_CONF_DIR/rootwrap.conf |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 39 | IRONIC_POLICY_JSON=$IRONIC_CONF_DIR/policy.json |
| 40 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 41 | # Set up defaults for functional / integration testing |
| 42 | IRONIC_SCRIPTS_DIR=${IRONIC_SCRIPTS_DIR:-$TOP_DIR/tools/ironic/scripts} |
| 43 | IRONIC_TEMPLATES_DIR=${IRONIC_TEMPLATES_DIR:-$TOP_DIR/tools/ironic/templates} |
| 44 | IRONIC_BAREMETAL_BASIC_OPS=$(trueorfalse False $IRONIC_BAREMETAL_BASIC_OPS) |
| 45 | IRONIC_SSH_USERNAME=${IRONIC_SSH_USERNAME:-`whoami`} |
| 46 | IRONIC_SSH_KEY_DIR=${IRONIC_SSH_KEY_DIR:-$IRONIC_DATA_DIR/ssh_keys} |
| 47 | IRONIC_SSH_KEY_FILENAME=${IRONIC_SSH_KEY_FILENAME:-ironic_key} |
| 48 | IRONIC_KEY_FILE=$IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME |
| 49 | IRONIC_SSH_VIRT_TYPE=${IRONIC_SSH_VIRT_TYPE:-virsh} |
| 50 | IRONIC_TFTPBOOT_DIR=${IRONIC_TFTPBOOT_DIR:-$IRONIC_DATA_DIR/tftpboot} |
| 51 | IRONIC_VM_SSH_PORT=${IRONIC_VM_SSH_PORT:-2222} |
| 52 | IRONIC_VM_SSH_ADDRESS=${IRONIC_VM_SSH_ADDRESS:-$HOST_IP} |
| 53 | IRONIC_VM_COUNT=${IRONIC_VM_COUNT:-1} |
| 54 | IRONIC_VM_SPECS_CPU=${IRONIC_VM_SPECS_CPU:-1} |
| 55 | IRONIC_VM_SPECS_RAM=${IRONIC_VM_SPECS_RAM:-256} |
| 56 | IRONIC_VM_SPECS_DISK=${IRONIC_VM_SPECS_DISK:-10} |
| 57 | IRONIC_VM_EMULATOR=${IRONIC_VM_EMULATOR:-/usr/bin/qemu-system-x86_64} |
| 58 | IRONIC_VM_NETWORK_BRIDGE=${IRONIC_VM_NETWORK_BRIDGE:-brbm} |
| 59 | IRONIC_VM_NETWORK_RANGE=${IRONIC_VM_NETWORK_RANGE:-192.0.2.0/24} |
| 60 | IRONIC_VM_MACS_CSV_FILE=${IRONIC_VM_MACS_CSV_FILE:-$IRONIC_DATA_DIR/ironic_macs.csv} |
| 61 | IRONIC_AUTHORIZED_KEYS_FILE=${IRONIC_AUTHORIZED_KEYS_FILE:-$HOME/.ssh/authorized_keys} |
| 62 | |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 63 | # Support entry points installation of console scripts |
| 64 | IRONIC_BIN_DIR=$(get_python_exec_prefix) |
| 65 | |
| 66 | # Ironic connection info. Note the port must be specified. |
| 67 | IRONIC_SERVICE_PROTOCOL=http |
| 68 | IRONIC_HOSTPORT=${IRONIC_HOSTPORT:-$SERVICE_HOST:6385} |
| 69 | |
Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 70 | # Tell Tempest this project is present |
| 71 | TEMPEST_SERVICES+=,ironic |
| 72 | |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 73 | |
| 74 | # Functions |
| 75 | # --------- |
| 76 | |
Dean Troyer | 1023ff7 | 2014-01-27 14:56:44 -0600 | [diff] [blame] | 77 | # Test if any Ironic services are enabled |
| 78 | # is_ironic_enabled |
| 79 | function is_ironic_enabled { |
| 80 | [[ ,${ENABLED_SERVICES} =~ ,"ir-" ]] && return 0 |
| 81 | return 1 |
| 82 | } |
| 83 | |
Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 84 | # install_ironic() - Collect source and prepare |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 85 | function install_ironic { |
Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 86 | git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH |
| 87 | setup_develop $IRONIC_DIR |
| 88 | } |
| 89 | |
| 90 | # install_ironicclient() - Collect sources and prepare |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 91 | function install_ironicclient { |
Roman Prykhodchenko | 43e0066 | 2013-10-15 17:03:15 +0300 | [diff] [blame] | 92 | git_clone $IRONICCLIENT_REPO $IRONICCLIENT_DIR $IRONICCLIENT_BRANCH |
| 93 | setup_develop $IRONICCLIENT_DIR |
| 94 | } |
| 95 | |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 96 | # cleanup_ironic() - Remove residual data files, anything left over from previous |
| 97 | # runs that would need to clean up. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 98 | function cleanup_ironic { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 99 | sudo rm -rf $IRONIC_AUTH_CACHE_DIR |
| 100 | } |
| 101 | |
| 102 | # configure_ironic() - Set config files, create data dirs, etc |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 103 | function configure_ironic { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 104 | if [[ ! -d $IRONIC_CONF_DIR ]]; then |
| 105 | sudo mkdir -p $IRONIC_CONF_DIR |
| 106 | fi |
| 107 | sudo chown $STACK_USER $IRONIC_CONF_DIR |
| 108 | |
| 109 | # Copy over ironic configuration file and configure common parameters. |
| 110 | cp $IRONIC_DIR/etc/ironic/ironic.conf.sample $IRONIC_CONF_FILE |
| 111 | iniset $IRONIC_CONF_FILE DEFAULT debug True |
| 112 | inicomment $IRONIC_CONF_FILE DEFAULT log_file |
| 113 | iniset $IRONIC_CONF_FILE DEFAULT sql_connection `database_connection_url ironic` |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 114 | iniset $IRONIC_CONF_FILE DEFAULT state_path $IRONIC_STATE_PATH |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 115 | iniset $IRONIC_CONF_FILE DEFAULT use_syslog $SYSLOG |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 116 | # Configure Ironic conductor, if it was enabled. |
| 117 | if is_service_enabled ir-cond; then |
| 118 | configure_ironic_conductor |
| 119 | fi |
| 120 | |
| 121 | # Configure Ironic API, if it was enabled. |
| 122 | if is_service_enabled ir-api; then |
| 123 | configure_ironic_api |
| 124 | fi |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 125 | |
| 126 | if [[ "$IRONIC_BAREMETAL_BASIC_OPS" == "True" ]]; then |
| 127 | configure_ironic_auxiliary |
| 128 | fi |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | # configure_ironic_api() - Is used by configure_ironic(). Performs |
| 132 | # API specific configuration. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 133 | function configure_ironic_api { |
Roman Prykhodchenko | c48c312 | 2013-10-01 17:19:05 +0300 | [diff] [blame] | 134 | iniset $IRONIC_CONF_FILE DEFAULT auth_strategy keystone |
| 135 | iniset $IRONIC_CONF_FILE DEFAULT policy_file $IRONIC_POLICY_JSON |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 136 | iniset $IRONIC_CONF_FILE keystone_authtoken auth_host $KEYSTONE_AUTH_HOST |
| 137 | iniset $IRONIC_CONF_FILE keystone_authtoken auth_port $KEYSTONE_AUTH_PORT |
| 138 | iniset $IRONIC_CONF_FILE keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL |
Jamie Lennox | bd24a8d | 2013-09-20 16:26:42 +1000 | [diff] [blame] | 139 | iniset $IRONIC_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 140 | iniset $IRONIC_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/ |
| 141 | iniset $IRONIC_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME |
| 142 | iniset $IRONIC_CONF_FILE keystone_authtoken admin_user ironic |
| 143 | iniset $IRONIC_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 144 | iniset_rpc_backend ironic $IRONIC_CONF_FILE DEFAULT |
| 145 | iniset $IRONIC_CONF_FILE keystone_authtoken signing_dir $IRONIC_AUTH_CACHE_DIR/api |
| 146 | |
| 147 | cp -p $IRONIC_DIR/etc/ironic/policy.json $IRONIC_POLICY_JSON |
| 148 | } |
| 149 | |
| 150 | # configure_ironic_conductor() - Is used by configure_ironic(). |
| 151 | # Sets conductor specific settings. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 152 | function configure_ironic_conductor { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 153 | cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF |
Lucas Alvares Gomes | 279295c | 2014-01-14 11:37:51 +0000 | [diff] [blame] | 154 | cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 155 | |
Alexander Gordeev | a67cb1a | 2014-03-04 18:38:33 +0400 | [diff] [blame] | 156 | iniset $IRONIC_CONF_FILE DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 157 | iniset $IRONIC_CONF_FILE conductor api_url http://$SERVICE_HOST:6385 |
| 158 | iniset $IRONIC_CONF_FILE pxe tftp_server $SERVICE_HOST |
| 159 | iniset $IRONIC_CONF_FILE pxe tftp_root $IRONIC_TFTPBOOT_DIR |
| 160 | iniset $IRONIC_CONF_FILE pxe tftp_master_path $IRONIC_TFTPBOOT_DIR/master_images |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | # create_ironic_cache_dir() - Part of the init_ironic() process |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 164 | function create_ironic_cache_dir { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 165 | # Create cache dir |
| 166 | sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/api |
| 167 | sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/api |
| 168 | rm -f $IRONIC_AUTH_CACHE_DIR/api/* |
| 169 | sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/registry |
| 170 | sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/registry |
| 171 | rm -f $IRONIC_AUTH_CACHE_DIR/registry/* |
| 172 | } |
| 173 | |
| 174 | # create_ironic_accounts() - Set up common required ironic accounts |
| 175 | |
| 176 | # Tenant User Roles |
| 177 | # ------------------------------------------------------------------ |
| 178 | # service ironic admin # if enabled |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 179 | function create_ironic_accounts { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 180 | |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 181 | SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }") |
| 182 | ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }") |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 183 | |
| 184 | # Ironic |
| 185 | if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 186 | IRONIC_USER=$(openstack user create \ |
| 187 | ironic \ |
| 188 | --password "$SERVICE_PASSWORD" \ |
| 189 | --project $SERVICE_TENANT \ |
| 190 | --email ironic@example.com \ |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 191 | | grep " id " | get_field 2) |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 192 | openstack role add \ |
| 193 | $ADMIN_ROLE \ |
| 194 | --project $SERVICE_TENANT \ |
| 195 | --user $IRONIC_USER |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 196 | if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 197 | IRONIC_SERVICE=$(openstack service create \ |
| 198 | ironic \ |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 199 | --type=baremetal \ |
| 200 | --description="Ironic baremetal provisioning service" \ |
| 201 | | grep " id " | get_field 2) |
Steve Martinelli | 1968542 | 2014-01-24 13:02:26 -0600 | [diff] [blame] | 202 | openstack endpoint create \ |
| 203 | $IRONIC_SERVICE \ |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 204 | --region RegionOne \ |
Roman Prykhodchenko | f5002ef | 2013-09-24 19:09:26 +0300 | [diff] [blame] | 205 | --publicurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \ |
| 206 | --adminurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \ |
| 207 | --internalurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 208 | fi |
| 209 | fi |
| 210 | } |
| 211 | |
| 212 | |
| 213 | # init_ironic() - Initialize databases, etc. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 214 | function init_ironic { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 215 | # (Re)create ironic database |
| 216 | recreate_database ironic utf8 |
| 217 | |
| 218 | # Migrate ironic database |
| 219 | $IRONIC_BIN_DIR/ironic-dbsync |
| 220 | |
| 221 | create_ironic_cache_dir |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 222 | } |
| 223 | |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 224 | # start_ironic() - Start running processes, including screen |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 225 | function start_ironic { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 226 | # Start Ironic API server, if enabled. |
| 227 | if is_service_enabled ir-api; then |
| 228 | start_ironic_api |
| 229 | fi |
| 230 | |
| 231 | # Start Ironic conductor, if enabled. |
| 232 | if is_service_enabled ir-cond; then |
| 233 | start_ironic_conductor |
| 234 | fi |
| 235 | } |
| 236 | |
| 237 | # start_ironic_api() - Used by start_ironic(). |
| 238 | # Starts Ironic API server. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 239 | function start_ironic_api { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 240 | screen_it ir-api "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-api --config-file=$IRONIC_CONF_FILE" |
| 241 | echo "Waiting for ir-api ($IRONIC_HOSTPORT) to start..." |
JUN JIE NAN | 0aa8534 | 2013-09-13 15:47:09 +0800 | [diff] [blame] | 242 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$IRONIC_HOSTPORT; do sleep 1; done"; then |
Sean Dague | 101b424 | 2013-10-22 08:47:11 -0400 | [diff] [blame] | 243 | die $LINENO "ir-api did not start" |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 244 | fi |
| 245 | } |
| 246 | |
| 247 | # start_ironic_conductor() - Used by start_ironic(). |
| 248 | # Starts Ironic conductor. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 249 | function start_ironic_conductor { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 250 | screen_it ir-cond "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-conductor --config-file=$IRONIC_CONF_FILE" |
| 251 | # TODO(romcheg): Find a way to check whether the conductor has started. |
| 252 | } |
| 253 | |
| 254 | # stop_ironic() - Stop running processes |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 255 | function stop_ironic { |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 256 | # Kill the Ironic screen windows |
| 257 | screen -S $SCREEN_NAME -p ir-api -X kill |
| 258 | screen -S $SCREEN_NAME -p ir-cond -X kill |
| 259 | } |
| 260 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 261 | function is_ironic { |
| 262 | if ( is_service_enabled ir-cond && is_service_enabled ir-api ); then |
| 263 | return 0 |
| 264 | fi |
| 265 | return 1 |
| 266 | } |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 267 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 268 | function configure_ironic_dirs { |
| 269 | sudo mkdir -p $IRONIC_DATA_DIR |
| 270 | sudo mkdir -p $IRONIC_STATE_PATH |
| 271 | sudo mkdir -p $IRONIC_TFTPBOOT_DIR |
| 272 | sudo chown -R $STACK_USER $IRONIC_DATA_DIR $IRONIC_STATE_PATH |
| 273 | sudo chown -R $STACK_USER:$LIBVIRT_GROUP $IRONIC_TFTPBOOT_DIR |
| 274 | if is_ubuntu; then |
| 275 | PXEBIN=/usr/lib/syslinux/pxelinux.0 |
| 276 | elif is_fedora; then |
| 277 | PXEBIN=/usr/share/syslinux/pxelinux.0 |
| 278 | fi |
| 279 | if [ ! -f $PXEBIN ]; then |
| 280 | die $LINENO "pxelinux.0 (from SYSLINUX) not found." |
| 281 | fi |
| 282 | |
| 283 | cp $PXEBIN $IRONIC_TFTPBOOT_DIR |
| 284 | mkdir -p $IRONIC_TFTPBOOT_DIR/pxelinux.cfg |
| 285 | } |
| 286 | |
| 287 | function ironic_ensure_libvirt_group { |
| 288 | groups $STACK_USER | grep -q $LIBVIRT_GROUP || adduser $STACK_USER $LIBVIRT_GROUP |
| 289 | } |
| 290 | |
| 291 | function create_bridge_and_vms { |
| 292 | ironic_ensure_libvirt_group |
| 293 | |
| 294 | # Call libvirt setup scripts in a new shell to ensure any new group membership |
| 295 | sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/setup-network" |
| 296 | |
| 297 | sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/create-nodes \ |
| 298 | $IRONIC_VM_SPECS_CPU $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK \ |
| 299 | amd64 $IRONIC_VM_COUNT $IRONIC_VM_NETWORK_BRIDGE $IRONIC_VM_EMULATOR" >> $IRONIC_VM_MACS_CSV_FILE |
| 300 | |
| 301 | } |
| 302 | |
| 303 | function enroll_vms { |
| 304 | |
| 305 | CHASSIS_ID=$(ironic chassis-create -d "ironic test chassis" | grep " uuid " | get_field 2) |
| 306 | IRONIC_NET_ID=$(neutron net-list | grep private | get_field 1) |
| 307 | local idx=0 |
| 308 | |
| 309 | # work around; need to know what netns neutron uses for private network |
| 310 | neutron port-create private |
| 311 | |
| 312 | while read MAC; do |
| 313 | |
| 314 | NODE_ID=$(ironic node-create --chassis_uuid $CHASSIS_ID --driver pxe_ssh \ |
| 315 | -i ssh_virt_type=$IRONIC_SSH_VIRT_TYPE \ |
| 316 | -i ssh_address=$IRONIC_VM_SSH_ADDRESS \ |
| 317 | -i ssh_port=$IRONIC_VM_SSH_PORT \ |
| 318 | -i ssh_username=$IRONIC_SSH_USERNAME \ |
| 319 | -i ssh_key_filename=$IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME \ |
| 320 | -p cpus=$IRONIC_VM_SPECS_CPU \ |
| 321 | -p memory_mb=$IRONIC_VM_SPECS_RAM \ |
| 322 | -p local_gb=$IRONIC_VM_SPECS_DISK \ |
| 323 | -p cpu_arch=x86_64 \ |
| 324 | | grep " uuid " | get_field 2) |
| 325 | |
| 326 | ironic port-create --address $MAC --node_uuid $NODE_ID |
| 327 | |
| 328 | idx=$((idx+1)) |
| 329 | |
| 330 | done < $IRONIC_VM_MACS_CSV_FILE |
| 331 | |
| 332 | # create the nova flavor |
| 333 | nova flavor-create baremetal auto $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK $IRONIC_VM_SPECS_CPU |
| 334 | nova flavor-key baremetal set "cpu_arch"="x86_64" "baremetal:deploy_kernel_id"="$BM_DEPLOY_KERNEL_ID" "baremetal:deploy_ramdisk_id"="$BM_DEPLOY_RAMDISK_ID" |
| 335 | |
| 336 | # intentional sleep to make sure the tag has been set to port |
| 337 | sleep 10 |
| 338 | TAPDEV=$(sudo ip netns exec qdhcp-${IRONIC_NET_ID} ip link list | grep tap | cut -d':' -f2 | cut -b2-) |
| 339 | TAG_ID=$(sudo ovs-vsctl show |grep ${TAPDEV} -A1 -m1 | grep tag | cut -d':' -f2 | cut -b2-) |
| 340 | |
| 341 | # make sure veth pair is not existing, otherwise delete its links |
| 342 | sudo ip link show ovs-tap1 && sudo ip link delete ovs-tap1 |
| 343 | sudo ip link show brbm-tap1 && sudo ip link delete brbm-tap1 |
| 344 | # create veth pair for future interconnection between br-int and brbm |
| 345 | sudo ip link add brbm-tap1 type veth peer name ovs-tap1 |
| 346 | sudo ip link set dev brbm-tap1 up |
| 347 | sudo ip link set dev ovs-tap1 up |
| 348 | |
| 349 | sudo ovs-vsctl -- --if-exists del-port ovs-tap1 -- add-port br-int ovs-tap1 tag=$TAG_ID |
| 350 | sudo ovs-vsctl -- --if-exists del-port brbm-tap1 -- add-port $IRONIC_VM_NETWORK_BRIDGE brbm-tap1 |
| 351 | } |
| 352 | |
| 353 | function configure_tftpd { |
| 354 | # enable tftp natting for allowing connections to SERVICE_HOST's tftp server |
| 355 | sudo modprobe nf_conntrack_tftp |
| 356 | sudo modprobe nf_nat_tftp |
| 357 | |
| 358 | if is_ubuntu; then |
| 359 | PXEBIN=/usr/lib/syslinux/pxelinux.0 |
| 360 | elif is_fedora; then |
| 361 | PXEBIN=/usr/share/syslinux/pxelinux.0 |
| 362 | fi |
| 363 | if [ ! -f $PXEBIN ]; then |
| 364 | die $LINENO "pxelinux.0 (from SYSLINUX) not found." |
| 365 | fi |
| 366 | |
| 367 | # stop tftpd and setup serving via xinetd |
| 368 | stop_service tftpd-hpa || true |
| 369 | [ -f /etc/init/tftpd-hpa.conf ] && echo "manual" | sudo tee /etc/init/tftpd-hpa.override |
| 370 | sudo cp $IRONIC_TEMPLATES_DIR/tftpd-xinetd.template /etc/xinetd.d/tftp |
| 371 | sudo sed -e "s|%TFTPBOOT_DIR%|$IRONIC_TFTPBOOT_DIR|g" -i /etc/xinetd.d/tftp |
| 372 | |
| 373 | # setup tftp file mapping to satisfy requests at the root (booting) and |
| 374 | # /tftpboot/ sub-dir (as per deploy-ironic elements) |
| 375 | echo "r ^([^/]) $IRONIC_TFTPBOOT_DIR/\1" >$IRONIC_TFTPBOOT_DIR/map-file |
| 376 | echo "r ^(/tftpboot/) $IRONIC_TFTPBOOT_DIR/\2" >>$IRONIC_TFTPBOOT_DIR/map-file |
| 377 | |
| 378 | chmod -R 0755 $IRONIC_TFTPBOOT_DIR |
| 379 | restart_service xinetd |
| 380 | } |
| 381 | |
| 382 | function configure_ironic_ssh_keypair { |
| 383 | # Generating ssh key pair for stack user |
| 384 | if [[ ! -d $IRONIC_SSH_KEY_DIR ]]; then |
| 385 | mkdir -p $IRONIC_SSH_KEY_DIR |
| 386 | fi |
| 387 | if [[ ! -d $HOME/.ssh ]]; then |
| 388 | mkdir -p $HOME/.ssh |
| 389 | chmod 700 $HOME/.ssh |
| 390 | fi |
| 391 | echo -e 'n\n' | ssh-keygen -q -t rsa -P '' -f $IRONIC_KEY_FILE |
| 392 | cat $IRONIC_KEY_FILE.pub | tee -a $IRONIC_AUTHORIZED_KEYS_FILE |
| 393 | } |
| 394 | |
| 395 | function ironic_ssh_check { |
| 396 | local KEY_FILE=$1 |
| 397 | local FLOATING_IP=$2 |
| 398 | local PORT=$3 |
| 399 | local DEFAULT_INSTANCE_USER=$4 |
| 400 | local ACTIVE_TIMEOUT=$5 |
| 401 | if ! timeout $ACTIVE_TIMEOUT sh -c "while ! ssh -p $PORT -o StrictHostKeyChecking=no -i $KEY_FILE ${DEFAULT_INSTANCE_USER}@$FLOATING_IP echo success; do sleep 1; done"; then |
| 402 | die $LINENO "server didn't become ssh-able!" |
| 403 | fi |
| 404 | } |
| 405 | |
| 406 | function configure_ironic_sshd { |
| 407 | # Ensure sshd server accepts connections from localhost only |
| 408 | |
| 409 | SSH_CONFIG=/etc/ssh/sshd_config |
| 410 | HOST_PORT=$IRONIC_VM_SSH_ADDRESS:$IRONIC_VM_SSH_PORT |
| 411 | if ! sudo grep ListenAddress $SSH_CONFIG | grep $HOST_PORT; then |
| 412 | echo "ListenAddress $HOST_PORT" | sudo tee -a $SSH_CONFIG |
| 413 | fi |
| 414 | |
| 415 | SSH_SERVICE_NAME=sshd |
| 416 | if is_ubuntu; then |
| 417 | SSH_SERVICE_NAME=ssh |
| 418 | fi |
| 419 | |
| 420 | restart_service $SSH_SERVICE_NAME |
| 421 | # to ensure ssh service is up and running |
| 422 | sleep 3 |
| 423 | ironic_ssh_check $IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME $IRONIC_VM_SSH_ADDRESS $IRONIC_VM_SSH_PORT $IRONIC_SSH_USERNAME 10 |
| 424 | |
| 425 | } |
| 426 | |
| 427 | function configure_ironic_auxiliary { |
| 428 | configure_ironic_dirs |
| 429 | configure_ironic_ssh_keypair |
| 430 | configure_ironic_sshd |
| 431 | } |
| 432 | |
| 433 | function prepare_baremetal_basic_ops { |
| 434 | |
| 435 | # install diskimage-builder |
| 436 | git_clone $BM_IMAGE_BUILD_REPO $BM_IMAGE_BUILD_DIR $BM_IMAGE_BUILD_BRANCH |
| 437 | |
| 438 | # make sure all needed service were enabled |
| 439 | for srv in nova glance key neutron; do |
| 440 | if ! is_service_enabled "$srv"; then |
| 441 | die $LINENO "$srv should be enabled for ironic tests" |
| 442 | fi |
| 443 | done |
| 444 | |
| 445 | SCREEN_NAME=${SCREEN_NAME:-stack} |
| 446 | SERVICE_DIR=${SERVICE_DIR:-${DEST}/status} |
| 447 | |
| 448 | # stop all nova services |
| 449 | stop_nova || true |
| 450 | |
| 451 | # remove any nova services failure status |
| 452 | find $SERVICE_DIR/$SCREEN_NAME -name 'n-*.failure' -exec rm -f '{}' \; |
| 453 | |
| 454 | # start them again |
| 455 | start_nova_api |
| 456 | start_nova |
| 457 | |
| 458 | TOKEN=$(keystone token-get | grep ' id ' | get_field 2) |
| 459 | die_if_not_set $LINENO TOKEN "Keystone fail to get token" |
| 460 | |
| 461 | echo_summary "Creating and uploading baremetal images for ironic" |
| 462 | |
| 463 | # build and upload separate deploy kernel & ramdisk |
| 464 | upload_baremetal_deploy $TOKEN |
| 465 | |
| 466 | create_bridge_and_vms |
| 467 | enroll_vms |
| 468 | configure_tftpd |
| 469 | } |
| 470 | |
| 471 | function cleanup_baremetal_basic_ops { |
| 472 | rm -f $IRONIC_VM_MACS_CSV_FILE |
| 473 | if [ -f $IRONIC_KEY_FILE ]; then |
| 474 | KEY=`cat $IRONIC_KEY_FILE.pub` |
| 475 | # remove public key from authorized_keys |
| 476 | grep -v "$KEY" $IRONIC_AUTHORIZED_KEYS_FILE > temp && mv temp $IRONIC_AUTHORIZED_KEYS_FILE |
| 477 | chmod 0600 $IRONIC_AUTHORIZED_KEYS_FILE |
| 478 | fi |
| 479 | sudo rm -rf $IRONIC_DATA_DIR $IRONIC_STATE_PATH |
| 480 | sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/cleanup-nodes $IRONIC_VM_COUNT $IRONIC_VM_NETWORK_BRIDGE" |
| 481 | sudo rm -rf /etc/xinetd.d/tftp /etc/init/tftpd-hpa.override |
| 482 | restart_service xinetd |
| 483 | } |
| 484 | |
| 485 | # Restore xtrace + pipefail |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 486 | $XTRACE |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame^] | 487 | $PIPEFAIL |
Roman Prykhodchenko | ce696b6 | 2013-08-09 10:40:45 +0300 | [diff] [blame] | 488 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 489 | # Tell emacs to use shell-script-mode |
| 490 | ## Local variables: |
| 491 | ## mode: shell-script |
| 492 | ## End: |