Migrate python-oneviewclient validations to oneview hardware type

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 ``oneview`` hardware type.

Change-Id: I9031f6e9a59901d3241c6802938252bb63cfe6ca
Partial-Bug: #1693788
This commit is contained in:
Hugo Nicodemos 2017-12-01 10:33:03 -03:00 committed by Dmitry Tantsur
parent c6b615cc5b
commit b1aa04481f
9 changed files with 429 additions and 107 deletions

View File

@ -16,6 +16,7 @@
import re
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import importutils
from six.moves.urllib import parse
@ -238,47 +239,28 @@ def get_oneview_info(node):
return oneview_info
def validate_oneview_resources_compatibility(oneview_client, task):
"""Validates if the node configuration is consistent with OneView.
def validate_oneview_resources_compatibility(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_client = get_hponeview_client()
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):
@ -344,3 +326,255 @@ def ensure_server_profile(task):
}
)
raise exception.OneViewError(error=exc)
def _get_server_hardware_mac_from_ilo(server_hardware):
"""Get the MAC of Server Hardware's iLO controller.
: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:
ilo_client = get_ilorest_client(server_hardware)
ilo_path = "/rest/v1/systems/1"
hardware = jsonutils.loads(ilo_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(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)

View File

@ -219,10 +219,6 @@ class OneViewIscsiDeploy(iscsi_deploy.ISCSIDeploy, OneViewPeriodicTasks):
oneview_driver = common.ISCSI_PXE_ONEVIEW
def __init__(self):
super(OneViewIscsiDeploy, self).__init__()
self.oneview_client = common.get_oneview_client()
def get_properties(self):
return deploy_utils.get_properties()
@ -230,8 +226,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(task)
except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc)
super(OneViewIscsiDeploy, self).validate(task)
@ -263,10 +258,6 @@ class OneViewAgentDeploy(agent.AgentDeploy, OneViewPeriodicTasks):
oneview_driver = common.AGENT_PXE_ONEVIEW
def __init__(self):
super(OneViewAgentDeploy, self).__init__()
self.oneview_client = common.get_oneview_client()
def get_properties(self):
return deploy_utils.get_properties()
@ -274,8 +265,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(task)
except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc)
super(OneViewAgentDeploy, self).validate(task)

View File

@ -34,10 +34,6 @@ oneview_utils = importutils.try_import('oneview_client.utils')
class OneViewInspect(inspector.Inspector):
"""Interface for in band inspection."""
def __init__(self):
super(OneViewInspect, self).__init__()
self.oneview_client = common.get_oneview_client()
def get_properties(self):
return deploy_utils.get_properties()
@ -59,8 +55,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(task)
except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc)

View File

@ -150,10 +150,6 @@ def set_boot_device(task):
class OneViewManagement(base.ManagementInterface):
def __init__(self):
super(OneViewManagement, self).__init__()
self.oneview_client = common.get_oneview_client()
def get_properties(self):
return deploy_utils.get_properties()
@ -177,8 +173,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(task)
if not deploy_utils.is_node_in_use_by_ironic(task.node):
raise exception.InvalidParameterValue(

View File

@ -58,10 +58,6 @@ SET_POWER_STATE_MAP = {
class OneViewPower(base.PowerInterface):
def __init__(self):
super(OneViewPower, self).__init__()
self.oneview_client = common.get_oneview_client()
def get_properties(self):
return deploy_utils.get_properties()
@ -90,9 +86,7 @@ class OneViewPower(base.PowerInterface):
common.verify_node_info(task.node)
try:
common.validate_oneview_resources_compatibility(
self.oneview_client, task
)
common.validate_oneview_resources_compatibility(task)
if deploy_utils.is_node_in_use_by_oneview(task.node):
raise exception.InvalidParameterValue(
_("Node %s is in use by OneView.") % task.node.uuid)

View File

@ -256,36 +256,137 @@ 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:
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)
task.ports = [fake_port]
common.validate_oneview_resources_compatibility(task)
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)

View File

@ -272,13 +272,17 @@ class OneViewIscsiDeployTestCase(db_base.DbTestCase):
expected = common.COMMON_PROPERTIES
self.assertEqual(expected, self.driver.deploy.get_properties())
@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):
def test_validate(
self, iscsi_deploy_validate_mock, mock_validate):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.validate(task)
iscsi_deploy_validate.assert_called_once_with(mock.ANY, task)
self.assertTrue(mock_validate.called)
iscsi_deploy_validate_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'prepare', autospec=True)
@mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic')
@ -395,13 +399,16 @@ class OneViewAgentDeployTestCase(db_base.DbTestCase):
expected = common.COMMON_PROPERTIES
self.assertEqual(expected, self.driver.deploy.get_properties())
@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):
def test_validate(
self, agent_deploy_validate_mock, mock_validate):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.validate(task)
agent_deploy_validate_mock.assert_called_once_with(mock.ANY, task)
self.assertTrue(mock_validate.called)
@mock.patch.object(agent.AgentDeploy, 'prepare',
spec_set=True, autospec=True)

View File

@ -43,13 +43,14 @@ 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(
oneview_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 +79,14 @@ 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(
oneview_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):

View File

@ -197,15 +197,19 @@ 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')
@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_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(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_ironic_node):
mock_ironic_node.return_value = False
with task_manager.acquire(self.context, self.node.uuid) as task: