blob: 0b0d6a5c22f17527426aa63ed065a45868c3c98f [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
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +020016import socket
17import urlparse
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/ '
Pavel Glazov6ed8d442022-09-20 12:50:18 +040059 'FTvqwe7ybBp68gPar2:5mcctTAXVL8mns4ef4:zrA9LZwu2tMc8BAZpsPUfwWwTyQnAtDN') # noqa
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +020060
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,
Pavel Glazov794b1a92022-10-03 16:33:04 +040076 cmd="maas mirantis vlan update "
77 "$(maas mirantis subnets read | jq '.[] | "
78 "select(.name==\"{net}\") | .vlan.fabric_id') " # noqa
79 "0 dhcp_on=True "
80 "primary_rack='cfg01'".format(
81 net=admin_net))
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +020082
83 underlay.check_call(
84 node_name=cfg_node, verbose=verbose,
85 cmd="ssh-keygen -y -f ~root/.ssh/id_rsa > ~root/.ssh/id_rsa.pub")
86 underlay.check_call(
87 node_name=cfg_node, verbose=verbose,
88 cmd='maas mirantis sshkeys create '
89 'key="$(cat ~root/.ssh/id_rsa.pub)"')
90
91 r, f = day1_cfg_config.salt.enforce_state('cfg01*', 'maas.machines')
92 LOG.info(r)
93 LOG.info(f)
94
95 # show_step(8)
Dmitry Tyzhnenko468564a2018-08-23 16:39:06 +030096 # nodes_amount = len(hardware.slave_nodes)
97 # 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 {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
98 cmd = """salt-call state.sls maas.machines.wait_for_ready"""
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +020099 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
100 underlay.check_call(node_name=cfg_node, verbose=verbose,
101 cmd='salt-key')
Dmitry Tyzhnenko468564a2018-08-23 16:39:06 +0300102
103 r, f = day1_cfg_config.salt.enforce_state(
104 'cfg01*',
105 'maas.machines.assign_ip')
106 LOG.info(r)
107 LOG.info(f)
108
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200109 r, f = day1_cfg_config.salt.enforce_state(
110 'cfg01*',
111 'maas.machines.storage')
112 LOG.info(r)
113 LOG.info(f)
114
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200115 # show_step(9)
116 underlay.check_call(
117 node_name=cfg_node, verbose=verbose,
118 cmd='salt-call state.sls maas.machines.deploy')
119 # show_step(10)
120 underlay.check_call(
121 node_name=cfg_node, verbose=verbose,
122 cmd='salt-call state.sls maas.machines.wait_for_deployed')
123 underlay.check_call(node_name=cfg_node, verbose=verbose,
124 cmd='salt-key')
125
126 underlay.check_call(
127 node_name=cfg_node,
128 verbose=verbose,
129 cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key))
130 underlay.check_call(
131 node_name=cfg_node,
132 verbose=verbose,
133 cmd='salt "*" ssh.set_auth_key root '
134 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
135
136 underlay.check_call(
137 node_name=cfg_node,
138 verbose=verbose,
139 cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key))
140 underlay.check_call(
141 node_name=cfg_node,
142 verbose=verbose,
143 cmd='salt "*" ssh.set_auth_key ubuntu '
144 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
145
146 result = \
147 day1_cfg_config.salt.get_pillar(cfg_node,
148 '_param:jenkins_salt_api_url')
149 result = result[0].get(cfg_node)
150
151 jenkins = JenkinsClient(
152 host='http://{host}:8081'.format(
153 host=day1_cfg_config.config.salt.salt_master_host),
154 username='admin',
155 password='r00tme')
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300156 params = jenkins.make_defaults_params('deploy_openstack')
Dmitry Tyzhnenko35413c02018-03-05 14:12:37 +0200157 params['SALT_MASTER_URL'] = result
158 params['STACK_INSTALL'] = "core,openstack,ovs"
159 build = jenkins.run_build('deploy_openstack', params)
160
161 jenkins.wait_end_of_build(
162 name=build[0],
163 build_id=build[1],
164 timeout=60 * 60 * 2)
165
166 assert \
167 jenkins.build_info(
168 name=build[0], build_id=build[1])['result'] == 'SUCCESS', \
169 "Deploy openstack was failed"
170
171 openstack = managers.openstack_manager.OpenstackManager(
172 day1_cfg_config.config, underlay, hardware,
173 day1_cfg_config.salt)
174
175 if settings.RUN_TEMPEST:
176 openstack.run_tempest(pattern=settings.PATTERN)
177 openstack.download_tempest_report()
178
179 LOG.info("*************** DONE **************")
180
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200181 def test_deploy_day1_pike(self, show_step, config, underlay, hardware,
182 core_deployed, salt_deployed, tempest_actions):
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200183 """Test for deploying an mcp from day01 images
184
185 Scenario:
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200186 1. Wait salt master
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200187 2. Run deploy OS job
188 3. Add test and root keys
189 2. Run deploy CVP sanity job
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200190
191 """
192 # group = hardware._get_default_node_group()
193 nodes = underlay.node_names()
194 LOG.info("Nodes - {}".format(nodes))
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200195 cfg_node = 'cfg01.mcp-offline-vxlan.local'
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200196 verbose = True
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200197 ssh_test_key = config.underlay.ssh_keys[0]['public']
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200198
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200199 show_step(1)
200 underlay.check_call(
201 node_name=cfg_node,
202 verbose=verbose,
203 cmd="""timeout 300s /bin/bash -c """
204 """'while ! salt-call test.ping; do """
205 """echo "salt master still isnt running"; sleep 10; done'"""
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200206 )
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200207
208 show_step(2)
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200209
210 salt_api = \
211 salt_deployed.get_pillar(cfg_node, '_param:jenkins_salt_api_url')
212 salt_api = salt_api[0].get(cfg_node)
213
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200214 jenkins = JenkinsClient(
215 host='http://172.16.44.33:8081',
216 username='admin',
217 password='r00tme')
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300218 params = jenkins.make_defaults_params('deploy_openstack')
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200219 params['SALT_MASTER_URL'] = salt_api
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200220 if settings.STACK_INSTALL:
221 params['STACK_INSTALL'] = settings.STACK_INSTALL
222 else:
223 params['STACK_INSTALL'] = \
224 'core,kvm,ceph,cicd,ovs,openstack,stacklight,finalize'
225 params['STATIC_MGMT_NETWORK'] = 'true'
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200226 build = jenkins.run_build('deploy_openstack', params)
227
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200228 LOG.info("Take a look deploy progress here - %s. Build #%s",
229 "http://172.16.44.33:8081/job/deploy_openstack/", build[1])
230
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200231 jenkins.wait_end_of_build(
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200232 name=build[0], build_id=build[1], timeout=60 * 60 * 5)
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200233
234 with open("{path}/cfg01_jenkins_deploy_openstack_console.log".format(
235 path=settings.LOGS_DIR), 'w') as f:
236 LOG.info("Save jenkins console log")
237 console_log = \
238 jenkins.get_build_output('deploy_openstack', build[1])
239 f.write(console_log)
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200240
241 assert \
242 jenkins.build_info(
243 name=build[0], build_id=build[1])['result'] == 'SUCCESS', \
244 "Deploy openstack was failed"
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200245
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200246 show_step(3)
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200247 underlay.check_call(
248 node_name=cfg_node,
249 verbose=verbose,
250 cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key))
251 underlay.check_call(
252 node_name=cfg_node,
253 verbose=verbose,
254 cmd='salt "*" ssh.set_auth_key root '
255 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
256 underlay.check_call(
257 node_name=cfg_node,
258 verbose=verbose,
259 cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key))
260 underlay.check_call(
261 node_name=cfg_node,
262 verbose=verbose,
263 cmd='salt "*" ssh.set_auth_key ubuntu '
264 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
265
Dennis Dmitriev83cc1d52018-11-09 15:35:30 +0200266 salt_deployed.update_ssh_data_from_minions()
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200267
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200268 show_step(4)
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200269 try:
270 maas_minion_id = salt_deployed.get_single_pillar(
271 tgt='I@maas:cluster or I@maas:region',
272 pillar="__reclass__:nodename")
273 ntp_skipped_nodes = 'ntp_skipped_nodes={0}'.format(maas_minion_id)
274 except LookupError:
275 ntp_skipped_nodes = ''
Dennis Dmitrieva51b89d2019-03-05 21:49:07 +0200276
Hanna Arhipova874c68f2021-03-29 15:57:19 +0300277 params = jenkins.make_defaults_params('cvp-sanity')
Dennis Dmitrieva51b89d2019-03-05 21:49:07 +0200278 params['TESTS_SETTINGS'] = (
Dennis Dmitriev85c52492019-03-12 15:26:56 +0200279 'drivetrain_version={0};{1}'
280 .format(settings.MCP_VERSION, ntp_skipped_nodes))
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200281 build = jenkins.run_build('cvp-sanity', params)
282 LOG.info("Take a look test progress here - %s. Build #%s",
283 "http://172.16.44.33:8081/job/cvp-sanity/", build[1])
284
285 jenkins.wait_end_of_build(
286 name=build[0], build_id=build[1], timeout=60 * 60 * 5)
287
288 assert \
289 jenkins.build_info(
290 name=build[0], build_id=build[1])['result'] == 'SUCCESS', \
291 "CVP sanity was failed"
292
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200293 time.sleep(120) # debug sleep
294 cmd = "salt '*' test.ping"
295 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
296
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200297 if settings.RUN_TEMPEST:
Dmitry Tyzhnenko80ce0202019-02-07 13:27:19 +0200298 pillar = tempest_actions.runtest_pillar
299 params = [
300 'glance_image_cirros_location',
301 'glance_image_fedora_location',
302 'glance_image_manila_location']
303
304 urls = []
305 for p in params:
306 url = pillar.get('parameters', {}).get('_param', {}).get(p)
307 if url:
308 urls.append(url)
309
310 LOG.info("Found url with images - %s", urls)
311
312 hosts = set()
313 hosts.add(settings.TEMPEST_IMAGE.split('/')[0])
314 for u in urls:
315 host = urlparse.urlparse(u)
316 hosts.add(host.netloc.split(':')[0]) # drop port if exists
317
318 records = []
319 for h in hosts:
320 ip = socket.gethostbyname(h)
321 records.append((ip, h))
322
323 for ip, h in records:
324 salt_deployed.local(cfg_node, 'hosts.add_host', args=(ip, h))
325
326 tempest_actions.prepare_and_run_tempest()
327
328 test_deploy_day1_queens = test_deploy_day1_pike