blob: 83f37660e1eb00a73a493068437a9c8019211b13 [file] [log] [blame]
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +02001# Copyright 2017 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +020014import pytest
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +020015import time
16
17from collections import Counter
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020018
19from tcp_tests import logger
20from tcp_tests.managers.jenkins.client import JenkinsClient
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +020021from tcp_tests import settings
22
23from tcp_tests import managers
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020024
25LOG = logger.logger
26
27
28class TestOfflineDeployment(object):
29 """docstring for TestOfflineDeployment"""
30
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +020031 @pytest.mark.day1_underlay
32 def test_maas_provision(self, show_step, hardware, underlay,
33 day1_cfg_config):
34 """Test for deploying an mcp dvr environment and check it
35
36 Scenario:
37 1. Prepare salt on hosts
38 2. Setup controller nodes
39 3. Setup compute nodes
40 """
41
42 show_step(1)
43 show_step(2)
44 show_step(3)
45
46 cfg_node = 'cfg01.virtual-mcp-pike-dvr.local'
47 ssh_test_key = day1_cfg_config.config.underlay.ssh_keys[0]['public']
48 verbose = True
49
50 cfg_admin_iface = next(i for i in hardware.master_nodes[0].interfaces
51 if i.network.name == 'admin')
52 admin_net = cfg_admin_iface.network.address_pool.ip_network
53
54 underlay.check_call(
55 node_name=cfg_node, verbose=verbose,
56 cmd='maas logout mirantis && '
57 'maas login mirantis '
58 'http://localhost:5240/MAAS/api/2.0/ '
59 'FTvqwe7ybBp68gPar2:5mcctTAXVL8mns4ef4:zrA9LZwu2tMc8BAZpsPUfwWwTyQnAtDN') # noqa
60
61 underlay.check_call(
62 node_name=cfg_node,
63 verbose=verbose,
64 cmd="maas mirantis package-repository update main_archive "
65 "disabled_pockets=backports,security")
66
67 underlay.check_call(
68 node_name=cfg_node, verbose=verbose,
69 cmd="maas mirantis ipranges create "
70 "type=dynamic start_ip={start} end_ip={end} "
71 "subnet=$(maas mirantis subnets read | jq '.[] | select(.name==\"{net}\") | .id')".format( # noqa
72 start=admin_net[191],
73 end=admin_net[253],
74 net=admin_net))
75 underlay.check_call(node_name=cfg_node, verbose=verbose,
76 cmd="maas mirantis vlan update "
77 "$(maas mirantis subnets read | jq '.[] | select(.name==\"{net}\") | .vlan.fabric_id') " # noqa
78 "0 dhcp_on=True primary_rack='cfg01'".format(net=admin_net))
79
80 underlay.check_call(
81 node_name=cfg_node, verbose=verbose,
82 cmd="ssh-keygen -y -f ~root/.ssh/id_rsa > ~root/.ssh/id_rsa.pub")
83 underlay.check_call(
84 node_name=cfg_node, verbose=verbose,
85 cmd='maas mirantis sshkeys create '
86 'key="$(cat ~root/.ssh/id_rsa.pub)"')
87
88 r, f = day1_cfg_config.salt.enforce_state('cfg01*', 'maas.machines')
89 LOG.info(r)
90 LOG.info(f)
91
92 # show_step(8)
93 nodes_amount = len(hardware.slave_nodes)
94 cmd = """ timeout 1800s bash -c 'hosts=$(maas mirantis nodes read | jq -r ".[] | select(.node_type_name==\\"Machine\\") | select(.status_name==\\"Ready\\") | .hostname "); while ! [ $(echo "$hosts" | wc -w) -eq {amount} ]; do echo "Ready hosts:\n$hosts"; sleep 30; hosts=$(maas mirantis nodes read | jq -r ".[] | select(.node_type_name==\\"Machine\\") | select(.status_name==\\"Ready\\") | .hostname "); done ' """.format(amount=nodes_amount) # noqa
95 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
96 underlay.check_call(node_name=cfg_node, verbose=verbose,
97 cmd='salt-key')
98 # show_step(9)
99 underlay.check_call(
100 node_name=cfg_node, verbose=verbose,
101 cmd='salt-call state.sls maas.machines.deploy')
102 # show_step(10)
103 underlay.check_call(
104 node_name=cfg_node, verbose=verbose,
105 cmd='salt-call state.sls maas.machines.wait_for_deployed')
106 underlay.check_call(node_name=cfg_node, verbose=verbose,
107 cmd='salt-key')
108
109 underlay.check_call(
110 node_name=cfg_node,
111 verbose=verbose,
112 cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key))
113 underlay.check_call(
114 node_name=cfg_node,
115 verbose=verbose,
116 cmd='salt "*" ssh.set_auth_key root '
117 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
118
119 underlay.check_call(
120 node_name=cfg_node,
121 verbose=verbose,
122 cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key))
123 underlay.check_call(
124 node_name=cfg_node,
125 verbose=verbose,
126 cmd='salt "*" ssh.set_auth_key ubuntu '
127 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
128
129 result = \
130 day1_cfg_config.salt.get_pillar(cfg_node,
131 '_param:jenkins_salt_api_url')
132 result = result[0].get(cfg_node)
133
134 jenkins = JenkinsClient(
135 host='http://{host}:8081'.format(
136 host=day1_cfg_config.config.salt.salt_master_host),
137 username='admin',
138 password='r00tme')
139 params = jenkins.make_defults_params('deploy_openstack')
140 params['SALT_MASTER_URL'] = result
141 params['STACK_INSTALL'] = "core,openstack,ovs"
142 build = jenkins.run_build('deploy_openstack', params)
143
144 jenkins.wait_end_of_build(
145 name=build[0],
146 build_id=build[1],
147 timeout=60 * 60 * 2)
148
149 assert \
150 jenkins.build_info(
151 name=build[0], build_id=build[1])['result'] == 'SUCCESS', \
152 "Deploy openstack was failed"
153
154 openstack = managers.openstack_manager.OpenstackManager(
155 day1_cfg_config.config, underlay, hardware,
156 day1_cfg_config.salt)
157
158 if settings.RUN_TEMPEST:
159 openstack.run_tempest(pattern=settings.PATTERN)
160 openstack.download_tempest_report()
161
162 LOG.info("*************** DONE **************")
163
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200164 def test_deploy_day1(self, show_step, config, underlay, hardware,
165 common_services_deployed, salt_deployed):
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200166 """Test for deploying an mcp from day01 images
167
168 Scenario:
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200169 1. Wait salt master
170 2. Addition config of MaaS
171 3. Wait dhcpd server
172 4. Start comissioning node via MaaS
173 5. Wait of comissioning node by MaaS
174 6. Start deploing node via MaaS
175 7. Wait of deploing node by
176 8. Accept all keys
177 9. Configure and baremetal nodes after MaaS deployment
178 10. Run deploy OS job
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200179
180 """
181 # group = hardware._get_default_node_group()
182 nodes = underlay.node_names()
183 LOG.info("Nodes - {}".format(nodes))
184 cfg_node = 'cfg01.offline-ocata-vxlan.local'
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200185 tempest_node = 'gtw01.offline-ocata-vxlan.local'
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200186 verbose = True
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200187 ssh_test_key = config.underlay.ssh_keys[0]['public']
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200188
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200189 show_step(1)
190 underlay.check_call(
191 node_name=cfg_node,
192 verbose=verbose,
193 cmd="""timeout 300s /bin/bash -c """
194 """'while ! salt-call test.ping; do """
195 """echo "salt master still isnt running"; sleep 10; done'"""
196 ) # noqa
197
198 show_step(2)
199 underlay.check_call(
200 node_name=cfg_node,
201 verbose=verbose,
202 cmd='salt-call saltutil.sync_all')
203
204 underlay.check_call(
205 node_name=cfg_node,
206 verbose=verbose,
207 cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key))
208 underlay.check_call(
209 node_name=cfg_node,
210 verbose=verbose,
211 cmd='salt "*" ssh.set_auth_key root '
212 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
213 underlay.check_call(
214 node_name=cfg_node,
215 verbose=verbose,
216 cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key))
217 underlay.check_call(
218 node_name=cfg_node,
219 verbose=verbose,
220 cmd='salt "*" ssh.set_auth_key ubuntu '
221 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
222
223 underlay.check_call(
224 node_name=cfg_node,
225 verbose=verbose,
226 cmd='salt-call state.sls maas.region')
227 underlay.check_call(
228 node_name=cfg_node,
229 verbose=verbose,
230 cmd='maas logout mirantis && '
231 'maas login mirantis '
232 'http://localhost:5240/MAAS/api/2.0/ '
233 'FTvqwe7ybBp68gPar2:5mcctTAXVL8mns4ef4:zrA9LZwu2tMc8BAZpsPUfwWwTyQnAtDN' # noqa
234 )
235
236 underlay.check_call(
237 node_name=cfg_node,
238 verbose=verbose,
239 cmd="maas mirantis maas set-config "
240 "name=upstream_dns value='10.10.0.15 8.8.8.8 8.8.4.4'")
241
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200242 # underlay.check_call(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200243 # node_name=cfg_node,
244 # verbose=verbose,
245 # cmd="maas mirantis ipranges create "
246 # "type=dynamic start_ip=10.10.191.255 end_ip=10.10.255.254 "
247 # "subnet=$(maas mirantis subnets read | jq '.[] | "
248 # "select(.name==\"10.10.0.0/16\") | .id')")
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200249
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200250 underlay.check_call(
251 node_name=cfg_node,
252 verbose=verbose,
253 cmd="maas mirantis vlan update "
254 "$(maas mirantis subnets read | jq '.[] | "
255 "select(.name==\"10.10.0.0/16\") | .vlan.fabric_id') "
256 "0 dhcp_on=True primary_rack='cfg01'")
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200257
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200258 underlay.check_call(
259 node_name=cfg_node,
260 verbose=verbose,
261 cmd="ssh-keygen -y -f ~root/.ssh/id_rsa > ~root/.ssh/id_rsa.pub")
262 underlay.check_call(
263 node_name=cfg_node,
264 verbose=verbose,
265 cmd='maas mirantis sshkeys create '
266 'key="$(cat ~root/.ssh/id_rsa.pub)"')
267
268 show_step(3)
269 underlay.check_call(
270 node_name=cfg_node,
271 verbose=verbose,
272 cmd="""timeout 90s /bin/bash -c 'while ! pidof dhcpd; do """
273 """echo "dhcpd still isnt running"; sleep 10; done'""")
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200274
275 show_step(4)
276 underlay.check_call(
277 node_name=cfg_node,
278 verbose=verbose,
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200279 cmd='salt-call state.sls maas.machines')
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200280 show_step(5)
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200281 cmd = """ timeout 600s bash -c 'hosts=$(maas mirantis nodes read | jq -r ".[] | select(.node_type_name==\\"Machine\\") | select(.status_name==\\"Ready\\") | .hostname "); while ! [ $(echo "$hosts" | wc -w) -eq 10 ]; do echo "Ready hosts:\n$hosts"; sleep 30; hosts=$(maas mirantis nodes read | jq -r ".[] | select(.node_type_name==\\"Machine\\") | select(.status_name==\\"Ready\\") | .hostname "); done ' """ # noqa
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200282 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200283 underlay.check_call(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200284 node_name=cfg_node, verbose=verbose, cmd='salt-key')
285 underlay.check_call(
286 node_name=cfg_node,
287 verbose=verbose,
288 cmd='salt-call state.sls maas.machines.assign_ip')
289 show_step(6)
290 underlay.check_call(
291 node_name=cfg_node,
292 verbose=verbose,
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200293 cmd='salt-call state.sls maas.machines.deploy')
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200294 show_step(7)
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200295 underlay.check_call(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200296 node_name=cfg_node,
297 verbose=verbose,
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200298 cmd='salt-call state.sls maas.machines.wait_for_deployed')
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200299 underlay.check_call(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200300 node_name=cfg_node, verbose=verbose, cmd='salt-key')
301
302 show_step(8)
303 underlay.check_call(
304 node_name=cfg_node,
305 verbose=verbose,
306 expected=[0, 1],
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200307 cmd='salt-key -A -y --include-denied --include-rejected')
308 underlay.check_call(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200309 node_name=cfg_node, verbose=verbose, cmd='salt-key')
310
311 show_step(9)
312 cmd = "salt '*' saltutil.refresh_pillar"
313 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
314 cmd = "salt '*' saltutil.sync_all"
315 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
316
317 underlay.check_call(
318 node_name=cfg_node, verbose=verbose, cmd="reclass-salt --top")
319
320 cmd = "salt -C " \
321 "'I@salt:control or I@nova:compute or I@neutron:gateway' " \
322 "cmd.run 'touch /run/is_rebooted'"
323 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
324
325 cmd = "salt --async -C " \
326 "'I@salt:control' cmd.run 'salt-call state.sls " \
327 "linux.system.user,openssh,linux.network;reboot'"
328 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
329
330 cmd = "salt --async -C " \
331 "'I@nova:compute' cmd.run 'salt-call state.sls " \
332 "linux.system.user,openssh,linux.network;reboot'"
333 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
334
335 cmd = "salt --async -C " \
336 "'I@neutron:gateway' cmd.run 'salt-call state.sls " \
337 "linux.system.user,openssh,linux.network;reboot'"
338 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
339
340 time.sleep(360) # TODO: Add ssh waiter
341
342 cmd = "salt -C " \
343 "'I@salt:control or I@nova:compute or I@neutron:gateway'" \
344 " test.ping"
345 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
346
347 cmd = """salt -C """ \
348 """'I@salt:control or I@nova:compute or I@neutron:gateway' """ \
349 """cmd.run '[ -f "/run/is_rebooted" ] && """ \
350 """echo "Has not been rebooted!" || echo "Rebooted"' """
351 ret = underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
352 count = Counter(ret['stdout_str'].split())
353
354 assert count['Rebooted'] == 10, "Should be rebooted 10 baremetal nodes"
355
356 underlay.check_call(
357 node_name=cfg_node,
358 verbose=verbose,
359 cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key))
360 underlay.check_call(
361 node_name=cfg_node,
362 verbose=verbose,
363 cmd='salt "*" ssh.set_auth_key root '
364 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
365 underlay.check_call(
366 node_name=cfg_node,
367 verbose=verbose,
368 cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key))
369 underlay.check_call(
370 node_name=cfg_node,
371 verbose=verbose,
372 cmd='salt "*" ssh.set_auth_key ubuntu '
373 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200374
375 salt_api = \
376 salt_deployed.get_pillar(cfg_node, '_param:jenkins_salt_api_url')
377 salt_api = salt_api[0].get(cfg_node)
378
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200379 show_step(10)
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200380 jenkins = JenkinsClient(
381 host='http://172.16.44.33:8081',
382 username='admin',
383 password='r00tme')
384 params = jenkins.make_defults_params('deploy_openstack')
385 params['SALT_MASTER_URL'] = salt_api
386 build = jenkins.run_build('deploy_openstack', params)
387
388 jenkins.wait_end_of_build(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200389 name=build[0], build_id=build[1], timeout=60 * 60 * 2)
390
391 with open("{path}/cfg01_jenkins_deploy_openstack_console.log".format(
392 path=settings.LOGS_DIR), 'w') as f:
393 LOG.info("Save jenkins console log")
394 console_log = \
395 jenkins.get_build_output('deploy_openstack', build[1])
396 f.write(console_log)
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200397
398 assert \
399 jenkins.build_info(
400 name=build[0], build_id=build[1])['result'] == 'SUCCESS', \
401 "Deploy openstack was failed"
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200402
403 underlay.check_call(
404 node_name=cfg_node,
405 verbose=verbose,
406 cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key))
407 underlay.check_call(
408 node_name=cfg_node,
409 verbose=verbose,
410 cmd='salt "*" ssh.set_auth_key root '
411 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
412 underlay.check_call(
413 node_name=cfg_node,
414 verbose=verbose,
415 cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key))
416 underlay.check_call(
417 node_name=cfg_node,
418 verbose=verbose,
419 cmd='salt "*" ssh.set_auth_key ubuntu '
420 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
421
422 salt_nodes = salt_deployed.get_ssh_data()
423 nodes_list = \
424 [node for node in salt_nodes
425 if not any(node['node_name'] == n['node_name']
426 for n in config.underlay.ssh)]
427 config.underlay.ssh = config.underlay.ssh + nodes_list
428 underlay.add_config_ssh(nodes_list)
429
430 time.sleep(120) # debug sleep
431 cmd = "salt '*' test.ping"
432 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
433
434 openstack = managers.openstack_manager.OpenstackManager(
435 config, underlay, hardware, salt_deployed)
436
437 if settings.RUN_TEMPEST:
438 openstack.run_tempest(
439 pattern=settings.PATTERN,
440 node_name=tempest_node)
441 openstack.download_tempest_report()