diff options
author | Kaifeng Wang <kaifeng.w@gmail.com> | 2018-03-23 16:59:45 +0800 |
---|---|---|
committer | Kaifeng Wang <kaifeng.w@gmail.com> | 2018-05-20 15:30:08 +0800 |
commit | 6b44f269c10c9e9e77d0242a70ac80a30f5ee2f6 (patch) | |
tree | 8747f33d5ba192c19ba30f7f0c6186cc43837322 /ironic/tests/unit | |
parent | ce4594e2c5f23eab4cec931afcc337f255bd8e7f (diff) | |
download | ironic-6b44f269c10c9e9e77d0242a70ac80a30f5ee2f6.tar.gz |
Power fault recovery: db and rpc implementation
This adds a fault field to the node table of database, and necessary rpc
object change and version bumping.
Story: #1596107
Task: #10469
Change-Id: I5539aa0406dbfbde25bc9aa91d5c1e615875e50e
Diffstat (limited to 'ironic/tests/unit')
-rw-r--r-- | ironic/tests/unit/api/utils.py | 2 | ||||
-rw-r--r-- | ironic/tests/unit/db/sqlalchemy/test_migrations.py | 7 | ||||
-rw-r--r-- | ironic/tests/unit/db/test_nodes.py | 14 | ||||
-rw-r--r-- | ironic/tests/unit/db/utils.py | 1 | ||||
-rw-r--r-- | ironic/tests/unit/objects/test_node.py | 66 | ||||
-rw-r--r-- | ironic/tests/unit/objects/test_objects.py | 2 |
6 files changed, 87 insertions, 5 deletions
diff --git a/ironic/tests/unit/api/utils.py b/ironic/tests/unit/api/utils.py index 595200e6d..233bea1a5 100644 --- a/ironic/tests/unit/api/utils.py +++ b/ironic/tests/unit/api/utils.py @@ -110,6 +110,8 @@ def node_post_data(**kw): node.pop(name) if 'resource_class' not in kw: node.pop('resource_class') + if 'fault' not in kw: + node.pop('fault') internal = node_controller.NodePatchType.internal_attrs() return remove_internal(node, internal) diff --git a/ironic/tests/unit/db/sqlalchemy/test_migrations.py b/ironic/tests/unit/db/sqlalchemy/test_migrations.py index b231c5d1e..94d408d66 100644 --- a/ironic/tests/unit/db/sqlalchemy/test_migrations.py +++ b/ironic/tests/unit/db/sqlalchemy/test_migrations.py @@ -712,6 +712,13 @@ class MigrationCheckersMixin(object): self.assertIsInstance(nodes.c.bios_interface.type, sqlalchemy.types.String) + def _check_fb3f10dd262e(self, engine, data): + nodes_tbl = db_utils.get_table(engine, 'nodes') + col_names = [column.name for column in nodes_tbl.c] + self.assertIn('fault', col_names) + self.assertIsInstance(nodes_tbl.c.fault.type, + sqlalchemy.types.String) + def test_upgrade_and_version(self): with patch_with_engine(self.engine): self.migration_api.upgrade('head') diff --git a/ironic/tests/unit/db/test_nodes.py b/ironic/tests/unit/db/test_nodes.py index 765a8b1f0..590b22420 100644 --- a/ironic/tests/unit/db/test_nodes.py +++ b/ironic/tests/unit/db/test_nodes.py @@ -143,6 +143,7 @@ class DbNodeTestCase(base.DbTestCase): driver='driver-two', uuid=uuidutils.generate_uuid(), maintenance=True, + fault='boom', resource_class='foo') node3 = utils.create_test_node( driver='driver-one', @@ -177,6 +178,12 @@ class DbNodeTestCase(base.DbTestCase): self.assertEqual(sorted([node1.id, node3.id]), sorted([r.id for r in res])) + res = self.dbapi.get_nodeinfo_list(filters={'fault': 'boom'}) + self.assertEqual([node2.id], [r.id for r in res]) + + res = self.dbapi.get_nodeinfo_list(filters={'fault': 'moob'}) + self.assertEqual([], [r.id for r in res]) + res = self.dbapi.get_nodeinfo_list(filters={'resource_class': 'foo'}) self.assertEqual([node2.id], [r.id for r in res]) @@ -284,6 +291,7 @@ class DbNodeTestCase(base.DbTestCase): uuid=uuidutils.generate_uuid(), chassis_id=ch2['id'], maintenance=True, + fault='boom', resource_class='foo') res = self.dbapi.get_node_list(filters={'chassis_uuid': ch1['uuid']}) @@ -316,6 +324,12 @@ class DbNodeTestCase(base.DbTestCase): res = self.dbapi.get_node_list(filters={'maintenance': False}) self.assertEqual([node1.id], [r.id for r in res]) + res = self.dbapi.get_nodeinfo_list(filters={'fault': 'boom'}) + self.assertEqual([node2.id], [r.id for r in res]) + + res = self.dbapi.get_nodeinfo_list(filters={'fault': 'moob'}) + self.assertEqual([], [r.id for r in res]) + res = self.dbapi.get_node_list(filters={'resource_class': 'foo'}) self.assertEqual([node2.id], [r.id for r in res]) diff --git a/ironic/tests/unit/db/utils.py b/ironic/tests/unit/db/utils.py index 57d456342..b0d297038 100644 --- a/ironic/tests/unit/db/utils.py +++ b/ironic/tests/unit/db/utils.py @@ -188,6 +188,7 @@ def get_test_node(**kw): 'reservation': kw.get('reservation'), 'maintenance': kw.get('maintenance', False), 'maintenance_reason': kw.get('maintenance_reason'), + 'fault': kw.get('fault'), 'console_enabled': kw.get('console_enabled', False), 'extra': kw.get('extra', {}), 'updated_at': kw.get('updated_at'), diff --git a/ironic/tests/unit/objects/test_node.py b/ironic/tests/unit/objects/test_node.py index ef4df2942..5149f6d64 100644 --- a/ironic/tests/unit/objects/test_node.py +++ b/ironic/tests/unit/objects/test_node.py @@ -408,6 +408,7 @@ class TestConvertToVersion(db_base.DbTestCase): node = obj_utils.get_test_node(self.ctxt, **self.fake_node) node.rescue_interface = 'fake' + node.fault = None node.obj_reset_changes() node._convert_to_version("1.21", False) self.assertIsNone(node.rescue_interface) @@ -420,6 +421,7 @@ class TestConvertToVersion(db_base.DbTestCase): node.rescue_interface = None node.traits = None + node.fault = None node.obj_reset_changes() node._convert_to_version("1.21", False) self.assertIsNone(node.rescue_interface) @@ -466,6 +468,7 @@ class TestConvertToVersion(db_base.DbTestCase): # traits not set, should be set to default. node = obj_utils.get_test_node(self.ctxt, **self.fake_node) delattr(node, 'traits') + node.fault = None node.obj_reset_changes() node._convert_to_version("1.22", False) @@ -478,18 +481,19 @@ class TestConvertToVersion(db_base.DbTestCase): node = obj_utils.get_test_node(self.ctxt, **self.fake_node) node.traits = objects.TraitList(self.ctxt) node.traits.obj_reset_changes() + node.fault = None node.obj_reset_changes() node._convert_to_version("1.22", False) self.assertIsNone(node.traits) - self.assertEqual({'traits': None}, - node.obj_get_changes()) + self.assertEqual({'traits': None}, node.obj_get_changes()) def test_trait_unsupported_set_no_remove_default(self): # traits set, no change required. node = obj_utils.get_test_node(self.ctxt, **self.fake_node) node.traits = None + node.fault = None node.obj_reset_changes() node._convert_to_version("1.22", False) @@ -544,22 +548,76 @@ class TestConvertToVersion(db_base.DbTestCase): node = obj_utils.get_test_node(self.ctxt, **self.fake_node) node.bios_interface = 'fake' + node.fault = None node.obj_reset_changes() node._convert_to_version("1.23", False) self.assertIsNone(node.bios_interface) - self.assertEqual({'bios_interface': None}, - node.obj_get_changes()) + self.assertEqual({'bios_interface': None}, node.obj_get_changes()) def test_bios_unsupported_set_no_remove_default(self): # bios_interface set, no change required. node = obj_utils.get_test_node(self.ctxt, **self.fake_node) node.bios_interface = None + node.fault = None node.obj_reset_changes() node._convert_to_version("1.23", False) self.assertIsNone(node.bios_interface) self.assertEqual({}, node.obj_get_changes()) + def test_fault_supported_missing(self): + node = obj_utils.get_test_node(self.ctxt, **self.fake_node) + delattr(node, 'fault') + node.obj_reset_changes() + + node._convert_to_version("1.25") + + self.assertIsNone(node.fault) + self.assertEqual({'fault': None}, node.obj_get_changes()) + + def test_fault_supported_untouched(self): + node = obj_utils.get_test_node(self.ctxt, **self.fake_node) + node.maintenance = True + node.fault = 'a fake fault' + node.obj_reset_changes() + + node._convert_to_version("1.25") + + self.assertEqual('a fake fault', node.fault) + self.assertEqual({}, node.obj_get_changes()) + + def test_fault_unsupported_missing(self): + node = obj_utils.get_test_node(self.ctxt, **self.fake_node) + delattr(node, 'fault') + node.obj_reset_changes() + + node._convert_to_version("1.24") + + self.assertNotIn('fault', node) + self.assertEqual({}, node.obj_get_changes()) + + def test_fault_unsupported_set_remove(self): + node = obj_utils.get_test_node(self.ctxt, **self.fake_node) + node.maintenance = True + node.fault = 'some fake fault' + node.obj_reset_changes() + + node._convert_to_version("1.24") + + self.assertNotIn('fault', node) + self.assertEqual({}, node.obj_get_changes()) + + def test_fault_unsupported_set_remove_in_maintenance(self): + node = obj_utils.get_test_node(self.ctxt, **self.fake_node) + node.maintenance = True + node.fault = 'some fake type' + node.obj_reset_changes() + + node._convert_to_version("1.24", False) + + self.assertIsNone(node.fault) + self.assertEqual({'fault': None}, node.obj_get_changes()) + class TestNodePayloads(db_base.DbTestCase): diff --git a/ironic/tests/unit/objects/test_objects.py b/ironic/tests/unit/objects/test_objects.py index 486084ea1..4f2c80cc9 100644 --- a/ironic/tests/unit/objects/test_objects.py +++ b/ironic/tests/unit/objects/test_objects.py @@ -663,7 +663,7 @@ class TestObject(_LocalTest, _TestObject): # version bump. It is an MD5 hash of the object fields and remotable methods. # The fingerprint values should only be changed if there is a version bump. expected_object_fingerprints = { - 'Node': '1.24-7d3d504e5e0d2535b2390d558b27196a', + 'Node': '1.25-3a468b3e88d0a8fe7709f822fc654e4b', 'MyObj': '1.5-9459d30d6954bffc7a9afd347a807ca6', 'Chassis': '1.3-d656e039fd8ae9f34efc232ab3980905', 'Port': '1.8-898a47921f4a1f53fcdddd4eeb179e0b', |