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. |
| 14 | # import pytest |
| 15 | |
| 16 | from tcp_tests import logger |
| 17 | from tcp_tests.managers.jenkins.client import JenkinsClient |
| 18 | |
| 19 | LOG = logger.logger |
| 20 | |
| 21 | |
| 22 | class TestOfflineDeployment(object): |
| 23 | """docstring for TestOfflineDeployment""" |
| 24 | |
| 25 | def test_deploy_day1(self, show_step, underlay, common_services_deployed, |
| 26 | salt_deployed): |
| 27 | """Test for deploying an mcp from day01 images |
| 28 | |
| 29 | Scenario: |
| 30 | 1. Approve local ssh key to jenkins |
| 31 | 2. Boot CFG and APT virtual machines |
| 32 | 3. Setup jq |
| 33 | 4. Wait salt master |
| 34 | 5. Addition config of MaaS |
| 35 | 6. Wait dhcpd server |
| 36 | 7. Start comissioning node via MaaS |
| 37 | 8. Wait of comissioning node by MaaS |
| 38 | 9. Start deploing node via MaaS |
| 39 | 10. Wait of deploing node by |
| 40 | 11. Accept all keys |
| 41 | 12. Run deploy OS job |
| 42 | |
| 43 | """ |
| 44 | # group = hardware._get_default_node_group() |
| 45 | nodes = underlay.node_names() |
| 46 | LOG.info("Nodes - {}".format(nodes)) |
| 47 | cfg_node = 'cfg01.offline-ocata-vxlan.local' |
| 48 | verbose = True |
| 49 | |
| 50 | # show_step(1) |
| 51 | # cmd = ("mkdir -p /var/lib/jenkins/.ssh && " |
| 52 | # "ssh-keyscan cfg01 > /var/lib/jenkins/.ssh/known_hosts && " |
| 53 | # "chown jenkins /var/lib/jenkins/.ssh/known_hosts") |
| 54 | # underlay.check_call( |
| 55 | # node_name=cfg_node, verbose=verbose, |
| 56 | # cmd=cmd) |
| 57 | |
| 58 | # show_step(2) |
| 59 | # underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 60 | # cmd='salt-key') |
| 61 | |
| 62 | # show_step(3) |
| 63 | # underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 64 | # cmd='apt install -y jq') |
| 65 | |
| 66 | show_step(4) |
| 67 | underlay.check_call( |
| 68 | node_name=cfg_node, |
| 69 | verbose=verbose, |
| 70 | cmd="""timeout 300s /bin/bash -c 'while ! salt-call test.ping; do echo "salt master still isnt running"; sleep 10; done'""") # noqa |
| 71 | |
| 72 | show_step(5) |
| 73 | underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 74 | cmd='salt-call saltutil.sync_all') |
| 75 | underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 76 | cmd='salt-call state.sls maas.region') |
| 77 | underlay.check_call( |
| 78 | node_name=cfg_node, verbose=verbose, |
| 79 | cmd='maas logout mirantis && ' |
| 80 | 'maas login mirantis ' |
| 81 | 'http://localhost/MAAS/api/2.0/ ' |
| 82 | 'FTvqwe7ybBp68gPar2:5mcctTAXVL8mns4ef4:zrA9LZwu2tMc8BAZpsPUfwWwTyQnAtDN') # noqa |
| 83 | |
| 84 | underlay.check_call( |
| 85 | node_name=cfg_node, verbose=verbose, |
| 86 | cmd="maas mirantis ipranges create " |
| 87 | "type=dynamic start_ip=10.10.191.255 end_ip=10.10.255.254 " |
| 88 | "subnet=$(maas mirantis subnets read | jq '.[] | select(.name==\"10.10.0.0/16\") | .id')") # noqa |
| 89 | underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 90 | cmd="maas mirantis vlan update " |
| 91 | "$(maas mirantis subnets read | jq '.[] | select(.name==\"10.10.0.0/16\") | .vlan.fabric_id') " # noqa |
| 92 | "0 dhcp_on=True primary_rack='cfg01'") |
| 93 | |
| 94 | underlay.check_call( |
| 95 | node_name=cfg_node, verbose=verbose, |
| 96 | cmd="ssh-keygen -y -f ~root/.ssh/id_rsa > ~root/.ssh/id_rsa.pub") |
| 97 | underlay.check_call( |
| 98 | node_name=cfg_node, verbose=verbose, |
| 99 | cmd='maas mirantis sshkeys create ' |
| 100 | 'key="$(cat ~root/.ssh/id_rsa.pub)"') |
| 101 | |
| 102 | show_step(6) |
| 103 | underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 104 | cmd="""timeout 90s /bin/bash -c 'while ! pidof dhcpd; do echo "dhcpd still isnt running"; sleep 10; done'""") # noqa |
| 105 | |
| 106 | show_step(7) |
| 107 | underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 108 | cmd='salt-call state.sls maas.machines') |
| 109 | show_step(8) |
| 110 | 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 |
| 111 | underlay.check_call(node_name=cfg_node, verbose=verbose, cmd=cmd) |
| 112 | underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 113 | cmd='salt-key') |
| 114 | show_step(9) |
| 115 | underlay.check_call( |
| 116 | node_name=cfg_node, verbose=verbose, |
| 117 | cmd='salt-call state.sls maas.machines.deploy') |
| 118 | show_step(10) |
| 119 | underlay.check_call( |
| 120 | node_name=cfg_node, verbose=verbose, |
| 121 | cmd='salt-call state.sls maas.machines.wait_for_deployed') |
| 122 | underlay.check_call(node_name=cfg_node, verbose=verbose, |
| 123 | cmd='salt-key') |
| 124 | |
| 125 | show_step(11) |
| 126 | underlay.check_call( |
| 127 | node_name=cfg_node, verbose=verbose, expected=[0, 1], |
| 128 | cmd='salt-key -A -y --include-denied --include-rejected') |
| 129 | underlay.check_call( |
| 130 | node_name=cfg_node, verbose=verbose, |
| 131 | cmd='salt-key') |
| 132 | |
| 133 | salt_api = \ |
| 134 | salt_deployed.get_pillar(cfg_node, '_param:jenkins_salt_api_url') |
| 135 | salt_api = salt_api[0].get(cfg_node) |
| 136 | |
| 137 | show_step(12) |
| 138 | jenkins = JenkinsClient( |
| 139 | host='http://172.16.44.33:8081', |
| 140 | username='admin', |
| 141 | password='r00tme') |
| 142 | params = jenkins.make_defults_params('deploy_openstack') |
| 143 | params['SALT_MASTER_URL'] = salt_api |
| 144 | build = jenkins.run_build('deploy_openstack', params) |
| 145 | |
| 146 | jenkins.wait_end_of_build( |
| 147 | name=build[0], |
| 148 | build_id=build[1], |
| 149 | timeout=60 * 60 * 2) |
| 150 | |
| 151 | assert \ |
| 152 | jenkins.build_info( |
| 153 | name=build[0], build_id=build[1])['result'] == 'SUCCESS', \ |
| 154 | "Deploy openstack was failed" |