summaryrefslogtreecommitdiff
path: root/ironic
diff options
context:
space:
mode:
authorHugo Nicodemos <nicodemos@lsd.ufcg.edu.br>2017-10-09 16:19:09 -0300
committerHugo Nicodemos <nicodemos@lsd.ufcg.edu.br>2017-10-30 10:50:02 -0300
commitc2eb357aa1a92670745d282423154e62709f570f (patch)
treed135e40ffc977640bee7ac627431f4ad5bb45160 /ironic
parenta710321f7df149454be246e0b889e9a035b5992c (diff)
downloadironic-c2eb357aa1a92670745d282423154e62709f570f.tar.gz
Migrate python-oneviewclient validations to Ironic OneView drivers
As part of the process to stop the use of python-oneviewclient in favor of python-hpOneView and python-ilorest-library, the validations of the python-oneviewclient have to be migrated to the Ironic OneView drivers. Change-Id: If1eb72192ed58b7d3b8bae780924879fed947a77 Partial-Bug: #1693788
Diffstat (limited to 'ironic')
-rw-r--r--ironic/drivers/modules/oneview/common.py302
-rw-r--r--ironic/drivers/modules/oneview/deploy.py6
-rw-r--r--ironic/drivers/modules/oneview/inspect.py3
-rw-r--r--ironic/drivers/modules/oneview/management.py3
-rw-r--r--ironic/drivers/modules/oneview/power.py9
-rw-r--r--ironic/tests/unit/drivers/modules/oneview/test_common.py155
-rw-r--r--ironic/tests/unit/drivers/modules/oneview/test_deploy.py24
-rw-r--r--ironic/tests/unit/drivers/modules/oneview/test_inspect.py14
-rw-r--r--ironic/tests/unit/drivers/modules/oneview/test_management.py18
9 files changed, 443 insertions, 91 deletions
diff --git a/ironic/drivers/modules/oneview/common.py b/ironic/drivers/modules/oneview/common.py
index 56376714e..cb0b871a6 100644
--- a/ironic/drivers/modules/oneview/common.py
+++ b/ironic/drivers/modules/oneview/common.py
@@ -12,7 +12,9 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+
from oslo_log import log as logging
+from oslo_serialization import jsonutils
from oslo_utils import importutils
from six.moves.urllib import parse
@@ -226,43 +228,25 @@ def get_oneview_info(node):
def validate_oneview_resources_compatibility(oneview_client, task):
"""Validate if the node configuration is consistent with OneView.
- This method calls python-oneviewclient functions to validate if the node
+ This method calls hpOneView functions to validate if the node
configuration is consistent with the OneView resources it represents,
- including server_hardware_uri, server_hardware_type_uri,
- server_profile_template_uri, enclosure_group_uri and node ports. Also
- verifies if a Server Profile is applied to the Server Hardware the node
- represents when in pre-allocation model. If any validation fails,
- python-oneviewclient will raise an appropriate OneViewException.
+ including serverHardwareUri, serverHardwareTypeUri, serverGroupUri
+ serverProfileTemplateUri, enclosureGroupUri and node ports. If any
+ validation fails, the driver will raise an appropriate OneViewError.
:param oneview_client: an instance of the OneView client
:param: task: a TaskManager instance containing the node to act on.
+ :raises: OneViewError if any validation fails.
"""
- node_ports = task.ports
-
+ ports = task.ports
oneview_info = get_oneview_info(task.node)
- try:
- spt_uuid = oneview_utils.get_uuid_from_uri(
- oneview_info.get("server_profile_template_uri")
- )
-
- oneview_client.validate_node_server_profile_template(oneview_info)
- oneview_client.validate_node_server_hardware_type(oneview_info)
- oneview_client.validate_node_enclosure_group(oneview_info)
- oneview_client.validate_node_server_hardware(
- oneview_info,
- task.node.properties.get('memory_mb'),
- task.node.properties.get('cpus')
- )
- oneview_client.is_node_port_mac_compatible_with_server_hardware(
- oneview_info, node_ports
- )
- oneview_client.validate_server_profile_template_mac_type(spt_uuid)
-
- except oneview_exceptions.OneViewException as oneview_exc:
- msg = (_("Error validating node resources with OneView: %s") %
- oneview_exc)
- raise exception.OneViewError(error=msg)
+ _validate_node_server_profile_template(oneview_client, oneview_info)
+ _validate_node_server_hardware_type(oneview_client, oneview_info)
+ _validate_node_enclosure_group(oneview_client, oneview_info)
+ _validate_server_profile_template_mac_type(oneview_client, oneview_info)
+ _validate_node_port_mac_server_hardware(
+ oneview_client, oneview_info, ports)
def _verify_node_info(node_namespace, node_info_dict, info_required):
@@ -292,8 +276,8 @@ def _verify_node_info(node_namespace, node_info_dict, info_required):
def node_has_server_profile(func):
"""Checks if the node's Server Hardware has a Server Profile associated.
- Decorator to execute before the function execution if the Server Profile
- is applied to the Server Hardware.
+ Decorator to execute before the function execution to check if the Server
+ Profile is applied to the Server Hardware.
:param func: a given decorated function.
"""
@@ -322,3 +306,257 @@ def has_server_profile(task, client):
{"node": task.node.uuid, "message": exc}
)
raise exception.OneViewError(error=exc)
+
+
+def _get_server_hardware_mac_from_ilo(oneview_client, server_hardware):
+ """Get the MAC of Server Hardware's iLO controller.
+
+ :param: oneview_client: an instance of the HPE OneView client
+ :param: server_hardware: a server hardware uuid or uri
+ :return: MAC of Server Hardware's iLO controller.
+ :raises: InvalidParameterValue if required iLO credentials are missing.
+ :raises: OneViewError if can't get mac from a server hardware via iLO or
+ if fails to get JSON object with the default path.
+ """
+ try:
+ client = get_ilorest_client(oneview_client, server_hardware)
+ ilo_path = "/rest/v1/systems/1"
+ hardware = jsonutils.loads(client.get(ilo_path).text)
+ hardware_mac = hardware['HostCorrelation']['HostMACAddress'][0]
+ except redfish.JsonDecodingError as exc:
+ LOG.error("Failed in JSON object getting path: %s", ilo_path)
+ raise exception.OneViewError(error=exc)
+ except (ValueError, TypeError, IndexError) as exc:
+ LOG.error(
+ "Failed to get mac from server hardware %(server_hardware)s "
+ "via iLO. Error: %(message)s", {
+ "server_hardware": server_hardware.get("uri"),
+ "message": exc
+ }
+ )
+ raise exception.OneViewError(error=exc)
+
+ return hardware_mac
+
+
+def _get_server_hardware_mac(server_hardware):
+ """Get the MAC address of the first PXE bootable port of an Ethernet port.
+
+ :param: server_hardware: OneView Server Hardware object
+ :return: MAC of the first Ethernet and function 'a' port of the
+ Server Hardware object
+ :raises: OneViewError if there is no Ethernet port on the Server Hardware
+ or if there is no portMap on the Server Hardware requested
+ """
+ sh_physical_port = None
+
+ if server_hardware.get('portMap'):
+ for device in server_hardware.get(
+ 'portMap', {}).get('deviceSlots', ()):
+ for physical_port in device.get('physicalPorts', ()):
+ if physical_port.get('type') == 'Ethernet':
+ sh_physical_port = physical_port
+ break
+ if sh_physical_port:
+ for virtual_port in sh_physical_port.get('virtualPorts', ()):
+ # NOTE(nicodemos): Ironic oneview drivers needs to use a
+ # port that type is Ethernet and function identifier 'a' for
+ # this FlexNIC to be able to make a deploy using PXE.
+ if virtual_port.get('portFunction') == 'a':
+ return virtual_port.get('mac', ()).lower()
+ raise exception.OneViewError(
+ _("There is no Ethernet port on the Server Hardware: %s") %
+ server_hardware.get('uri'))
+ else:
+ raise exception.OneViewError(
+ _("The Server Hardware: %s doesn't have a list of adapters/slots, "
+ "their ports and attributes. This information is available only "
+ "for blade servers. Is this a rack server?") %
+ server_hardware.get('uri'))
+
+
+def _validate_node_server_profile_template(oneview_client, oneview_info):
+ """Validate if the Server Profile Template is consistent.
+
+ :param: oneview_client: an instance of the HPE OneView client
+ :param: oneview_info: the OneView related info in an Ironic node
+ :raises: OneViewError if the node's Server Profile Template is not
+ consistent
+ """
+ server_profile_template = oneview_client.server_profile_templates.get(
+ oneview_info['server_profile_template_uri'])
+ server_hardware = oneview_client.server_hardware.get(
+ oneview_info['server_hardware_uri'])
+
+ _validate_server_profile_template_server_hardware_type(
+ server_profile_template, server_hardware)
+ _validate_spt_enclosure_group(server_profile_template, server_hardware)
+ _validate_server_profile_template_manage_boot(server_profile_template)
+
+
+def _validate_server_profile_template_server_hardware_type(
+ server_profile_template, server_hardware):
+ """Validate if the Server Hardware Types are the same.
+
+ Validate if the Server Profile Template and the Server Hardware have the
+ same Server Hardware Type
+
+ :param: server_profile_template: OneView Server Profile Template object
+ :param: server_hardware: OneView Server Hardware object
+ :raises: OneViewError if the Server Profile Template and the Server
+ Hardware does not have the same Server Hardware Type
+ """
+ spt_server_hardware_type_uri = (
+ server_profile_template.get('serverHardwareTypeUri')
+ )
+ sh_server_hardware_type_uri = server_hardware.get('serverHardwareTypeUri')
+
+ if spt_server_hardware_type_uri != sh_server_hardware_type_uri:
+ message = _(
+ "Server profile template %(spt_uri)s serverHardwareTypeUri is "
+ "inconsistent with server hardware %(server_hardware_uri)s "
+ "serverHardwareTypeUri.") % {
+ 'spt_uri': server_profile_template.get('uri'),
+ 'server_hardware_uri': server_hardware.get('uri')}
+ raise exception.OneViewError(message)
+
+
+def _validate_spt_enclosure_group(server_profile_template, server_hardware):
+ """Validate Server Profile Template's Enclosure Group and Server Hardware's.
+
+ :param: server_profile_template: OneView Server Profile Template object
+ :param: server_hardware: OneView Server Hardware object
+ :raises: OneViewError if the Server Profile Template's Enclosure Group does
+ not match the Server Hardware's
+ """
+ spt_enclosure_group_uri = server_profile_template.get('enclosureGroupUri')
+ sh_enclosure_group_uri = server_hardware.get('serverGroupUri')
+
+ if spt_enclosure_group_uri != sh_enclosure_group_uri:
+ message = _("Server profile template %(spt_uri)s enclosureGroupUri is "
+ "inconsistent with server hardware %(sh_uri)s "
+ "serverGroupUri.") % {
+ 'spt_uri': server_profile_template.get('uri'),
+ 'sh_uri': server_hardware.get('uri')}
+ raise exception.OneViewError(message)
+
+
+def _validate_server_profile_template_manage_boot(server_profile_template):
+ """Validate if the Server Profile Template allows to manage the boot order.
+
+ :param: server_profile_template: OneView Server Profile Template object
+ :raises: OneViewError if the Server Profile Template does not allows to
+ manage the boot order.
+ """
+ manage_boot = server_profile_template.get('boot', {}).get('manageBoot')
+
+ if not manage_boot:
+ message = _("Server Profile Template: %s, does not allow to manage "
+ "boot order.") % server_profile_template.get('uri')
+ raise exception.OneViewError(message)
+
+
+def _validate_node_server_hardware_type(oneview_client, oneview_info):
+ """Validate if the node's Server Hardware Type matches Server Hardware's.
+
+ :param: oneview_client: the HPE OneView Client
+ :param: oneview_info: the OneView related info in an Ironic node
+ :raises: OneViewError if the node's Server Hardware Type group doesn't
+ match the Server Hardware's
+ """
+ node_server_hardware_type_uri = oneview_info['server_hardware_type_uri']
+ server_hardware = oneview_client.server_hardware.get(
+ oneview_info['server_hardware_uri'])
+ server_hardware_sht_uri = server_hardware.get('serverHardwareTypeUri')
+
+ if server_hardware_sht_uri != node_server_hardware_type_uri:
+ message = _("Node server_hardware_type_uri is inconsistent "
+ "with OneView's server hardware %(server_hardware_uri)s "
+ "serverHardwareTypeUri.") % {
+ 'server_hardware_uri': server_hardware.get('uri')}
+ raise exception.OneViewError(message)
+
+
+def _validate_node_enclosure_group(oneview_client, oneview_info):
+ """Validate if the node's Enclosure Group matches the Server Hardware's.
+
+ :param: oneview_client: an instance of the HPE OneView client
+ :param: oneview_info: the OneView related info in an Ironic node
+ :raises: OneViewError if the node's enclosure group doesn't match the
+ Server Hardware's
+ """
+ server_hardware = oneview_client.server_hardware.get(
+ oneview_info['server_hardware_uri'])
+ sh_enclosure_group_uri = server_hardware.get('serverGroupUri')
+ node_enclosure_group_uri = oneview_info['enclosure_group_uri']
+
+ if node_enclosure_group_uri and (
+ sh_enclosure_group_uri != node_enclosure_group_uri):
+ message = _(
+ "Node enclosure_group_uri '%(node_enclosure_group_uri)s' "
+ "is inconsistent with OneView's server hardware "
+ "serverGroupUri '%(sh_enclosure_group_uri)s' of "
+ "ServerHardware %(server_hardware)s") % {
+ 'node_enclosure_group_uri': node_enclosure_group_uri,
+ 'sh_enclosure_group_uri': sh_enclosure_group_uri,
+ 'server_hardware': server_hardware.get('uri')}
+ raise exception.OneViewError(message)
+
+
+def _validate_node_port_mac_server_hardware(oneview_client,
+ oneview_info, ports):
+ """Validate if a port matches the node's Server Hardware's MAC.
+
+ :param: oneview_client: an instance of the HPE OneView client
+ :param: oneview_info: the OneView related info in an Ironic node
+ :param: ports: a list of Ironic node's ports
+ :raises: OneViewError if there is no port with MAC address matching one
+ in OneView
+
+ """
+ server_hardware = oneview_client.server_hardware.get(
+ oneview_info['server_hardware_uri'])
+
+ if not ports:
+ return
+
+ # NOTE(nicodemos) If hponeview client's unable to get the MAC of the Server
+ # Hardware and raises an exception, the driver will try to get it from
+ # the iLOrest client.
+ try:
+ mac = _get_server_hardware_mac(server_hardware)
+ except exception.OneViewError:
+ mac = _get_server_hardware_mac_from_ilo(
+ oneview_client, server_hardware)
+
+ incompatible_macs = []
+ for port in ports:
+ if port.address.lower() == mac.lower():
+ return
+ incompatible_macs.append(port.address)
+
+ message = _("The ports of the node are not compatible with its "
+ "server hardware %(server_hardware_uri)s. There are no Ironic "
+ "port MAC's: %(port_macs)s, that matches with the "
+ "server hardware's MAC: %(server_hardware_mac)s") % {
+ 'server_hardware_uri': server_hardware.get('uri'),
+ 'port_macs': ', '.join(incompatible_macs),
+ 'server_hardware_mac': mac}
+ raise exception.OneViewError(message)
+
+
+def _validate_server_profile_template_mac_type(oneview_client, oneview_info):
+ """Validate if the node's Server Profile Template's MAC type is physical.
+
+ :param: oneview_client: an instance of the HPE OneView client
+ :param: oneview_info: the OneView related info in an Ironic node
+ :raises: OneViewError if the node's Server Profile Template's MAC type is
+ not physical
+ """
+ server_profile_template = oneview_client.server_profile_templates.get(
+ oneview_info['server_profile_template_uri']
+ )
+ if server_profile_template.get('macType') != 'Physical':
+ message = _("The server profile template %s is not set to use "
+ "physical MAC.") % server_profile_template.get('uri')
+ raise exception.OneViewError(message)
diff --git a/ironic/drivers/modules/oneview/deploy.py b/ironic/drivers/modules/oneview/deploy.py
index e8fa9e92d..d4553a32f 100644
--- a/ironic/drivers/modules/oneview/deploy.py
+++ b/ironic/drivers/modules/oneview/deploy.py
@@ -230,8 +230,7 @@ class OneViewIscsiDeploy(iscsi_deploy.ISCSIDeploy, OneViewPeriodicTasks):
def validate(self, task):
common.verify_node_info(task.node)
try:
- common.validate_oneview_resources_compatibility(
- self.oneview_client, task)
+ common.validate_oneview_resources_compatibility(self.client, task)
except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc)
super(OneViewIscsiDeploy, self).validate(task)
@@ -275,8 +274,7 @@ class OneViewAgentDeploy(agent.AgentDeploy, OneViewPeriodicTasks):
def validate(self, task):
common.verify_node_info(task.node)
try:
- common.validate_oneview_resources_compatibility(
- self.oneview_client, task)
+ common.validate_oneview_resources_compatibility(self.client, task)
except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc)
super(OneViewAgentDeploy, self).validate(task)
diff --git a/ironic/drivers/modules/oneview/inspect.py b/ironic/drivers/modules/oneview/inspect.py
index 8ea77d77e..a1ae5382a 100644
--- a/ironic/drivers/modules/oneview/inspect.py
+++ b/ironic/drivers/modules/oneview/inspect.py
@@ -60,8 +60,7 @@ class OneViewInspect(inspector.Inspector):
common.verify_node_info(task.node)
try:
- common.validate_oneview_resources_compatibility(
- self.oneview_client, task)
+ common.validate_oneview_resources_compatibility(self.client, task)
except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc)
diff --git a/ironic/drivers/modules/oneview/management.py b/ironic/drivers/modules/oneview/management.py
index 5984b906a..f94c1bca3 100644
--- a/ironic/drivers/modules/oneview/management.py
+++ b/ironic/drivers/modules/oneview/management.py
@@ -191,8 +191,7 @@ class OneViewManagement(base.ManagementInterface):
common.verify_node_info(task.node)
try:
- common.validate_oneview_resources_compatibility(
- self.oneview_client, task)
+ common.validate_oneview_resources_compatibility(self.client, task)
if not deploy_utils.is_node_in_use_by_ironic(
self.client, task.node
diff --git a/ironic/drivers/modules/oneview/power.py b/ironic/drivers/modules/oneview/power.py
index fadc0956d..fe4115bf5 100644
--- a/ironic/drivers/modules/oneview/power.py
+++ b/ironic/drivers/modules/oneview/power.py
@@ -90,15 +90,12 @@ class OneViewPower(base.PowerInterface):
common.verify_node_info(task.node)
try:
- if deploy_utils.is_node_in_use_by_oneview(
- self.client, task.node
- ):
+ common.validate_oneview_resources_compatibility(self.client, task)
+
+ if deploy_utils.is_node_in_use_by_oneview(self.client, task.node):
raise exception.InvalidParameterValue(
_("Node %s is in use by OneView.") % task.node.uuid)
- common.validate_oneview_resources_compatibility(
- self.oneview_client, task
- )
except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc)
diff --git a/ironic/tests/unit/drivers/modules/oneview/test_common.py b/ironic/tests/unit/drivers/modules/oneview/test_common.py
index 751e5a0d3..7f26221ed 100644
--- a/ironic/tests/unit/drivers/modules/oneview/test_common.py
+++ b/ironic/tests/unit/drivers/modules/oneview/test_common.py
@@ -14,6 +14,7 @@
# under the License.
import mock
+
from oslo_utils import importutils
from ironic.common import exception
@@ -239,35 +240,139 @@ class OneViewCommonTestCase(db_base.DbTestCase):
{"a": '', "b": None, "c": "something"},
["a", "b", "c"])
- @mock.patch.object(common, 'get_oneview_client', spec_set=True,
- autospec=True)
+ @mock.patch.object(common, 'get_hponeview_client', autospec=True)
+ @mock.patch.object(common, '_validate_node_server_profile_template')
+ @mock.patch.object(common, '_validate_node_server_hardware_type')
+ @mock.patch.object(common, '_validate_node_enclosure_group')
+ @mock.patch.object(common, '_validate_node_port_mac_server_hardware')
+ @mock.patch.object(common, '_validate_server_profile_template_mac_type')
def test_validate_oneview_resources_compatibility(
- self, mock_get_ov_client):
+ self, mock_spt_mac_type, mock_port_mac_sh, mock_enclosure,
+ mock_sh_type, mock_sp_template, mock_hponeview):
"""Validate compatibility of resources.
- 1) Check validate_node_server_profile_template method is called
- 2) Check validate_node_server_hardware_type method is called
- 3) Check validate_node_enclosure_group method is called
- 4) Check validate_node_server_hardware method is called
- 5) Check is_node_port_mac_compatible_with_server_hardware method
- is called
- 6) Check validate_server_profile_template_mac_type method is called
+ 1) Check _validate_node_server_profile_template method is called
+ 2) Check _validate_node_server_hardware_type method is called
+ 3) Check _validate_node_enclosure_group method is called
+ 4) Check _validate_node_port_mac_server_hardware method is called
+ 5) Check _validate_server_profile_template_mac_type method is called
"""
- oneview_client = mock_get_ov_client()
+ oneview_client = mock_hponeview()
+ fake_port = db_utils.create_test_port()
+ fake_port.address = 'AA:BB:CC:DD:EE'
+ fake_device = {'physicalPorts': [
+ {'type': 'Ethernet',
+ 'virtualPorts': [
+ {'portFunction': 'a',
+ 'mac': 'AA:BB:CC:DD:EE'}
+ ]}
+ ]}
+ fake_spt = {
+ 'serverHardwareTypeUri': 'fake_sht_uri',
+ 'enclosureGroupUri': 'fake_eg_uri',
+ 'macType': 'Physical',
+ 'boot': {'manageBoot': True}
+ }
+ fake_sh = {
+ 'serverHardwareTypeUri': 'fake_sht_uri',
+ 'serverGroupUri': 'fake_eg_uri',
+ 'processorCoreCount': 4,
+ 'processorCount': 2,
+ 'memoryMb': 4096,
+ 'portMap': {'deviceSlots': [fake_device]}
+ }
+ oneview_client.server_profile_templates.get.return_value = fake_spt
+ oneview_client.server_hardware.get.return_value = fake_sh
+
with task_manager.acquire(self.context, self.node.uuid) as task:
+ task.ports = [fake_port]
common.validate_oneview_resources_compatibility(oneview_client,
task)
- self.assertTrue(
- oneview_client.validate_node_server_profile_template.called)
- self.assertTrue(
- oneview_client.validate_node_server_hardware_type.called)
- self.assertTrue(
- oneview_client.validate_node_enclosure_group.called)
- self.assertTrue(
- oneview_client.validate_node_server_hardware.called)
- self.assertTrue(
- oneview_client.
- is_node_port_mac_compatible_with_server_hardware.called)
- self.assertTrue(
- oneview_client.
- validate_server_profile_template_mac_type.called)
+ self.assertTrue(mock_sp_template.called)
+ self.assertTrue(mock_sh_type.called)
+ self.assertTrue(mock_enclosure.called)
+ self.assertTrue(mock_port_mac_sh.called)
+ self.assertTrue(mock_spt_mac_type.called)
+
+ @mock.patch.object(common, 'get_hponeview_client', autospec=True)
+ def test__validate_server_profile_template_mac_type_virtual(
+ self, mock_hponeview):
+ oneview_client = mock_hponeview()
+ fake_spt = {'macType': 'Virtual'}
+ oneview_client.server_hardware.get.return_value = fake_spt
+ oneview_info = {'server_profile_template_uri': 'fake_uri'}
+
+ self.assertRaises(exception.OneViewError,
+ common._validate_server_profile_template_mac_type,
+ oneview_client, oneview_info)
+
+ @mock.patch.object(common, 'get_hponeview_client', autospec=True)
+ def test__validate_node_port_mac_server_hardware_invalid(
+ self, mock_hponeview):
+ oneview_client = mock_hponeview()
+ fake_device = {
+ 'physicalPorts': [
+ {'type': 'notEthernet',
+ 'mac': '00:11:22:33:44',
+ 'virtualPorts': [{
+ 'portFunction': 'a',
+ 'mac': 'AA:BB:CC:DD:EE'}]},
+ {'type': 'Ethernet',
+ 'mac': '11:22:33:44:55',
+ 'virtualPorts': [{
+ 'portFunction': 'a',
+ 'mac': 'BB:CC:DD:EE:FF'}]}]}
+ fake_sh = {'portMap': {'deviceSlots': [fake_device]}}
+ fake_port = db_utils.create_test_port(address='AA:BB:CC:DD:EE')
+ oneview_client.server_hardware.get.return_value = fake_sh
+ oneview_info = db_utils.get_test_oneview_driver_info()
+
+ self.assertRaises(exception.OneViewError,
+ common._validate_node_port_mac_server_hardware,
+ oneview_client, oneview_info, [fake_port])
+
+ @mock.patch.object(common, 'get_hponeview_client', autospec=True)
+ def test__validate_node_enclosure_group_invalid(self, mock_hponeview):
+ oneview_client = mock_hponeview()
+ fake_sh = {'serverGroupUri': 'invalid_fake_eg_uri'}
+ oneview_client.server_hardware.get.return_value = fake_sh
+ oneview_info = {'server_hardware_uri': 'fake_sh_uri',
+ 'enclosure_group_uri': 'fake_eg_uri'}
+
+ self.assertRaises(exception.OneViewError,
+ common._validate_node_enclosure_group,
+ oneview_client, oneview_info)
+
+ @mock.patch.object(common, 'get_hponeview_client', autospec=True)
+ def test__validate_node_server_hardware_type(self, mock_hponeview):
+ oneview_client = mock_hponeview()
+ fake_sh = {'serverHardwareTypeUri': 'invalid_fake_sh_uri'}
+ oneview_client.server_hardware.get.return_value = fake_sh
+ oneview_info = {'server_hardware_uri': 'fake_sh_uri',
+ 'server_hardware_type_uri': 'fake_sht_uri'}
+
+ self.assertRaises(exception.OneViewError,
+ common._validate_node_server_hardware_type,
+ oneview_client, oneview_info)
+
+ def test__validate_server_profile_template_manage_boot_false(self):
+ fake_spt = {'boot': {'manageBoot': False}}
+ self.assertRaises(exception.OneViewError,
+ common._validate_server_profile_template_manage_boot,
+ fake_spt)
+
+ def test__validate_spt_enclosure_group_invalid(self):
+ fake_spt = {'enclosureGroupUri': 'fake_eg_uri'}
+ fake_sh = {'serverGroupUri': 'invalid_fake_eg_uri'}
+ self.assertRaises(exception.OneViewError,
+ common._validate_spt_enclosure_group,
+ fake_spt, fake_sh)
+
+ def test__validate_server_profile_template_server_hardware_type(self):
+ fake_spt = {'serverHardwareTypeUri': 'fake_sht_uri'}
+ fake_sh = {'serverHardwareTypeUri': 'invalid_fake_sht_uri'}
+ self.assertRaises(
+ exception.OneViewError,
+ common._validate_server_profile_template_server_hardware_type,
+ fake_spt, fake_sh
+ )
diff --git a/ironic/tests/unit/drivers/modules/oneview/test_deploy.py b/ironic/tests/unit/drivers/modules/oneview/test_deploy.py
index 233ea487f..0dd8e003f 100644
--- a/ironic/tests/unit/drivers/modules/oneview/test_deploy.py
+++ b/ironic/tests/unit/drivers/modules/oneview/test_deploy.py
@@ -278,10 +278,16 @@ class OneViewIscsiDeployTestCase(db_base.DbTestCase):
expected = common.COMMON_PROPERTIES
self.assertEqual(expected, self.driver.deploy.get_properties())
- @mock.patch.object(iscsi_deploy.ISCSIDeploy, 'validate', autospec=True)
- def test_validate(self, iscsi_deploy_validate_mock, mock_get_ov_client):
- with task_manager.acquire(self.context, self.node.uuid) as task:
+ @mock.patch.object(common, 'validate_oneview_resources_compatibility',
+ spect_set=True, autospec=True)
+ @mock.patch.object(iscsi_deploy.ISCSIDeploy, 'validate',
+ spec_set=True, autospec=True)
+ def test_validate(self, iscsi_deploy_validate_mock,
+ mock_validate_resources, mock_ov_client):
+ with task_manager.acquire(self.context, self.node.uuid,
+ shared=False) as task:
task.driver.deploy.validate(task)
+ self.assertTrue(mock_validate_resources.called)
iscsi_deploy_validate_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'prepare', autospec=True)
@@ -397,10 +403,16 @@ class OneViewAgentDeployTestCase(db_base.DbTestCase):
expected = common.COMMON_PROPERTIES
self.assertEqual(expected, self.driver.deploy.get_properties())
- @mock.patch.object(agent.AgentDeploy, 'validate', autospec=True)
- def test_validate(self, agent_deploy_validate_mock, mock_get_ov_client):
- with task_manager.acquire(self.context, self.node.uuid) as task:
+ @mock.patch.object(common, 'validate_oneview_resources_compatibility',
+ spect_set=True, autospec=True)
+ @mock.patch.object(agent.AgentDeploy, 'validate',
+ spec_set=True, autospec=True)
+ def test_validate(self, agent_deploy_validate_mock,
+ mock_validate_resources, mock_ov_client):
+ with task_manager.acquire(self.context, self.node.uuid,
+ shared=False) as task:
task.driver.deploy.validate(task)
+ self.assertTrue(mock_validate_resources.called)
agent_deploy_validate_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(agent.AgentDeploy, 'prepare', autospec=True)
diff --git a/ironic/tests/unit/drivers/modules/oneview/test_inspect.py b/ironic/tests/unit/drivers/modules/oneview/test_inspect.py
index f42f97870..53f0a3ca1 100644
--- a/ironic/tests/unit/drivers/modules/oneview/test_inspect.py
+++ b/ironic/tests/unit/drivers/modules/oneview/test_inspect.py
@@ -16,7 +16,7 @@
import mock
from ironic.conductor import task_manager
-from ironic.drivers.modules.oneview import common as oneview_common
+from ironic.drivers.modules.oneview import common
from ironic.drivers.modules.oneview import deploy_utils
from ironic.tests.unit.conductor import mgr_utils
from ironic.tests.unit.db import base as db_base
@@ -43,13 +43,13 @@ class AgentPXEOneViewInspectTestCase(db_base.DbTestCase):
shared=True) as task:
self.assertEqual(expected, task.driver.inspect.get_properties())
- @mock.patch.object(oneview_common, 'verify_node_info')
- def test_validate(self, mock_verify_node_info):
+ @mock.patch.object(common, 'validate_oneview_resources_compatibility')
+ def test_validate(self, mock_validate):
self.config(enabled=False, group='inspector')
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.inspect.validate(task)
- mock_verify_node_info.assert_called_once_with(task.node)
+ self.assertTrue(mock_validate.called)
@mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic')
def test_inspect_hardware(self, mock_allocate_server_hardware_to_ironic):
@@ -78,13 +78,13 @@ class ISCSIPXEOneViewInspectTestCase(db_base.DbTestCase):
shared=True) as task:
self.assertEqual(expected, task.driver.inspect.get_properties())
- @mock.patch.object(oneview_common, 'verify_node_info')
- def test_validate(self, mock_verify_node_info):
+ @mock.patch.object(common, 'validate_oneview_resources_compatibility')
+ def test_validate(self, mock_validate):
self.config(enabled=False, group='inspector')
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.inspect.validate(task)
- mock_verify_node_info.assert_called_once_with(task.node)
+ self.assertTrue(mock_validate.called)
@mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic')
def test_inspect_hardware(self, mock_allocate_server_hardware_to_ironic):
diff --git a/ironic/tests/unit/drivers/modules/oneview/test_management.py b/ironic/tests/unit/drivers/modules/oneview/test_management.py
index 9b0054fae..c6bbf1f69 100644
--- a/ironic/tests/unit/drivers/modules/oneview/test_management.py
+++ b/ironic/tests/unit/drivers/modules/oneview/test_management.py
@@ -236,18 +236,22 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
)
self.info = common.get_oneview_info(self.node)
- @mock.patch.object(deploy_utils, 'is_node_in_use_by_ironic')
- @mock.patch.object(common, 'validate_oneview_resources_compatibility')
- def test_validate(self, mock_validate, mock_ironic_node, mock_ovclient):
+ @mock.patch.object(deploy_utils, 'is_node_in_use_by_ironic',
+ spect_set=True, autospec=True)
+ @mock.patch.object(common, 'validate_oneview_resources_compatibility',
+ spect_set=True, autospec=True)
+ def test_validate(self, mock_validate, mock_ironic_node, mock_ov_client):
mock_ironic_node.return_value = True
- with task_manager.acquire(self.context, self.node.uuid) as task:
+ with task_manager.acquire(self.context, self.node.uuid,
+ shared=False) as task:
task.driver.management.validate(task)
self.assertTrue(mock_validate.called)
- @mock.patch.object(deploy_utils, 'is_node_in_use_by_ironic')
- @mock.patch.object(common, 'validate_oneview_resources_compatibility')
+ @mock.patch.object(deploy_utils, 'is_node_in_use_by_ironic',
+ spect_set=True, autospec=True)
def test_validate_for_node_not_in_use_by_ironic(
- self, mock_validate, mock_ironic_node, mock_ovclient):
+ self, mock_ironic_node, mock_get_ov_client
+ ):
mock_ironic_node.return_value = False
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.InvalidParameterValue,