blob: 51757fd881798acdf58a71b2a71087d7831a6b06 [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.
14# import 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 Tyzhnenkob610afd2018-02-19 15:43:45 +020031 def test_deploy_day1(self, show_step, config, underlay, hardware,
32 common_services_deployed, salt_deployed):
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020033 """Test for deploying an mcp from day01 images
34
35 Scenario:
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +020036 1. Wait salt master
37 2. Addition config of MaaS
38 3. Wait dhcpd server
39 4. Start comissioning node via MaaS
40 5. Wait of comissioning node by MaaS
41 6. Start deploing node via MaaS
42 7. Wait of deploing node by
43 8. Accept all keys
44 9. Configure and baremetal nodes after MaaS deployment
45 10. Run deploy OS job
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020046
47 """
48 # group = hardware._get_default_node_group()
49 nodes = underlay.node_names()
50 LOG.info("Nodes - {}".format(nodes))
51 cfg_node = 'cfg01.offline-ocata-vxlan.local'
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +020052 tempest_node = 'gtw01.offline-ocata-vxlan.local'
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020053 verbose = True
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +020054 ssh_test_key = config.underlay.ssh_keys[0]['public']
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +020055
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +020056 show_step(1)
57 underlay.check_call(
58 node_name=cfg_node,
59 verbose=verbose,
60 cmd="""timeout 300s /bin/bash -c """
61 """'while ! salt-call test.ping; do """
62 """echo "salt master still isnt running"; sleep 10; done'"""
63 ) # noqa
64
65 show_step(2)
66 underlay.check_call(
67 node_name=cfg_node,
68 verbose=verbose,
69 cmd='salt-call saltutil.sync_all')
70
71 underlay.check_call(
72 node_name=cfg_node,
73 verbose=verbose,
74 cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key))
75 underlay.check_call(
76 node_name=cfg_node,
77 verbose=verbose,
78 cmd='salt "*" ssh.set_auth_key root '
79 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
80 underlay.check_call(
81 node_name=cfg_node,
82 verbose=verbose,
83 cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key))
84 underlay.check_call(
85 node_name=cfg_node,
86 verbose=verbose,
87 cmd='salt "*" ssh.set_auth_key ubuntu '
88 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
89
90 underlay.check_call(
91 node_name=cfg_node,
92 verbose=verbose,
93 cmd='salt-call state.sls maas.region')
94 underlay.check_call(
95 node_name=cfg_node,
96 verbose=verbose,
97 cmd='maas logout mirantis && '
98 'maas login mirantis '
99 'http://localhost:5240/MAAS/api/2.0/ '
100 'FTvqwe7ybBp68gPar2:5mcctTAXVL8mns4ef4:zrA9LZwu2tMc8BAZpsPUfwWwTyQnAtDN' # noqa
101 )
102
103 underlay.check_call(
104 node_name=cfg_node,
105 verbose=verbose,
106 cmd="maas mirantis maas set-config "
107 "name=upstream_dns value='10.10.0.15 8.8.8.8 8.8.4.4'")
108
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200109 # underlay.check_call(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200110 # node_name=cfg_node,
111 # verbose=verbose,
112 # cmd="maas mirantis ipranges create "
113 # "type=dynamic start_ip=10.10.191.255 end_ip=10.10.255.254 "
114 # "subnet=$(maas mirantis subnets read | jq '.[] | "
115 # "select(.name==\"10.10.0.0/16\") | .id')")
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200116
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200117 underlay.check_call(
118 node_name=cfg_node,
119 verbose=verbose,
120 cmd="maas mirantis vlan update "
121 "$(maas mirantis subnets read | jq '.[] | "
122 "select(.name==\"10.10.0.0/16\") | .vlan.fabric_id') "
123 "0 dhcp_on=True primary_rack='cfg01'")
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200124
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200125 underlay.check_call(
126 node_name=cfg_node,
127 verbose=verbose,
128 cmd="ssh-keygen -y -f ~root/.ssh/id_rsa > ~root/.ssh/id_rsa.pub")
129 underlay.check_call(
130 node_name=cfg_node,
131 verbose=verbose,
132 cmd='maas mirantis sshkeys create '
133 'key="$(cat ~root/.ssh/id_rsa.pub)"')
134
135 show_step(3)
136 underlay.check_call(
137 node_name=cfg_node,
138 verbose=verbose,
139 cmd="""timeout 90s /bin/bash -c 'while ! pidof dhcpd; do """
140 """echo "dhcpd still isnt running"; sleep 10; done'""")
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200141
142 show_step(4)
143 underlay.check_call(
144 node_name=cfg_node,
145 verbose=verbose,
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200146 cmd='salt-call state.sls maas.machines')
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200147 show_step(5)
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200148 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 +0200149 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200150 underlay.check_call(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200151 node_name=cfg_node, verbose=verbose, cmd='salt-key')
152 underlay.check_call(
153 node_name=cfg_node,
154 verbose=verbose,
155 cmd='salt-call state.sls maas.machines.assign_ip')
156 show_step(6)
157 underlay.check_call(
158 node_name=cfg_node,
159 verbose=verbose,
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200160 cmd='salt-call state.sls maas.machines.deploy')
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200161 show_step(7)
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200162 underlay.check_call(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200163 node_name=cfg_node,
164 verbose=verbose,
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200165 cmd='salt-call state.sls maas.machines.wait_for_deployed')
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200166 underlay.check_call(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200167 node_name=cfg_node, verbose=verbose, cmd='salt-key')
168
169 show_step(8)
170 underlay.check_call(
171 node_name=cfg_node,
172 verbose=verbose,
173 expected=[0, 1],
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200174 cmd='salt-key -A -y --include-denied --include-rejected')
175 underlay.check_call(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200176 node_name=cfg_node, verbose=verbose, cmd='salt-key')
177
178 show_step(9)
179 cmd = "salt '*' saltutil.refresh_pillar"
180 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
181 cmd = "salt '*' saltutil.sync_all"
182 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
183
184 underlay.check_call(
185 node_name=cfg_node, verbose=verbose, cmd="reclass-salt --top")
186
187 cmd = "salt -C " \
188 "'I@salt:control or I@nova:compute or I@neutron:gateway' " \
189 "cmd.run 'touch /run/is_rebooted'"
190 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
191
192 cmd = "salt --async -C " \
193 "'I@salt:control' cmd.run 'salt-call state.sls " \
194 "linux.system.user,openssh,linux.network;reboot'"
195 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
196
197 cmd = "salt --async -C " \
198 "'I@nova:compute' cmd.run 'salt-call state.sls " \
199 "linux.system.user,openssh,linux.network;reboot'"
200 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
201
202 cmd = "salt --async -C " \
203 "'I@neutron:gateway' cmd.run 'salt-call state.sls " \
204 "linux.system.user,openssh,linux.network;reboot'"
205 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
206
207 time.sleep(360) # TODO: Add ssh waiter
208
209 cmd = "salt -C " \
210 "'I@salt:control or I@nova:compute or I@neutron:gateway'" \
211 " test.ping"
212 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
213
214 cmd = """salt -C """ \
215 """'I@salt:control or I@nova:compute or I@neutron:gateway' """ \
216 """cmd.run '[ -f "/run/is_rebooted" ] && """ \
217 """echo "Has not been rebooted!" || echo "Rebooted"' """
218 ret = underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
219 count = Counter(ret['stdout_str'].split())
220
221 assert count['Rebooted'] == 10, "Should be rebooted 10 baremetal nodes"
222
223 underlay.check_call(
224 node_name=cfg_node,
225 verbose=verbose,
226 cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key))
227 underlay.check_call(
228 node_name=cfg_node,
229 verbose=verbose,
230 cmd='salt "*" ssh.set_auth_key root '
231 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
232 underlay.check_call(
233 node_name=cfg_node,
234 verbose=verbose,
235 cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key))
236 underlay.check_call(
237 node_name=cfg_node,
238 verbose=verbose,
239 cmd='salt "*" ssh.set_auth_key ubuntu '
240 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200241
242 salt_api = \
243 salt_deployed.get_pillar(cfg_node, '_param:jenkins_salt_api_url')
244 salt_api = salt_api[0].get(cfg_node)
245
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200246 show_step(10)
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200247 jenkins = JenkinsClient(
248 host='http://172.16.44.33:8081',
249 username='admin',
250 password='r00tme')
251 params = jenkins.make_defults_params('deploy_openstack')
252 params['SALT_MASTER_URL'] = salt_api
253 build = jenkins.run_build('deploy_openstack', params)
254
255 jenkins.wait_end_of_build(
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200256 name=build[0], build_id=build[1], timeout=60 * 60 * 2)
257
258 with open("{path}/cfg01_jenkins_deploy_openstack_console.log".format(
259 path=settings.LOGS_DIR), 'w') as f:
260 LOG.info("Save jenkins console log")
261 console_log = \
262 jenkins.get_build_output('deploy_openstack', build[1])
263 f.write(console_log)
Dmitry Tyzhnenko5a5d8da2017-12-14 14:14:42 +0200264
265 assert \
266 jenkins.build_info(
267 name=build[0], build_id=build[1])['result'] == 'SUCCESS', \
268 "Deploy openstack was failed"
Dmitry Tyzhnenkob610afd2018-02-19 15:43:45 +0200269
270 underlay.check_call(
271 node_name=cfg_node,
272 verbose=verbose,
273 cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key))
274 underlay.check_call(
275 node_name=cfg_node,
276 verbose=verbose,
277 cmd='salt "*" ssh.set_auth_key root '
278 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
279 underlay.check_call(
280 node_name=cfg_node,
281 verbose=verbose,
282 cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key))
283 underlay.check_call(
284 node_name=cfg_node,
285 verbose=verbose,
286 cmd='salt "*" ssh.set_auth_key ubuntu '
287 '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"')
288
289 salt_nodes = salt_deployed.get_ssh_data()
290 nodes_list = \
291 [node for node in salt_nodes
292 if not any(node['node_name'] == n['node_name']
293 for n in config.underlay.ssh)]
294 config.underlay.ssh = config.underlay.ssh + nodes_list
295 underlay.add_config_ssh(nodes_list)
296
297 time.sleep(120) # debug sleep
298 cmd = "salt '*' test.ping"
299 underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd)
300
301 openstack = managers.openstack_manager.OpenstackManager(
302 config, underlay, hardware, salt_deployed)
303
304 if settings.RUN_TEMPEST:
305 openstack.run_tempest(
306 pattern=settings.PATTERN,
307 node_name=tempest_node)
308 openstack.download_tempest_report()