forked from theforeman/foreman-bats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb-setup-libvirt.bats
executable file
·183 lines (162 loc) · 5.94 KB
/
fb-setup-libvirt.bats
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
#!/usr/bin/env bats
# vim: ft=sh:sw=2:et
set -o pipefail
load os_helper
load foreman_helper
@test "install and configure libvirt daemon" {
if tIsRedHatCompatible; then
tPackageExists qemu-kvm || yum -y groupinstall Virtualization
tPackageExists libvirt || tPackageInstall libvirt
tServiceStart libvirtd; tServiceEnable libvirtd
elif tIsDebianCompatible; then
tPackageInstall qemu-kvm libvirt-bin
fi
echo 'auth_unix_rw = "none"' >> /etc/libvirt/libvirtd.conf
echo 'auth_tls = "none"' >> /etc/libvirt/libvirtd.conf
service libvirtd restart && sleep 10
}
@test "configure nested network and storage" {
virsh net-info nested && skip "already configured"
# https://bugzilla.redhat.com/show_bug.cgi?id=1160183
touch /tmp/nested.xml && chcon system_u:object_r:lib_t:s0 /tmp/nested.xml
# create network
cat >/tmp/nested.xml <<'EON'
<network>
<name>nested</name>
<uuid>71e5409e-59d0-11e4-8c48-3ca9f45639f8</uuid>
<forward mode='nat'/>
<bridge name='virbr1' stp='on' delay='0' />
<mac address='52:54:C4:9E:13:05'/>
<ip address='192.168.222.1' netmask='255.255.255.0'>
</ip>
</network>
EON
virsh net-define /tmp/nested.xml
virsh net-start nested
virsh net-autostart nested
# create pool
mkdir -p /var/lib/libvirt/nested
cat >/tmp/nested.xml <<'EOP'
<pool type='dir'>
<name>nested</name>
<uuid>1117824d-b2dc-441f-8543-f49308c77d2a</uuid>
<source>
</source>
<target>
<path>/var/lib/libvirt/nested</path>
<permissions>
<mode>0755</mode>
<owner>-1</owner>
<group>-1</group>
</permissions>
</target>
</pool>
EOP
virsh pool-define /tmp/nested.xml
virsh pool-start nested
virsh pool-autostart nested
}
@test "configure proxy and services" {
foreman-installer -v \
--enable-foreman-proxy \
--foreman-proxy-tftp=true \
--foreman-proxy-tftp-servername=192.168.222.1 \
--foreman-proxy-dhcp=true \
--foreman-proxy-dhcp-interface=virbr1 \
--foreman-proxy-dhcp-gateway=192.168.222.1 \
--foreman-proxy-dhcp-range="192.168.222.2 192.168.222.200" \
--foreman-proxy-dhcp-nameservers="192.168.222.1" \
--foreman-proxy-dns=true \
--foreman-proxy-dns-interface=virbr1 \
--foreman-proxy-dns-zone=nested.lan \
--foreman-proxy-dns-forwarders=$(awk '/nameserver/ { print $2 ; exit }' /etc/resolv.conf) \
--foreman-proxy-dns-reverse=222.168.192.in-addr.arpa \
--foreman-proxy-foreman-base-url=https://$(hostname -f)
}
@test "refresh puppet facts" {
puppet agent -v -o --no-daemonize
}
@test "create nested libvirt compute resource" {
hammer -d compute-resource create --provider libvirt --name libvirt --url qemu:///system
}
@test "verify expected operating system" {
# at least one was created via puppet agent above
test $(hammer --csv os list | wc -l) -ge 2
}
@test "create installation medium" {
# this one is only for use in Red Hat labs
hammer -d medium create --os-family Redhat --name rhlabs_rhel \
--path 'http://download/pub/rhel/released/RHEL-$major/$major.$minor/Server/$arch/os/'
}
@test "associate architectures" {
hammer -d os add-architecture --id 1 --architecture x86_64
hammer -d os add-architecture --id 1 --architecture i386
}
@test "associate partition table" {
hammer -d os add-ptable --id 1 --partition-table "Kickstart default"
}
@test "associate installation media" {
# must use the IDs because of http://projects.theforeman.org/issues/8231
# we hardcode CentOS in this case
hammer -d medium add-operatingsystem --id 1 --operatingsystem-id 1
hammer -d medium add-operatingsystem --id 7 --operatingsystem-id 1
}
@test "associate templates" {
# we hardcode CentOS in this case
hammer -d os add-config-template --id 1 --config-template "Kickstart default"
hammer -d os add-config-template --id 1 --config-template "Kickstart default finish"
hammer -d os add-config-template --id 1 --config-template "Kickstart default PXELinux"
hammer -d os add-config-template --id 1 --config-template "Kickstart default PXEGrub"
hammer -d os add-config-template --id 1 --config-template "Kickstart default PXEGrub2"
hammer -d os add-config-template --id 1 --config-template "Kickstart default user data"
}
@test "set default templates" {
tForemanGetTemplateId "Kickstart default" "provision"
hammer -d os set-default-template --id 1 --config-template-id $TPL_ID
tForemanGetTemplateId "Kickstart default finish" "finish"
hammer -d os set-default-template --id 1 --config-template-id $TPL_ID
tForemanGetTemplateId "Kickstart default PXELinux" "PXELinux"
hammer -d os set-default-template --id 1 --config-template-id $TPL_ID
tForemanGetTemplateId "Kickstart default PXEGrub" "PXEGrub"
hammer -d os set-default-template --id 1 --config-template-id $TPL_ID
tForemanGetTemplateId "Kickstart default PXEGrub2" "PXEGrub2"
hammer -d os set-default-template --id 1 --config-template-id $TPL_ID
tForemanGetTemplateId "Kickstart default user data" "user_data"
hammer -d os set-default-template --id 1 --config-template-id $TPL_ID
}
@test "create subnet" {
hammer -d subnet create --name nested.lan \
--network 192.168.222.0 \
--mask 255.255.255.0 \
--gateway 192.168.222.1 \
--dns-primary 192.168.222.1 \
--boot-mode Static \
--ipam DHCP \
--from 192.168.222.100 \
--to 192.168.222.200 \
--tftp-id 1 \
--dhcp-id 1 \
--dns-id 1
}
@test "create domain" {
hammer -d domain create --name nested.lan --dns-id 1
hammer --csv domain list | grep nested.lan
}
@test "associate subnet and domain" {
hammer -d subnet update --id 1 --domain-ids 2
}
@test "create hostgroup" {
hammer -d hostgroup create --name bats-centos \
--architecture x86_64 \
--domain nested.lan \
--subnet nested.lan \
--operatingsystem-id 1 \
--medium-id 1 \
--partition-table "Kickstart default" \
--puppet-proxy-id 1 \
--puppet-ca-proxy-id 1 \
--environment production
}
@test "set default root password to 'foreman'" {
echo 'Setting["root_pass"] = "$1$qudcAKx2$.CFQlnjI8tZysDA9/d9wR/"' | foreman-rake console
}