summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/objects/test_bios.py
diff options
context:
space:
mode:
authorZenghui Shi <zshi@redhat.com>2018-06-01 16:49:09 +0800
committerZenghui Shi <zshi@redhat.com>2018-06-20 15:15:01 +0800
commitb17c5280e1b750ea5cdaf72ad81cf74675676d7c (patch)
treeec64729316b8e23bd4a9d26375c9592dd4bb6d9e /ironic/tests/unit/objects/test_bios.py
parent585427ab8ec188c82562c20feace22f868eea532 (diff)
downloadironic-b17c5280e1b750ea5cdaf72ad81cf74675676d7c.tar.gz
BIOS Settings: add sync_node_setting
sync_node_setting takes a list of bios settings as input and sorts out a tuple of lists of create, update, delete and nochange settings by comparing the given settings with node 'bios_settings' database table. This commit also modifies fake BIOS interface to use sync_node_setting for testing purpose. Change-Id: I831b3db8f4da24d88a81b4d85889f7fd6f83ffdb Story: #1712032
Diffstat (limited to 'ironic/tests/unit/objects/test_bios.py')
-rw-r--r--ironic/tests/unit/objects/test_bios.py53
1 files changed, 51 insertions, 2 deletions
diff --git a/ironic/tests/unit/objects/test_bios.py b/ironic/tests/unit/objects/test_bios.py
index e1c601cc1..0d31ae4ec 100644
--- a/ironic/tests/unit/objects/test_bios.py
+++ b/ironic/tests/unit/objects/test_bios.py
@@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import types
+
import mock
from ironic.common import context
@@ -141,9 +143,56 @@ class TestBIOSSettingObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn):
self.assertEqual(bios_setting2['name'], bios_obj_list[1].name)
self.assertEqual(bios_setting2['value'], bios_obj_list[1].value)
- @mock.patch.object(dbapi.IMPL, 'delete_bios_setting', autospec=True)
+ @mock.patch.object(dbapi.IMPL, 'delete_bios_setting_list', autospec=True)
def test_delete(self, mock_delete):
objects.BIOSSetting.delete(self.context, self.node_id,
self.bios_setting['name'])
mock_delete.assert_called_once_with(self.node_id,
- self.bios_setting['name'])
+ [self.bios_setting['name']])
+
+ @mock.patch.object(dbapi.IMPL, 'delete_bios_setting_list', autospec=True)
+ def test_list_delete(self, mock_delete):
+ bios_setting2 = db_utils.get_test_bios_setting(name='hyperthread')
+ name_list = [self.bios_setting['name'], bios_setting2['name']]
+ objects.BIOSSettingList.delete(self.context, self.node_id, name_list)
+ mock_delete.assert_called_once_with(self.node_id, name_list)
+
+ @mock.patch('ironic.objects.bios.BIOSSettingList.get_by_node_id',
+ spec_set=types.FunctionType)
+ def test_sync_node_setting_create_and_update(self, mock_get):
+ node = obj_utils.create_test_node(self.ctxt)
+ bios_obj = [obj_utils.create_test_bios_setting(
+ self.ctxt, node_id=node.id)]
+ mock_get.return_value = bios_obj
+ settings = db_utils.get_test_bios_setting_setting_list()
+ settings[0]['value'] = 'off'
+ create, update, delete, nochange = (
+ objects.BIOSSettingList.sync_node_setting(self.ctxt, node.id,
+ settings))
+
+ self.assertEqual(create, settings[1:])
+ self.assertEqual(update, [settings[0]])
+ self.assertEqual(delete, [])
+ self.assertEqual(nochange, [])
+
+ @mock.patch('ironic.objects.bios.BIOSSettingList.get_by_node_id',
+ spec_set=types.FunctionType)
+ def test_sync_node_setting_delete_nochange(self, mock_get):
+ node = obj_utils.create_test_node(self.ctxt)
+ bios_obj_1 = obj_utils.create_test_bios_setting(
+ self.ctxt, node_id=node.id)
+ bios_obj_2 = obj_utils.create_test_bios_setting(
+ self.ctxt, node_id=node.id, name='numlock', value='off')
+ mock_get.return_value = [bios_obj_1, bios_obj_2]
+ settings = db_utils.get_test_bios_setting_setting_list()
+ settings[0]['name'] = 'fake-bios-option'
+ create, update, delete, nochange = (
+ objects.BIOSSettingList.sync_node_setting(self.ctxt, node.id,
+ settings))
+
+ expected_delete = [{'name': bios_obj_1.name,
+ 'value': bios_obj_1.value}]
+ self.assertEqual(create, settings[:2])
+ self.assertEqual(update, [])
+ self.assertEqual(delete, expected_delete)
+ self.assertEqual(nochange, [settings[2]])