Anton Arefiev | 44f678c | 2016-03-17 12:11:30 +0200 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | import tempest |
| 14 | |
| 15 | from tempest.config import CONF |
| 16 | from tempest import test # noqa |
| 17 | |
| 18 | from ironic_inspector.test.inspector_tempest_plugin.tests import manager |
| 19 | from ironic_tempest_plugin.tests.api.admin.api_microversion_fixture import \ |
| 20 | APIMicroversionFixture as IronicMicroversionFixture |
| 21 | from ironic_tempest_plugin.tests.scenario.baremetal_manager import \ |
| 22 | BaremetalProvisionStates |
| 23 | from tempest.lib.common.api_version_utils import LATEST_MICROVERSION |
| 24 | |
| 25 | |
| 26 | class InspectorBasicTest(manager.InspectorScenarioTest): |
| 27 | wait_provisioning_state_interval = 15 |
| 28 | |
| 29 | def node_cleanup(self, node_id): |
| 30 | if (self.node_show(node_id)['provision_state'] == |
| 31 | BaremetalProvisionStates.AVAILABLE): |
| 32 | return |
| 33 | try: |
| 34 | self.baremetal_client.set_node_provision_state(node_id, 'provide') |
| 35 | except tempest.lib.exceptions.RestClientException: |
| 36 | # maybe node already cleaning or available |
| 37 | pass |
| 38 | |
| 39 | self.wait_provisioning_state( |
| 40 | node_id, [BaremetalProvisionStates.AVAILABLE, |
| 41 | BaremetalProvisionStates.NOSTATE], |
| 42 | timeout=CONF.baremetal.unprovision_timeout, |
| 43 | interval=self.wait_provisioning_state_interval) |
| 44 | |
| 45 | def introspect_node(self, node_id): |
| 46 | # in case there are properties remove those |
| 47 | patch = {('properties/%s' % key): None for key in |
| 48 | self.node_show(node_id)['properties']} |
| 49 | # reset any previous rule result |
| 50 | patch['extra/rule_success'] = None |
| 51 | self.node_update(node_id, patch) |
| 52 | |
| 53 | self.baremetal_client.set_node_provision_state(node_id, 'manage') |
| 54 | self.baremetal_client.set_node_provision_state(node_id, 'inspect') |
| 55 | self.addCleanup(self.node_cleanup, node_id) |
| 56 | |
| 57 | def setUp(self): |
| 58 | super(InspectorBasicTest, self).setUp() |
| 59 | # we rely on the 'available' provision_state; using latest |
| 60 | # microversion |
| 61 | self.useFixture(IronicMicroversionFixture(LATEST_MICROVERSION)) |
| 62 | # avoid testing nodes that aren't available |
| 63 | self.node_ids = {node['uuid'] for node in |
| 64 | self.node_filter(filter=lambda node: |
| 65 | node['provision_state'] == |
| 66 | BaremetalProvisionStates.AVAILABLE)} |
| 67 | if not self.node_ids: |
| 68 | self.skipTest('no available nodes detected') |
| 69 | self.rule_purge() |
| 70 | |
| 71 | def verify_node_introspection_data(self, node): |
| 72 | self.assertEqual('yes', node['extra']['rule_success']) |
| 73 | data = self.introspection_data(node['uuid']) |
| 74 | self.assertEqual(data['cpu_arch'], |
| 75 | self.flavor['properties']['cpu_arch']) |
| 76 | self.assertEqual(int(data['memory_mb']), |
| 77 | int(self.flavor['ram'])) |
| 78 | self.assertEqual(int(data['cpus']), int(self.flavor['vcpus'])) |
| 79 | |
| 80 | def verify_node_flavor(self, node): |
| 81 | expected_cpus = self.flavor['vcpus'] |
| 82 | expected_memory_mb = self.flavor['ram'] |
| 83 | expected_cpu_arch = self.flavor['properties']['cpu_arch'] |
| 84 | disk_size = self.flavor['disk'] |
| 85 | ephemeral_size = self.flavor['OS-FLV-EXT-DATA:ephemeral'] |
| 86 | expected_local_gb = disk_size + ephemeral_size |
| 87 | |
| 88 | self.assertEqual(expected_cpus, |
| 89 | int(node['properties']['cpus'])) |
| 90 | self.assertEqual(expected_memory_mb, |
| 91 | int(node['properties']['memory_mb'])) |
| 92 | self.assertEqual(expected_local_gb, |
| 93 | int(node['properties']['local_gb'])) |
| 94 | self.assertEqual(expected_cpu_arch, |
| 95 | node['properties']['cpu_arch']) |
| 96 | |
| 97 | @test.idempotent_id('03bf7990-bee0-4dd7-bf74-b97ad7b52a4b') |
| 98 | @test.services('baremetal', 'compute', 'image', |
| 99 | 'network', 'object_storage') |
| 100 | def test_baremetal_introspection(self): |
| 101 | """This smoke test case follows this basic set of operations: |
| 102 | |
| 103 | * Fetches expected properties from baremetal flavor |
| 104 | * Removes all properties from nodes |
| 105 | * Sets nodes to manageable state |
| 106 | * Imports introspection rule basic_ops_rule.json |
| 107 | * Inspects nodes |
| 108 | * Verifies all properties are inspected |
| 109 | * Verifies introspection data |
| 110 | * Sets node to available state |
| 111 | * Creates a keypair |
| 112 | * Boots an instance using the keypair |
| 113 | * Deletes the instance |
| 114 | |
| 115 | """ |
| 116 | # prepare introspection rule |
| 117 | rule_path = self.get_rule_path("basic_ops_rule.json") |
| 118 | self.rule_import(rule_path) |
| 119 | self.addCleanup(self.rule_purge) |
| 120 | |
| 121 | for node_id in self.node_ids: |
| 122 | self.introspect_node(node_id) |
| 123 | |
| 124 | # settle down introspection |
| 125 | self.wait_for_introspection_finished(self.node_ids) |
| 126 | for node_id in self.node_ids: |
| 127 | self.wait_provisioning_state( |
| 128 | node_id, 'manageable', |
| 129 | timeout=CONF.baremetal_introspection.ironic_sync_timeout, |
| 130 | interval=self.wait_provisioning_state_interval) |
| 131 | |
| 132 | for node_id in self.node_ids: |
| 133 | node = self.node_show(node_id) |
| 134 | self.verify_node_introspection_data(node) |
| 135 | self.verify_node_flavor(node) |
| 136 | |
| 137 | for node_id in self.node_ids: |
| 138 | self.baremetal_client.set_node_provision_state(node_id, 'provide') |
| 139 | |
| 140 | for node_id in self.node_ids: |
| 141 | self.wait_provisioning_state( |
| 142 | node_id, BaremetalProvisionStates.AVAILABLE, |
| 143 | timeout=CONF.baremetal.active_timeout, |
| 144 | interval=self.wait_provisioning_state_interval) |
| 145 | |
| 146 | self.wait_for_nova_aware_of_bvms() |
| 147 | self.add_keypair() |
| 148 | self.boot_instance() |
| 149 | self.terminate_instance() |