blob: 9fb290f5ab0c43af0d3f44c9ec57e6205844cb58 [file] [log] [blame]
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +03001# lib/ironic
2# Functions to control the configuration and operation of the **Ironic** service
3
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
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 Prykhodchenkoce696b62013-08-09 10:40:45 +030011
12# ``stack.sh`` calls the entry points in this order:
13#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010014# - install_ironic
15# - install_ironicclient
16# - init_ironic
17# - start_ironic
18# - stop_ironic
19# - cleanup_ironic
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030020
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040021# Save trace and pipefail settings
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030022XTRACE=$(set +o | grep xtrace)
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040023PIPEFAIL=$(set +o | grep pipefail)
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030024set +o xtrace
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040025set +o pipefail
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030026
27# Defaults
28# --------
29
30# Set up default directories
31IRONIC_DIR=$DEST/ironic
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040032IRONIC_DATA_DIR=$DATA_DIR/ironic
33IRONIC_STATE_PATH=/var/lib/ironic
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030034IRONICCLIENT_DIR=$DEST/python-ironicclient
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030035IRONIC_AUTH_CACHE_DIR=${IRONIC_AUTH_CACHE_DIR:-/var/cache/ironic}
36IRONIC_CONF_DIR=${IRONIC_CONF_DIR:-/etc/ironic}
37IRONIC_CONF_FILE=$IRONIC_CONF_DIR/ironic.conf
38IRONIC_ROOTWRAP_CONF=$IRONIC_CONF_DIR/rootwrap.conf
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030039IRONIC_POLICY_JSON=$IRONIC_CONF_DIR/policy.json
40
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040041# Set up defaults for functional / integration testing
42IRONIC_SCRIPTS_DIR=${IRONIC_SCRIPTS_DIR:-$TOP_DIR/tools/ironic/scripts}
43IRONIC_TEMPLATES_DIR=${IRONIC_TEMPLATES_DIR:-$TOP_DIR/tools/ironic/templates}
44IRONIC_BAREMETAL_BASIC_OPS=$(trueorfalse False $IRONIC_BAREMETAL_BASIC_OPS)
45IRONIC_SSH_USERNAME=${IRONIC_SSH_USERNAME:-`whoami`}
46IRONIC_SSH_KEY_DIR=${IRONIC_SSH_KEY_DIR:-$IRONIC_DATA_DIR/ssh_keys}
47IRONIC_SSH_KEY_FILENAME=${IRONIC_SSH_KEY_FILENAME:-ironic_key}
48IRONIC_KEY_FILE=$IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME
49IRONIC_SSH_VIRT_TYPE=${IRONIC_SSH_VIRT_TYPE:-virsh}
50IRONIC_TFTPBOOT_DIR=${IRONIC_TFTPBOOT_DIR:-$IRONIC_DATA_DIR/tftpboot}
51IRONIC_VM_SSH_PORT=${IRONIC_VM_SSH_PORT:-2222}
52IRONIC_VM_SSH_ADDRESS=${IRONIC_VM_SSH_ADDRESS:-$HOST_IP}
53IRONIC_VM_COUNT=${IRONIC_VM_COUNT:-1}
54IRONIC_VM_SPECS_CPU=${IRONIC_VM_SPECS_CPU:-1}
Alexander Gordeev84d0ec52014-03-17 17:58:54 +040055# NOTE(agordeev): both ubuntu and fedora deploy images won't work with 256MB of RAM.
56# System halts and throws kernel panic during initramfs unpacking.
57# Ubuntu needs at least 384MB, but fedora requires 448.
58# So placing 512 here to satisfy both.
59IRONIC_VM_SPECS_RAM=${IRONIC_VM_SPECS_RAM:-512}
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040060IRONIC_VM_SPECS_DISK=${IRONIC_VM_SPECS_DISK:-10}
61IRONIC_VM_EMULATOR=${IRONIC_VM_EMULATOR:-/usr/bin/qemu-system-x86_64}
62IRONIC_VM_NETWORK_BRIDGE=${IRONIC_VM_NETWORK_BRIDGE:-brbm}
63IRONIC_VM_NETWORK_RANGE=${IRONIC_VM_NETWORK_RANGE:-192.0.2.0/24}
64IRONIC_VM_MACS_CSV_FILE=${IRONIC_VM_MACS_CSV_FILE:-$IRONIC_DATA_DIR/ironic_macs.csv}
65IRONIC_AUTHORIZED_KEYS_FILE=${IRONIC_AUTHORIZED_KEYS_FILE:-$HOME/.ssh/authorized_keys}
66
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030067# Support entry points installation of console scripts
68IRONIC_BIN_DIR=$(get_python_exec_prefix)
69
70# Ironic connection info. Note the port must be specified.
71IRONIC_SERVICE_PROTOCOL=http
72IRONIC_HOSTPORT=${IRONIC_HOSTPORT:-$SERVICE_HOST:6385}
73
Dean Troyer4237f592014-01-29 16:22:11 -060074# Tell Tempest this project is present
75TEMPEST_SERVICES+=,ironic
76
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030077
78# Functions
79# ---------
80
Dean Troyer1023ff72014-01-27 14:56:44 -060081# Test if any Ironic services are enabled
82# is_ironic_enabled
83function is_ironic_enabled {
84 [[ ,${ENABLED_SERVICES} =~ ,"ir-" ]] && return 0
85 return 1
86}
87
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030088# install_ironic() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +110089function install_ironic {
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030090 git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH
91 setup_develop $IRONIC_DIR
92}
93
94# install_ironicclient() - Collect sources and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +110095function install_ironicclient {
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030096 git_clone $IRONICCLIENT_REPO $IRONICCLIENT_DIR $IRONICCLIENT_BRANCH
97 setup_develop $IRONICCLIENT_DIR
98}
99
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300100# cleanup_ironic() - Remove residual data files, anything left over from previous
101# runs that would need to clean up.
Ian Wienandaee18c72014-02-21 15:35:08 +1100102function cleanup_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300103 sudo rm -rf $IRONIC_AUTH_CACHE_DIR
104}
105
106# configure_ironic() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100107function configure_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300108 if [[ ! -d $IRONIC_CONF_DIR ]]; then
109 sudo mkdir -p $IRONIC_CONF_DIR
110 fi
111 sudo chown $STACK_USER $IRONIC_CONF_DIR
112
113 # Copy over ironic configuration file and configure common parameters.
114 cp $IRONIC_DIR/etc/ironic/ironic.conf.sample $IRONIC_CONF_FILE
115 iniset $IRONIC_CONF_FILE DEFAULT debug True
116 inicomment $IRONIC_CONF_FILE DEFAULT log_file
117 iniset $IRONIC_CONF_FILE DEFAULT sql_connection `database_connection_url ironic`
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400118 iniset $IRONIC_CONF_FILE DEFAULT state_path $IRONIC_STATE_PATH
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300119 iniset $IRONIC_CONF_FILE DEFAULT use_syslog $SYSLOG
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300120 # Configure Ironic conductor, if it was enabled.
121 if is_service_enabled ir-cond; then
122 configure_ironic_conductor
123 fi
124
125 # Configure Ironic API, if it was enabled.
126 if is_service_enabled ir-api; then
127 configure_ironic_api
128 fi
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400129
130 if [[ "$IRONIC_BAREMETAL_BASIC_OPS" == "True" ]]; then
131 configure_ironic_auxiliary
132 fi
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300133}
134
135# configure_ironic_api() - Is used by configure_ironic(). Performs
136# API specific configuration.
Ian Wienandaee18c72014-02-21 15:35:08 +1100137function configure_ironic_api {
Roman Prykhodchenkoc48c3122013-10-01 17:19:05 +0300138 iniset $IRONIC_CONF_FILE DEFAULT auth_strategy keystone
139 iniset $IRONIC_CONF_FILE DEFAULT policy_file $IRONIC_POLICY_JSON
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300140 iniset $IRONIC_CONF_FILE keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
141 iniset $IRONIC_CONF_FILE keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
142 iniset $IRONIC_CONF_FILE keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000143 iniset $IRONIC_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300144 iniset $IRONIC_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
145 iniset $IRONIC_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
146 iniset $IRONIC_CONF_FILE keystone_authtoken admin_user ironic
147 iniset $IRONIC_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300148 iniset_rpc_backend ironic $IRONIC_CONF_FILE DEFAULT
149 iniset $IRONIC_CONF_FILE keystone_authtoken signing_dir $IRONIC_AUTH_CACHE_DIR/api
150
151 cp -p $IRONIC_DIR/etc/ironic/policy.json $IRONIC_POLICY_JSON
152}
153
154# configure_ironic_conductor() - Is used by configure_ironic().
155# Sets conductor specific settings.
Ian Wienandaee18c72014-02-21 15:35:08 +1100156function configure_ironic_conductor {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300157 cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF
Lucas Alvares Gomes279295c2014-01-14 11:37:51 +0000158 cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300159
Alexander Gordeeva67cb1a2014-03-04 18:38:33 +0400160 iniset $IRONIC_CONF_FILE DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400161 iniset $IRONIC_CONF_FILE conductor api_url http://$SERVICE_HOST:6385
162 iniset $IRONIC_CONF_FILE pxe tftp_server $SERVICE_HOST
163 iniset $IRONIC_CONF_FILE pxe tftp_root $IRONIC_TFTPBOOT_DIR
164 iniset $IRONIC_CONF_FILE pxe tftp_master_path $IRONIC_TFTPBOOT_DIR/master_images
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300165}
166
167# create_ironic_cache_dir() - Part of the init_ironic() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100168function create_ironic_cache_dir {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300169 # Create cache dir
170 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/api
171 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/api
172 rm -f $IRONIC_AUTH_CACHE_DIR/api/*
173 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/registry
174 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/registry
175 rm -f $IRONIC_AUTH_CACHE_DIR/registry/*
176}
177
178# create_ironic_accounts() - Set up common required ironic accounts
179
180# Tenant User Roles
181# ------------------------------------------------------------------
182# service ironic admin # if enabled
Ian Wienandaee18c72014-02-21 15:35:08 +1100183function create_ironic_accounts {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300184
Steve Martinelli19685422014-01-24 13:02:26 -0600185 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
186 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300187
188 # Ironic
189 if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600190 IRONIC_USER=$(openstack user create \
191 ironic \
192 --password "$SERVICE_PASSWORD" \
193 --project $SERVICE_TENANT \
194 --email ironic@example.com \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300195 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600196 openstack role add \
197 $ADMIN_ROLE \
198 --project $SERVICE_TENANT \
199 --user $IRONIC_USER
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300200 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600201 IRONIC_SERVICE=$(openstack service create \
202 ironic \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300203 --type=baremetal \
204 --description="Ironic baremetal provisioning service" \
205 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600206 openstack endpoint create \
207 $IRONIC_SERVICE \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300208 --region RegionOne \
Roman Prykhodchenkof5002ef2013-09-24 19:09:26 +0300209 --publicurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
210 --adminurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
211 --internalurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300212 fi
213 fi
214}
215
216
217# init_ironic() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100218function init_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300219 # (Re)create ironic database
220 recreate_database ironic utf8
221
222 # Migrate ironic database
223 $IRONIC_BIN_DIR/ironic-dbsync
224
225 create_ironic_cache_dir
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300226}
227
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300228# start_ironic() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100229function start_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300230 # Start Ironic API server, if enabled.
231 if is_service_enabled ir-api; then
232 start_ironic_api
233 fi
234
235 # Start Ironic conductor, if enabled.
236 if is_service_enabled ir-cond; then
237 start_ironic_conductor
238 fi
239}
240
241# start_ironic_api() - Used by start_ironic().
242# Starts Ironic API server.
Ian Wienandaee18c72014-02-21 15:35:08 +1100243function start_ironic_api {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300244 screen_it ir-api "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-api --config-file=$IRONIC_CONF_FILE"
245 echo "Waiting for ir-api ($IRONIC_HOSTPORT) to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800246 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$IRONIC_HOSTPORT; do sleep 1; done"; then
Sean Dague101b4242013-10-22 08:47:11 -0400247 die $LINENO "ir-api did not start"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300248 fi
249}
250
251# start_ironic_conductor() - Used by start_ironic().
252# Starts Ironic conductor.
Ian Wienandaee18c72014-02-21 15:35:08 +1100253function start_ironic_conductor {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300254 screen_it ir-cond "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-conductor --config-file=$IRONIC_CONF_FILE"
255 # TODO(romcheg): Find a way to check whether the conductor has started.
256}
257
258# stop_ironic() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100259function stop_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300260 # Kill the Ironic screen windows
261 screen -S $SCREEN_NAME -p ir-api -X kill
262 screen -S $SCREEN_NAME -p ir-cond -X kill
263}
264
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400265function is_ironic {
266 if ( is_service_enabled ir-cond && is_service_enabled ir-api ); then
267 return 0
268 fi
269 return 1
270}
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300271
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400272function configure_ironic_dirs {
273 sudo mkdir -p $IRONIC_DATA_DIR
274 sudo mkdir -p $IRONIC_STATE_PATH
275 sudo mkdir -p $IRONIC_TFTPBOOT_DIR
276 sudo chown -R $STACK_USER $IRONIC_DATA_DIR $IRONIC_STATE_PATH
277 sudo chown -R $STACK_USER:$LIBVIRT_GROUP $IRONIC_TFTPBOOT_DIR
278 if is_ubuntu; then
279 PXEBIN=/usr/lib/syslinux/pxelinux.0
280 elif is_fedora; then
281 PXEBIN=/usr/share/syslinux/pxelinux.0
282 fi
283 if [ ! -f $PXEBIN ]; then
284 die $LINENO "pxelinux.0 (from SYSLINUX) not found."
285 fi
286
287 cp $PXEBIN $IRONIC_TFTPBOOT_DIR
288 mkdir -p $IRONIC_TFTPBOOT_DIR/pxelinux.cfg
289}
290
291function ironic_ensure_libvirt_group {
292 groups $STACK_USER | grep -q $LIBVIRT_GROUP || adduser $STACK_USER $LIBVIRT_GROUP
293}
294
295function create_bridge_and_vms {
296 ironic_ensure_libvirt_group
297
298 # Call libvirt setup scripts in a new shell to ensure any new group membership
299 sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/setup-network"
300
301 sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/create-nodes \
302 $IRONIC_VM_SPECS_CPU $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK \
303 amd64 $IRONIC_VM_COUNT $IRONIC_VM_NETWORK_BRIDGE $IRONIC_VM_EMULATOR" >> $IRONIC_VM_MACS_CSV_FILE
304
305}
306
307function enroll_vms {
308
309 CHASSIS_ID=$(ironic chassis-create -d "ironic test chassis" | grep " uuid " | get_field 2)
310 IRONIC_NET_ID=$(neutron net-list | grep private | get_field 1)
311 local idx=0
312
313 # work around; need to know what netns neutron uses for private network
314 neutron port-create private
315
316 while read MAC; do
317
318 NODE_ID=$(ironic node-create --chassis_uuid $CHASSIS_ID --driver pxe_ssh \
319 -i ssh_virt_type=$IRONIC_SSH_VIRT_TYPE \
320 -i ssh_address=$IRONIC_VM_SSH_ADDRESS \
321 -i ssh_port=$IRONIC_VM_SSH_PORT \
322 -i ssh_username=$IRONIC_SSH_USERNAME \
323 -i ssh_key_filename=$IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME \
324 -p cpus=$IRONIC_VM_SPECS_CPU \
325 -p memory_mb=$IRONIC_VM_SPECS_RAM \
326 -p local_gb=$IRONIC_VM_SPECS_DISK \
327 -p cpu_arch=x86_64 \
328 | grep " uuid " | get_field 2)
329
330 ironic port-create --address $MAC --node_uuid $NODE_ID
331
332 idx=$((idx+1))
333
334 done < $IRONIC_VM_MACS_CSV_FILE
335
336 # create the nova flavor
337 nova flavor-create baremetal auto $IRONIC_VM_SPECS_RAM $IRONIC_VM_SPECS_DISK $IRONIC_VM_SPECS_CPU
338 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"
339
340 # intentional sleep to make sure the tag has been set to port
341 sleep 10
342 TAPDEV=$(sudo ip netns exec qdhcp-${IRONIC_NET_ID} ip link list | grep tap | cut -d':' -f2 | cut -b2-)
343 TAG_ID=$(sudo ovs-vsctl show |grep ${TAPDEV} -A1 -m1 | grep tag | cut -d':' -f2 | cut -b2-)
344
345 # make sure veth pair is not existing, otherwise delete its links
346 sudo ip link show ovs-tap1 && sudo ip link delete ovs-tap1
347 sudo ip link show brbm-tap1 && sudo ip link delete brbm-tap1
348 # create veth pair for future interconnection between br-int and brbm
349 sudo ip link add brbm-tap1 type veth peer name ovs-tap1
350 sudo ip link set dev brbm-tap1 up
351 sudo ip link set dev ovs-tap1 up
352
353 sudo ovs-vsctl -- --if-exists del-port ovs-tap1 -- add-port br-int ovs-tap1 tag=$TAG_ID
354 sudo ovs-vsctl -- --if-exists del-port brbm-tap1 -- add-port $IRONIC_VM_NETWORK_BRIDGE brbm-tap1
355}
356
357function configure_tftpd {
358 # enable tftp natting for allowing connections to SERVICE_HOST's tftp server
359 sudo modprobe nf_conntrack_tftp
360 sudo modprobe nf_nat_tftp
361
362 if is_ubuntu; then
363 PXEBIN=/usr/lib/syslinux/pxelinux.0
364 elif is_fedora; then
365 PXEBIN=/usr/share/syslinux/pxelinux.0
366 fi
367 if [ ! -f $PXEBIN ]; then
368 die $LINENO "pxelinux.0 (from SYSLINUX) not found."
369 fi
370
371 # stop tftpd and setup serving via xinetd
372 stop_service tftpd-hpa || true
373 [ -f /etc/init/tftpd-hpa.conf ] && echo "manual" | sudo tee /etc/init/tftpd-hpa.override
374 sudo cp $IRONIC_TEMPLATES_DIR/tftpd-xinetd.template /etc/xinetd.d/tftp
375 sudo sed -e "s|%TFTPBOOT_DIR%|$IRONIC_TFTPBOOT_DIR|g" -i /etc/xinetd.d/tftp
376
377 # setup tftp file mapping to satisfy requests at the root (booting) and
378 # /tftpboot/ sub-dir (as per deploy-ironic elements)
379 echo "r ^([^/]) $IRONIC_TFTPBOOT_DIR/\1" >$IRONIC_TFTPBOOT_DIR/map-file
380 echo "r ^(/tftpboot/) $IRONIC_TFTPBOOT_DIR/\2" >>$IRONIC_TFTPBOOT_DIR/map-file
381
382 chmod -R 0755 $IRONIC_TFTPBOOT_DIR
383 restart_service xinetd
384}
385
386function configure_ironic_ssh_keypair {
387 # Generating ssh key pair for stack user
388 if [[ ! -d $IRONIC_SSH_KEY_DIR ]]; then
389 mkdir -p $IRONIC_SSH_KEY_DIR
390 fi
391 if [[ ! -d $HOME/.ssh ]]; then
392 mkdir -p $HOME/.ssh
393 chmod 700 $HOME/.ssh
394 fi
395 echo -e 'n\n' | ssh-keygen -q -t rsa -P '' -f $IRONIC_KEY_FILE
396 cat $IRONIC_KEY_FILE.pub | tee -a $IRONIC_AUTHORIZED_KEYS_FILE
397}
398
399function ironic_ssh_check {
400 local KEY_FILE=$1
401 local FLOATING_IP=$2
402 local PORT=$3
403 local DEFAULT_INSTANCE_USER=$4
404 local ACTIVE_TIMEOUT=$5
405 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
406 die $LINENO "server didn't become ssh-able!"
407 fi
408}
409
410function configure_ironic_sshd {
411 # Ensure sshd server accepts connections from localhost only
412
413 SSH_CONFIG=/etc/ssh/sshd_config
414 HOST_PORT=$IRONIC_VM_SSH_ADDRESS:$IRONIC_VM_SSH_PORT
415 if ! sudo grep ListenAddress $SSH_CONFIG | grep $HOST_PORT; then
416 echo "ListenAddress $HOST_PORT" | sudo tee -a $SSH_CONFIG
417 fi
418
419 SSH_SERVICE_NAME=sshd
420 if is_ubuntu; then
421 SSH_SERVICE_NAME=ssh
422 fi
423
424 restart_service $SSH_SERVICE_NAME
425 # to ensure ssh service is up and running
426 sleep 3
427 ironic_ssh_check $IRONIC_SSH_KEY_DIR/$IRONIC_SSH_KEY_FILENAME $IRONIC_VM_SSH_ADDRESS $IRONIC_VM_SSH_PORT $IRONIC_SSH_USERNAME 10
428
429}
430
431function configure_ironic_auxiliary {
432 configure_ironic_dirs
433 configure_ironic_ssh_keypair
434 configure_ironic_sshd
435}
436
437function prepare_baremetal_basic_ops {
438
439 # install diskimage-builder
440 git_clone $BM_IMAGE_BUILD_REPO $BM_IMAGE_BUILD_DIR $BM_IMAGE_BUILD_BRANCH
441
442 # make sure all needed service were enabled
443 for srv in nova glance key neutron; do
444 if ! is_service_enabled "$srv"; then
445 die $LINENO "$srv should be enabled for ironic tests"
446 fi
447 done
448
449 SCREEN_NAME=${SCREEN_NAME:-stack}
450 SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
451
452 # stop all nova services
453 stop_nova || true
454
455 # remove any nova services failure status
456 find $SERVICE_DIR/$SCREEN_NAME -name 'n-*.failure' -exec rm -f '{}' \;
457
458 # start them again
459 start_nova_api
460 start_nova
461
462 TOKEN=$(keystone token-get | grep ' id ' | get_field 2)
463 die_if_not_set $LINENO TOKEN "Keystone fail to get token"
464
465 echo_summary "Creating and uploading baremetal images for ironic"
466
467 # build and upload separate deploy kernel & ramdisk
468 upload_baremetal_deploy $TOKEN
469
470 create_bridge_and_vms
471 enroll_vms
472 configure_tftpd
473}
474
475function cleanup_baremetal_basic_ops {
476 rm -f $IRONIC_VM_MACS_CSV_FILE
477 if [ -f $IRONIC_KEY_FILE ]; then
478 KEY=`cat $IRONIC_KEY_FILE.pub`
479 # remove public key from authorized_keys
480 grep -v "$KEY" $IRONIC_AUTHORIZED_KEYS_FILE > temp && mv temp $IRONIC_AUTHORIZED_KEYS_FILE
481 chmod 0600 $IRONIC_AUTHORIZED_KEYS_FILE
482 fi
483 sudo rm -rf $IRONIC_DATA_DIR $IRONIC_STATE_PATH
484 sudo su $STACK_USER -c "$IRONIC_SCRIPTS_DIR/cleanup-nodes $IRONIC_VM_COUNT $IRONIC_VM_NETWORK_BRIDGE"
485 sudo rm -rf /etc/xinetd.d/tftp /etc/init/tftpd-hpa.override
486 restart_service xinetd
487}
488
489# Restore xtrace + pipefail
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300490$XTRACE
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400491$PIPEFAIL
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300492
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100493# Tell emacs to use shell-script-mode
494## Local variables:
495## mode: shell-script
496## End: