summaryrefslogtreecommitdiff
path: root/ironic/tests
diff options
context:
space:
mode:
authorHugo Nicodemos <nicodemos@lsd.ufcg.edu.br>2017-11-29 14:26:13 -0300
committerFellype Cavalcante <fellypefca@lsd.ufcg.edu.br>2017-12-13 14:57:10 -0300
commit97a8ae1c7765aae06b86162b3191186b14f1c8c6 (patch)
tree5bcac034dcd6ef30e0a69470e3d93ec13cf4a5a1 /ironic/tests
parent638943dbf8e4adbcbe81a2af0f8a1d5ffd9771f6 (diff)
downloadironic-97a8ae1c7765aae06b86162b3191186b14f1c8c6.tar.gz
Introduce hpOneView and ilorest to OneView
It introduces the ``hpOneView`` and ``ilorest`` library to the OneView Driver. This patch will be used as the standard patch to other patches related to the removal of the ``python-oneviewclient`` library dependency. Change-Id: Ib9d72ff5713d58631bcdccc817707b5d512e156e Partial-Bug: #1693788 Co-Authored-By: Fellype Cavalcante <fellypefca@lsd.ufcg.edu.br> Co-Authored-By: Ricardo Araujo <ricardo@lsd.ufcg.edu.br>
Diffstat (limited to 'ironic/tests')
-rw-r--r--ironic/tests/unit/drivers/modules/oneview/test_common.py47
-rw-r--r--ironic/tests/unit/drivers/modules/oneview/test_inspect.py2
-rw-r--r--ironic/tests/unit/drivers/third_party_driver_mock_specs.py18
-rw-r--r--ironic/tests/unit/drivers/third_party_driver_mocks.py17
4 files changed, 84 insertions, 0 deletions
diff --git a/ironic/tests/unit/drivers/modules/oneview/test_common.py b/ironic/tests/unit/drivers/modules/oneview/test_common.py
index 47d16c42f..56e29395c 100644
--- a/ironic/tests/unit/drivers/modules/oneview/test_common.py
+++ b/ironic/tests/unit/drivers/modules/oneview/test_common.py
@@ -25,6 +25,7 @@ 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
+hponeview_client = importutils.try_import('hpOneView.oneview_client')
oneview_states = importutils.try_import('oneview_client.states')
@@ -40,8 +41,54 @@ class OneViewCommonTestCase(db_base.DbTestCase):
self.config(manager_url='https://1.2.3.4', group='oneview')
self.config(username='user', group='oneview')
self.config(password='password', group='oneview')
+ self.config(tls_cacert_file='ca_file', group='oneview')
+ self.config(allow_insecure_connections=False, group='oneview')
mgr_utils.mock_the_extension_manager(driver="fake_oneview")
+ def test_prepare_manager_url(self):
+ self.assertEqual(
+ common.prepare_manager_url("https://1.2.3.4/"), "1.2.3.4")
+ self.assertEqual(
+ common.prepare_manager_url("http://oneview"), "oneview")
+ self.assertEqual(
+ common.prepare_manager_url("http://oneview:8080"), "oneview:8080")
+ self.assertEqual(
+ common.prepare_manager_url("http://oneview/something"), "oneview")
+ self.assertEqual(
+ common.prepare_manager_url("oneview/something"), "oneview")
+ self.assertEqual(
+ common.prepare_manager_url("oneview"), "oneview")
+
+ @mock.patch.object(hponeview_client, 'OneViewClient', autospec=True)
+ def test_get_hponeview_client(self, mock_hponeview_client):
+ common.get_hponeview_client()
+ mock_hponeview_client.assert_called_once_with(self.config)
+
+ def test_get_hponeview_client_insecure_false(self):
+ self.config(tls_cacert_file=None, group='oneview')
+ self.assertRaises(exception.OneViewError, common.get_hponeview_client)
+
+ @mock.patch.object(hponeview_client, 'OneViewClient', autospec=True)
+ def test_get_hponeview_client_insecure_cafile(self, mock_oneview):
+ self.config(allow_insecure_connections=True, group='oneview')
+ credentials = {
+ "ip": 'https://1.2.3.4',
+ "credentials": {
+ "userName": 'user',
+ "password": 'password'
+ },
+ "ssl_certificate": None
+ }
+ mock_oneview.assert_called_once_with(credentials)
+
+ def test_get_ilo_access(self):
+ url = ("hplocons://addr=1.2.3.4&sessionkey" +
+ "=a79659e3b3b7c8209c901ac3509a6719")
+ remote_console = {'remoteConsoleUrl': url}
+ host_ip, token = common._get_ilo_access(remote_console)
+ self.assertEqual(host_ip, "1.2.3.4")
+ self.assertEqual(token, "a79659e3b3b7c8209c901ac3509a6719")
+
def test_verify_node_info(self):
common.verify_node_info(self.node)
diff --git a/ironic/tests/unit/drivers/modules/oneview/test_inspect.py b/ironic/tests/unit/drivers/modules/oneview/test_inspect.py
index b2ef499a0..ebc01b101 100644
--- a/ironic/tests/unit/drivers/modules/oneview/test_inspect.py
+++ b/ironic/tests/unit/drivers/modules/oneview/test_inspect.py
@@ -31,6 +31,7 @@ class AgentPXEOneViewInspectTestCase(db_base.DbTestCase):
def setUp(self):
super(AgentPXEOneViewInspectTestCase, self).setUp()
self.config(enabled=True, group='inspector')
+ self.config(manager_url='https://1.2.3.4', group='oneview')
mgr_utils.mock_the_extension_manager(driver="agent_pxe_oneview")
self.node = obj_utils.create_test_node(
self.context, driver='agent_pxe_oneview',
@@ -69,6 +70,7 @@ class ISCSIPXEOneViewInspectTestCase(db_base.DbTestCase):
def setUp(self):
super(ISCSIPXEOneViewInspectTestCase, self).setUp()
self.config(enabled=True, group='inspector')
+ self.config(manager_url='https://1.2.3.4', group='oneview')
mgr_utils.mock_the_extension_manager(driver="iscsi_pxe_oneview")
self.node = obj_utils.create_test_node(
self.context, driver='iscsi_pxe_oneview',
diff --git a/ironic/tests/unit/drivers/third_party_driver_mock_specs.py b/ironic/tests/unit/drivers/third_party_driver_mock_specs.py
index f21adafd4..d3c006b14 100644
--- a/ironic/tests/unit/drivers/third_party_driver_mock_specs.py
+++ b/ironic/tests/unit/drivers/third_party_driver_mock_specs.py
@@ -144,6 +144,24 @@ ONEVIEWCLIENT_STATES_SPEC = (
'ONEVIEW_ERROR',
)
+HPE_ONEVIEW_SPEC = (
+ 'oneview_client',
+ 'resources',
+ 'exceptions',
+)
+
+HPE_ONEVIEW_CLS_SPEC = (
+)
+
+HPE_ONEVIEW_STATES_SPEC = (
+ 'ONEVIEW_POWER_OFF',
+ 'ONEVIEW_POWERING_OFF',
+ 'ONEVIEW_POWER_ON',
+ 'ONEVIEW_POWERING_ON',
+ 'ONEVIEW_RESETTING',
+ 'ONEVIEW_ERROR',
+)
+
SUSHY_CONSTANTS_SPEC = (
'BOOT_SOURCE_TARGET_PXE',
'BOOT_SOURCE_TARGET_HDD',
diff --git a/ironic/tests/unit/drivers/third_party_driver_mocks.py b/ironic/tests/unit/drivers/third_party_driver_mocks.py
index 31fec78b7..430293bb6 100644
--- a/ironic/tests/unit/drivers/third_party_driver_mocks.py
+++ b/ironic/tests/unit/drivers/third_party_driver_mocks.py
@@ -26,6 +26,7 @@ Current list of mocked libraries:
- pysnmp
- scciclient
- oneview_client
+- hpOneView
- pywsman
- python-dracclient
"""
@@ -99,6 +100,22 @@ if 'ironic.drivers.oneview' in sys.modules:
six.moves.reload_module(sys.modules['ironic.drivers.modules.oneview'])
+hpOneView = importutils.try_import('hpOneView')
+if not hpOneView:
+ hpOneView = mock.MagicMock(spec_set=mock_specs.HPE_ONEVIEW_SPEC)
+ sys.modules['hpOneView'] = hpOneView
+ sys.modules['hpOneView.oneview_client'] = hpOneView.oneview_client
+ sys.modules['hpOneView.resources'] = hpOneView.resources
+ sys.modules['hpOneView.exceptions'] = hpOneView.exceptions
+ hpOneView.exceptions.HPOneViewException = type('HPOneViewException',
+ (Exception,), {})
+sys.modules['hpOneView.oneview_client'].OneViewClient = mock.MagicMock(
+ spec_set=mock_specs.HPE_ONEVIEW_CLS_SPEC
+)
+if 'ironic.drivers.oneview' in sys.modules:
+ six.moves.reload_module(sys.modules['ironic.drivers.modules.oneview'])
+
+
# attempt to load the external 'python-dracclient' library, which is required
# by the optional drivers.modules.drac module
dracclient = importutils.try_import('dracclient')