Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 1 | # 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 Tyzhnenko | 35413c0 | 2018-03-05 14:12:37 +0200 | [diff] [blame] | 14 | import pytest |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 15 | import time |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 16 | import socket |
| 17 | import urlparse |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 18 | |
| 19 | from tcp_tests import logger |
| 20 | from tcp_tests.managers.jenkins.client import JenkinsClient |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 21 | from tcp_tests import settings |
| 22 | |
| 23 | from tcp_tests import managers |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 24 | |
| 25 | LOG = logger.logger |
| 26 | |
| 27 | |
| 28 | class TestOfflineDeployment(object): |
| 29 | """docstring for TestOfflineDeployment""" |
| 30 | |
Dmitry Tyzhnenko | 35413c0 | 2018-03-05 14:12:37 +0200 | [diff] [blame] | 31 | @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) |
Dmitry Tyzhnenko | 468564a | 2018-08-23 16:39:06 +0300 | [diff] [blame] | 93 | # nodes_amount = len(hardware.slave_nodes) |
| 94 | # 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 |
| 95 | cmd = """salt-call state.sls maas.machines.wait_for_ready""" |
Dmitry Tyzhnenko | 35413c0 | 2018-03-05 14:12:37 +0200 | [diff] [blame] | 96 | underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd) |
| 97 | underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 98 | cmd='salt-key') |
Dmitry Tyzhnenko | 468564a | 2018-08-23 16:39:06 +0300 | [diff] [blame] | 99 | |
| 100 | r, f = day1_cfg_config.salt.enforce_state( |
| 101 | 'cfg01*', |
| 102 | 'maas.machines.assign_ip') |
| 103 | LOG.info(r) |
| 104 | LOG.info(f) |
| 105 | |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 106 | r, f = day1_cfg_config.salt.enforce_state( |
| 107 | 'cfg01*', |
| 108 | 'maas.machines.storage') |
| 109 | LOG.info(r) |
| 110 | LOG.info(f) |
| 111 | |
Dmitry Tyzhnenko | 35413c0 | 2018-03-05 14:12:37 +0200 | [diff] [blame] | 112 | # show_step(9) |
| 113 | underlay.check_call( |
| 114 | node_name=cfg_node, verbose=verbose, |
| 115 | cmd='salt-call state.sls maas.machines.deploy') |
| 116 | # show_step(10) |
| 117 | underlay.check_call( |
| 118 | node_name=cfg_node, verbose=verbose, |
| 119 | cmd='salt-call state.sls maas.machines.wait_for_deployed') |
| 120 | underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 121 | cmd='salt-key') |
| 122 | |
| 123 | underlay.check_call( |
| 124 | node_name=cfg_node, |
| 125 | verbose=verbose, |
| 126 | cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key)) |
| 127 | underlay.check_call( |
| 128 | node_name=cfg_node, |
| 129 | verbose=verbose, |
| 130 | cmd='salt "*" ssh.set_auth_key root ' |
| 131 | '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"') |
| 132 | |
| 133 | underlay.check_call( |
| 134 | node_name=cfg_node, |
| 135 | verbose=verbose, |
| 136 | cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key)) |
| 137 | underlay.check_call( |
| 138 | node_name=cfg_node, |
| 139 | verbose=verbose, |
| 140 | cmd='salt "*" ssh.set_auth_key ubuntu ' |
| 141 | '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"') |
| 142 | |
| 143 | result = \ |
| 144 | day1_cfg_config.salt.get_pillar(cfg_node, |
| 145 | '_param:jenkins_salt_api_url') |
| 146 | result = result[0].get(cfg_node) |
| 147 | |
| 148 | jenkins = JenkinsClient( |
| 149 | host='http://{host}:8081'.format( |
| 150 | host=day1_cfg_config.config.salt.salt_master_host), |
| 151 | username='admin', |
| 152 | password='r00tme') |
| 153 | params = jenkins.make_defults_params('deploy_openstack') |
| 154 | params['SALT_MASTER_URL'] = result |
| 155 | params['STACK_INSTALL'] = "core,openstack,ovs" |
| 156 | build = jenkins.run_build('deploy_openstack', params) |
| 157 | |
| 158 | jenkins.wait_end_of_build( |
| 159 | name=build[0], |
| 160 | build_id=build[1], |
| 161 | timeout=60 * 60 * 2) |
| 162 | |
| 163 | assert \ |
| 164 | jenkins.build_info( |
| 165 | name=build[0], build_id=build[1])['result'] == 'SUCCESS', \ |
| 166 | "Deploy openstack was failed" |
| 167 | |
| 168 | openstack = managers.openstack_manager.OpenstackManager( |
| 169 | day1_cfg_config.config, underlay, hardware, |
| 170 | day1_cfg_config.salt) |
| 171 | |
| 172 | if settings.RUN_TEMPEST: |
| 173 | openstack.run_tempest(pattern=settings.PATTERN) |
| 174 | openstack.download_tempest_report() |
| 175 | |
| 176 | LOG.info("*************** DONE **************") |
| 177 | |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 178 | def test_deploy_day1_pike(self, show_step, config, underlay, hardware, |
| 179 | core_deployed, salt_deployed, tempest_actions): |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 180 | """Test for deploying an mcp from day01 images |
| 181 | |
| 182 | Scenario: |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 183 | 1. Wait salt master |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 184 | 2. Run deploy OS job |
| 185 | 3. Add test and root keys |
| 186 | 2. Run deploy CVP sanity job |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 187 | |
| 188 | """ |
| 189 | # group = hardware._get_default_node_group() |
| 190 | nodes = underlay.node_names() |
| 191 | LOG.info("Nodes - {}".format(nodes)) |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 192 | cfg_node = 'cfg01.mcp-offline-vxlan.local' |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 193 | verbose = True |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 194 | ssh_test_key = config.underlay.ssh_keys[0]['public'] |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 195 | |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 196 | show_step(1) |
| 197 | underlay.check_call( |
| 198 | node_name=cfg_node, |
| 199 | verbose=verbose, |
| 200 | cmd="""timeout 300s /bin/bash -c """ |
| 201 | """'while ! salt-call test.ping; do """ |
| 202 | """echo "salt master still isnt running"; sleep 10; done'""" |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 203 | ) |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 204 | |
| 205 | show_step(2) |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 206 | |
| 207 | salt_api = \ |
| 208 | salt_deployed.get_pillar(cfg_node, '_param:jenkins_salt_api_url') |
| 209 | salt_api = salt_api[0].get(cfg_node) |
| 210 | |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 211 | jenkins = JenkinsClient( |
| 212 | host='http://172.16.44.33:8081', |
| 213 | username='admin', |
| 214 | password='r00tme') |
| 215 | params = jenkins.make_defults_params('deploy_openstack') |
| 216 | params['SALT_MASTER_URL'] = salt_api |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 217 | if settings.STACK_INSTALL: |
| 218 | params['STACK_INSTALL'] = settings.STACK_INSTALL |
| 219 | else: |
| 220 | params['STACK_INSTALL'] = \ |
| 221 | 'core,kvm,ceph,cicd,ovs,openstack,stacklight,finalize' |
| 222 | params['STATIC_MGMT_NETWORK'] = 'true' |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 223 | build = jenkins.run_build('deploy_openstack', params) |
| 224 | |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 225 | LOG.info("Take a look deploy progress here - %s. Build #%s", |
| 226 | "http://172.16.44.33:8081/job/deploy_openstack/", build[1]) |
| 227 | |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 228 | jenkins.wait_end_of_build( |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 229 | name=build[0], build_id=build[1], timeout=60 * 60 * 5) |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 230 | |
| 231 | with open("{path}/cfg01_jenkins_deploy_openstack_console.log".format( |
| 232 | path=settings.LOGS_DIR), 'w') as f: |
| 233 | LOG.info("Save jenkins console log") |
| 234 | console_log = \ |
| 235 | jenkins.get_build_output('deploy_openstack', build[1]) |
| 236 | f.write(console_log) |
Dmitry Tyzhnenko | 5a5d8da | 2017-12-14 14:14:42 +0200 | [diff] [blame] | 237 | |
| 238 | assert \ |
| 239 | jenkins.build_info( |
| 240 | name=build[0], build_id=build[1])['result'] == 'SUCCESS', \ |
| 241 | "Deploy openstack was failed" |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 242 | |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 243 | show_step(3) |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 244 | underlay.check_call( |
| 245 | node_name=cfg_node, |
| 246 | verbose=verbose, |
| 247 | cmd="salt '*' ssh.set_auth_key root '{}'".format(ssh_test_key)) |
| 248 | underlay.check_call( |
| 249 | node_name=cfg_node, |
| 250 | verbose=verbose, |
| 251 | cmd='salt "*" ssh.set_auth_key root ' |
| 252 | '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"') |
| 253 | underlay.check_call( |
| 254 | node_name=cfg_node, |
| 255 | verbose=verbose, |
| 256 | cmd="salt '*' ssh.set_auth_key ubuntu '{}'".format(ssh_test_key)) |
| 257 | underlay.check_call( |
| 258 | node_name=cfg_node, |
| 259 | verbose=verbose, |
| 260 | cmd='salt "*" ssh.set_auth_key ubuntu ' |
| 261 | '"$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)"') |
| 262 | |
Dennis Dmitriev | 83cc1d5 | 2018-11-09 15:35:30 +0200 | [diff] [blame] | 263 | salt_deployed.update_ssh_data_from_minions() |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 264 | |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 265 | show_step(4) |
Dennis Dmitriev | 85c5249 | 2019-03-12 15:26:56 +0200 | [diff] [blame] | 266 | try: |
| 267 | maas_minion_id = salt_deployed.get_single_pillar( |
| 268 | tgt='I@maas:cluster or I@maas:region', |
| 269 | pillar="__reclass__:nodename") |
| 270 | ntp_skipped_nodes = 'ntp_skipped_nodes={0}'.format(maas_minion_id) |
| 271 | except LookupError: |
| 272 | ntp_skipped_nodes = '' |
Dennis Dmitriev | a51b89d | 2019-03-05 21:49:07 +0200 | [diff] [blame] | 273 | |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 274 | params = jenkins.make_defults_params('cvp-sanity') |
Dennis Dmitriev | a51b89d | 2019-03-05 21:49:07 +0200 | [diff] [blame] | 275 | params['TESTS_SETTINGS'] = ( |
Dennis Dmitriev | 85c5249 | 2019-03-12 15:26:56 +0200 | [diff] [blame] | 276 | 'drivetrain_version={0};{1}' |
| 277 | .format(settings.MCP_VERSION, ntp_skipped_nodes)) |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 278 | build = jenkins.run_build('cvp-sanity', params) |
| 279 | LOG.info("Take a look test progress here - %s. Build #%s", |
| 280 | "http://172.16.44.33:8081/job/cvp-sanity/", build[1]) |
| 281 | |
| 282 | jenkins.wait_end_of_build( |
| 283 | name=build[0], build_id=build[1], timeout=60 * 60 * 5) |
| 284 | |
| 285 | assert \ |
| 286 | jenkins.build_info( |
| 287 | name=build[0], build_id=build[1])['result'] == 'SUCCESS', \ |
| 288 | "CVP sanity was failed" |
| 289 | |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 290 | time.sleep(120) # debug sleep |
| 291 | cmd = "salt '*' test.ping" |
| 292 | underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd) |
| 293 | |
Dmitry Tyzhnenko | b610afd | 2018-02-19 15:43:45 +0200 | [diff] [blame] | 294 | if settings.RUN_TEMPEST: |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 295 | pillar = tempest_actions.runtest_pillar |
| 296 | params = [ |
| 297 | 'glance_image_cirros_location', |
| 298 | 'glance_image_fedora_location', |
| 299 | 'glance_image_manila_location'] |
| 300 | |
| 301 | urls = [] |
| 302 | for p in params: |
| 303 | url = pillar.get('parameters', {}).get('_param', {}).get(p) |
| 304 | if url: |
| 305 | urls.append(url) |
| 306 | |
| 307 | LOG.info("Found url with images - %s", urls) |
| 308 | |
| 309 | hosts = set() |
| 310 | hosts.add(settings.TEMPEST_IMAGE.split('/')[0]) |
| 311 | for u in urls: |
| 312 | host = urlparse.urlparse(u) |
| 313 | hosts.add(host.netloc.split(':')[0]) # drop port if exists |
| 314 | |
| 315 | records = [] |
| 316 | for h in hosts: |
| 317 | ip = socket.gethostbyname(h) |
| 318 | records.append((ip, h)) |
| 319 | |
| 320 | for ip, h in records: |
| 321 | salt_deployed.local(cfg_node, 'hosts.add_host', args=(ip, h)) |
| 322 | |
| 323 | tempest_actions.prepare_and_run_tempest() |
| 324 | |
| 325 | test_deploy_day1_queens = test_deploy_day1_pike |