forked from SUSE-Cloud/automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkcloud
executable file
·1582 lines (1428 loc) · 53.6 KB
/
mkcloud
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# mkcloud - Setup a virtual cloud on one system (physical or even virtual)
#
# Authors: J. Daniel Schmidt <jdsn@suse.de>
# Bernhard M. Wiedemann <bwiedemann@suse.de>
#
# 2012, SUSE LINUX Products GmbH
#
# Quick introduction:
#
# 1. read the usage: mkcloud help
# or visit https://github.com/SUSE-Cloud/automation/blob/master/docs/mkcloud.md
# 2. This tool relies on the script qa_crowbarsetup.sh
# 3. Please 'export' environment variables according to your needs.
: ${cloud:=cloud}
log_dir_default=/var/log/mkcloud/$cloud
[[ $UID != 0 ]] && log_dir_default="./log"
: ${log_dir:=$log_dir_default}
mkdir -p "$log_dir"
log_file=$log_dir/`date -Iseconds`.log
exec > >(exec tee -ia $log_file)
exec 2> >(exec tee -ia $log_file >&2)
if [[ $debug_mkcloud = 1 ]] ; then
set -x
PS4='+(${BASH_SOURCE##*/}:${LINENO}) ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
fi
cache_dir_default=/var/cache/mkcloud/$cloud
[[ $UID != 0 ]] && cache_dir_default="${XDG_CACHE_HOME:-./cache}/mkcloud"
: ${cache_dir:=$cache_dir_default}
mkdir -p "$cache_dir"
# FIXME: separate user-tweakable parameters from script local variables.
# Currently there is no clearly defined interface point. One of the
# causes of this is violation of the common shell coding standard which
# uses uppercase for environment variables and constants, and lowercase
# for local variables.
: ${SCRIPTS_DIR:=$mkcloud_dir} # for backward compatibility
: ${SCRIPTS_DIR:=$(dirname $(readlink -e $0))}
: ${qa_crowbarsetup:=${SCRIPTS_DIR}/qa_crowbarsetup.sh}
: ${iscsictl:=${SCRIPTS_DIR}/iscsictl.py}
: ${mkclouddriver:=libvirt}
scripts_lib_dir=${SCRIPTS_DIR}/lib
# include separate bash libs
# NOTE that this is a temporary solution during refactoring of mkcloud
common_scripts="mkcloud-onhost.sh mkcloud-common.sh mkcloud-driver-$mkclouddriver.sh qa_crowbarsetup-help.sh mkcloud-ipmi.sh"
for script in $common_scripts; do
source ${scripts_lib_dir}/$script
done
mkcconf=mkcloud.config
rm -f $mkcconf # we dont want to source old info in the line below
: ${virtualcloud:=virtual}
: ${net_admin:=192.168.124}
setcloudnetvars $virtualcloud
: ${forwardmode:=nat}
: ${adminnetmask:=255.255.248.0}
: ${ironicnetmask:=255.255.255.0}
: ${nodenumber:=2}
# expect to have this many physical machines attached via $mkch_physcloudif
# these replace virtual machines, so we start less VMs
: ${nodenumberphys:=0}
[[ $nodenumberphys = 0 ]] || [[ $mkch_physcloudif ]] || complain 100 "need to set mkch_physcloudif for physical nodes"
# configuration of clusters
: ${clusterconfig:=''}
# '+'-separated list of MAC#serial_of_drbd_volume of the drbd cluster nodes
# (used only internally to transport this information to qa_crowbarsetup):
: ${drbdnode_mac_vol:=''}
: ${cephvolumenumber:=1}
: ${controller_raid_volumes:=0}
: ${vcpus:=2}
nicsdefault=1
[[ $want_ironic ]] && nicsdefault=2
[[ $crowbar_networkingmode = team ]] && nicsdefault=$((nicsdefault + 1))
[[ $want_separate_ceph_network ]] && crowbar_networkingmode="team"
[[ $want_separate_ceph_network ]] && nicsdefault=4
: ${nics:=$nicsdefault}
: ${adminvcpus:=2}
cpuflags=''
working_dir_orig=`pwd`
: ${artifacts_dir:=$working_dir_orig/.artifacts}
mkdir -p $artifacts_dir
start_time=`date`
: ${cloudvg:=cloud}
needcvol=1
: ${vdisk_dir:=/dev/$cloudvg}
: ${admin_node_disk:=$vdisk_dir/$cloud.admin}
: ${admin_node_memory:=4194304}
iscloudver 7plus && : ${controller_node_memory:=12582912}
: ${controller_node_memory:=6291456}
: ${compute_node_memory:=2621440}
[[ "$libvirt_type" = "hyperv" ]] && \
compute_node_memory=$(max $compute_node_memory ${hyperv_node_memory:-3000000})
[[ "$libvirt_type" = "xen" ]] && \
compute_node_memory=$(max $compute_node_memory ${xen_node_memory:-4000000})
# hdd size defaults (unless defined otherwise)
: ${adminnode_hdd_size:=15}
[[ "$upgrade_cloudsource" ]] && \
adminnode_hdd_size=$(max $adminnode_hdd_size 20)
: ${controller_hdd_size:=20}
: ${computenode_hdd_size:=20}
: ${cephvolume_hdd_size:=21}
: ${controller_ceph_hdd_size:=25}
: ${lonelynode_hdd_size:=20}
: ${ironicnode_hdd_size:=20}
if [[ $hacloud ]] && [[ "$want_database_sql_engine" != "mysql" ]]; then
: ${drbd_hdd_size:=15}
else
: ${drbd_hdd_size:=0}
fi
: ${drbd_database_size:=5}
: ${drbd_rabbitmq_size:=5}
# magnum sets up two nodes using docker/kubernetes on compute node
# each node requiring 2GB of RAM and 20GB of harddisk for the images
if [[ $want_magnum_proposal = 1 ]]; then
: ${compute_node_memory:=6621440}
: ${computenode_hdd_size:=80}
fi
# pvlist is filled below
pvlist=
next_pv_device=
pv_cur_device_no=0
: ${cloudbr:=${cloud}br}
# IFNAMSIZ - 1 - 4 (vlan suffix likely length)
cloudbrlimit=11
[[ ${#cloudbr} -gt $cloudbrlimit ]] && complain 100 "cloudbr name is too long (> $cloudbrlimit); \$cloud must be shorter"
: ${ironicbr:=${cloud}irobr}
if [[ $want_ironic ]]; then
[[ ${#ironicbr} -gt $cloudbrlimit ]] && complain 100 "ironicbr name is too long (> $cloudbrlimit); \$cloud must be shorter"
# network card index for ironic network
: ${ironicnic:=1}
fi
#if localreposdir_src string is available, the local repositories are used for setup
: ${localreposdir_src:=""}
: ${cct_tests:="features:base"}
[ -n "$cache_clouddata" ] && {
# Reduce scope a bit for road-warriers
# Only host architecture, nothing else
export architectures="$arch"
# Remove cct: requires SDK to mirror which is huge
export cct_tests=""
export localreposdir_src=$cache_dir
# make sure the cached images are used
export want_cached_images=1
}
#localreposdir_target is the 9p target dir and also the mount target dir in the VM
: ${localreposdir_target:="/repositories"}
[ -z "$localreposdir_src" ] && localreposdir_target=""
: ${install_chef_suse_override:=./install-chef-suse.sh}
host_mtu=$(determine_mtu)
iscloudver 7plus && [[ $arch == x86_64 ]] && \
[[ -n $want_efi ]] && firmware_type="uefi"
pidfile=mkcloud.pid
exec </dev/null
function show_environment
{
end_time=`date`
echo
echo "Crowbar /etc/motd"
echo "---------------------"
nc -z -w 1 $adminip 22 && $ssh root@$adminip "cat /etc/motd"
echo
echo "Environment Details"
echo "-------------------------------"
if $(which git >&/dev/null); then
pushd $SCRIPTS_DIR
echo " git: $(git --no-pager show -s --oneline)"
popd
fi
echo " hostname: `hostname -f`"
echo " started: $start_time"
echo " ended: $end_time"
echo "-------------------------------"
echo " cloudsource: $cloudsource"
echo " TESTHEAD: $TESTHEAD"
echo " want_test_updates: $want_test_updates"
echo " scenario: $scenario"
echo " nodenumber: $nodenumber"
echo " cloudpv: $cloudpv"
echo " UPDATEREPOS: $UPDATEREPOS"
echo " UPDATEREPOS_EXTRA: $UPDATEREPOS_EXTRA"
echo " cephvolumenumber: $cephvolumenumber"
echo " upgrade_cloudsource: $upgrade_cloudsource"
echo "-------------------------------"
env | grep -i "^want_"
echo "-------------------------------"
if [[ $CI_RUN = 1 ]]; then
column -s"," -t $timing_file_host | tee ${timing_file_host}.byTime.txt
sort -t, -k3,3 -k1,1 $timing_file_host | column -s"," -t | tee ${timing_file_host}.byType.txt
fi
}
function pre_exit_cleanup
{
rm $pidfile
}
function onhost_supportconfig
{
if [ -z "$SKIPSUPPORTCONFIG" ] ; then
ssh $sshopts root@$adminip '
set -x
for node in $(crowbar machines list | grep ^d) ; do
(
echo "Collecting supportconfig from $node"
timeout 400 ssh $node supportconfig | wc
timeout 300 scp $node:/var/log/\*tbz /var/log/
)&
done
timeout 500 supportconfig | wc &
wait
'
$scp root@$adminip:/var/log/*tbz $artifacts_dir/
fi
}
function onhost_stop_chef_clients_on_nodes
{
# stop chef-client on nodes so the env will not be altered after a failure
ssh $sshopts root@$adminip '
set -x
for node in $(crowbar machines list | grep ^d) ; do
(
echo "Stopping chef-client on $node"
timeout 30 ssh $node rcchef-client stop
)
done
'
}
function error_exit
{
exitcode=$1
message=$2
onhost_supportconfig
onhost_stop_chef_clients_on_nodes
pre_exit_cleanup
echo $message
show_environment
echo "exitcode: $exitcode"
exit $exitcode
} >&2
function sshrun
{
cat > $mkcconf <<EOF
export drbdnode_mac_vol=$drbdnode_mac_vol ;
export cloud=$virtualcloud ;
# hostnames of repo, nfs, rsync and smt servers
# (*_ip and *_fqdn suffix variables are computed automatically)
export reposerver=$reposerver ;
export reposerver_ip=$reposerver_ip ;
export reposerver_fqdn=$reposerver_fqdn ;
export reposerver_base_path=$reposerver_base_path ;
export reposerver_url=$reposerver_url ;
export imageserver_url=$imageserver_url ;
export nfsserver=$nfsserver ;
export nfsserver_ip=$nfsserver_ip ;
export nfsserver_fqdn=$nfsserver_fqdn ;
export nfsserver_base_path=$nfsserver_base_path ;
export rsyncserver=$rsyncserver ;
export rsyncserver_ip=$rsyncserver_ip ;
export rsyncserver_fqdn=$rsyncserver_fqdn ;
export rsyncserver_images_dir=$rsyncserver_images_dir ;
export susedownload=$susedownload ;
export cloudfqdn=$cloudfqdn ;
export cloudsource=$cloudsource ;
export mkclouddriver=$mkclouddriver ;
export adminip=$adminip ;
export hacloud=$hacloud ;
export libvirt_type=$libvirt_type ;
export firmware_type=$firmware_type ;
export networkingplugin=$networkingplugin ;
export networkingmode=$networkingmode ;
export nosetestparameters=${nosetestparameters} ;
export tempestoptions='${tempestoptions}' ;
export cephvolumenumber=$cephvolumenumber ;
export controller_raid_volumes=$controller_raid_volumes ;
export drbd_database_size=$drbd_database_size ;
export drbd_rabbitmq_size=$drbd_rabbitmq_size ;
export shell=$shell ;
export keep_existing_hostname=$keep_existing_hostname ;
export http_proxy=$http_proxy ;
export https_proxy=$https_proxy ;
export no_proxy=$no_proxy ;
export cct_tests=$cct_tests ;
export scenario=$scenario ;
export host_mtu=$host_mtu ;
export architectures='$architectures';
export crowbar_networkingmode=$crowbar_networkingmode;
export nova_shared_instance_storage=$nova_shared_instance_storage ;
export localreposdir_target=$localreposdir_target ;
export cinder_backend=$cinder_backend;
export cinder_netapp_storage_protocol=$cinder_netapp_storage_protocol;
export cinder_netapp_login=$cinder_netapp_login;
export cinder_netapp_password=$cinder_netapp_password;
export UPDATEREPOS=$UPDATEREPOS ;
export UPDATEREPOS_UPGRADE=$UPDATEREPOS_UPGRADE ;
export UPDATEREPOS_EXTRA=$UPDATEREPOS_EXTRA ;
export TESTHEAD=$TESTHEAD ;
export NOINSTALLCLOUDPATTERN=$NOINSTALLCLOUDPATTERN ;
export clouddescription='$clouddescription';
export JENKINS_BUILD_URL=$BUILD_URL;
export JENKINS_NODE_NAME=$NODE_NAME;
export JENKINS_EXECUTOR_NUMBER=$EXECUTOR_NUMBER;
export JENKINS_WORKSPACE=$WORKSPACE;
export test_internet_url=$test_internet_url;
export extraipmipw=$extraipmipw;
export ipmi_ip_addrs=$ipmi_ip_addrs;
export bmc_user=$bmc_user;
export bmc_password=$bmc_password;
export upgrade_progress_file=$upgrade_progress_file;
EOF
# setting these variables within mkcloud does not make them part of the env, so we need to export them
export nodenumber nodenumberlonelynode nodenumberironicnode clusterconfig ironicnetmask
env|grep -e ^debug_ -e ^pre_ -e ^vlan_ -e ^want_ -e ^net_ -e ^nodenumber -e ^clusterconfig -e ^ironicnetmask | sort >> $mkcconf
cp -a $mkcconf $artifacts_dir/
$scp -r $SCRIPTS_DIR $mkcconf root@$adminip:
[[ $need_scenario = 1 ]] && $scp $scenario_path root@$adminip:
ssh $sshopts root@$adminip "echo `hostname` > cloud ; . ./$(basename $SCRIPTS_DIR)/qa_crowbarsetup.sh ; $@"
return $?
}
function onadmin
{
# functions can have parameters, so pass on all except $1
local cmd=$1
shift
safely sshrun "TIMEFORMAT=\"timing for mkcloud call 'onadmin_$cmd' real=%R user=%U system=%S\" ;" \
time onadmin_$cmd "$@"
local ret=$?
# append timing information of admin node to host timing file
$ssh root@$adminip "( [ -e $timing_file_admin ] && cat $timing_file_admin && rm -f $timing_file_admin ) || :" >> $timing_file_host
return $ret
}
function onhost
{
# functions can have parameters, so pass on all except $1
local cmd=$1
shift
safely onhost_$cmd "$@"
}
function cleanup
{
ipmi_cleanup
${mkclouddriver}_do_cleanup
}
function onhost_cleanup_admin_node
{
${mkclouddriver}_do_cleanup_admin_node
}
function onhost_get_next_pv_device
{
${mkclouddriver}_do_get_next_pv_device
}
function onhost_add_etchosts_entries
{
grep -q crowbar /etc/hosts || echo "$adminip crowbar.$cloudfqdn crowbar" >> /etc/hosts
}
function setuphost
{
${mkclouddriver}_do_setuphost
}
function prepare
{
if ! [ -e ~/.ssh/id_rsa ]; then
echo "Creating key for controlling our VMs..."
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N ""
fi
onhost_cacheclouddata
${mkclouddriver}_do_prepare
}
function wait_for_crowbar_ssh
{
wait_for 240 1 "nc -w 1 -z $adminip 22" 'admin node to start ssh daemon'
}
function wait_for_crowbar_ntpd
{
wait_for 200 10 "ntpdate -d $adminip" "admin node ntpd service"
}
# bring up the VM for crowbar
function setupadmin
{
${mkclouddriver}_do_setupadmin
wait_for 300 1 "ping -q -c 1 -w 1 $adminip >/dev/null" 'crowbar admin VM'
wait_for_crowbar_ssh
echo "Injecting public key into admin node..."
local x keyfile
for keyfile in ~/.ssh/*.pub ; do
local pubkey=`cat $keyfile`
ssh_password root@$adminip "
mkdir -p ~/.ssh;
grep -q '$pubkey' ~/.ssh/authorized_keys 2>/dev/null ||
echo '$pubkey injected-from-host' >> ~/.ssh/authorized_keys
"
done
if [[ $user_keyfile ]]; then
cat $user_keyfile | sshrun "cat >> ~/.ssh/authorized_keys"
fi
onadmin write_cloud_info
echo "you can now proceed with installing crowbar"
# prevent jumbo frames from going out
if [[ $want_mtu_size -gt 1500 ]] || [[ $host_mtu -lt 1500 ]]; then
# we subtract 40 to account for the IP + TCP headers.
local mss=$(( $host_mtu - 40 ))
local rule
# Remove all previous TCPMSS rules
iptables -S FORWARD | grep -o FORWARD.*TCPMSS.* | while read rule ; do
$sudo iptables -w -D ${rule} 2>/dev/null
done
$sudo iptables -w -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss $mss
fi
}
function wait_for_node_shutdown
{
wait_for 150 1 "LC_ALL=C virsh domstate $1 | grep shut.off" "$1 node to shut down"
}
function remove_snapshot_volume
{
if $($sudo lvs "$1.snap" > /dev/null 2>&1) ; then
safely $sudo lvremove -f "$1.snap"
fi
}
function merge_snapshot_volume
{
if $($sudo lvs "$1.snap" > /dev/null 2>&1) ; then
safely $sudo lvconvert --merge "$1.snap"
fi
}
function create_snapshot_volume
{
safely $sudo lvcreate -l100%ORIGIN -s -n "$1.snap" "$1"
}
function createadminsnapshot
{
$sudo virsh shutdown $cloud-admin
wait_for_node_shutdown $cloud-admin
remove_snapshot_volume $admin_node_disk
create_snapshot_volume $admin_node_disk
$sudo virsh start $cloud-admin
wait_for_crowbar_ssh
}
function restoreadminfromsnapshot
{
$sudo virsh destroy $cloud-admin
merge_snapshot_volume $admin_node_disk
createadminsnapshot
}
function lvs_lv_name
{
$sudo lvs -o lv_name ${cloudvg}
}
function createcloudsnapshot
{
shutdowncloud
wait_for_node_shutdown $cloud-admin
local i d
for i in $(nodes ids all) ; do
wait_for_node_shutdown $cloud-node$i
done
for d in $(lvs_lv_name | grep "${cloud}\..*snap") ; do
remove_snapshot_volume "${cloudvg}/${d%.snap}"
done
for d in $(lvs_lv_name | grep ${cloud}\.) ; do
create_snapshot_volume "${cloudvg}/${d}"
done
restartcloud
}
function restorecloudfromsnapshot
{
local i d can_restore=1
lvs_lv_name | grep "${cloud}.admin.snap" || {
echo "Missing snapshot for ${cloud}.admin"
can_restore=
}
for i in $(nodes ids all) ; do
if [[ ! ${can_restore} ]]; then
break
fi
lvs_lv_name | grep "${cloud}.node$i.snap" || {
echo "Missing snapshot for ${cloud}.node$i"
can_restore=
}
done
if [[ ! ${can_restore} ]]; then
complain 88 "Cannot restore cloud, missing snapshot(s)"
return
fi
$sudo virsh destroy $cloud-admin
for i in $(nodes ids all) ; do
$sudo virsh destroy $cloud-node$i
done
for d in $(lvs_lv_name | grep "${cloud}\..*snap") ; do
merge_snapshot_volume "${cloudvg}/${d%.snap}"
done
createcloudsnapshot
}
# bring up lonely_node(s) in the admin network
function setuplonelynodes
{
${mkclouddriver}_do_setuplonelynodes
}
# bring up ironic nodes in the ironic network
function setupironicnodes
{
if [[ $(nodes number ironic) -lt 1 ]] ; then
complain 80 "Please set nodenumberironicnode."
return
fi
${mkclouddriver}_do_setupironicnodes
}
# register lonely_node against crowbar
function crowbar_register
{
local i
for i in $(nodes ids lonely) ; do
local mac=$(macfunc $i)
sshrun "lonelymac=$mac adminip=$adminip onadmin_crowbar_register"
done
}
# setup an NFS server on the first lonely node
function lonelynode_nfs_server
{
local nfsserver=($(nodes ids lonely))
local mac=$(macfunc $nfsserver)
onadmin setup_nfs_server $mac
}
function prepareinstcrowbar
{
echo "connecting to crowbar admin server at $adminip"
onadmin prepareinstallcrowbar
return $?
}
function bootstrapcrowbar
{
echo "bootstrapping crowbar"
onadmin bootstrapcrowbar
return $?
}
function scp_install_chef_suse_override
{
if [ -e "$install_chef_suse_override" ]; then
ssh root@$adminip "mv /opt/dell/bin/install-chef-suse.sh{,.orig}"
$scp -p "$install_chef_suse_override" \
root@$adminip:/opt/dell/bin/install-chef-suse.sh
ssh root@$adminip "chmod +x /opt/dell/bin/install-chef-suse.sh"
fi
}
function instcrowbar
{
scp_install_chef_suse_override
onadmin installcrowbar
local ret=$?
$scp root@$adminip:$crowbar_install_log "$artifacts_dir/"
return $ret
}
function instcrowbarfromgit
{
scp_install_chef_suse_override
safely rsync -av --exclude ".git" --exclude ".ci-tracking" ./crowbar root@$adminip:/root/
onadmin installcrowbarfromgit
local ret=$?
$scp root@$adminip:$crowbar_install_log "$artifacts_dir/"
return $ret
}
function mkvlan
{
local DEFVLAN=$1 ; shift
local IP=$1 ; shift
$sudo ip link add link $cloudbr name $cloudbr.$DEFVLAN type vlan id $DEFVLAN
safely $sudo ip link set $cloudbr.$DEFVLAN up
safely $sudo ip addr add $IP/24 dev $cloudbr.$DEFVLAN
}
function setuppublicnet
{
# workaround https://bugzilla.novell.com/show_bug.cgi?id=845496
echo 0 > /proc/sys/net/bridge/bridge-nf-call-iptables
mkvlan $vlan_public $net_public.1
if [[ $mkch_physcloudif ]] ; then
$sudo brctl addif $cloudbr $mkch_physcloudif
$sudo ip link set dev $mkch_physcloudif up
fi
}
function shutdowncloud
{
echo "Shutting down: $cloud"
echo
${mkclouddriver}_do_shutdowncloud
}
function restartcloud
{
vgchange -ay $cloudvg
libvirt_net_start
$sudo virsh start $cloud-admin
setuppublicnet
wait_for_crowbar_ntpd
local i
for i in $(nodes ids all) ; do
$sudo virsh start $cloud-node$i
done
wait_for_crowbar_ssh
}
# bring up VMs that will take cloud controller/compute/storage roles
function setupnodes
{
onadmin wait_tftpd || return $?
setuppublicnet
local i
for i in $(nodes ids normal) ; do
local macaddress=$(macfunc $i)
# transport drdb volume information to admin node (needed for proposal of data cluster)
drbd_serial=""
if [ $drbd_hdd_size != 0 ]; then
if [ $i -le 2 ] ; then
drbd_serial="$cloud-node$i-drbd"
# libvirt does not accept anything other than [:alnum:]_-
# for serial strings:
drbd_serial=${drbd_serial//[^A-Za-z0-9-_]/_}
drbdnode_mac_vol="${drbdnode_mac_vol}+${macaddress}#${drbd_serial}"
drbdnode_mac_vol="${drbdnode_mac_vol#+}"
fi
fi
local mac_params=""
for nicnumber in $(seq 1 $nics) ; do
mac_params+=" --macaddress $(macfunc $i $nicnumber)";
done
local ironic_params=""
[[ $want_ironic ]] && ironic_params="--ironicnic $ironicnic"
local localrepos_params=""
if [ -n "${localreposdir_src}" -a -n "${localreposdir_target}" ] ; then
localrepos_params="--localreposrc ${localreposdir_src} --localrepotgt ${localreposdir_target}"
fi
local ipmi_params=""
if [[ $want_ipmi = 1 ]] ; then
ipmi_params="--ipmi"
local bmc_addr=$(( 162 + $i ))
if [[ $bmc_addr > 240 ]] ; then
echo "You have more nodes than allocated addresses."
exit 1
fi
bmc_addr=$net.$bmc_addr
mkveth $i $bmc_addr
generate_lan_config $i $bmc_user $bmc_password $bmc_addr
screen -S $cloud-node$i-bmc-lan -d -m ipmi_sim -c /tmp/ipmi-lan-$cloud-node$i.conf -f ${SCRIPTS_DIR}/lib/ipmi/ipmi_sim.emu
fi
${scripts_lib_dir}/libvirt/compute-config $cloud $i \
$mac_params \
$ironic_params \
$ipmi_params \
--cephvolumenumber $cephvolumenumber \
--drbdserial "$drbd_serial"\
--computenodememory $compute_node_memory \
--controllernodememory $controller_node_memory \
--libvirttype $libvirt_type \
--vcpus $vcpus \
--emulator $(get_emulator) \
--vdiskdir $vdisk_dir \
--bootorder 3 \
--numcontrollers $(get_nodenumbercontroller) \
$localrepos_params \
--firmwaretype "$firmware_type" \
--controller-raid-volumes $controller_raid_volumes > /tmp/$cloud-node$i.xml
safely libvirt_vm_start /tmp/$cloud-node$i.xml
done
echo "========================================================"
echo " Note: If you interrupt mkcloud now and want to proceed"
echo " later, make sure to run the following command:"
echo
echo " export drbdnode_mac_vol=\"${drbdnode_mac_vol}\""
echo
echo "========================================================"
sleep 10
# mkch_physwol can be set by the user to a space-separated list of MAC-addrs
# of pysical nodes to wake up using WoL
for i in $mkch_physwol ; do
$sudo ether-wake -i $cloudbr $i
done
return 0
}
# allocate cloud nodes with an operating system
# and wait for nodes to reach the ready state
function instnodes
{
safely onadmin allocate
echo "Waiting for the installation of the nodes ..."
safely onadmin waitcloud
safely onadmin post_allocate
}
function deployexternalceph
{
if [[ $want_external_ceph = 0 ]] ; then
echo "\$want_external_ceph not set, skipping"
return
fi
if [[ $(nodes number lonely) = 0 ]] ; then
echo "\$nodenumberlonelynode = 0, can't build a ceph cluster of 0 nodes"
return
fi
local new_nodes=()
for i in $(nodes ids lonely) ; do
local mac=$(macfunc $i)
new_nodes=(${new_nodes[@]} $(mac_to_nodename $mac))
done
onadmin external_ceph ${new_nodes[@]}
}
function proposal
{
onadmin proposal
return $?
}
function testsetup
{
onadmin testsetup
local ret=$?
$scp root@$adminip:tempest*.log "$artifacts_dir/"
# Register the cloud in Rally and import the results
if [[ $rally_server && -f $artifacts_dir/tempest.subunit.log ]] ; then
local title=$(testname)
local type=$(testtype)
$scp root@$adminip:.openrc "$artifacts_dir/"
local tmpdir=`ssh $sshopts rally@$rally_server "mktemp -d rally-XXXXXX"`
$scp "$artifacts_dir/tempest.subunit.log" "$artifacts_dir/.openrc" rally@$rally_server:$tmpdir
ssh $sshopts rally@$rally_server "
source rally/bin/activate
source $tmpdir/.openrc
deployment=\$(rally deployment create --fromenv --name=\"$title\" | awk '/Using deployment:/{print \$3}')
rally verify import --set-name=\"$type\" --file=$tmpdir/tempest.subunit.log --deployment=\$deployment
rm -fr $tmpdir
"
fi
return $ret
}
function testpreupgrade
{
onadmin testpreupgrade
}
function testpostupgrade
{
onadmin testpostupgrade
}
function testname
{
local -a var_names=(ha cluster upgrade ceph cinder drbd net
netmode sles12 dvr rootfs)
local -a var_values=("$hacloud" "$clusterconfig"
"$upgrade_cloudsource" "$cephvolumenumber" "$cinder_backend"
"$drbd_hdd_size" "$networkingplugin" "$networkingmode"
"$want_sles12" "$want_dvr" "$want_rootfs")
if [[ ${#var_names[@]} != ${#var_values[@]} ]] ; then
complain 123 "testname error: arrays of different length, please check the code"
fi
local name="$cloudsource"
local n i=0
for n in ${var_names[@]} ; do
if [[ ${var_values[$i]} ]] ; then
name="$name/$n:${var_values[$i]}"
fi
i=$(($i+1))
done
# Check if this instance of mkcloud is running inside Jenkins
if [[ $JENKINS_URL ]] ; then
name="$BUILD_NUMBER - $name - $BUILD_URL"
fi
echo $name
}
function testtype
{
# If `tempestoptions` contains '-s' or '--smoke' parameter, is a
# smoke test. If there is '--load-list 2015.03.required.txt' is a
# defcore test. A full test is assumed by default.
local type="full"
if [[ $tempestoptions ]] ; then
if [[ $tempestoptions =~ -s ]] ; then
type="smoke"
elif [[ $tempestoptions =~ --load-list.*.required.txt ]] ; then
type="defcore"
elif [[ $tempestoptions =~ --load-list ]] ; then
type="ad-hoc"
fi
fi
echo $type
}
function rebootcrowbar
{
# reboot the crowbar instance
# and test if everything is up and running afterwards
sshrun "reboot"
wait_for 50 3 "! nc -w 1 -z $adminip 22" 'crowbar to go down'
wait_for_crowbar_ssh
echo "waiting another 180 seconds for services"
sleep 180
sshrun "mount -a -t nfs" # workaround repos not mounted on reboot because NFS needs bind, but bind says it requires NFS
return $?
}
function rebootcloud
{
# reboot compute nodes
# and test if everthing is up and running afterwards
onadmin rebootcloud
return $?
}
function rebootcompute
{
echo "WARNING: called deprecated rebootcompute step" >&2
rebootcloud
return $?
}
function rebootneutron
{
onadmin rebootneutron
return $?
}
function qa_test
{
local ghsc=github.com/SUSE-Cloud
mkdir -p ~/$ghsc/
pushd ~/$ghsc/
if [ -e "qa-openstack-cli" ] ; then
cd qa-openstack-cli/
git pull
else
git clone https://$ghsc/qa-openstack-cli.git
fi
popd
rsync -av ~/$ghsc/qa-openstack-cli root@$adminip:
onadmin qa_test
ret=$?
$scp -r root@$adminip:qa_test.logs/ $artifacts_dir/
return $ret
}
function crowbarbackup
{
safely onadmin crowbarbackup "$@"
local btargetdir=${artifacts_dir:-.}
mkdir -p "$btargetdir"
safely $scp root@$adminip:/tmp/backup-crowbar.tar.gz "$btargetdir"
}
function crowbarrestore
{
local btarball=backup-crowbar.tar.gz
[ -e "$artifacts_dir/$btarball" ] && btarball="$artifacts_dir/$btarball"
if [ ! -e "$btarball" ] ; then
complain 56 "No crowbar backup tarball found."
fi
onhost_reset_admin
safely $scp "$btarball" root@$adminip:/tmp/
safely onadmin crowbarrestore "$@"
}
function onhost_reset_admin
{
# deploy and setup a fresh admin node
safely onhost_cleanup_admin_node
safely onhost_prepareadmin
safely setupadmin
safely prepareinstcrowbar
safely bootstrapcrowbar
}
function crowbarupgrade_5plus
{
if iscloudver 6plus ; then
cloudsource=$upgrade_cloudsource onadmin prepare_cloudupgrade_nodes_repos
iscloudver 6 && onadmin upgrade_ses_to_4
onadmin zypper_patch_all
onadmin upgrade_prechecks
if [[ $cloudsource =~ devel ]] || [[ $upgrade_cloudsource =~ devel ]]; then
onadmin allow_vendor_change_at_nodes
fi
export cloudsource=$upgrade_cloudsource
onadmin prepare_crowbar_upgrade
onadmin prepare_cloudupgrade_admin_repos
onadmin addupdaterepo upgrade
onadmin upgrade_admin_backup
onadmin upgrade_admin_repocheck
onadmin upgrade_admin_server
wait_for 400 3 "! nc -w 1 -z $adminip 22" 'crowbar to go down after upgrade'
wait_for_crowbar_ssh
onadmin check_admin_server_upgraded
# use crowbar-init to bootstrap crowbar (only for 6-7 upgrade)
iscloudver 7 && onadmin bootstrapcrowbar "with_upgrade"
onadmin wait_for_crowbar_api
else
onadmin prepare_crowbar_upgrade
crowbarbackup "with_upgrade"
export cloudsource=$upgrade_cloudsource
crowbarrestore "with_upgrade"
fi
}
function cloudupgrade
{
if iscloudver 6plus; then
local cloudver=$(getcloudver)
# this must be set at the start of upgrade, before we switch to new cloudsource:
export upgrade_progress_file="/var/lib/crowbar/upgrade/$cloudver-to-$((cloudver+1))-progress.yml"
crowbarupgrade_5plus
if [[ $want_ping_running_instances = 1 ]]; then
onadmin ping_running_instances
fi
onadmin crowbar_nodeupgrade
elif iscloudver 5plus ; then
crowbarupgrade_5plus
# upgrade and reapply all barclamps
onadmin runlist crowbar_nodeupgrade \
proposal