From 8608d3420b35e896d2af9877f57ea6f28ff5884e Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 5 Jul 2018 15:40:42 +0200 Subject: [PATCH] Add unit tests that "remove" is acceptable on /XXX_interface node fields This feature is a side effect of how driver_factory works, but it proved quite useful, so let's unit test it to avoid regressions. Change-Id: I12f018ae823dfe85b2eac8a77ea5073fda7c2982 Story: #2002868 Task: #22827 --- .../unit/api/controllers/v1/test_node.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py index d0bf8e0c49..ea4f8599df 100644 --- a/ironic/tests/unit/api/controllers/v1/test_node.py +++ b/ironic/tests/unit/api/controllers/v1/test_node.py @@ -2223,6 +2223,18 @@ class TestPatch(test_api_base.BaseApiTest): self.assertEqual('application/json', response.content_type) self.assertEqual(http_client.OK, response.status_code) + def test_reset_network_interface(self): + node = obj_utils.create_test_node(self.context, + uuid=uuidutils.generate_uuid()) + self.mock_update_node.return_value = node + headers = {api_base.Version.string: str(api_v1.max_version())} + response = self.patch_json('/nodes/%s' % node.uuid, + [{'path': '/network_interface', + 'op': 'remove'}], + headers=headers) + self.assertEqual('application/json', response.content_type) + self.assertEqual(http_client.OK, response.status_code) + def test_update_network_interface_old_api(self): node = obj_utils.create_test_node(self.context, uuid=uuidutils.generate_uuid()) @@ -2310,6 +2322,20 @@ class TestPatch(test_api_base.BaseApiTest): self.assertEqual('application/json', response.content_type) self.assertEqual(http_client.OK, response.status_code) + def test_reset_interface_fields(self): + # Using remove on an interface resets it to its default + node = obj_utils.create_test_node(self.context, + uuid=uuidutils.generate_uuid()) + self.mock_update_node.return_value = node + headers = {api_base.Version.string: str(api_v1.max_version())} + for field in api_utils.V31_FIELDS: + response = self.patch_json('/nodes/%s' % node.uuid, + [{'path': '/%s' % field, + 'op': 'remove'}], + headers=headers) + self.assertEqual('application/json', response.content_type) + self.assertEqual(http_client.OK, response.status_code) + def test_update_interface_fields_bad_version(self): node = obj_utils.create_test_node(self.context, uuid=uuidutils.generate_uuid()) @@ -2339,6 +2365,18 @@ class TestPatch(test_api_base.BaseApiTest): self.assertEqual('application/json', response.content_type) self.assertEqual(http_client.OK, response.status_code) + def test_reset_storage_interface(self): + node = obj_utils.create_test_node(self.context, + uuid=uuidutils.generate_uuid()) + self.mock_update_node.return_value = node + headers = {api_base.Version.string: str(api_v1.max_version())} + response = self.patch_json('/nodes/%s' % node.uuid, + [{'path': '/storage_interface', + 'op': 'remove'}], + headers=headers) + self.assertEqual('application/json', response.content_type) + self.assertEqual(http_client.OK, response.status_code) + def test_update_storage_interface_old_api(self): node = obj_utils.create_test_node(self.context, uuid=uuidutils.generate_uuid())