Rework the ironic-inspector auto-discovery test

Currently this test relies on changing the driver in introspection rules.
This is quite fragile, since for hardware types changing the driver may
involve changing some or all of the interface fields. It's also absolutely
unnecessary to verify the functioning of the discovery process.
This change removes it.

Instead, the change starts verifying the "auto_discovered" flag in
the introspection data, as well as uses introspection rules to verify
it indirectly.

Finally, the discovery driver is checked. The expected value is provided
by the new configuration option auto_discovery_default_driver.

Change-Id: Ia0e95cbc1bb4dbd32793705b876ab8b474b753ad
This commit is contained in:
Dmitry Tantsur 2018-03-28 12:46:48 +02:00
parent fe0819a019
commit 39579c63af
2 changed files with 34 additions and 31 deletions

View File

@ -168,4 +168,10 @@ BaremetalIntrospectionGroup = [
help="Is the auto-discovery feature enabled. Enroll hook "
"should be specified in node_not_found_hook - processing "
"section of inspector.conf"),
cfg.StrOpt('auto_discovery_default_driver',
# TODO(dtantsur): change to fake-hardware when Queens is no
# longer supported.
default='fake',
help="The driver expected to be set on newly discovered nodes. "
"Only has effect with auto_discovery_feature is True."),
]

View File

@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from tempest import config
from tempest.lib import decorators
from tempest import test # noqa
@ -40,7 +38,26 @@ class InspectorDiscoveryTest(introspection_manager.InspectorScenarioTest):
discovered_node = self._get_discovery_node()
self.node_info = self._get_node_info(discovered_node)
rule = self._generate_discovery_rule(self.node_info)
rule = {
"description": "Auto-discovery rule",
"actions": [
# Set an attribute in case we cannot access the introspection
# data to check the auto_discovered flag directly.
{"action": "set-attribute",
"path": "/extra/discovered",
"value": "yes"},
# Re-assign the name to use it later in the test.
{"action": "set-attribute",
"path": "/name",
"value": self.node_info['name']},
],
# This flag must be automatically set by the auto-discovery process
"conditions": [
{"op": "eq",
"field": "data://auto_discovered",
"value": True}
]
}
self.rule_import_from_dict(rule)
self.addCleanup(self.rule_purge)
@ -65,27 +82,9 @@ class InspectorDiscoveryTest(introspection_manager.InspectorScenarioTest):
self.assertIsNotNone(discovered_node)
return discovered_node
def _generate_discovery_rule(self, node):
rule = dict()
rule["description"] = "Node %s discovery rule" % node['name']
rule["actions"] = [
{"action": "set-attribute", "path": "/name",
"value": "%s" % node['name']},
{"action": "set-attribute", "path": "/driver",
"value": "%s" % node['driver']},
]
for key, value in node['driver_info'].items():
rule["actions"].append(
{"action": "set-attribute", "path": "/driver_info/%s" % key,
"value": "%s" % value})
rule["conditions"] = [
{"op": "eq", "field": "data://auto_discovered", "value": True}
]
return rule
def verify_node_introspection_data(self, node):
data = self.introspection_data(node['uuid'])
self.assertTrue(data['auto_discovered'])
self.assertEqual(data['cpu_arch'],
self.flavor['properties']['cpu_arch'])
self.assertEqual(int(data['memory_mb']),
@ -109,11 +108,6 @@ class InspectorDiscoveryTest(introspection_manager.InspectorScenarioTest):
self.assertEqual(expected_cpu_arch,
node['properties']['cpu_arch'])
def verify_node_driver_info(self, node_info, inspected_node):
for key in node_info['driver_info']:
self.assertEqual(six.text_type(node_info['driver_info'][key]),
inspected_node['driver_info'].get(key))
@decorators.idempotent_id('dd3abe5e-0d23-488d-bb4e-344cdeff7dcb')
def test_bearmetal_auto_discovery(self):
"""This test case follows this set of operations:
@ -121,9 +115,9 @@ class InspectorDiscoveryTest(introspection_manager.InspectorScenarioTest):
* Choose appropriate node, based on provision state;
* Get node info;
* Generate discovery rule;
* Delete discovered node from ironic;
* Start baremetal vm via virsh;
* Wating for node introspection;
* Start introspection via ironic-inspector API;
* Delete the node from ironic;
* Wating for node discovery;
* Verify introspected node.
"""
# NOTE(aarefiev): workaround for infra, 'tempest' user doesn't
@ -145,6 +139,9 @@ class InspectorDiscoveryTest(introspection_manager.InspectorScenarioTest):
self.verify_node_flavor(inspected_node)
if CONF.service_available.swift:
self.verify_node_introspection_data(inspected_node)
self.verify_node_driver_info(self.node_info, inspected_node)
self.assertEqual(ProvisionStates.ENROLL,
inspected_node['provision_state'])
self.assertEqual(
CONF.baremetal_introspection.auto_discovery_default_driver,
inspected_node['driver'])
self.assertEqual('yes', inspected_node['extra']['discovered'])