blob: c6fa563e6ad6dd32ac4e30b4fa7fed0ed0585204 [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}
55IRONIC_VM_SPECS_RAM=${IRONIC_VM_SPECS_RAM:-256}
56IRONIC_VM_SPECS_DISK=${IRONIC_VM_SPECS_DISK:-10}
57IRONIC_VM_EMULATOR=${IRONIC_VM_EMULATOR:-/usr/bin/qemu-system-x86_64}
58IRONIC_VM_NETWORK_BRIDGE=${IRONIC_VM_NETWORK_BRIDGE:-brbm}
59IRONIC_VM_NETWORK_RANGE=${IRONIC_VM_NETWORK_RANGE:-192.0.2.0/24}
60IRONIC_VM_MACS_CSV_FILE=${IRONIC_VM_MACS_CSV_FILE:-$IRONIC_DATA_DIR/ironic_macs.csv}
61IRONIC_AUTHORIZED_KEYS_FILE=${IRONIC_AUTHORIZED_KEYS_FILE:-$HOME/.ssh/authorized_keys}
62
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030063# Support entry points installation of console scripts
64IRONIC_BIN_DIR=$(get_python_exec_prefix)
65
66# Ironic connection info. Note the port must be specified.
67IRONIC_SERVICE_PROTOCOL=http
68IRONIC_HOSTPORT=${IRONIC_HOSTPORT:-$SERVICE_HOST:6385}
69
Dean Troyer4237f592014-01-29 16:22:11 -060070# Tell Tempest this project is present
71TEMPEST_SERVICES+=,ironic
72
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030073
74# Functions
75# ---------
76
Dean Troyer1023ff72014-01-27 14:56:44 -060077# Test if any Ironic services are enabled
78# is_ironic_enabled
79function is_ironic_enabled {
80 [[ ,${ENABLED_SERVICES} =~ ,"ir-" ]] && return 0
81 return 1
82}
83
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030084# install_ironic() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +110085function install_ironic {
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030086 git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH
87 setup_develop $IRONIC_DIR
88}
89
90# install_ironicclient() - Collect sources and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +110091function install_ironicclient {
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030092 git_clone $IRONICCLIENT_REPO $IRONICCLIENT_DIR $IRONICCLIENT_BRANCH
93 setup_develop $IRONICCLIENT_DIR
94}
95
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030096# cleanup_ironic() - Remove residual data files, anything left over from previous
97# runs that would need to clean up.
Ian Wienandaee18c72014-02-21 15:35:08 +110098function cleanup_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030099 sudo rm -rf $IRONIC_AUTH_CACHE_DIR
100}
101
102# configure_ironic() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100103function configure_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300104 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 Gordeev06fb29c2014-01-31 18:02:07 +0400114 iniset $IRONIC_CONF_FILE DEFAULT state_path $IRONIC_STATE_PATH
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300115 iniset $IRONIC_CONF_FILE DEFAULT use_syslog $SYSLOG
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300116 # 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 Gordeev06fb29c2014-01-31 18:02:07 +0400125
126 if [[ "$IRONIC_BAREMETAL_BASIC_OPS" == "True" ]]; then
127 configure_ironic_auxiliary
128 fi
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300129}
130
131# configure_ironic_api() - Is used by configure_ironic(). Performs
132# API specific configuration.
Ian Wienandaee18c72014-02-21 15:35:08 +1100133function configure_ironic_api {
Roman Prykhodchenkoc48c3122013-10-01 17:19:05 +0300134 iniset $IRONIC_CONF_FILE DEFAULT auth_strategy keystone
135 iniset $IRONIC_CONF_FILE DEFAULT policy_file $IRONIC_POLICY_JSON
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300136 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 Lennoxbd24a8d2013-09-20 16:26:42 +1000139 iniset $IRONIC_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300140 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 Prykhodchenkoce696b62013-08-09 10:40:45 +0300144 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 Wienandaee18c72014-02-21 15:35:08 +1100152function configure_ironic_conductor {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300153 cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF
Lucas Alvares Gomes279295c2014-01-14 11:37:51 +0000154 cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300155
Alexander Gordeeva67cb1a2014-03-04 18:38:33 +0400156 iniset $IRONIC_CONF_FILE DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400157 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 Prykhodchenkoce696b62013-08-09 10:40:45 +0300161}
162
163# create_ironic_cache_dir() - Part of the init_ironic() process
Ian Wienandaee18c72014-02-21 15:35:08 +1100164function create_ironic_cache_dir {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300165 # 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 Wienandaee18c72014-02-21 15:35:08 +1100179function create_ironic_accounts {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300180
Steve Martinelli19685422014-01-24 13:02:26 -0600181 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
182 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300183
184 # Ironic
185 if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600186 IRONIC_USER=$(openstack user create \
187 ironic \
188 --password "$SERVICE_PASSWORD" \
189 --project $SERVICE_TENANT \
190 --email ironic@example.com \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300191 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600192 openstack role add \
193 $ADMIN_ROLE \
194 --project $SERVICE_TENANT \
195 --user $IRONIC_USER
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300196 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -0600197 IRONIC_SERVICE=$(openstack service create \
198 ironic \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300199 --type=baremetal \
200 --description="Ironic baremetal provisioning service" \
201 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600202 openstack endpoint create \
203 $IRONIC_SERVICE \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300204 --region RegionOne \
Roman Prykhodchenkof5002ef2013-09-24 19:09:26 +0300205 --publicurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
206 --adminurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
207 --internalurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300208 fi
209 fi
210}
211
212
213# init_ironic() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100214function init_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300215 # (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 Prykhodchenkoce696b62013-08-09 10:40:45 +0300222}
223
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300224# start_ironic() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100225function start_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300226 # 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 Wienandaee18c72014-02-21 15:35:08 +1100239function start_ironic_api {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300240 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 NAN0aa85342013-09-13 15:47:09 +0800242 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 -0400243 die $LINENO "ir-api did not start"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300244 fi
245}
246
247# start_ironic_conductor() - Used by start_ironic().
248# Starts Ironic conductor.
Ian Wienandaee18c72014-02-21 15:35:08 +1100249function start_ironic_conductor {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300250 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 Wienandaee18c72014-02-21 15:35:08 +1100255function stop_ironic {
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300256 # 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 Gordeev06fb29c2014-01-31 18:02:07 +0400261function 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 Prykhodchenkoce696b62013-08-09 10:40:45 +0300267
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400268function 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
287function ironic_ensure_libvirt_group {
288 groups $STACK_USER | grep -q $LIBVIRT_GROUP || adduser $STACK_USER $LIBVIRT_GROUP
289}
290
291function 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
303function 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
353function 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
382function 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
395function 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
406function 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
427function configure_ironic_auxiliary {
428 configure_ironic_dirs
429 configure_ironic_ssh_keypair
430 configure_ironic_sshd
431}
432
433function 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
471function 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 Prykhodchenkoce696b62013-08-09 10:40:45 +0300486$XTRACE
Alexander Gordeev06fb29c2014-01-31 18:02:07 +0400487$PIPEFAIL
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300488
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100489# Tell emacs to use shell-script-mode
490## Local variables:
491## mode: shell-script
492## End: