diff options
-rw-r--r-- | ironic/drivers/modules/oneview/common.py | 26 | ||||
-rw-r--r-- | ironic/drivers/modules/oneview/deploy.py | 34 | ||||
-rw-r--r-- | ironic/drivers/modules/oneview/deploy_utils.py | 43 | ||||
-rw-r--r-- | ironic/drivers/modules/oneview/inspect.py | 12 | ||||
-rw-r--r-- | ironic/drivers/modules/oneview/management.py | 22 | ||||
-rw-r--r-- | ironic/drivers/modules/oneview/power.py | 22 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/oneview/test_common.py | 3 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/oneview/test_deploy.py | 79 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/oneview/test_deploy_utils.py | 21 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/oneview/test_management.py | 49 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/oneview/test_power.py | 38 |
11 files changed, 131 insertions, 218 deletions
diff --git a/ironic/drivers/modules/oneview/common.py b/ironic/drivers/modules/oneview/common.py index 122c847f2..2bd23436c 100644 --- a/ironic/drivers/modules/oneview/common.py +++ b/ironic/drivers/modules/oneview/common.py @@ -95,15 +95,15 @@ def get_hponeview_client(): return hponeview_client.OneViewClient(config) -def get_ilorest_client(oneview_client, server_hardware): +def get_ilorest_client(server_hardware): """Generate an instance of the iLORest library client. - :param oneview_client: an instance of a python-hpOneView - :param: server_hardware: a server hardware uuid or uri + :param server_hardware: a server hardware uuid or uri :returns: an instance of the iLORest client :raises: InvalidParameterValue if mandatory information is missing on the node or on invalid input. """ + oneview_client = get_hponeview_client() remote_console = oneview_client.server_hardware.get_remote_console_url( server_hardware ) @@ -196,7 +196,7 @@ def get_oneview_info(node): return oneview_info -def validate_oneview_resources_compatibility(oneview_client, task): +def validate_oneview_resources_compatibility(task): """Validate if the node configuration is consistent with OneView. This method calls hpOneView functions to validate if the node @@ -205,11 +205,11 @@ def validate_oneview_resources_compatibility(oneview_client, task): 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. """ ports = task.ports + oneview_client = get_hponeview_client() oneview_info = get_oneview_info(task.node) _validate_node_server_profile_template(oneview_client, oneview_info) @@ -254,22 +254,22 @@ def node_has_server_profile(func): """ def inner(self, *args, **kwargs): task = args[0] - has_server_profile(task, self.client) + has_server_profile(task) return func(self, *args, **kwargs) return inner -def has_server_profile(task, client): +def has_server_profile(task): """Checks if the node's Server Hardware has a Server Profile associated. Function to check if the Server Profile is applied to the Server Hardware. - :param client: an instance of the OneView client :param task: a TaskManager instance containing the node to act on. """ + oneview_client = get_hponeview_client() try: profile = task.node.driver_info.get('applied_server_profile_uri') - client.server_profiles.get(profile) + oneview_client.server_profiles.get(profile) except client_exception.HPOneViewException as exc: LOG.error( "Failed to get server profile from OneView appliance for" @@ -279,10 +279,9 @@ def has_server_profile(task, client): raise exception.OneViewError(error=exc) -def _get_server_hardware_mac_from_ilo(oneview_client, server_hardware): +def _get_server_hardware_mac_from_ilo(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. @@ -290,7 +289,7 @@ def _get_server_hardware_mac_from_ilo(oneview_client, server_hardware): if fails to get JSON object with the default path. """ try: - client = get_ilorest_client(oneview_client, server_hardware) + client = get_ilorest_client(server_hardware) ilo_path = "/rest/v1/systems/1" hardware = jsonutils.loads(client.get(ilo_path).text) hardware_mac = hardware['HostCorrelation']['HostMACAddress'][0] @@ -497,8 +496,7 @@ def _validate_node_port_mac_server_hardware(oneview_client, try: mac = _get_server_hardware_mac(server_hardware) except exception.OneViewError: - mac = _get_server_hardware_mac_from_ilo( - oneview_client, server_hardware) + mac = _get_server_hardware_mac_from_ilo(server_hardware) incompatible_macs = [] for port in ports: diff --git a/ironic/drivers/modules/oneview/deploy.py b/ironic/drivers/modules/oneview/deploy.py index 3f2704986..5bf4cdf7e 100644 --- a/ironic/drivers/modules/oneview/deploy.py +++ b/ironic/drivers/modules/oneview/deploy.py @@ -66,9 +66,7 @@ class OneViewPeriodicTasks(object): node = objects.Node.get(context, node_uuid) try: - oneview_using = deploy_utils.is_node_in_use_by_oneview( - self.client, node - ) + oneview_using = deploy_utils.is_node_in_use_by_oneview(node) except exception.OneViewError as e: # NOTE(xavierr): Skip this node and process the # remaining nodes. This node will be checked in @@ -128,7 +126,7 @@ class OneViewPeriodicTasks(object): try: oneview_using = deploy_utils.is_node_in_use_by_oneview( - self.client, node + node ) except exception.OneViewError as e: # NOTE(xavierr): Skip this node and process the @@ -218,10 +216,6 @@ class OneViewIscsiDeploy(iscsi_deploy.ISCSIDeploy, OneViewPeriodicTasks): oneview_driver = common.ISCSI_PXE_ONEVIEW - def __init__(self): - super(OneViewIscsiDeploy, self).__init__() - self.client = common.get_hponeview_client() - def get_properties(self): return deploy_utils.get_properties() @@ -229,30 +223,30 @@ 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(task) except exception.OneViewError as oneview_exc: raise exception.InvalidParameterValue(oneview_exc) super(OneViewIscsiDeploy, self).validate(task) @METRICS.timer('OneViewIscsiDeploy.prepare') def prepare(self, task): - deploy_utils.prepare(self.client, task) + deploy_utils.prepare(task) super(OneViewIscsiDeploy, self).prepare(task) @METRICS.timer('OneViewIscsiDeploy.tear_down') def tear_down(self, task): if not CONF.conductor.automated_clean: - deploy_utils.tear_down(self.client, task) + deploy_utils.tear_down(task) return super(OneViewIscsiDeploy, self).tear_down(task) @METRICS.timer('OneViewIscsiDeploy.prepare_cleaning') def prepare_cleaning(self, task): - deploy_utils.prepare_cleaning(self.client, task) + deploy_utils.prepare_cleaning(task) return super(OneViewIscsiDeploy, self).prepare_cleaning(task) @METRICS.timer('OneViewIscsiDeploy.tear_down_cleaning') def tear_down_cleaning(self, task): - deploy_utils.tear_down_cleaning(self.client, task) + deploy_utils.tear_down_cleaning(task) super(OneViewIscsiDeploy, self).tear_down_cleaning(task) @@ -261,10 +255,6 @@ class OneViewAgentDeploy(agent.AgentDeploy, OneViewPeriodicTasks): oneview_driver = common.AGENT_PXE_ONEVIEW - def __init__(self): - super(OneViewAgentDeploy, self).__init__() - self.client = common.get_hponeview_client() - def get_properties(self): return deploy_utils.get_properties() @@ -272,28 +262,28 @@ 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(task) except exception.OneViewError as oneview_exc: raise exception.InvalidParameterValue(oneview_exc) super(OneViewAgentDeploy, self).validate(task) @METRICS.timer('OneViewAgentDeploy.prepare') def prepare(self, task): - deploy_utils.prepare(self.client, task) + deploy_utils.prepare(task) super(OneViewAgentDeploy, self).prepare(task) @METRICS.timer('OneViewAgentDeploy.tear_down') def tear_down(self, task): if not CONF.conductor.automated_clean: - deploy_utils.tear_down(self.client, task) + deploy_utils.tear_down(task) return super(OneViewAgentDeploy, self).tear_down(task) @METRICS.timer('OneViewAgentDeploy.prepare_cleaning') def prepare_cleaning(self, task): - deploy_utils.prepare_cleaning(self.client, task) + deploy_utils.prepare_cleaning(task) return super(OneViewAgentDeploy, self).prepare_cleaning(task) @METRICS.timer('OneViewAgentDeploy.tear_down_cleaning') def tear_down_cleaning(self, task): - deploy_utils.tear_down_cleaning(self.client, task) + deploy_utils.tear_down_cleaning(task) super(OneViewAgentDeploy, self).tear_down_cleaning(task) diff --git a/ironic/drivers/modules/oneview/deploy_utils.py b/ironic/drivers/modules/oneview/deploy_utils.py index 9b6b31b1d..a8a05b0a1 100644 --- a/ironic/drivers/modules/oneview/deploy_utils.py +++ b/ironic/drivers/modules/oneview/deploy_utils.py @@ -32,14 +32,13 @@ def get_properties(): return common.COMMON_PROPERTIES -def prepare(client, task): +def prepare(task): """Apply Server Profile and update the node when preparing. This method is responsible for applying a Server Profile to the Server Hardware and add the uri of the applied Server Profile in the node's 'applied_server_profile_uri' field on properties/capabilities. - :param client: an instance of the OneView client :param task: A TaskManager object :raises InstanceDeployFailure: If the node doesn't have the needed OneView informations, if Server Hardware is in use by an OneView user, or @@ -55,14 +54,13 @@ def prepare(client, task): {"instance_name": instance_display_name, "instance_uuid": instance_uuid} ) - allocate_server_hardware_to_ironic(client, task.node, - server_profile_name) + allocate_server_hardware_to_ironic(task.node, server_profile_name) except exception.OneViewError as e: raise exception.InstanceDeployFailure(node=task.node.uuid, reason=e) -def tear_down(client, task): +def tear_down(task): """Remove Server profile and update the node when tear down. This method is responsible for power a Server Hardware off, remove a Server @@ -70,26 +68,24 @@ def tear_down(client, task): Profile from the node's 'applied_server_profile_uri' in properties/capabilities. - :param client: an instance of the OneView client :param task: A TaskManager object :raises InstanceDeployFailure: If node has no uri of applied Server Profile, or if some error occur while deleting Server Profile. """ try: - deallocate_server_hardware_from_ironic(client, task) + deallocate_server_hardware_from_ironic(task) except exception.OneViewError as e: raise exception.InstanceDeployFailure(node=task.node.uuid, reason=e) -def prepare_cleaning(client, task): +def prepare_cleaning(task): """Apply Server Profile and update the node when preparing cleaning. This method is responsible for applying a Server Profile to the Server Hardware and add the uri of the applied Server Profile in the node's 'applied_server_profile_uri' field on properties/capabilities. - :param client: an instance of the OneView client :param task: A TaskManager object :raises NodeCleaningFailure: If the node doesn't have the needed OneView informations, if Server Hardware is in use by an OneView user, or @@ -98,8 +94,7 @@ def prepare_cleaning(client, task): """ try: server_profile_name = "Ironic Cleaning [%s]" % task.node.uuid - allocate_server_hardware_to_ironic(client, task.node, - server_profile_name) + allocate_server_hardware_to_ironic(task.node, server_profile_name) except exception.OneViewError as e: oneview_error = common.SERVER_HARDWARE_ALLOCATION_ERROR driver_internal_info = task.node.driver_internal_info @@ -110,7 +105,7 @@ def prepare_cleaning(client, task): reason=e) -def tear_down_cleaning(client, task): +def tear_down_cleaning(task): """Remove Server profile and update the node when tear down cleaning. This method is responsible for power a Server Hardware off, remove a Server @@ -118,14 +113,13 @@ def tear_down_cleaning(client, task): Profile from the node's 'applied_server_profile_uri' in properties/capabilities. - :param client: an instance of the OneView client :param task: A TaskManager object :raises NodeCleaningFailure: If node has no uri of applied Server Profile, or if some error occur while deleting Server Profile. """ try: - deallocate_server_hardware_from_ironic(client, task) + deallocate_server_hardware_from_ironic(task) except exception.OneViewError as e: raise exception.NodeCleaningFailure(node=task.node.uuid, reason=e) @@ -171,10 +165,9 @@ def _is_node_in_use(server_hardware, applied_sp_uri, by_oneview=False): operation(applied_sp_uri, server_profile_uri)) -def is_node_in_use_by_oneview(client, node): +def is_node_in_use_by_oneview(node): """Check if node is in use by OneView user. - :param client: an instance of the OneView client :param node: an ironic node object :returns: Boolean value. True if node is in use by OneView, False otherwise. @@ -185,6 +178,7 @@ def is_node_in_use_by_oneview(client, node): """ positive = _("Node '%s' is in use by OneView.") % node.uuid negative = _("Node '%s' is not in use by OneView.") % node.uuid + client = common.get_hponeview_client() def predicate(server_hardware, applied_sp_uri): # Check if Profile exists in Oneview and it is different of the one @@ -196,10 +190,9 @@ def is_node_in_use_by_oneview(client, node): predicate, positive, negative) -def is_node_in_use_by_ironic(client, node): +def is_node_in_use_by_ironic(node): """Check if node is in use by ironic in OneView. - :param client: an instance of the HPE OneView client :param node: an ironic node object :returns: Boolean value. True if node is in use by ironic, False otherwise. @@ -210,6 +203,7 @@ def is_node_in_use_by_ironic(client, node): """ positive = _("Node '%s' is in use by Ironic.") % node.uuid negative = _("Node '%s' is not in use by Ironic.") % node.uuid + client = common.get_hponeview_client() def predicate(server_hardware, applied_sp_uri): # Check if Profile exists in Oneview and it is equals of the one @@ -280,11 +274,9 @@ def _del_applied_server_profile_uri_field(node): node.save() -def allocate_server_hardware_to_ironic(client, node, - server_profile_name): +def allocate_server_hardware_to_ironic(node, server_profile_name): """Allocate Server Hardware to ironic. - :param client: an instance of the OneView client :param node: an ironic node object :param server_profile_name: a formatted string with the Server Profile name @@ -292,7 +284,8 @@ def allocate_server_hardware_to_ironic(client, node, Hardware to ironic """ - node_in_use_by_oneview = is_node_in_use_by_oneview(client, node) + client = common.get_hponeview_client() + node_in_use_by_oneview = is_node_in_use_by_oneview(node) if not node_in_use_by_oneview: oneview_info = common.get_oneview_info(node) @@ -347,17 +340,17 @@ def allocate_server_hardware_to_ironic(client, node, raise exception.OneViewError(error=msg) -def deallocate_server_hardware_from_ironic(client, task): +def deallocate_server_hardware_from_ironic(task): """Deallocate Server Hardware from ironic. - :param client: an instance of the OneView client :param task: a TaskManager object :raises OneViewError: if an error occurs while deallocating the Server Hardware to ironic """ + client = common.get_hponeview_client() node = task.node - if is_node_in_use_by_ironic(client, node): + if is_node_in_use_by_ironic(node): oneview_info = common.get_oneview_info(node) server_profile_uri = oneview_info.get('applied_server_profile_uri') diff --git a/ironic/drivers/modules/oneview/inspect.py b/ironic/drivers/modules/oneview/inspect.py index 40d674547..f06652dc5 100644 --- a/ironic/drivers/modules/oneview/inspect.py +++ b/ironic/drivers/modules/oneview/inspect.py @@ -30,10 +30,6 @@ METRICS = metrics_utils.get_metrics_logger(__name__) class OneViewInspect(inspector.Inspector): """Interface for in band inspection.""" - def __init__(self): - super(OneViewInspect, self).__init__() - self.client = common.get_hponeview_client() - def get_properties(self): return deploy_utils.get_properties() @@ -54,7 +50,7 @@ class OneViewInspect(inspector.Inspector): common.verify_node_info(task.node) try: - common.validate_oneview_resources_compatibility(self.client, task) + common.validate_oneview_resources_compatibility(task) except exception.OneViewError as oneview_exc: raise exception.InvalidParameterValue(oneview_exc) @@ -62,7 +58,7 @@ class OneViewInspect(inspector.Inspector): def inspect_hardware(self, task): profile_name = 'Ironic Inspecting [%s]' % task.node.uuid deploy_utils.allocate_server_hardware_to_ironic( - self.client, task.node, profile_name + task.node, profile_name ) return super(OneViewInspect, self).inspect_hardware(task) @@ -93,8 +89,6 @@ class OneViewInspect(inspector.Inspector): if state_before == states.INSPECTING and state_after in [ states.MANAGEABLE, states.INSPECTFAIL ]: - deploy_utils.deallocate_server_hardware_from_ironic( - self.client, task.node - ) + deploy_utils.deallocate_server_hardware_from_ironic(task.node) return result diff --git a/ironic/drivers/modules/oneview/management.py b/ironic/drivers/modules/oneview/management.py index bf6549c22..f164c2a9a 100644 --- a/ironic/drivers/modules/oneview/management.py +++ b/ironic/drivers/modules/oneview/management.py @@ -68,9 +68,8 @@ def set_onetime_boot(task): persistent = next_boot_device.get('persistent') if not persistent: - client = common.get_hponeview_client() server_hardware = task.node.driver_info.get('server_hardware_uri') - ilo_client = common.get_ilorest_client(client, server_hardware) + ilo_client = common.get_ilorest_client(server_hardware) boot_device = BOOT_DEVICE_MAP_ILO.get(boot_device) body = { "Boot": { @@ -93,9 +92,8 @@ def _is_onetime_boot(task): False otherwise. """ - client = common.get_hponeview_client() server_hardware = task.node.driver_info.get('server_hardware_uri') - ilo_client = common.get_ilorest_client(client, server_hardware) + ilo_client = common.get_ilorest_client(server_hardware) response = ilo_client.get(path=ILO_SYSTEM_PATH, headers=ILO_REQUEST_HEADERS) boot = response.dict.get('Boot') @@ -114,7 +112,7 @@ def set_boot_device(task): :raises: OneViewError if the communication with OneView fails """ client = common.get_hponeview_client() - common.has_server_profile(task, client) + common.has_server_profile(task) driver_internal_info = task.node.driver_internal_info next_boot_device = driver_internal_info.get('next_boot_device') @@ -163,10 +161,6 @@ def set_boot_device(task): class OneViewManagement(base.ManagementInterface): - def __init__(self): - super(OneViewManagement, self).__init__() - self.client = common.get_hponeview_client() - def get_properties(self): return deploy_utils.get_properties() @@ -187,12 +181,9 @@ class OneViewManagement(base.ManagementInterface): resources in OneView """ common.verify_node_info(task.node) - try: - common.validate_oneview_resources_compatibility(self.client, task) - if not deploy_utils.is_node_in_use_by_ironic( - self.client, task.node - ): + common.validate_oneview_resources_compatibility(task) + if not deploy_utils.is_node_in_use_by_ironic(task.node): raise exception.InvalidParameterValue( _("Node %s is not in use by ironic.") % task.node.uuid) except exception.OneViewError as oneview_exc: @@ -264,6 +255,7 @@ class OneViewManagement(base.ManagementInterface): """ driver_internal_info = task.node.driver_internal_info next_boot_device = driver_internal_info.get('next_boot_device') + client = common.get_hponeview_client() if next_boot_device: return next_boot_device @@ -272,7 +264,7 @@ class OneViewManagement(base.ManagementInterface): server_profile = driver_info.get('applied_server_profile_uri') try: - profile = self.client.server_profiles.get(server_profile) + profile = client.server_profiles.get(server_profile) except client_exception.HPOneViewException as exc: msg = _("Error getting boot device from OneView. Error: %s") % exc raise exception.OneViewError(msg) diff --git a/ironic/drivers/modules/oneview/power.py b/ironic/drivers/modules/oneview/power.py index ab0091f55..3cedca81a 100644 --- a/ironic/drivers/modules/oneview/power.py +++ b/ironic/drivers/modules/oneview/power.py @@ -56,10 +56,6 @@ SET_POWER_STATE_MAP = { class OneViewPower(base.PowerInterface): - def __init__(self): - super(OneViewPower, self).__init__() - self.client = common.get_hponeview_client() - def get_properties(self): return deploy_utils.get_properties() @@ -88,9 +84,9 @@ class OneViewPower(base.PowerInterface): common.verify_node_info(task.node) try: - common.validate_oneview_resources_compatibility(self.client, task) + common.validate_oneview_resources_compatibility(task) - if deploy_utils.is_node_in_use_by_oneview(self.client, task.node): + if deploy_utils.is_node_in_use_by_oneview(task.node): raise exception.InvalidParameterValue( _("Node %s is in use by OneView.") % task.node.uuid) @@ -108,8 +104,9 @@ class OneViewPower(base.PowerInterface): resource """ server_hardware = task.node.driver_info.get('server_hardware_uri') + client = common.get_hponeview_client() try: - server_hardware = self.client.server_hardware.get(server_hardware) + server_hardware = client.server_hardware.get(server_hardware) except client_exception.HPOneViewException as exc: LOG.error( "Error getting power state for node %(node)s. Error:" @@ -135,7 +132,8 @@ class OneViewPower(base.PowerInterface): :raises: PowerStateFailure if the power couldn't be set to power_state. :raises: OneViewError if OneView fails setting the power state. """ - if deploy_utils.is_node_in_use_by_oneview(self.client, task.node): + client = common.get_hponeview_client() + if deploy_utils.is_node_in_use_by_oneview(task.node): raise exception.PowerStateFailure(_( "Cannot set power state '%(power_state)s' to node %(node)s. " "The node is in use by OneView.") % @@ -157,19 +155,19 @@ class OneViewPower(base.PowerInterface): try: if power_state == states.POWER_ON: management.set_boot_device(task) - self.client.server_hardware.update_power_state( + client.server_hardware.update_power_state( SET_POWER_STATE_MAP.get(power_state), server_hardware, timeout=timeout) elif power_state == states.REBOOT: - self.client.server_hardware.update_power_state( + client.server_hardware.update_power_state( SET_POWER_STATE_MAP.get(states.POWER_OFF), server_hardware, timeout=timeout) management.set_boot_device(task) - self.client.server_hardware.update_power_state( + client.server_hardware.update_power_state( SET_POWER_STATE_MAP.get(states.POWER_ON), server_hardware, timeout=timeout) else: - self.client.server_hardware.update_power_state( + client.server_hardware.update_power_state( SET_POWER_STATE_MAP.get(power_state), server_hardware, timeout=timeout) except client_exception.HPOneViewException as exc: diff --git a/ironic/tests/unit/drivers/modules/oneview/test_common.py b/ironic/tests/unit/drivers/modules/oneview/test_common.py index 0755d5c06..2641c202b 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_common.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_common.py @@ -285,8 +285,7 @@ class OneViewCommonTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: task.ports = [fake_port] - common.validate_oneview_resources_compatibility(oneview_client, - task) + common.validate_oneview_resources_compatibility(task) self.assertTrue(mock_sp_template.called) self.assertTrue(mock_sh_type.called) self.assertTrue(mock_enclosure.called) diff --git a/ironic/tests/unit/drivers/modules/oneview/test_deploy.py b/ironic/tests/unit/drivers/modules/oneview/test_deploy.py index 7304786de..526edd494 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_deploy.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_deploy.py @@ -81,9 +81,6 @@ def _setup_node_in_cleanfailed_state_without_oneview_error(node): class OneViewDriverDeploy(deploy.OneViewPeriodicTasks): oneview_driver = 'fake_oneview' - def __init__(self): - self.client = mock.MagicMock() - @mock.patch('ironic.objects.Node', spec_set=True, autospec=True) @mock.patch.object(deploy_utils, 'is_node_in_use_by_oneview') @@ -114,9 +111,7 @@ class OneViewPeriodicTasks(db_base.DbTestCase): self.deploy._periodic_check_nodes_taken_by_oneview( self.os_primary, self.context ) - mock_is_node_in_use_by_oneview.assert_called_once_with( - self.deploy.client, self.node - ) + mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) self.assertTrue(self.os_primary.update_node.called) self.assertTrue(self.os_primary.do_provisioning_action.called) self.assertTrue(self.node.maintenance) @@ -133,9 +128,7 @@ class OneViewPeriodicTasks(db_base.DbTestCase): self.deploy._periodic_check_nodes_taken_by_oneview( self.os_primary, self.context ) - mock_is_node_in_use_by_oneview.assert_called_once_with( - self.deploy.client, self.node - ) + mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) self.assertFalse(self.os_primary.update_node.called) self.assertFalse(self.os_primary.do_provisioning_action.called) self.assertFalse(self.node.maintenance) @@ -151,9 +144,7 @@ class OneViewPeriodicTasks(db_base.DbTestCase): self.deploy._periodic_check_nodes_taken_by_oneview( self.os_primary, self.context ) - mock_is_node_in_use_by_oneview.assert_called_once_with( - self.deploy.client, self.node - ) + mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) self.assertFalse(self.os_primary.update_node.called) self.assertFalse(self.os_primary.do_provisioning_action.called) self.assertFalse(self.node.maintenance) @@ -169,9 +160,7 @@ class OneViewPeriodicTasks(db_base.DbTestCase): self.deploy._periodic_check_nodes_freed_by_oneview( self.os_primary, self.context ) - mock_is_node_in_use_by_oneview.assert_called_once_with( - self.deploy.client, self.node - ) + mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) self.assertTrue(self.os_primary.update_node.called) self.assertTrue(self.os_primary.do_provisioning_action.called) self.assertFalse(self.node.maintenance) @@ -186,9 +175,7 @@ class OneViewPeriodicTasks(db_base.DbTestCase): self.deploy._periodic_check_nodes_freed_by_oneview( self.os_primary, self.context ) - mock_is_node_in_use_by_oneview.assert_called_once_with( - self.deploy.client, self.node - ) + mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) self.assertFalse(self.os_primary.update_node.called) self.assertFalse(self.os_primary.do_provisioning_action.called) self.assertTrue(self.node.maintenance) @@ -205,9 +192,7 @@ class OneViewPeriodicTasks(db_base.DbTestCase): self.deploy._periodic_check_nodes_freed_by_oneview( self.os_primary, self.context ) - mock_is_node_in_use_by_oneview.assert_called_once_with( - self.deploy.client, self.node - ) + mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) self.assertFalse(self.os_primary.update_node.called) self.assertFalse(self.os_primary.do_provisioning_action.called) self.assertTrue(self.node.maintenance) @@ -246,7 +231,6 @@ class OneViewPeriodicTasks(db_base.DbTestCase): self.assertNotIn('oneview_error', self.node.driver_internal_info) -@mock.patch.object(common, 'get_hponeview_client') class OneViewIscsiDeployTestCase(db_base.DbTestCase): def setUp(self): @@ -270,7 +254,7 @@ class OneViewIscsiDeployTestCase(db_base.DbTestCase): node_id=self.node.id) self.info = common.get_oneview_info(self.node) - def test_get_properties(self, mock_get_ov_client): + def test_get_properties(self): expected = common.COMMON_PROPERTIES self.assertEqual(expected, self.driver.deploy.get_properties()) @@ -278,19 +262,17 @@ class OneViewIscsiDeployTestCase(db_base.DbTestCase): 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): + 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) - self.assertTrue(mock_validate_resources.called) + 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') def test_prepare( - self, allocate_server_hardware_mock, iscsi_deploy_prepare_mock, - mock_get_ov_client): + self, allocate_server_hardware_mock, iscsi_deploy_prepare_mock): self.node.provision_state = states.DEPLOYING self.node.save() with task_manager.acquire(self.context, self.node.uuid) as task: @@ -299,8 +281,7 @@ class OneViewIscsiDeployTestCase(db_base.DbTestCase): self.assertTrue(allocate_server_hardware_mock.called) @mock.patch.object(iscsi_deploy.ISCSIDeploy, 'prepare', autospec=True) - def test_prepare_active_node( - self, iscsi_deploy_prepare_mock, mock_get_ov_client): + def test_prepare_active_node(self, iscsi_deploy_prepare_mock): """Ensure nodes in running states are not inadvertently changed.""" test_states = list(states.STABLE_STATES) test_states.extend([ @@ -318,13 +299,13 @@ class OneViewIscsiDeployTestCase(db_base.DbTestCase): mock.ANY, task) @mock.patch.object(iscsi_deploy.ISCSIDeploy, 'deploy', autospec=True) - def test_deploy(self, iscsi_deploy_mock, mock_get_ov_client): + def test_deploy(self, iscsi_deploy_mock): with task_manager.acquire(self.context, self.node.uuid) as task: task.driver.deploy.deploy(task) iscsi_deploy_mock.assert_called_once_with(mock.ANY, task) @mock.patch.object(iscsi_deploy.ISCSIDeploy, 'tear_down', autospec=True) - def test_tear_down(self, iscsi_tear_down_mock, mock_get_ov_client): + def test_tear_down(self, iscsi_tear_down_mock): iscsi_tear_down_mock.return_value = states.DELETED with task_manager.acquire(self.context, self.node.uuid) as task: returned_state = task.driver.deploy.tear_down(task) @@ -334,8 +315,7 @@ class OneViewIscsiDeployTestCase(db_base.DbTestCase): @mock.patch.object(iscsi_deploy.ISCSIDeploy, 'tear_down', autospec=True) @mock.patch.object(deploy_utils, 'deallocate_server_hardware_from_ironic') def test_tear_down_with_automated_clean_disabled( - self, deallocate_server_hardware_mock, iscsi_tear_down_mock, - mock_get_ov_client): + self, deallocate_server_hardware_mock, iscsi_tear_down_mock,): CONF.conductor.automated_clean = False iscsi_tear_down_mock.return_value = states.DELETED @@ -349,8 +329,7 @@ class OneViewIscsiDeployTestCase(db_base.DbTestCase): autospec=True) @mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic') def test_prepare_cleaning( - self, allocate_server_hardware_mock, iscsi_prep_clean_mock, - mock_get_ov_client): + self, allocate_server_hardware_mock, iscsi_prep_clean_mock): iscsi_prep_clean_mock.return_value = states.CLEANWAIT with task_manager.acquire(self.context, self.node.uuid) as task: ret = task.driver.deploy.prepare_cleaning(task) @@ -362,8 +341,7 @@ class OneViewIscsiDeployTestCase(db_base.DbTestCase): autospec=True) @mock.patch.object(deploy_utils, 'deallocate_server_hardware_from_ironic') def test_tear_down_cleaning( - self, deallocate_server_hardware_mock, iscsi_tear_down_clean_mock, - mock_get_ov_client): + self, deallocate_server_hardware_mock, iscsi_tear_down_clean_mock): iscsi_tear_down_clean_mock.return_value = states.CLEANWAIT with task_manager.acquire(self.context, self.node.uuid) as task: @@ -372,7 +350,6 @@ class OneViewIscsiDeployTestCase(db_base.DbTestCase): self.assertTrue(deallocate_server_hardware_mock.called) -@mock.patch.object(common, 'get_hponeview_client') class OneViewAgentDeployTestCase(db_base.DbTestCase): def setUp(self): super(OneViewAgentDeployTestCase, self).setUp() @@ -395,7 +372,7 @@ class OneViewAgentDeployTestCase(db_base.DbTestCase): node_id=self.node.id) self.info = common.get_oneview_info(self.node) - def test_get_properties(self, mock_get_ov_client): + def test_get_properties(self): expected = common.COMMON_PROPERTIES self.assertEqual(expected, self.driver.deploy.get_properties()) @@ -403,19 +380,17 @@ class OneViewAgentDeployTestCase(db_base.DbTestCase): 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): + 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) - self.assertTrue(mock_validate_resources.called) + self.assertTrue(mock_validate.called) agent_deploy_validate_mock.assert_called_once_with(mock.ANY, task) @mock.patch.object(agent.AgentDeploy, 'prepare', autospec=True) @mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic') def test_prepare( - self, allocate_server_hardware_mock, agent_deploy_prepare_mock, - mock_get_ov_client): + self, allocate_server_hardware_mock, agent_deploy_prepare_mock): self.node.provision_state = states.DEPLOYING self.node.save() with task_manager.acquire(self.context, self.node.uuid) as task: @@ -424,8 +399,7 @@ class OneViewAgentDeployTestCase(db_base.DbTestCase): self.assertTrue(allocate_server_hardware_mock.called) @mock.patch.object(agent.AgentDeploy, 'prepare', autospec=True) - def test_prepare_active_node( - self, agent_deploy_prepare_mock, mock_get_ov_client): + def test_prepare_active_node(self, agent_deploy_prepare_mock): """Ensure nodes in running states are not inadvertently changed.""" test_states = list(states.STABLE_STATES) test_states.extend([states.CLEANING, @@ -441,7 +415,7 @@ class OneViewAgentDeployTestCase(db_base.DbTestCase): mock.ANY, task) @mock.patch.object(agent.AgentDeploy, 'deploy', autospec=True) - def test_deploy(self, agent_deploy_mock, mock_get_ov_client): + def test_deploy(self, agent_deploy_mock): with task_manager.acquire(self.context, self.node.uuid) as task: task.driver.deploy.deploy(task) agent_deploy_mock.assert_called_once_with(mock.ANY, task) @@ -450,8 +424,7 @@ class OneViewAgentDeployTestCase(db_base.DbTestCase): autospec=True) @mock.patch.object(deploy_utils, 'deallocate_server_hardware_from_ironic') def test_tear_down_with_automated_clean_disabled( - self, deallocate_server_hardware_mock, agent_tear_down_mock, - mock_get_ov_client): + self, deallocate_server_hardware_mock, agent_tear_down_mock): CONF.conductor.automated_clean = False agent_tear_down_mock.return_value = states.DELETED with task_manager.acquire(self.context, self.node.uuid) as task: @@ -463,8 +436,7 @@ class OneViewAgentDeployTestCase(db_base.DbTestCase): @mock.patch.object(agent.AgentDeploy, 'prepare_cleaning', autospec=True) @mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic') def test_prepare_cleaning( - self, allocate_server_hardware_mock, - agent_prep_clean_mock, mock_get_ov_client): + self, allocate_server_hardware_mock, agent_prep_clean_mock): agent_prep_clean_mock.return_value = states.CLEANWAIT with task_manager.acquire(self.context, self.node.uuid) as task: ret = task.driver.deploy.prepare_cleaning(task) @@ -475,8 +447,7 @@ class OneViewAgentDeployTestCase(db_base.DbTestCase): @mock.patch.object(agent.AgentDeploy, 'tear_down_cleaning', autospec=True) @mock.patch.object(deploy_utils, 'deallocate_server_hardware_from_ironic') def test_tear_down_cleaning( - self, deallocate_server_hardware_mock, - agent_tear_down_clean_mock, mock_get_ov_client): + self, deallocate_server_hardware_mock, agent_tear_down_clean_mock): agent_tear_down_clean_mock.return_value = states.CLEANWAIT with task_manager.acquire(self.context, self.node.uuid) as task: task.driver.deploy.tear_down_cleaning(task) diff --git a/ironic/tests/unit/drivers/modules/oneview/test_deploy_utils.py b/ironic/tests/unit/drivers/modules/oneview/test_deploy_utils.py index 44929456a..97b99eef1 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_deploy_utils.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_deploy_utils.py @@ -55,14 +55,12 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase): # Tests for prepare def test_prepare_node_is_in_use_by_oneview(self, mock_oneview_client): """`prepare` behavior when the node has a Profile on OneView.""" - client = mock_oneview_client() deploy_utils.is_node_in_use_by_oneview.return_value = True with task_manager.acquire(self.context, self.node.uuid) as task: task.node.provision_state = states.DEPLOYING self.assertRaises( exception.InstanceDeployFailure, deploy_utils.prepare, - client, task ) @@ -72,7 +70,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase): """`prepare` behavior when the node is free from OneView standpoint.""" with task_manager.acquire(self.context, self.node.uuid) as task: task.node.provision_state = states.DEPLOYING - deploy_utils.prepare(mock_oneview_client(), task) + deploy_utils.prepare(task) self.assertTrue(mock_save.called) # Tests for tear_down @@ -86,7 +84,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase): self.assertIn( 'applied_server_profile_uri', task.node.driver_info ) - deploy_utils.tear_down(client, task) + deploy_utils.tear_down(task) self.assertNotIn( 'applied_server_profile_uri', task.node.driver_info ) @@ -101,7 +99,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase): self.assertFalse( 'applied_server_profile_uri' in task.node.driver_info ) - deploy_utils.prepare_cleaning(mock_oneview_client(), task) + deploy_utils.prepare_cleaning(task) self.assertTrue( 'applied_server_profile_uri' in task.node.driver_info ) @@ -118,7 +116,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase): task.node.driver_info['applied_server_profile_uri'] = ( 'same/sp_applied' ) - deploy_utils.prepare_cleaning(client, task) + deploy_utils.prepare_cleaning(task) self.assertFalse(mock_node_save.called) def test_prepare_cleaning_node_is_in_use_by_oneview( @@ -130,7 +128,6 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase): self.assertRaises( exception.NodeCleaningFailure, deploy_utils.prepare_cleaning, - mock_oneview_client(), task ) @@ -145,7 +142,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase): self.assertTrue( 'applied_server_profile_uri' in task.node.driver_info ) - deploy_utils.tear_down_cleaning(client, task) + deploy_utils.tear_down_cleaning(task) self.assertFalse( 'applied_server_profile_uri' in task.node.driver_info ) @@ -296,7 +293,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase): with task_manager.acquire(self.context, self.node.uuid) as task: deploy_utils.allocate_server_hardware_to_ironic( - client, task.node, 'serverProfileName' + task.node, 'serverProfileName' ) self.assertTrue(mock_node_save.called) self.assertIn('applied_server_profile_uri', task.node.driver_info) @@ -320,7 +317,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase): 'any/applied_sp_uri/' ) deploy_utils.allocate_server_hardware_to_ironic( - client, task.node, 'serverProfileName' + task.node, 'serverProfileName' ) self.assertTrue(mock_node_save.called) @@ -335,9 +332,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase): task.node.driver_info['applied_server_profile_uri'] = ( 'any/applied_sp_uri/' ) - deploy_utils.deallocate_server_hardware_from_ironic( - client, task - ) + deploy_utils.deallocate_server_hardware_from_ironic(task) self.assertTrue(client.server_profiles.delete.called) self.assertNotIn( 'applied_server_profile_uri', task.node.driver_info diff --git a/ironic/tests/unit/drivers/modules/oneview/test_management.py b/ironic/tests/unit/drivers/modules/oneview/test_management.py index af48dbe9b..0d06a0c99 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_management.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_management.py @@ -214,7 +214,6 @@ class OneViewManagementDriverFunctionsTestCase(db_base.DbTestCase): ) -@mock.patch.object(common, 'get_hponeview_client') class OneViewManagementDriverTestCase(db_base.DbTestCase): def setUp(self): @@ -237,7 +236,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): 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): + def test_validate(self, mock_validate, mock_ironic_node): mock_ironic_node.return_value = True with task_manager.acquire(self.context, self.node.uuid, shared=False) as task: @@ -246,15 +245,13 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): @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_get_ov_client - ): + 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: self.assertRaises(exception.InvalidParameterValue, task.driver.management.validate, task) - def test_validate_fail(self, mock_get_ov_client): + def test_validate_fail(self): node = obj_utils.create_test_node( self.context, uuid=uuidutils.generate_uuid(), id=999, driver='fake_oneview' @@ -264,19 +261,19 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): task.driver.management.validate, task) @mock.patch.object(common, 'validate_oneview_resources_compatibility') - def test_validate_fail_exception(self, mock_validate, mock_get_ov_client): + def test_validate_fail_exception(self, mock_validate): mock_validate.side_effect = exception.OneViewError('message') with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises(exception.InvalidParameterValue, task.driver.management.validate, task) - def test_get_properties(self, mock_get_ov_client): + def test_get_properties(self): expected = common.COMMON_PROPERTIES self.assertItemsEqual(expected, self.driver.management.get_properties()) - def test_set_boot_device_persistent_true(self, mock_get_ov_client): + def test_set_boot_device_persistent_true(self): with task_manager.acquire(self.context, self.node.uuid) as task: task.driver.management.set_boot_device( task, boot_devices.PXE, True) @@ -287,7 +284,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): next_boot_device.get('boot_device'), boot_devices.PXE) self.assertTrue(next_boot_device.get('persistent')) - def test_set_boot_device_persistent_false(self, mock_get_ov_client): + def test_set_boot_device_persistent_false(self): with task_manager.acquire(self.context, self.node.uuid) as task: task.driver.management.set_boot_device( task, boot_devices.PXE, False) @@ -298,7 +295,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): next_boot_device.get('boot_device'), boot_devices.PXE) self.assertFalse(next_boot_device.get('persistent')) - def test_set_boot_device_invalid_device(self, mock_get_ov_client): + def test_set_boot_device_invalid_device(self): with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises(exception.InvalidParameterValue, task.driver.management.set_boot_device, @@ -306,7 +303,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): driver_internal_info = task.node.driver_internal_info self.assertNotIn('next_boot_device', driver_internal_info) - def test_get_supported_boot_devices(self, mock_get_ov_client): + def test_get_supported_boot_devices(self): with task_manager.acquire(self.context, self.node.uuid) as task: expected = [ boot_devices.PXE, boot_devices.DISK, boot_devices.CDROM @@ -316,10 +313,10 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): task.driver.management.get_supported_boot_devices(task), ) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(common, 'get_ilorest_client') - def test_get_boot_device( - self, mock_ilo_client, mock_get_ov_client): - client = mock_get_ov_client() + def test_get_boot_device(self, mock_ilo_client, mock_ov_client): + client = mock_ov_client() ilo_client = mock_ilo_client() self.driver.management.client = client device_mapping = management.BOOT_DEVICE_MAP_ONEVIEW.items() @@ -337,11 +334,8 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): self.assertTrue(ilo_client.get.called) @mock.patch.object(common, 'get_ilorest_client') - def test_get_boot_device_from_next_boot_device( - self, mock_ilo_client, mock_get_ov_client): - client = mock_get_ov_client() + def test_get_boot_device_from_next_boot_device(self, mock_ilo_client): ilo_client = mock_ilo_client() - self.driver.management.client = client with task_manager.acquire(self.context, self.node.uuid) as task: driver_internal_info = task.node.driver_internal_info @@ -355,13 +349,12 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): } response = self.driver.management.get_boot_device(task) self.assertEqual(expected_response, response) - self.assertFalse(client.get_boot_order.called) self.assertFalse(ilo_client.get.called) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(common, 'get_ilorest_client') - def test_get_boot_device_fail( - self, mock_ilo_client, mock_get_ov_client): - client = mock_get_ov_client() + def test_get_boot_device_fail(self, mock_ilo_client, mock_ov_client): + client = mock_ov_client() ilo_client = mock_ilo_client() self.driver.management.client = client exc = client_exception.HPOneViewException() @@ -376,14 +369,8 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): self.assertFalse(ilo_client.get.called) @mock.patch.object(common, 'get_ilorest_client') - def test_get_boot_device_unknown_device( - self, mock_ilo_client, mock_get_ov_client): - client = mock_get_ov_client() + def test_get_boot_device_unknown_device(self, mock_ilo_client): ilo_client = mock_ilo_client() - order = ['Eggs', 'Bacon'] - profile = {'boot': {'order': order}} - client.server_profiles.get.return_value = profile - self.driver.management.client = client with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.InvalidParameterValue, @@ -392,7 +379,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase): ) self.assertFalse(ilo_client.get.called) - def test_get_sensors_data_not_implemented(self, mock_get_ov_client): + def test_get_sensors_data_not_implemented(self): with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( NotImplementedError, diff --git a/ironic/tests/unit/drivers/modules/oneview/test_power.py b/ironic/tests/unit/drivers/modules/oneview/test_power.py index f4cb60055..193d71ac1 100644 --- a/ironic/tests/unit/drivers/modules/oneview/test_power.py +++ b/ironic/tests/unit/drivers/modules/oneview/test_power.py @@ -33,7 +33,6 @@ from ironic.tests.unit.objects import utils as obj_utils client_exception = importutils.try_import('hpOneView.exceptions') -@mock.patch.object(common, 'get_hponeview_client') class OneViewPowerDriverTestCase(db_base.DbTestCase): def setUp(self): @@ -54,12 +53,12 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): deploy_utils.is_node_in_use_by_oneview = mock.Mock(return_value=False) @mock.patch.object(common, 'validate_oneview_resources_compatibility') - def test_validate(self, mock_validate, mock_get_ov_client): + def test_validate(self, mock_validate): with task_manager.acquire(self.context, self.node.uuid) as task: task.driver.power.validate(task) self.assertTrue(mock_validate.called) - def test_validate_missing_parameter(self, mock_get_ov_client): + def test_validate_missing_parameter(self): node = obj_utils.create_test_node( self.context, uuid=uuidutils.generate_uuid(), id=999, driver='fake_oneview') @@ -70,7 +69,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): task) @mock.patch.object(common, 'validate_oneview_resources_compatibility') - def test_validate_exception(self, mock_validate, mock_get_ov_client): + def test_validate_exception(self, mock_validate): mock_validate.side_effect = exception.OneViewError('message') with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( @@ -78,7 +77,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): task.driver.power.validate, task) - def test_validate_node_in_use_by_oneview(self, mock_get_ov_client): + def test_validate_node_in_use_by_oneview(self): deploy_utils.is_node_in_use_by_oneview.return_value = True with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( @@ -86,34 +85,34 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): task.driver.power.validate, task) - def test_get_properties(self, mock_get_ov_client): + def test_get_properties(self): expected = common.COMMON_PROPERTIES self.assertEqual(expected, self.driver.power.get_properties()) + @mock.patch.object(common, 'get_hponeview_client') def test_get_power_state(self, mock_get_ov_client): client = mock_get_ov_client() server_hardware = {'powerState': 'On'} client.server_hardware.get.return_value = server_hardware - self.driver.power.client = client with task_manager.acquire(self.context, self.node.uuid) as task: power_state = self.driver.power.get_power_state(task) self.assertEqual(states.POWER_ON, power_state) + @mock.patch.object(common, 'get_hponeview_client') def test_get_power_state_fail(self, mock_get_ov_client): client = mock_get_ov_client() exc = client_exception.HPOneViewException() client.server_hardware.get.side_effect = exc - self.driver.power.client = client with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, self.driver.power.get_power_state, task) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(management, 'set_boot_device') def test_set_power_on(self, mock_set_boot_device, mock_get_ov_client): client = mock_get_ov_client() - self.driver.power.client = client server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: self.driver.power.set_power_state(task, states.POWER_ON) @@ -122,10 +121,10 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): update.assert_called_once_with(power.POWER_ON, server_hardware, timeout=-1) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(management, 'set_boot_device') def test_set_power_off(self, mock_set_boot_device, mock_get_ov_client): client = mock_get_ov_client() - self.driver.power.client = client server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: self.driver.power.set_power_state(task, states.POWER_OFF) @@ -134,10 +133,10 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): update.assert_called_once_with(power.POWER_OFF, server_hardware, timeout=-1) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(management, 'set_boot_device') def test_set_power_reboot(self, mock_set_boot_device, mock_get_ov_client): client = mock_get_ov_client() - self.driver.power.client = client server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: self.driver.power.set_power_state(task, states.REBOOT) @@ -146,12 +145,12 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): update = client.server_hardware.update_power_state update.assert_has_calls(calls) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(management, 'set_boot_device') def test_set_power_on_fail(self, mock_set_boot_device, mock_get_ov_client): client = mock_get_ov_client() exc = client_exception.HPOneViewException() client.server_hardware.update_power_state.side_effect = exc - self.driver.power.client = client with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, @@ -160,13 +159,13 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): states.POWER_ON) mock_set_boot_device.assert_called_once_with(task) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(management, 'set_boot_device') def test_set_power_off_fail( self, mock_set_boot_device, mock_get_ov_client): client = mock_get_ov_client() exc = client_exception.HPOneViewException() client.server_hardware.update_power_state.side_effect = exc - self.driver.power.client = client with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, @@ -175,16 +174,15 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): states.POWER_OFF) self.assertFalse(mock_set_boot_device.called) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(management, 'set_boot_device') def test_reboot_fail_with_hardware_on( self, mock_set_boot_device, mock_get_ov_client): client = mock_get_ov_client() server_hardware = {'powerState': 'On'} client.server_hardware.get.return_value = server_hardware - self.driver.power.client = client exc = client_exception.HPOneViewException() client.server_hardware.update_power_state.side_effect = exc - self.driver.power.client = client with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, @@ -192,16 +190,15 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): task) self.assertFalse(mock_set_boot_device.called) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(management, 'set_boot_device') def test_reboot_fail_with_hardware_off( self, mock_set_boot_device, mock_get_ov_client): client = mock_get_ov_client() server_hardware = {'powerState': 'Off'} client.server_hardware.get.return_value = server_hardware - self.driver.power.client = client exc = client_exception.HPOneViewException() client.server_hardware.update_power_state.side_effect = exc - self.driver.power.client = client with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.OneViewError, @@ -210,8 +207,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): mock_set_boot_device.assert_called_once_with(task) @mock.patch.object(management, 'set_boot_device') - def test_set_power_invalid_state( - self, mock_set_boot_device, mock_get_ov_client): + def test_set_power_invalid_state(self, mock_set_boot_device): with task_manager.acquire(self.context, self.node.uuid) as task: self.assertRaises( exception.InvalidParameterValue, @@ -220,13 +216,13 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): 'fake_state') self.assertFalse(mock_set_boot_device.called) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(management, 'set_boot_device') def test_set_power_reboot_with_hardware_on( self, mock_set_boot_device, mock_get_ov_client): client = mock_get_ov_client() server_hardware = {'powerState': 'On'} client.server_hardware.get.return_value = server_hardware - self.driver.power.client = client server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: self.driver.power.reboot(task) @@ -236,13 +232,13 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase): update.assert_has_calls(calls) mock_set_boot_device.assert_called_once_with(task) + @mock.patch.object(common, 'get_hponeview_client') @mock.patch.object(management, 'set_boot_device') def test_set_power_reboot_with_hardware_off( self, mock_set_boot_device, mock_get_ov_client): client = mock_get_ov_client() server_hardware = {'powerState': 'Off'} client.server_hardware.get.return_value = server_hardware - self.driver.power.client = client server_hardware = self.node.driver_info.get('server_hardware_uri') with task_manager.acquire(self.context, self.node.uuid) as task: self.driver.power.reboot(task, timeout=-1) |