Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 1 | import pytest |
| 2 | |
| 3 | from tcp_tests import logger |
| 4 | |
| 5 | LOG = logger.logger |
| 6 | |
Hanna Arhipova | d60430e | 2021-02-12 18:23:47 +0200 | [diff] [blame^] | 7 | xtra_network_interface = """ |
| 8 | parameters: |
| 9 | _param: |
| 10 | linux_network_interfaces: |
| 11 | br_ctl: |
| 12 | address: ${_param:single_address} |
| 13 | enabled: True |
| 14 | name_servers: |
| 15 | - ${_param:dns_server01} |
| 16 | - ${_param:dns_server02} |
| 17 | netmask: ${_param:control_network_netmask} |
| 18 | proto: static |
| 19 | require_interfaces: ['ens4'] |
| 20 | type: bridge |
| 21 | use_interfaces: ['ens4'] |
| 22 | ens3: |
| 23 | enabled: True |
| 24 | name: ens3 |
| 25 | proto: dhcp |
| 26 | type: eth |
| 27 | ens4: |
| 28 | enabled: True |
| 29 | ipflush_onchange: True |
| 30 | name: ens4 |
| 31 | proto: manual |
| 32 | type: eth |
| 33 | """ |
| 34 | |
Hanna Arhipova | d33353e | 2021-02-15 23:14:51 +0200 | [diff] [blame] | 35 | add_osd_ceph_init_yml = """ |
| 36 | parameters: |
| 37 | _param: |
| 38 | ceph_osd_node04_hostname: xtra |
| 39 | ceph_osd_node04_address: 10.6.0.205 |
Hanna Arhipova | d33353e | 2021-02-15 23:14:51 +0200 | [diff] [blame] | 40 | ceph_osd_system_codename: xenial |
| 41 | linux: |
| 42 | network: |
| 43 | host: |
| 44 | xtra: |
| 45 | address: ${_param:ceph_osd_node04_address} |
| 46 | names: |
| 47 | - ${_param:ceph_osd_node04_hostname} |
| 48 | - ${_param:ceph_osd_node04_hostname}.${_param:cluster_domain} |
| 49 | """ |
| 50 | |
| 51 | add_osd_config_init_yml = """ |
| 52 | parameters: |
| 53 | reclass: |
| 54 | storage: |
| 55 | node: |
| 56 | ceph_osd_node04: |
| 57 | name: ${_param:ceph_osd_node04_hostname} |
| 58 | domain: ${_param:cluster_domain} |
| 59 | classes: |
| 60 | - cluster.${_param:cluster_name}.ceph.osd |
| 61 | params: |
| 62 | salt_master_host: ${_param:reclass_config_master} |
| 63 | linux_system_codename: ${_param:ceph_osd_system_codename} |
| 64 | single_address: ${_param:ceph_osd_node04_address} |
| 65 | ceph_crush_parent: rack02 |
| 66 | """ |
| 67 | |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 68 | |
| 69 | @pytest.fixture(scope='module') |
Hanna Arhipova | d60430e | 2021-02-12 18:23:47 +0200 | [diff] [blame^] | 70 | def add_xtra_node_to_salt(salt_actions, underlay_actions, |
| 71 | config, reclass_actions): |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 72 | """ |
| 73 | |
| 74 | :return: |
| 75 | """ |
| 76 | LOG.info("Executing pytest SETUP from add_xtra_node_to_salt fixture") |
| 77 | xtra_node = [node['node_name'] for node in config.underlay.ssh |
| 78 | if 'xtra' in node.get('node_name')][0] |
| 79 | |
| 80 | cfg_node = [node['node_name'] for node in config.underlay.ssh |
| 81 | if 'salt_master' in node.get('roles')][0] |
| 82 | |
| 83 | underlay_actions.check_call( |
| 84 | "salt-key -a {node} --include-all -y".format(node=xtra_node), |
| 85 | node_name=cfg_node, |
| 86 | raise_on_err=False) |
| 87 | # Need to restart salt-minion service after accepting it in Salt Master |
| 88 | underlay_actions.check_call( |
| 89 | "systemctl restart salt-minion", |
| 90 | node_name=xtra_node, |
| 91 | raise_on_err=False) |
Hanna Arhipova | d60430e | 2021-02-12 18:23:47 +0200 | [diff] [blame^] | 92 | salt_actions.enforce_state("I@salt:master", "reclass") |
| 93 | |
| 94 | reclass_actions.merge_context(yaml_context=xtra_network_interface, |
| 95 | short_path="../nodes/_generated/xtra.*.yml") |
| 96 | |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 97 | yield |
| 98 | |
| 99 | # LOG.info("Executing pytest TEARDOWN from add_xtra_node_to_salt fixture") |
| 100 | # underlay_actions.check_call( |
| 101 | # "salt-key -r {node} --include-all -y".format(node=node), |
| 102 | # node_name=cfg_node, |
| 103 | # raise_on_err=False) |
| 104 | |
| 105 | |
| 106 | @pytest.mark.usefixtures("add_xtra_node_to_salt") |
| 107 | class TestCephOsd(object): |
| 108 | |
| 109 | @pytest.fixture |
| 110 | def describe_node_in_reclass(self, |
Hanna Arhipova | d33353e | 2021-02-15 23:14:51 +0200 | [diff] [blame] | 111 | reclass_actions, |
| 112 | salt_actions): |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 113 | LOG.info("Executing pytest SETUP " |
| 114 | "from describe_node_in_reclass fixture") |
| 115 | reclass = reclass_actions |
| 116 | # ---- cluster/*/ceph/init.yml --------------- |
Hanna Arhipova | d33353e | 2021-02-15 23:14:51 +0200 | [diff] [blame] | 117 | reclass.merge_context(yaml_context=add_osd_ceph_init_yml, |
| 118 | short_path="cluster/*/ceph/init.yml") |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 119 | |
| 120 | # ------- cluster/infra/config/init.yml ----------- |
Hanna Arhipova | d33353e | 2021-02-15 23:14:51 +0200 | [diff] [blame] | 121 | reclass.merge_context(yaml_context=add_osd_config_init_yml, |
| 122 | short_path="cluster/*/infra/config/init.yml") |
Hanna Arhipova | d60430e | 2021-02-12 18:23:47 +0200 | [diff] [blame^] | 123 | salt_actions.run_state("*", "saltutil.refresh_pillar") |
| 124 | |
| 125 | @pytest.fixture |
| 126 | def remove_node_from_reclass(self, |
| 127 | reclass_actions): |
| 128 | reclass = reclass_actions |
| 129 | |
| 130 | reclass.delete_key( |
| 131 | key="parameters.reclass.storage.node.ceph_osd_node04", |
| 132 | short_path="cluster/*/infra/config/init.yml" |
| 133 | ) |
| 134 | reclass.delete_key( |
| 135 | key="parameters.linux.network.host.xtra", |
| 136 | short_path="cluster/*/ceph/init.yml" |
| 137 | ) |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 138 | |
| 139 | def test_add_node_process(self, describe_node_in_reclass, |
| 140 | drivetrain_actions): |
| 141 | """ |
| 142 | https://docs.mirantis.com/mcp/q4-18/mcp-operations-guide/openstack-operations/ceph-operations/manage-nodes/add-osd-nodes.html |
| 143 | :param describe_node_in_reclass: |
| 144 | :param drivetrain_actions: |
| 145 | :return: |
| 146 | test took about 20 min |
| 147 | """ |
| 148 | dt = drivetrain_actions |
PGlazov | 89ba918 | 2021-02-19 13:36:46 +0400 | [diff] [blame] | 149 | # Workaround for PROD-36132 |
| 150 | job_name = "ceph-add-node" |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 151 | job_parameters = { |
| 152 | 'HOST': 'xtra*', |
PGlazov | 89ba918 | 2021-02-19 13:36:46 +0400 | [diff] [blame] | 153 | 'OSD_ONLY': False |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 154 | } |
Hanna Arhipova | 508f653 | 2021-01-27 15:52:45 +0200 | [diff] [blame] | 155 | job_result, job_description = dt.start_job_on_jenkins( |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 156 | job_name=job_name, |
| 157 | job_parameters=job_parameters, |
| 158 | verbose=True) |
Hanna Arhipova | 508f653 | 2021-01-27 15:52:45 +0200 | [diff] [blame] | 159 | assert job_result == 'SUCCESS', job_description |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 160 | |
| 161 | def test_added_node(self): |
| 162 | # root@osd001:~# ceph osd tree in |
| 163 | # ID CLASS WEIGHT TYPE NAME STATUS REWEIGHT PRI-AFF |
| 164 | # -1 0.18585 root default |
| 165 | # -3 0.04646 host osd001 |
| 166 | # 0 hdd 0.01549 osd.0 up 1.00000 1.00000 |
| 167 | # 1 hdd 0.01549 osd.1 up 1.00000 1.00000 |
| 168 | # 2 hdd 0.01549 osd.2 up 1.00000 1.00000 |
| 169 | # -5 0.04646 host osd002 |
| 170 | # 3 hdd 0.01549 osd.3 up 1.00000 1.00000 |
| 171 | # 5 hdd 0.01549 osd.5 up 1.00000 1.00000 |
| 172 | # 6 hdd 0.01549 osd.6 up 1.00000 1.00000 |
| 173 | # -7 0.04646 host osd003 |
| 174 | # 4 hdd 0.01549 osd.4 up 1.00000 1.00000 |
| 175 | # 7 hdd 0.01549 osd.7 up 1.00000 1.00000 |
| 176 | # 8 hdd 0.01549 osd.8 up 1.00000 1.00000 |
| 177 | # -9 0.04646 host xtra |
| 178 | # 9 hdd 0.01549 osd.9 up 1.00000 1.00000 |
| 179 | # 10 hdd 0.01549 osd.10 up 1.00000 1.00000 |
| 180 | # 11 hdd 0.01549 osd.11 up 1.00000 1.00000 |
| 181 | pass |
| 182 | |
Hanna Arhipova | d60430e | 2021-02-12 18:23:47 +0200 | [diff] [blame^] | 183 | def test_delete_node_process(self, |
| 184 | remove_node_from_reclass, |
| 185 | drivetrain_actions): |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 186 | dt = drivetrain_actions |
| 187 | |
| 188 | job_name = "ceph-remove-node" |
| 189 | job_parameters = { |
| 190 | 'HOST': 'xtra*', |
PGlazov | 89ba918 | 2021-02-19 13:36:46 +0400 | [diff] [blame] | 191 | 'OSD': '*' |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 192 | } |
Hanna Arhipova | 508f653 | 2021-01-27 15:52:45 +0200 | [diff] [blame] | 193 | job_result, job_description = dt.start_job_on_jenkins( |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 194 | job_name=job_name, |
| 195 | job_parameters=job_parameters, |
| 196 | verbose=True) |
Hanna Arhipova | 508f653 | 2021-01-27 15:52:45 +0200 | [diff] [blame] | 197 | assert job_result == 'SUCCESS', job_description |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 198 | |
| 199 | |
Hanna Arhipova | d60430e | 2021-02-12 18:23:47 +0200 | [diff] [blame^] | 200 | add_mon_ceph_init_yml = """ |
| 201 | parameters: |
| 202 | _param: |
| 203 | ceph_mon_node04_hostname: xtra |
| 204 | ceph_mon_node04_address: 10.6.0.205 |
| 205 | ceph_mon_node04_ceph_public_address: 10.166.49.209 |
| 206 | ceph_mon_node04_ceph_backup_hour: 4 |
| 207 | ceph_mon_node04_ceph_backup_minute: 0 |
| 208 | linux: |
| 209 | network: |
| 210 | host: |
| 211 | xtra: |
| 212 | address: ${_param:ceph_mon_node04_address} |
| 213 | names: |
| 214 | - ${_param:ceph_mon_node04_hostname} |
| 215 | - ${_param:ceph_mon_node04_hostname}.${_param:cluster_domain} |
| 216 | """ |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 217 | |
Hanna Arhipova | d60430e | 2021-02-12 18:23:47 +0200 | [diff] [blame^] | 218 | add_mon_ceph_common_yml = """ |
| 219 | parameters: |
| 220 | ceph: |
| 221 | common: |
| 222 | members: |
| 223 | - name: ${_param:ceph_mon_node04_hostname} |
| 224 | host: ${_param:ceph_mon_node04_address} |
| 225 | """ |
| 226 | |
| 227 | add_mon_config_node_yml = """ |
| 228 | parameters: |
| 229 | reclass: |
| 230 | storage: |
| 231 | node: |
| 232 | ceph_mon_node04: |
| 233 | name: ${_param:ceph_mon_node04_hostname} |
| 234 | domain: ${_param:cluster_domain} |
| 235 | classes: |
| 236 | - cluster.${_param:cluster_name}.ceph.mon |
| 237 | params: |
| 238 | ceph_public_address: ${_param:ceph_mon_node04_ceph_public_address} |
| 239 | ceph_backup_time_hour: ${_param:ceph_mon_node04_ceph_backup_hour} |
| 240 | ceph_backup_time_minute: ${_param:ceph_mon_node04_ceph_backup_minute} |
| 241 | salt_master_host: ${_param:reclass_config_master} |
| 242 | linux_system_codename: ${_param:ceph_mon_system_codename} |
| 243 | single_address: ${_param:ceph_mon_node04_address} |
| 244 | keepalived_vip_priority: 104 |
| 245 | """ # noqa: E501 |
| 246 | |
| 247 | add_mon_infra_kvm_yml = """ |
| 248 | parameters: |
| 249 | salt: |
| 250 | control: |
| 251 | size: |
| 252 | ceph.mon: |
| 253 | cpu: 8 |
| 254 | ram: 16384 |
| 255 | disk_profile: small |
| 256 | net_profile: default |
| 257 | cluster: |
| 258 | internal: |
| 259 | node: |
| 260 | cmn04: |
| 261 | name: ${_param:ceph_mon_node04_hostname} |
| 262 | provider: ${_param:infra_kvm_node03_hostname}.${_param:cluster_domain} |
| 263 | image: ${_param:salt_control_xenial_image} |
| 264 | size: ceph.mon |
| 265 | """ # noqa: E501 |
| 266 | |
| 267 | |
| 268 | @pytest.mark.usefixtures("add_xtra_node_to_salt") |
| 269 | class TestCephMon(object): |
| 270 | @pytest.fixture |
| 271 | def describe_node_in_reclass(self, |
| 272 | reclass_actions, salt_actions): |
| 273 | LOG.info("Executing pytest SETUP " |
| 274 | "from describe_node_in_reclass fixture") |
| 275 | reclass = reclass_actions |
| 276 | # ---- cluster/*/ceph/init.yml -------------- |
| 277 | reclass.merge_context(yaml_context=add_mon_ceph_init_yml, |
| 278 | short_path="cluster/*/ceph/init.yml") |
| 279 | |
| 280 | # ------- cluster/infra/config/init.yml ----------- |
| 281 | reclass.merge_context(yaml_context=add_mon_ceph_common_yml, |
| 282 | short_path="cluster/*/ceph/common.yml") |
| 283 | reclass.merge_context(yaml_context=add_mon_config_node_yml, |
| 284 | short_path="cluster/*/infra/config/nodes.yml") |
| 285 | |
| 286 | # ------- define settings for new mon node in KVM cluster ----------- |
| 287 | reclass.merge_context(yaml_context=add_mon_infra_kvm_yml, |
| 288 | short_path="cluster/*/infra/kvm.yml") |
| 289 | |
| 290 | salt_actions.run_state("*", "saltutil.refresh_pillar") |
| 291 | |
| 292 | @pytest.fixture |
| 293 | def remove_node_from_reclass(self, |
| 294 | reclass_actions, salt_actions): |
| 295 | LOG.info("Executing pytest SETUP " |
| 296 | "from remove_node_from_reclass fixture") |
| 297 | reclass = reclass_actions |
| 298 | reclass.delete_key( |
| 299 | key="parameters.reclass.storage.node.ceph_mon_node04", |
| 300 | short_path="cluster/*/infra/config/init.yml") |
| 301 | reclass.delete_key( |
| 302 | key="parameters.salt.control.cluster.internal.node.cmn04", |
| 303 | short_path="cluster/*/infra/kvm.yml" |
| 304 | ) |
| 305 | reclass.delete_key( |
| 306 | key="parameters.linux.network.host.xtra", |
| 307 | short_path="cluster/*/ceph/init.yml" |
| 308 | ) |
| 309 | |
| 310 | def test_add_node_process(self, |
| 311 | drivetrain_actions, |
| 312 | describe_node_in_reclass): |
| 313 | dt = drivetrain_actions |
| 314 | |
| 315 | job_name = "ceph-add-node" |
| 316 | job_parameters = { |
| 317 | 'HOST': 'xtra*', |
| 318 | 'USE_UPMAP': True |
| 319 | } |
| 320 | job_result, job_description = dt.start_job_on_jenkins( |
| 321 | job_name=job_name, |
| 322 | job_parameters=job_parameters, |
| 323 | verbose=True) |
| 324 | assert job_result == 'SUCCESS', job_description |
| 325 | |
| 326 | def test_delete_node_process(self, |
| 327 | remove_node_from_reclass, |
| 328 | drivetrain_actions): |
| 329 | dt = drivetrain_actions |
| 330 | |
| 331 | job_name = "ceph-remove-node" |
| 332 | job_parameters = { |
| 333 | 'HOST': 'xtra*', |
| 334 | 'USE_UPMAP': True |
| 335 | } |
| 336 | job_result, job_description = dt.start_job_on_jenkins( |
| 337 | job_name=job_name, |
| 338 | job_parameters=job_parameters, |
| 339 | verbose=True) |
| 340 | assert job_result == 'SUCCESS', job_description |
Hanna Arhipova | 54fec80 | 2020-10-30 12:45:46 +0200 | [diff] [blame] | 341 | |
| 342 | |
| 343 | class TestCephMgr(object): |
| 344 | def test_add_node(self): |
| 345 | pass |
| 346 | |
| 347 | def test_delete_node(self): |
| 348 | pass |