summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/drivers/modules
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-01-22 23:30:27 +0000
committerGerrit Code Review <review@openstack.org>2018-01-22 23:30:28 +0000
commit83e3afbdee95ad5e01d790f54da25653decf2b25 (patch)
tree9da4bfb516ecafff708a550f7c9945d2da54040f /ironic/tests/unit/drivers/modules
parentc3ed7dfb9e7e878f30fbff68f066a409879b7a3b (diff)
parent346a9a3bfc5312deb78bda8a82ae238e031413bd (diff)
downloadironic-83e3afbdee95ad5e01d790f54da25653decf2b25.tar.gz
Merge "Add XClarity Driver"
Diffstat (limited to 'ironic/tests/unit/drivers/modules')
-rw-r--r--ironic/tests/unit/drivers/modules/xclarity/__init__.py0
-rw-r--r--ironic/tests/unit/drivers/modules/xclarity/test_common.py65
-rw-r--r--ironic/tests/unit/drivers/modules/xclarity/test_management.py125
-rw-r--r--ironic/tests/unit/drivers/modules/xclarity/test_power.py113
4 files changed, 303 insertions, 0 deletions
diff --git a/ironic/tests/unit/drivers/modules/xclarity/__init__.py b/ironic/tests/unit/drivers/modules/xclarity/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/ironic/tests/unit/drivers/modules/xclarity/__init__.py
diff --git a/ironic/tests/unit/drivers/modules/xclarity/test_common.py b/ironic/tests/unit/drivers/modules/xclarity/test_common.py
new file mode 100644
index 000000000..563e48f06
--- /dev/null
+++ b/ironic/tests/unit/drivers/modules/xclarity/test_common.py
@@ -0,0 +1,65 @@
+# Copyright 2017 Lenovo, Inc.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import mock
+
+from oslo_utils import importutils
+
+from ironic.drivers.modules.xclarity import common
+from ironic.tests.unit.db import base as db_base
+from ironic.tests.unit.db import utils as db_utils
+from ironic.tests.unit.objects import utils as obj_utils
+
+xclarity_exceptions = importutils.try_import('xclarity_client.exceptions')
+xclarity_constants = importutils.try_import('xclarity_client.constants')
+
+
+class XClarityCommonTestCase(db_base.DbTestCase):
+
+ def setUp(self):
+ super(XClarityCommonTestCase, self).setUp()
+
+ self.config(manager_ip='1.2.3.4', group='xclarity')
+ self.config(username='user', group='xclarity')
+ self.config(password='password', group='xclarity')
+
+ self.node = obj_utils.create_test_node(
+ self.context, driver='fake-xclarity',
+ properties=db_utils.get_test_xclarity_properties(),
+ driver_info=db_utils.get_test_xclarity_driver_info(),
+ )
+
+ def test_get_server_hardware_id(self):
+ driver_info = self.node.driver_info
+ driver_info['xclarity_hardware_id'] = 'test'
+ self.node.driver_info = driver_info
+ result = common.get_server_hardware_id(self.node)
+ self.assertEqual(result, 'test')
+
+ @mock.patch.object(common, 'get_server_hardware_id',
+ spec_set=True, autospec=True)
+ @mock.patch.object(common, 'get_xclarity_client',
+ spec_set=True, autospec=True)
+ def test_check_node_managed_by_xclarity(self, mock_xc_client,
+ mock_validate_driver_info):
+ driver_info = self.node.driver_info
+ driver_info['xclarity_hardware_id'] = 'abcd'
+ self.node.driver_info = driver_info
+
+ xclarity_client = mock_xc_client()
+ mock_validate_driver_info.return_value = '12345'
+ common.is_node_managed_by_xclarity(xclarity_client,
+ self.node)
+ xclarity_client.is_node_managed.assert_called_once_with('12345')
diff --git a/ironic/tests/unit/drivers/modules/xclarity/test_management.py b/ironic/tests/unit/drivers/modules/xclarity/test_management.py
new file mode 100644
index 000000000..1d4fc9209
--- /dev/null
+++ b/ironic/tests/unit/drivers/modules/xclarity/test_management.py
@@ -0,0 +1,125 @@
+# Copyright 2017 Lenovo, Inc.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import sys
+
+import six
+
+import mock
+
+from oslo_utils import importutils
+
+from ironic.common import boot_devices
+from ironic.conductor import task_manager
+from ironic.drivers.modules.xclarity import common
+from ironic.drivers.modules.xclarity import management
+from ironic.tests.unit.conductor import mgr_utils
+from ironic.tests.unit.db import base as db_base
+from ironic.tests.unit.db import utils as db_utils
+from ironic.tests.unit.objects import utils as obj_utils
+
+
+xclarity_client_exceptions = importutils.try_import(
+ 'xclarity_client.exceptions')
+
+
+@mock.patch.object(common, 'get_xclarity_client', spect_set=True,
+ autospec=True)
+class XClarityManagementDriverTestCase(db_base.DbTestCase):
+
+ def setUp(self):
+ super(XClarityManagementDriverTestCase, self).setUp()
+ self.config(enabled_hardware_types=['xclarity'],
+ enabled_power_interfaces=['xclarity'],
+ enabled_management_interfaces=['xclarity'])
+ mgr_utils.mock_the_extension_manager(
+ driver='xclarity', namespace='ironic.hardware.types')
+ self.node = obj_utils.create_test_node(
+ self.context,
+ driver='xclarity',
+ driver_info=db_utils.get_test_xclarity_driver_info())
+
+ @mock.patch.object(common, 'get_server_hardware_id',
+ spect_set=True, autospec=True)
+ def test_validate(self, mock_validate, mock_get_xc_client):
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ task.driver.management.validate(task)
+ common.get_server_hardware_id(task.node)
+ mock_validate.assert_called_with(task.node)
+
+ def test_get_properties(self, mock_get_xc_client):
+
+ expected = common.REQUIRED_ON_DRIVER_INFO
+ self.assertItemsEqual(expected,
+ self.node.driver_info)
+
+ @mock.patch.object(management.XClarityManagement, 'get_boot_device',
+ return_value='pxe')
+ def test_set_boot_device(self, mock_get_boot_device,
+ mock_get_xc_client):
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ task.driver.management.set_boot_device(task, 'pxe')
+ result = task.driver.management.get_boot_device(task)
+ self.assertEqual(result, 'pxe')
+
+ def test_set_boot_device_fail(self, mock_get_xc_client):
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ xclarity_client_exceptions.XClarityError = Exception
+ sys.modules['xclarity_client.exceptions'] = (
+ xclarity_client_exceptions)
+ if 'ironic.drivers.modules.xclarity' in sys.modules:
+ six.moves.reload_module(
+ sys.modules['ironic.drivers.modules.xclarity'])
+ ex = common.XClarityError('E')
+ mock_get_xc_client.return_value.set_node_boot_info.side_effect = ex
+ self.assertRaises(common.XClarityError,
+ task.driver.management.set_boot_device,
+ task,
+ "pxe")
+
+ def test_get_supported_boot_devices(self, mock_get_xc_client):
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ expected = [boot_devices.PXE, boot_devices.BIOS,
+ boot_devices.DISK, boot_devices.CDROM]
+ self.assertItemsEqual(
+ expected,
+ task.driver.management.get_supported_boot_devices(task))
+
+ @mock.patch.object(
+ management.XClarityManagement,
+ 'get_boot_device',
+ return_value={'boot_device': 'pxe', 'persistent': False})
+ def test_get_boot_device(self, mock_get_boot_device, mock_get_xc_client):
+ reference = {'boot_device': 'pxe', 'persistent': False}
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ expected_boot_device = task.driver.management.get_boot_device(
+ task=task)
+
+ self.assertEqual(reference, expected_boot_device)
+
+ def test_get_boot_device_fail(self, mock_xc_client):
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ xclarity_client_exceptions.XClarityError = Exception
+ sys.modules['xclarity_client.exceptions'] = (
+ xclarity_client_exceptions)
+ if 'ironic.drivers.modules.xclarity' in sys.modules:
+ six.moves.reload_module(
+ sys.modules['ironic.drivers.modules.xclarity'])
+ ex = common.XClarityError('E')
+ mock_xc_client.return_value.get_node_all_boot_info.side_effect = ex
+ self.assertRaises(
+ common.XClarityError,
+ task.driver.management.get_boot_device,
+ task)
diff --git a/ironic/tests/unit/drivers/modules/xclarity/test_power.py b/ironic/tests/unit/drivers/modules/xclarity/test_power.py
new file mode 100644
index 000000000..f695c4c29
--- /dev/null
+++ b/ironic/tests/unit/drivers/modules/xclarity/test_power.py
@@ -0,0 +1,113 @@
+# Copyright 2017 Lenovo, Inc.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+STATE_POWER_ON = "power on"
+STATE_POWER_OFF = "power off"
+STATE_POWERING_ON = "power on"
+STATE_POWERING_OFF = "power on"
+
+import sys
+
+import six
+
+import mock
+
+from oslo_utils import importutils
+
+from ironic.common import states
+from ironic.conductor import task_manager
+from ironic.drivers.modules.xclarity import common
+from ironic.drivers.modules.xclarity import power
+from ironic.tests.unit.conductor import mgr_utils
+from ironic.tests.unit.db import base as db_base
+from ironic.tests.unit.db import utils as db_utils
+from ironic.tests.unit.objects import utils as obj_utils
+
+xclarity_constants = importutils.try_import('xclarity_client.constants')
+xclarity_client_exceptions = importutils.try_import(
+ 'xclarity_client.exceptions')
+
+
+@mock.patch.object(common, 'get_xclarity_client',
+ spect_set=True, autospec=True)
+class XClarityPowerDriverTestCase(db_base.DbTestCase):
+
+ def setUp(self):
+ super(XClarityPowerDriverTestCase, self).setUp()
+ self.config(enabled_hardware_types=['xclarity'],
+ enabled_power_interfaces=['xclarity'],
+ enabled_management_interfaces=['xclarity'])
+ mgr_utils.mock_the_extension_manager(
+ driver='xclarity', namespace='ironic.hardware.types')
+ self.node = obj_utils.create_test_node(
+ self.context,
+ driver='xclarity',
+ driver_info=db_utils.get_test_xclarity_driver_info())
+
+ def test_get_properties(self, mock_get_xc_client):
+ expected = common.REQUIRED_ON_DRIVER_INFO
+ self.assertItemsEqual(expected,
+ self.node.driver_info)
+
+ @mock.patch.object(common, 'get_server_hardware_id',
+ spect_set=True, autospec=True)
+ def test_validate(self, mock_validate_driver_info, mock_get_xc_client):
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ task.driver.power.validate(task)
+ common.get_server_hardware_id(task.node)
+ mock_validate_driver_info.assert_called_with(task.node)
+
+ @mock.patch.object(power.XClarityPower, 'get_power_state',
+ return_value=STATE_POWER_ON)
+ def test_get_power_state(self, mock_get_power_state, mock_get_xc_client):
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ result = power.XClarityPower.get_power_state(task)
+ self.assertEqual(STATE_POWER_ON, result)
+
+ def test_get_power_state_fail(self, mock_xc_client):
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ xclarity_client_exceptions.XClarityError = Exception
+ sys.modules['xclarity_client.exceptions'] = (
+ xclarity_client_exceptions)
+ if 'ironic.drivers.modules.xclarity' in sys.modules:
+ six.moves.reload_module(
+ sys.modules['ironic.drivers.modules.xclarity'])
+ ex = common.XClarityError('E')
+ mock_xc_client.return_value.get_node_power_status.side_effect = ex
+ self.assertRaises(common.XClarityError,
+ task.driver.power.get_power_state,
+ task)
+
+ @mock.patch.object(power.XClarityPower, 'get_power_state',
+ return_value=states.POWER_ON)
+ def test_set_power(self, mock_set_power_state, mock_get_xc_client):
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ task.driver.power.set_power_state(task, states.POWER_ON)
+ expected = task.driver.power.get_power_state(task)
+ self.assertEqual(expected, states.POWER_ON)
+
+ def test_set_power_fail(self, mock_xc_client):
+ with task_manager.acquire(self.context, self.node.uuid) as task:
+ xclarity_client_exceptions.XClarityError = Exception
+ sys.modules['xclarity_client.exceptions'] = (
+ xclarity_client_exceptions)
+ if 'ironic.drivers.modules.xclarity' in sys.modules:
+ six.moves.reload_module(
+ sys.modules['ironic.drivers.modules.xclarity'])
+ ex = common.XClarityError('E')
+ mock_xc_client.return_value.set_node_power_status.side_effect = ex
+ self.assertRaises(common.XClarityError,
+ task.driver.power.set_power_state,
+ task, states.POWER_OFF)