diff options
author | Hugo Nicodemos <nicodemos@lsd.ufcg.edu.br> | 2017-11-09 18:07:43 +0000 |
---|---|---|
committer | Hugo Nicodemos <nicodemos@lsd.ufcg.edu.br> | 2017-11-09 16:12:22 -0300 |
commit | 6023e68c8940bd3ce76a2a36d7acca6976b49c71 (patch) | |
tree | ad671f30404b038be422af7a34551d299ad8cc26 | |
parent | 9b523967e1aeb996e5567eebe6184b00fbbc4377 (diff) | |
download | ironic-6023e68c8940bd3ce76a2a36d7acca6976b49c71.tar.gz |
Revert "Migrate python-oneviewclient validations to Ironic OneView drivers"
Reverting these changes because python-hpOneView does not provide HTTPS
secure connection with custom CAcert and could cause a possible security issue.
This reverts commit c2eb357aa1a92670745d282423154e62709f570f.
Change-Id: Ief2468afd01587469b1c2e9aa5bc9835ca2eb7e9
-rw-r--r-- | ironic/drivers/modules/oneview/common.py | 302 | ||||
-rw-r--r-- | ironic/drivers/modules/oneview/deploy.py | 6 | ||||
-rw-r--r-- | ironic/drivers/modules/oneview/inspect.py | 3 | ||||
-rw-r--r-- | ironic/drivers/modules/oneview/management.py | 3 | ||||
-rw-r--r-- | ironic/drivers/modules/oneview/power.py | 9 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/oneview/test_common.py | 155 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/oneview/test_deploy.py | 24 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/oneview/test_inspect.py | 14 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/oneview/test_management.py | 18 |
9 files changed, 91 insertions, 443 deletions
diff --git a/ironic/drivers/modules/oneview/common.py b/ironic/drivers/modules/oneview/common.py index cb0b871a6..56376714e 100644 --- a/ironic/drivers/modules/oneview/common.py +++ b/ironic/drivers/modules/oneview/common.py @@ -12,9 +12,7 @@ # 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 @@ -228,25 +226,43 @@ 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 hpOneView functions to validate if the node + This method calls python-oneviewclient functions to validate if the node configuration is consistent with the OneView resources it represents, - including serverHardwareUri, serverHardwareTypeUri, serverGroupUri - serverProfileTemplateUri, enclosureGroupUri and node ports. If any - validation fails, the driver will raise an appropriate OneViewError. + 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. :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. """ - ports = task.ports + node_ports = task.ports + oneview_info = get_oneview_info(task.node) - _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) + 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) def _verify_node_info(node_namespace, node_info_dict, info_required): @@ -276,8 +292,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 to check if the Server - Profile is applied to the Server Hardware. + Decorator to execute before the function execution if the Server Profile + is applied to the Server Hardware. :param func: a given decorated function. """ @@ -306,257 +322,3 @@ 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 d4553a32f..e8fa9e92d 100644 --- a/ironic/drivers/modules/oneview/deploy.py +++ b/ironic/drivers/modules/oneview/deploy.py @@ -230,7 +230,8 @@ class OneViewIscsiDeploy(iscsi_deploy.ISCSIDeploy, OneViewPeriodicTasks): def validate(self, task): common.verify_node_info(task.node) try: - common.validate_oneview_resources_compatibility(self.client, task) + common.validate_oneview_resources_compatibility( + self.oneview_client, task) except exception.OneViewError as oneview_exc: raise exception.InvalidParameterValue(oneview_exc) super(OneViewIscsiDeploy, self).validate(task) @@ -274,7 +275,8 @@ class OneViewAgentDeploy(agent.AgentDeploy, OneViewPeriodicTasks): def validate(self, task): common.verify_node_info(task.node) try: - common.validate_oneview_resources_compatibility(self.client, task) + common.validate_oneview_resources_compatibility( + self.oneview_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 fc3838d50..5aa87e9bb 100644 --- a/ironic/drivers/modules/oneview/inspect.py +++ b/ironic/drivers/modules/oneview/inspect.py @@ -59,7 +59,8 @@ class OneViewInspect(inspector.Inspector): common.verify_node_info(task.node) try: - common.validate_oneview_resources_compatibility(self.client, task) + common.validate_oneview_resources_compatibility( + self.oneview_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 f94c1bca3..5984b906a 100644 --- a/ironic/drivers/modules/oneview/management.py +++ b/ironic/drivers/modules/oneview/management.py @@ -191,7 +191,8 @@ class OneViewManagement(base.ManagementInterface): common.verify_node_info(task.node) try: - common.validate_oneview_resources_compatibility(self.client, task) + common.validate_oneview_resources_compatibility( + self.oneview_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 fe4115bf5..fadc0956d 100644 --- a/ironic/drivers/modules/oneview/power.py +++ b/ironic/drivers/modules/oneview/power.py @@ -90,12 +90,15 @@ class OneViewPower(base.PowerInterface): common.verify_node_info(task.node) try: - common.validate_oneview_resources_compatibility(self.client, task) - - if deploy_utils.is_node_in_use_by_oneview(self.client, task.node): + 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 7f26221ed..751e5a0d3 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_common.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_common.py @@ -14,7 +14,6 @@ # under the License. import mock - from oslo_utils import importutils from ironic.common import exception @@ -240,139 +239,35 @@ class OneViewCommonTestCase(db_base.DbTestCase): {"a": '', "b": None, "c": "something"}, ["a", "b", "c"]) - @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') + @mock.patch.object(common, 'get_oneview_client', spec_set=True, + autospec=True) def test_validate_oneview_resources_compatibility( - self, mock_spt_mac_type, mock_port_mac_sh, mock_enclosure, - mock_sh_type, mock_sp_template, mock_hponeview): + self, mock_get_ov_client): """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_port_mac_server_hardware method is called - 5) 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_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 """ - 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 - + oneview_client = mock_get_ov_client() 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(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 - ) + 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) diff --git a/ironic/tests/unit/drivers/modules/oneview/test_deploy.py b/ironic/tests/unit/drivers/modules/oneview/test_deploy.py index 0dd8e003f..233ea487f 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_deploy.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_deploy.py @@ -278,16 +278,10 @@ 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_mock, - mock_validate_resources, mock_ov_client): - with task_manager.acquire(self.context, self.node.uuid, - shared=False) as task: + @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: 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) @@ -403,16 +397,10 @@ 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, - mock_validate_resources, mock_ov_client): - with task_manager.acquire(self.context, self.node.uuid, - shared=False) as task: + @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: 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 53f0a3ca1..f42f97870 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 +from ironic.drivers.modules.oneview import common as oneview_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(common, 'validate_oneview_resources_compatibility') - def test_validate(self, mock_validate): + @mock.patch.object(oneview_common, 'verify_node_info') + def test_validate(self, mock_verify_node_info): self.config(enabled=False, group='inspector') with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: task.driver.inspect.validate(task) - self.assertTrue(mock_validate.called) + mock_verify_node_info.assert_called_once_with(task.node) @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(common, 'validate_oneview_resources_compatibility') - def test_validate(self, mock_validate): + @mock.patch.object(oneview_common, 'verify_node_info') + def test_validate(self, mock_verify_node_info): self.config(enabled=False, group='inspector') with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: task.driver.inspect.validate(task) - self.assertTrue(mock_validate.called) + mock_verify_node_info.assert_called_once_with(task.node) @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 c6bbf1f69..9b0054fae 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_management.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_management.py @@ -236,22 +236,18 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): ) self.info = common.get_oneview_info(self.node) - @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.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_ironic_node.return_value = True - with task_manager.acquire(self.context, self.node.uuid, - shared=False) as task: + with task_manager.acquire(self.context, self.node.uuid) as task: task.driver.management.validate(task) self.assertTrue(mock_validate.called) - @mock.patch.object(deploy_utils, 'is_node_in_use_by_ironic', - spect_set=True, autospec=True) + @mock.patch.object(deploy_utils, 'is_node_in_use_by_ironic') + @mock.patch.object(common, 'validate_oneview_resources_compatibility') def test_validate_for_node_not_in_use_by_ironic( - self, mock_ironic_node, mock_get_ov_client - ): + self, mock_validate, mock_ironic_node, mock_ovclient): mock_ironic_node.return_value = False with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises(exception.InvalidParameterValue, |