Reusing oneview_client when possible

A simple experiment showed that all calls to OneView were calling for
authentication. Reviewing the code, I perceived that every single call to
python-oneviewclient were creating a new instance of the client, which
authenticated again and generated a new session token on OneView.

This patch aims to reuse oneview_client instances when possible, avoiding
to create unecessary new sessions that can be reused.

Co-Authored-By: Hugo Nicodemos <nicodemos@lsd.ufcg.edu.br>
Co-Authored-By: Xavier <marcusrafael@lsd.ufcg.edu.br>

Change-Id: I0c26f0e033ca7f53f648c4ed29c6ef19f6f2e578
Closes-Bug: #1615070
This commit is contained in:
Thiago Paiva 2016-08-19 15:32:28 -03:00 committed by Hugo Nicodemos
parent 51c6d7a6ed
commit 83b2d563a9
13 changed files with 663 additions and 154 deletions

View File

@ -23,7 +23,6 @@ from ironic.common import states
from ironic.conf import CONF from ironic.conf import CONF
from ironic.drivers import utils from ironic.drivers import utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
client = importutils.try_import('oneview_client.client') client = importutils.try_import('oneview_client.client')
@ -147,7 +146,7 @@ def get_oneview_info(node):
return oneview_info return oneview_info
def validate_oneview_resources_compatibility(task): def validate_oneview_resources_compatibility(oneview_client, task):
"""Validates if the node configuration is consistent with OneView. """Validates if the node configuration is consistent with OneView.
This method calls python-oneviewclient functions to validate if the node This method calls python-oneviewclient functions to validate if the node
@ -158,6 +157,7 @@ def validate_oneview_resources_compatibility(task):
represents when in pre-allocation model. If any validation fails, represents when in pre-allocation model. If any validation fails,
python-oneviewclient will raise an appropriate OneViewException. 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. :param: task: a TaskManager instance containing the node to act on.
""" """
@ -166,12 +166,9 @@ def validate_oneview_resources_compatibility(task):
oneview_info = get_oneview_info(task.node) oneview_info = get_oneview_info(task.node)
try: try:
oneview_client = get_oneview_client()
oneview_client.validate_node_server_profile_template(oneview_info) oneview_client.validate_node_server_profile_template(oneview_info)
oneview_client.validate_node_server_hardware_type(oneview_info) oneview_client.validate_node_server_hardware_type(oneview_info)
oneview_client.validate_node_enclosure_group(oneview_info) oneview_client.validate_node_enclosure_group(oneview_info)
oneview_client.validate_node_server_hardware( oneview_client.validate_node_server_hardware(
oneview_info, oneview_info,
task.node.properties.get('memory_mb'), task.node.properties.get('memory_mb'),
@ -244,10 +241,10 @@ def node_has_server_profile(func):
"""Checks if the node's Server Hardware has a Server Profile associated. """Checks if the node's Server Hardware has a Server Profile associated.
""" """
def inner(*args, **kwargs): def inner(self, *args, **kwargs):
task = args[1] oneview_client = self.oneview_client
task = args[0]
oneview_info = get_oneview_info(task.node) oneview_info = get_oneview_info(task.node)
oneview_client = get_oneview_client()
try: try:
node_has_server_profile = ( node_has_server_profile = (
oneview_client.get_server_profile_from_hardware(oneview_info) oneview_client.get_server_profile_from_hardware(oneview_info)
@ -264,7 +261,7 @@ def node_has_server_profile(func):
_("A Server Profile is not associated with node %s.") % _("A Server Profile is not associated with node %s.") %
task.node.uuid task.node.uuid
) )
return func(*args, **kwargs) return func(self, *args, **kwargs)
return inner return inner

View File

@ -26,6 +26,7 @@ from ironic.common import exception
from ironic.common.i18n import _LE, _LI, _LW from ironic.common.i18n import _LE, _LI, _LW
from ironic.common import states from ironic.common import states
from ironic.conductor import utils as manager_utils from ironic.conductor import utils as manager_utils
from ironic.conf import CONF
from ironic.drivers.modules import agent from ironic.drivers.modules import agent
from ironic.drivers.modules import agent_base_vendor from ironic.drivers.modules import agent_base_vendor
from ironic.drivers.modules import deploy_utils as ironic_deploy_utils from ironic.drivers.modules import deploy_utils as ironic_deploy_utils
@ -35,11 +36,8 @@ from ironic.drivers.modules.oneview import deploy_utils
from ironic import objects from ironic import objects
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
METRICS = metrics_utils.get_metrics_logger(__name__) METRICS = metrics_utils.get_metrics_logger(__name__)
CONF = common.CONF
@six.add_metaclass(abc.ABCMeta) @six.add_metaclass(abc.ABCMeta)
class OneViewPeriodicTasks(object): class OneViewPeriodicTasks(object):
@ -75,7 +73,9 @@ class OneViewPeriodicTasks(object):
node = objects.Node.get(context, node_uuid) node = objects.Node.get(context, node_uuid)
try: try:
oneview_using = deploy_utils.is_node_in_use_by_oneview(node) oneview_using = deploy_utils.is_node_in_use_by_oneview(
self.oneview_client, node
)
except exception.OneViewError as e: except exception.OneViewError as e:
# NOTE(xavierr): Skip this node and process the # NOTE(xavierr): Skip this node and process the
# remaining nodes. This node will be checked in # remaining nodes. This node will be checked in
@ -136,7 +136,7 @@ class OneViewPeriodicTasks(object):
try: try:
oneview_using = deploy_utils.is_node_in_use_by_oneview( oneview_using = deploy_utils.is_node_in_use_by_oneview(
node self.oneview_client, node
) )
except exception.OneViewError as e: except exception.OneViewError as e:
# NOTE(xavierr): Skip this node and process the # NOTE(xavierr): Skip this node and process the
@ -227,6 +227,10 @@ class OneViewIscsiDeploy(iscsi_deploy.ISCSIDeploy, OneViewPeriodicTasks):
oneview_driver = common.ISCSI_PXE_ONEVIEW oneview_driver = common.ISCSI_PXE_ONEVIEW
def __init__(self):
super(OneViewIscsiDeploy, self).__init__()
self.oneview_client = common.get_oneview_client()
def get_properties(self): def get_properties(self):
deploy_utils.get_properties() deploy_utils.get_properties()
@ -234,7 +238,8 @@ class OneViewIscsiDeploy(iscsi_deploy.ISCSIDeploy, OneViewPeriodicTasks):
def validate(self, task): def validate(self, task):
common.verify_node_info(task.node) common.verify_node_info(task.node)
try: try:
common.validate_oneview_resources_compatibility(task) common.validate_oneview_resources_compatibility(
self.oneview_client, task)
except exception.OneViewError as oneview_exc: except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc) raise exception.InvalidParameterValue(oneview_exc)
super(OneViewIscsiDeploy, self).validate(task) super(OneViewIscsiDeploy, self).validate(task)
@ -242,26 +247,26 @@ class OneViewIscsiDeploy(iscsi_deploy.ISCSIDeploy, OneViewPeriodicTasks):
@METRICS.timer('OneViewIscsiDeploy.prepare') @METRICS.timer('OneViewIscsiDeploy.prepare')
def prepare(self, task): def prepare(self, task):
if common.is_dynamic_allocation_enabled(task.node): if common.is_dynamic_allocation_enabled(task.node):
deploy_utils.prepare(task) deploy_utils.prepare(self.oneview_client, task)
super(OneViewIscsiDeploy, self).prepare(task) super(OneViewIscsiDeploy, self).prepare(task)
@METRICS.timer('OneViewIscsiDeploy.tear_down') @METRICS.timer('OneViewIscsiDeploy.tear_down')
def tear_down(self, task): def tear_down(self, task):
if (common.is_dynamic_allocation_enabled(task.node) and if (common.is_dynamic_allocation_enabled(task.node) and
not CONF.conductor.automated_clean): not CONF.conductor.automated_clean):
deploy_utils.tear_down(task) deploy_utils.tear_down(self.oneview_client, task)
super(OneViewIscsiDeploy, self).tear_down(task) super(OneViewIscsiDeploy, self).tear_down(task)
@METRICS.timer('OneViewIscsiDeploy.prepare_cleaning') @METRICS.timer('OneViewIscsiDeploy.prepare_cleaning')
def prepare_cleaning(self, task): def prepare_cleaning(self, task):
if common.is_dynamic_allocation_enabled(task.node): if common.is_dynamic_allocation_enabled(task.node):
deploy_utils.prepare_cleaning(task) deploy_utils.prepare_cleaning(self.oneview_client, task)
return super(OneViewIscsiDeploy, self).prepare_cleaning(task) return super(OneViewIscsiDeploy, self).prepare_cleaning(task)
@METRICS.timer('OneViewIscsiDeploy.tear_down_cleaning') @METRICS.timer('OneViewIscsiDeploy.tear_down_cleaning')
def tear_down_cleaning(self, task): def tear_down_cleaning(self, task):
if common.is_dynamic_allocation_enabled(task.node): if common.is_dynamic_allocation_enabled(task.node):
deploy_utils.tear_down_cleaning(task) deploy_utils.tear_down_cleaning(self.oneview_client, task)
return super(OneViewIscsiDeploy, self).tear_down_cleaning(task) return super(OneViewIscsiDeploy, self).tear_down_cleaning(task)
@ -357,6 +362,10 @@ class OneViewAgentDeploy(OneViewAgentDeployMixin, agent.AgentDeploy,
oneview_driver = common.AGENT_PXE_ONEVIEW oneview_driver = common.AGENT_PXE_ONEVIEW
def __init__(self):
super(OneViewAgentDeploy, self).__init__()
self.oneview_client = common.get_oneview_client()
def get_properties(self): def get_properties(self):
deploy_utils.get_properties() deploy_utils.get_properties()
@ -364,7 +373,8 @@ class OneViewAgentDeploy(OneViewAgentDeployMixin, agent.AgentDeploy,
def validate(self, task): def validate(self, task):
common.verify_node_info(task.node) common.verify_node_info(task.node)
try: try:
common.validate_oneview_resources_compatibility(task) common.validate_oneview_resources_compatibility(
self.oneview_client, task)
except exception.OneViewError as oneview_exc: except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc) raise exception.InvalidParameterValue(oneview_exc)
super(OneViewAgentDeploy, self).validate(task) super(OneViewAgentDeploy, self).validate(task)
@ -372,24 +382,24 @@ class OneViewAgentDeploy(OneViewAgentDeployMixin, agent.AgentDeploy,
@METRICS.timer('OneViewAgentDeploy.prepare') @METRICS.timer('OneViewAgentDeploy.prepare')
def prepare(self, task): def prepare(self, task):
if common.is_dynamic_allocation_enabled(task.node): if common.is_dynamic_allocation_enabled(task.node):
deploy_utils.prepare(task) deploy_utils.prepare(self.oneview_client, task)
super(OneViewAgentDeploy, self).prepare(task) super(OneViewAgentDeploy, self).prepare(task)
@METRICS.timer('OneViewAgentDeploy.tear_down') @METRICS.timer('OneViewAgentDeploy.tear_down')
def tear_down(self, task): def tear_down(self, task):
if (common.is_dynamic_allocation_enabled(task.node) and if (common.is_dynamic_allocation_enabled(task.node) and
not CONF.conductor.automated_clean): not CONF.conductor.automated_clean):
deploy_utils.tear_down(task) deploy_utils.tear_down(self.oneview_client, task)
super(OneViewAgentDeploy, self).tear_down(task) super(OneViewAgentDeploy, self).tear_down(task)
@METRICS.timer('OneViewAgentDeploy.prepare_cleaning') @METRICS.timer('OneViewAgentDeploy.prepare_cleaning')
def prepare_cleaning(self, task): def prepare_cleaning(self, task):
if common.is_dynamic_allocation_enabled(task.node): if common.is_dynamic_allocation_enabled(task.node):
deploy_utils.prepare_cleaning(task) deploy_utils.prepare_cleaning(self.oneview_client, task)
return super(OneViewAgentDeploy, self).prepare_cleaning(task) return super(OneViewAgentDeploy, self).prepare_cleaning(task)
@METRICS.timer('OneViewAgentDeploy.tear_down_cleaning') @METRICS.timer('OneViewAgentDeploy.tear_down_cleaning')
def tear_down_cleaning(self, task): def tear_down_cleaning(self, task):
if common.is_dynamic_allocation_enabled(task.node): if common.is_dynamic_allocation_enabled(task.node):
deploy_utils.tear_down_cleaning(task) deploy_utils.tear_down_cleaning(self.oneview_client, task)
return super(OneViewAgentDeploy, self).tear_down_cleaning(task) return super(OneViewAgentDeploy, self).tear_down_cleaning(task)

View File

@ -34,13 +34,14 @@ def get_properties():
return common.COMMON_PROPERTIES return common.COMMON_PROPERTIES
def prepare(task): def prepare(oneview_client, task):
"""Applies Server Profile and update the node when preparing. """Applies Server Profile and update the node when preparing.
This method is responsible for applying a Server Profile to the Server 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 Hardware and add the uri of the applied Server Profile in the node's
'applied_server_profile_uri' field on properties/capabilities. 'applied_server_profile_uri' field on properties/capabilities.
:param oneview_client: an instance of the OneView client
:param task: A TaskManager object :param task: A TaskManager object
:raises InstanceDeployFailure: If the node doesn't have the needed OneView :raises InstanceDeployFailure: If the node doesn't have the needed OneView
informations, if Server Hardware is in use by an OneView user, or informations, if Server Hardware is in use by an OneView user, or
@ -56,13 +57,14 @@ def prepare(task):
{"instance_name": instance_display_name, {"instance_name": instance_display_name,
"instance_uuid": instance_uuid} "instance_uuid": instance_uuid}
) )
allocate_server_hardware_to_ironic(task.node, server_profile_name) allocate_server_hardware_to_ironic(oneview_client, task.node,
server_profile_name)
except exception.OneViewError as e: except exception.OneViewError as e:
raise exception.InstanceDeployFailure(node=task.node.uuid, raise exception.InstanceDeployFailure(node=task.node.uuid,
reason=e) reason=e)
def tear_down(task): def tear_down(oneview_client, task):
"""Remove Server profile and update the node when tear down. """Remove Server profile and update the node when tear down.
This method is responsible for power a Server Hardware off, remove a Server This method is responsible for power a Server Hardware off, remove a Server
@ -70,24 +72,26 @@ def tear_down(task):
Profile from the node's 'applied_server_profile_uri' in Profile from the node's 'applied_server_profile_uri' in
properties/capabilities. properties/capabilities.
:param oneview_client: an instance of the OneView client
:param task: A TaskManager object :param task: A TaskManager object
:raises InstanceDeployFailure: If node has no uri of applied Server :raises InstanceDeployFailure: If node has no uri of applied Server
Profile, or if some error occur while deleting Server Profile. Profile, or if some error occur while deleting Server Profile.
""" """
try: try:
deallocate_server_hardware_from_ironic(task.node) deallocate_server_hardware_from_ironic(oneview_client, task.node)
except exception.OneViewError as e: except exception.OneViewError as e:
raise exception.InstanceDeployFailure(node=task.node.uuid, reason=e) raise exception.InstanceDeployFailure(node=task.node.uuid, reason=e)
def prepare_cleaning(task): def prepare_cleaning(oneview_client, task):
"""Applies Server Profile and update the node when preparing cleaning. """Applies Server Profile and update the node when preparing cleaning.
This method is responsible for applying a Server Profile to the Server 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 Hardware and add the uri of the applied Server Profile in the node's
'applied_server_profile_uri' field on properties/capabilities. 'applied_server_profile_uri' field on properties/capabilities.
:param oneview_client: an instance of the OneView client
:param task: A TaskManager object :param task: A TaskManager object
:raises NodeCleaningFailure: If the node doesn't have the needed OneView :raises NodeCleaningFailure: If the node doesn't have the needed OneView
informations, if Server Hardware is in use by an OneView user, or informations, if Server Hardware is in use by an OneView user, or
@ -96,7 +100,8 @@ def prepare_cleaning(task):
""" """
try: try:
server_profile_name = "Ironic Cleaning [%s]" % task.node.uuid server_profile_name = "Ironic Cleaning [%s]" % task.node.uuid
allocate_server_hardware_to_ironic(task.node, server_profile_name) allocate_server_hardware_to_ironic(oneview_client, task.node,
server_profile_name)
except exception.OneViewError as e: except exception.OneViewError as e:
oneview_error = common.SERVER_HARDWARE_ALLOCATION_ERROR oneview_error = common.SERVER_HARDWARE_ALLOCATION_ERROR
driver_internal_info = task.node.driver_internal_info driver_internal_info = task.node.driver_internal_info
@ -107,7 +112,7 @@ def prepare_cleaning(task):
reason=e) reason=e)
def tear_down_cleaning(task): def tear_down_cleaning(oneview_client, task):
"""Remove Server profile and update the node when tear down cleaning. """Remove Server profile and update the node when tear down cleaning.
This method is responsible for power a Server Hardware off, remove a Server This method is responsible for power a Server Hardware off, remove a Server
@ -115,13 +120,14 @@ def tear_down_cleaning(task):
Profile from the node's 'applied_server_profile_uri' in Profile from the node's 'applied_server_profile_uri' in
properties/capabilities. properties/capabilities.
:param oneview_client: an instance of the OneView client
:param task: A TaskManager object :param task: A TaskManager object
:raises NodeCleaningFailure: If node has no uri of applied Server Profile, :raises NodeCleaningFailure: If node has no uri of applied Server Profile,
or if some error occur while deleting Server Profile. or if some error occur while deleting Server Profile.
""" """
try: try:
deallocate_server_hardware_from_ironic(task.node) deallocate_server_hardware_from_ironic(oneview_client, task.node)
except exception.OneViewError as e: except exception.OneViewError as e:
raise exception.NodeCleaningFailure(node=task.node.uuid, reason=e) raise exception.NodeCleaningFailure(node=task.node.uuid, reason=e)
@ -144,9 +150,10 @@ def _is_node_in_use(server_hardware, applied_sp_uri, by_oneview=False):
operation(applied_sp_uri, server_hardware.server_profile_uri)) operation(applied_sp_uri, server_hardware.server_profile_uri))
def is_node_in_use_by_oneview(node): def is_node_in_use_by_oneview(oneview_client, node):
"""Check if node is in use by OneView user. """Check if node is in use by OneView user.
:param oneview_client: an instance of the OneView client
:param node: an ironic node object :param node: an ironic node object
:returns: Boolean value. True if node is in use by OneView, :returns: Boolean value. True if node is in use by OneView,
False otherwise. False otherwise.
@ -165,12 +172,14 @@ def is_node_in_use_by_oneview(node):
return _is_node_in_use(server_hardware, applied_sp_uri, return _is_node_in_use(server_hardware, applied_sp_uri,
by_oneview=True) by_oneview=True)
return _check_applied_server_profile(node, predicate, positive, negative) return _check_applied_server_profile(oneview_client, node,
predicate, positive, negative)
def is_node_in_use_by_ironic(node): def is_node_in_use_by_ironic(oneview_client, node):
"""Check if node is in use by ironic in OneView. """Check if node is in use by ironic in OneView.
:param oneview_client: an instance of the OneView client
:param node: an ironic node object :param node: an ironic node object
:returns: Boolean value. True if node is in use by ironic, :returns: Boolean value. True if node is in use by ironic,
False otherwise. False otherwise.
@ -189,12 +198,15 @@ def is_node_in_use_by_ironic(node):
return _is_node_in_use(server_hardware, applied_sp_uri, return _is_node_in_use(server_hardware, applied_sp_uri,
by_oneview=False) by_oneview=False)
return _check_applied_server_profile(node, predicate, positive, negative) return _check_applied_server_profile(oneview_client, node,
predicate, positive, negative)
def _check_applied_server_profile(node, predicate, positive, negative): def _check_applied_server_profile(oneview_client, node,
predicate, positive, negative):
"""Check if node is in use by ironic in OneView. """Check if node is in use by ironic in OneView.
:param oneview_client: an instance of the OneView client
:param node: an ironic node object :param node: an ironic node object
:returns: Boolean value. True if node is in use by ironic, :returns: Boolean value. True if node is in use by ironic,
False otherwise. False otherwise.
@ -205,8 +217,6 @@ def _check_applied_server_profile(node, predicate, positive, negative):
""" """
oneview_info = common.get_oneview_info(node) oneview_info = common.get_oneview_info(node)
oneview_client = common.get_oneview_client()
sh_uuid = oneview_utils.get_uuid_from_uri( sh_uuid = oneview_utils.get_uuid_from_uri(
oneview_info.get("server_hardware_uri") oneview_info.get("server_hardware_uri")
) )
@ -259,9 +269,11 @@ def _del_applied_server_profile_uri_field(node):
node.save() node.save()
def allocate_server_hardware_to_ironic(node, server_profile_name): def allocate_server_hardware_to_ironic(oneview_client, node,
server_profile_name):
"""Allocate Server Hardware to ironic. """Allocate Server Hardware to ironic.
:param oneview_client: an instance of the OneView client
:param node: an ironic node object :param node: an ironic node object
:param server_profile_name: a formatted string with the Server Profile :param server_profile_name: a formatted string with the Server Profile
name name
@ -269,7 +281,7 @@ def allocate_server_hardware_to_ironic(node, server_profile_name):
Hardware to ironic Hardware to ironic
""" """
node_in_use_by_oneview = is_node_in_use_by_oneview(node) node_in_use_by_oneview = is_node_in_use_by_oneview(oneview_client, node)
if not node_in_use_by_oneview: if not node_in_use_by_oneview:
@ -283,7 +295,6 @@ def allocate_server_hardware_to_ironic(node, server_profile_name):
spt_uuid = oneview_utils.get_uuid_from_uri( spt_uuid = oneview_utils.get_uuid_from_uri(
oneview_info.get("server_profile_template_uri") oneview_info.get("server_profile_template_uri")
) )
oneview_client = common.get_oneview_client()
server_hardware = oneview_client.get_server_hardware_by_uuid(sh_uuid) server_hardware = oneview_client.get_server_hardware_by_uuid(sh_uuid)
# Don't have Server Profile on OneView but has # Don't have Server Profile on OneView but has
@ -334,9 +345,10 @@ def allocate_server_hardware_to_ironic(node, server_profile_name):
raise exception.OneViewError(error=msg) raise exception.OneViewError(error=msg)
def deallocate_server_hardware_from_ironic(node): def deallocate_server_hardware_from_ironic(oneview_client, node):
"""Deallocate Server Hardware from ironic. """Deallocate Server Hardware from ironic.
:param oneview_client: an instance of the OneView client
:param node: an ironic node object :param node: an ironic node object
:raises OneViewError: if an error occurs while deallocating the Server :raises OneViewError: if an error occurs while deallocating the Server
Hardware to ironic Hardware to ironic
@ -344,7 +356,6 @@ def deallocate_server_hardware_from_ironic(node):
""" """
oneview_info = common.get_oneview_info(node) oneview_info = common.get_oneview_info(node)
oneview_client = common.get_oneview_client()
oneview_client.power_off(oneview_info) oneview_client.power_off(oneview_info)
applied_sp_uuid = oneview_utils.get_uuid_from_uri( applied_sp_uuid = oneview_utils.get_uuid_from_uri(

View File

@ -39,8 +39,12 @@ oneview_utils = importutils.try_import('oneview_client.utils')
class OneViewInspect(inspector.Inspector): class OneViewInspect(inspector.Inspector):
"""Interface for in band inspection.""" """Interface for in band inspection."""
def __init__(self):
super(OneViewInspect, self).__init__()
self.oneview_client = common.get_oneview_client()
def get_properties(self): def get_properties(self):
return common.COMMON_PROPERTIES return deploy_utils.get_properties()
@METRICS.timer('OneViewInspect.validate') @METRICS.timer('OneViewInspect.validate')
def validate(self, task): def validate(self, task):
@ -60,7 +64,8 @@ class OneViewInspect(inspector.Inspector):
common.verify_node_info(task.node) common.verify_node_info(task.node)
try: try:
common.validate_oneview_resources_compatibility(task) common.validate_oneview_resources_compatibility(
self.oneview_client, task)
except exception.OneViewError as oneview_exc: except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc) raise exception.InvalidParameterValue(oneview_exc)
@ -68,7 +73,7 @@ class OneViewInspect(inspector.Inspector):
def inspect_hardware(self, task): def inspect_hardware(self, task):
profile_name = 'Ironic Inspecting [%s]' % task.node.uuid profile_name = 'Ironic Inspecting [%s]' % task.node.uuid
deploy_utils.allocate_server_hardware_to_ironic( deploy_utils.allocate_server_hardware_to_ironic(
task.node, profile_name self.oneview_client, task.node, profile_name
) )
return super(OneViewInspect, self).inspect_hardware(task) return super(OneViewInspect, self).inspect_hardware(task)
@ -96,8 +101,12 @@ class OneViewInspect(inspector.Inspector):
state_after = task.node.provision_state state_after = task.node.provision_state
# inspection finished # inspection finished
if (state_before == states.INSPECTING and if (
state_after in [states.MANAGEABLE, states.INSPECTFAIL]): state_before == states.INSPECTING and state_after in [
deploy_utils.deallocate_server_hardware_from_ironic(task.node) states.MANAGEABLE, states.INSPECTFAIL
]
):
deploy_utils.deallocate_server_hardware_from_ironic(
self.oneview_client, task.node)
return result return result

View File

@ -46,8 +46,12 @@ oneview_exceptions = importutils.try_import('oneview_client.exceptions')
class OneViewManagement(base.ManagementInterface): class OneViewManagement(base.ManagementInterface):
def __init__(self):
super(OneViewManagement, self).__init__()
self.oneview_client = common.get_oneview_client()
def get_properties(self): def get_properties(self):
return common.COMMON_PROPERTIES return deploy_utils.get_properties()
@METRICS.timer('OneViewManagement.validate') @METRICS.timer('OneViewManagement.validate')
def validate(self, task): def validate(self, task):
@ -69,9 +73,12 @@ class OneViewManagement(base.ManagementInterface):
common.verify_node_info(task.node) common.verify_node_info(task.node)
try: try:
common.validate_oneview_resources_compatibility(task) common.validate_oneview_resources_compatibility(
self.oneview_client, task)
if not deploy_utils.is_node_in_use_by_ironic(task.node): if not deploy_utils.is_node_in_use_by_ironic(
self.oneview_client, task.node
):
raise exception.InvalidParameterValue( raise exception.InvalidParameterValue(
_("Node %s is not in use by ironic.") % task.node.uuid) _("Node %s is not in use by ironic.") % task.node.uuid)
except exception.OneViewError as oneview_exc: except exception.OneViewError as oneview_exc:
@ -117,9 +124,9 @@ class OneViewManagement(base.ManagementInterface):
LOG.debug("Setting boot device to %(device)s for node %(node)s", LOG.debug("Setting boot device to %(device)s for node %(node)s",
{"device": device, "node": task.node.uuid}) {"device": device, "node": task.node.uuid})
try: try:
oneview_client = common.get_oneview_client()
device_to_oneview = BOOT_DEVICE_MAPPING_TO_OV.get(device) device_to_oneview = BOOT_DEVICE_MAPPING_TO_OV.get(device)
oneview_client.set_boot_device(oneview_info, device_to_oneview) self.oneview_client.set_boot_device(oneview_info,
device_to_oneview)
except oneview_exceptions.OneViewException as oneview_exc: except oneview_exceptions.OneViewException as oneview_exc:
msg = (_( msg = (_(
"Error setting boot device on OneView. Error: %s") "Error setting boot device on OneView. Error: %s")
@ -148,8 +155,7 @@ class OneViewManagement(base.ManagementInterface):
oneview_info = common.get_oneview_info(task.node) oneview_info = common.get_oneview_info(task.node)
try: try:
oneview_client = common.get_oneview_client() boot_order = self.oneview_client.get_boot_order(oneview_info)
boot_order = oneview_client.get_boot_order(oneview_info)
except oneview_exceptions.OneViewException as oneview_exc: except oneview_exceptions.OneViewException as oneview_exc:
msg = (_( msg = (_(
"Error getting boot device from OneView. Error: %s") "Error getting boot device from OneView. Error: %s")

View File

@ -24,6 +24,7 @@ from ironic.common import states
from ironic.conductor import task_manager from ironic.conductor import task_manager
from ironic.drivers import base from ironic.drivers import base
from ironic.drivers.modules.oneview import common from ironic.drivers.modules.oneview import common
from ironic.drivers.modules.oneview import deploy_utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -34,8 +35,12 @@ oneview_exceptions = importutils.try_import('oneview_client.exceptions')
class OneViewPower(base.PowerInterface): class OneViewPower(base.PowerInterface):
def __init__(self):
super(OneViewPower, self).__init__()
self.oneview_client = common.get_oneview_client()
def get_properties(self): def get_properties(self):
return common.COMMON_PROPERTIES return deploy_utils.get_properties()
@METRICS.timer('OneViewPower.validate') @METRICS.timer('OneViewPower.validate')
def validate(self, task): def validate(self, task):
@ -57,7 +62,8 @@ class OneViewPower(base.PowerInterface):
common.verify_node_info(task.node) common.verify_node_info(task.node)
try: try:
common.validate_oneview_resources_compatibility(task) common.validate_oneview_resources_compatibility(
self.oneview_client, task)
except exception.OneViewError as oneview_exc: except exception.OneViewError as oneview_exc:
raise exception.InvalidParameterValue(oneview_exc) raise exception.InvalidParameterValue(oneview_exc)
@ -74,9 +80,10 @@ class OneViewPower(base.PowerInterface):
""" """
oneview_info = common.get_oneview_info(task.node) oneview_info = common.get_oneview_info(task.node)
oneview_client = common.get_oneview_client()
try: try:
power_state = oneview_client.get_node_power_state(oneview_info) power_state = self.oneview_client.get_node_power_state(
oneview_info
)
except oneview_exceptions.OneViewException as oneview_exc: except oneview_exceptions.OneViewException as oneview_exc:
LOG.error( LOG.error(
_LE("Error getting power state for node %(node)s. Error:" _LE("Error getting power state for node %(node)s. Error:"
@ -101,20 +108,18 @@ class OneViewPower(base.PowerInterface):
""" """
oneview_info = common.get_oneview_info(task.node) oneview_info = common.get_oneview_info(task.node)
oneview_client = common.get_oneview_client()
LOG.debug('Setting power state of node %(node_uuid)s to ' LOG.debug('Setting power state of node %(node_uuid)s to '
'%(power_state)s', '%(power_state)s',
{'node_uuid': task.node.uuid, 'power_state': power_state}) {'node_uuid': task.node.uuid, 'power_state': power_state})
try: try:
if power_state == states.POWER_ON: if power_state == states.POWER_ON:
oneview_client.power_on(oneview_info) self.oneview_client.power_on(oneview_info)
elif power_state == states.POWER_OFF: elif power_state == states.POWER_OFF:
oneview_client.power_off(oneview_info) self.oneview_client.power_off(oneview_info)
elif power_state == states.REBOOT: elif power_state == states.REBOOT:
oneview_client.power_off(oneview_info) self.oneview_client.power_off(oneview_info)
oneview_client.power_on(oneview_info) self.oneview_client.power_on(oneview_info)
else: else:
raise exception.InvalidParameterValue( raise exception.InvalidParameterValue(
_("set_power_state called with invalid power state %s.") _("set_power_state called with invalid power state %s.")

View File

@ -236,7 +236,8 @@ class OneViewCommonTestCase(db_base.DbTestCase):
): ):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
common.validate_oneview_resources_compatibility(task) common.validate_oneview_resources_compatibility(oneview_client,
task)
self.assertTrue( self.assertTrue(
oneview_client.validate_node_server_hardware_type.called) oneview_client.validate_node_server_hardware_type.called)
self.assertTrue( self.assertTrue(
@ -279,7 +280,8 @@ class OneViewCommonTestCase(db_base.DbTestCase):
driver_info['dynamic_allocation'] = True driver_info['dynamic_allocation'] = True
task.node.driver_info = driver_info task.node.driver_info = driver_info
common.validate_oneview_resources_compatibility(task) common.validate_oneview_resources_compatibility(oneview_client,
task)
self.assertTrue( self.assertTrue(
oneview_client.validate_node_server_hardware_type.called) oneview_client.validate_node_server_hardware_type.called)
self.assertTrue( self.assertTrue(

View File

@ -25,7 +25,10 @@ from ironic.common import exception
from ironic.common import states from ironic.common import states
from ironic.conductor import task_manager from ironic.conductor import task_manager
from ironic.conductor import utils as manager_utils from ironic.conductor import utils as manager_utils
from ironic.conf import CONF
from ironic.drivers.modules import agent
from ironic.drivers.modules import agent_client from ironic.drivers.modules import agent_client
from ironic.drivers.modules import iscsi_deploy
from ironic.drivers.modules.oneview import common from ironic.drivers.modules.oneview import common
from ironic.drivers.modules.oneview import deploy from ironic.drivers.modules.oneview import deploy
from ironic.drivers.modules.oneview import deploy_utils from ironic.drivers.modules.oneview import deploy_utils
@ -40,6 +43,8 @@ from ironic.tests.unit.objects import utils as obj_utils
oneview_models = importutils.try_import('oneview_client.models') oneview_models = importutils.try_import('oneview_client.models')
METHODS = ['iter_nodes', 'update_node', 'do_provisioning_action'] METHODS = ['iter_nodes', 'update_node', 'do_provisioning_action']
PXE_DRV_INFO_DICT = db_utils.get_test_pxe_driver_info()
PXE_INST_INFO_DICT = db_utils.get_test_pxe_instance_info()
oneview_error = common.SERVER_HARDWARE_ALLOCATION_ERROR oneview_error = common.SERVER_HARDWARE_ALLOCATION_ERROR
maintenance_reason = common.NODE_IN_USE_BY_ONEVIEW maintenance_reason = common.NODE_IN_USE_BY_ONEVIEW
@ -88,10 +93,12 @@ def _setup_node_in_cleanfailed_state_without_oneview_error(node):
class OneViewDriverDeploy(deploy.OneViewPeriodicTasks): class OneViewDriverDeploy(deploy.OneViewPeriodicTasks):
oneview_driver = 'fake_oneview' oneview_driver = 'fake_oneview'
def __init__(self):
self.oneview_client = mock.MagicMock()
@mock.patch('ironic.objects.Node', spec_set=True, autospec=True) @mock.patch('ironic.objects.Node', spec_set=True, autospec=True)
@mock.patch.object(deploy_utils, 'is_node_in_use_by_oneview', @mock.patch.object(deploy_utils, 'is_node_in_use_by_oneview')
spec_set=True, autospec=True)
class OneViewPeriodicTasks(db_base.DbTestCase): class OneViewPeriodicTasks(db_base.DbTestCase):
def setUp(self): def setUp(self):
@ -121,7 +128,9 @@ class OneViewPeriodicTasks(db_base.DbTestCase):
self.deploy._periodic_check_nodes_taken_by_oneview( self.deploy._periodic_check_nodes_taken_by_oneview(
self.manager, self.context self.manager, self.context
) )
mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) mock_is_node_in_use_by_oneview.assert_called_once_with(
self.deploy.oneview_client, self.node
)
self.assertTrue(self.manager.update_node.called) self.assertTrue(self.manager.update_node.called)
self.assertTrue(self.manager.do_provisioning_action.called) self.assertTrue(self.manager.do_provisioning_action.called)
self.assertTrue(self.node.maintenance) self.assertTrue(self.node.maintenance)
@ -139,7 +148,9 @@ class OneViewPeriodicTasks(db_base.DbTestCase):
self.deploy._periodic_check_nodes_taken_by_oneview( self.deploy._periodic_check_nodes_taken_by_oneview(
self.manager, self.context self.manager, self.context
) )
mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) mock_is_node_in_use_by_oneview.assert_called_once_with(
self.deploy.oneview_client, self.node
)
self.assertFalse(self.manager.update_node.called) self.assertFalse(self.manager.update_node.called)
self.assertFalse(self.manager.do_provisioning_action.called) self.assertFalse(self.manager.do_provisioning_action.called)
self.assertFalse(self.node.maintenance) self.assertFalse(self.node.maintenance)
@ -156,7 +167,9 @@ class OneViewPeriodicTasks(db_base.DbTestCase):
self.deploy._periodic_check_nodes_taken_by_oneview( self.deploy._periodic_check_nodes_taken_by_oneview(
self.manager, self.context self.manager, self.context
) )
mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) mock_is_node_in_use_by_oneview.assert_called_once_with(
self.deploy.oneview_client, self.node
)
self.assertFalse(self.manager.update_node.called) self.assertFalse(self.manager.update_node.called)
self.assertFalse(self.manager.do_provisioning_action.called) self.assertFalse(self.manager.do_provisioning_action.called)
self.assertFalse(self.node.maintenance) self.assertFalse(self.node.maintenance)
@ -173,7 +186,9 @@ class OneViewPeriodicTasks(db_base.DbTestCase):
self.deploy._periodic_check_nodes_freed_by_oneview( self.deploy._periodic_check_nodes_freed_by_oneview(
self.manager, self.context self.manager, self.context
) )
mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) mock_is_node_in_use_by_oneview.assert_called_once_with(
self.deploy.oneview_client, self.node
)
self.assertTrue(self.manager.update_node.called) self.assertTrue(self.manager.update_node.called)
self.assertTrue(self.manager.do_provisioning_action.called) self.assertTrue(self.manager.do_provisioning_action.called)
self.assertFalse(self.node.maintenance) self.assertFalse(self.node.maintenance)
@ -189,7 +204,9 @@ class OneViewPeriodicTasks(db_base.DbTestCase):
self.deploy._periodic_check_nodes_freed_by_oneview( self.deploy._periodic_check_nodes_freed_by_oneview(
self.manager, self.context self.manager, self.context
) )
mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) mock_is_node_in_use_by_oneview.assert_called_once_with(
self.deploy.oneview_client, self.node
)
self.assertFalse(self.manager.update_node.called) self.assertFalse(self.manager.update_node.called)
self.assertFalse(self.manager.do_provisioning_action.called) self.assertFalse(self.manager.do_provisioning_action.called)
self.assertTrue(self.node.maintenance) self.assertTrue(self.node.maintenance)
@ -207,7 +224,9 @@ class OneViewPeriodicTasks(db_base.DbTestCase):
self.deploy._periodic_check_nodes_freed_by_oneview( self.deploy._periodic_check_nodes_freed_by_oneview(
self.manager, self.context self.manager, self.context
) )
mock_is_node_in_use_by_oneview.assert_called_once_with(self.node) mock_is_node_in_use_by_oneview.assert_called_once_with(
self.deploy.oneview_client, self.node
)
self.assertFalse(self.manager.update_node.called) self.assertFalse(self.manager.update_node.called)
self.assertFalse(self.manager.do_provisioning_action.called) self.assertFalse(self.manager.do_provisioning_action.called)
self.assertTrue(self.node.maintenance) self.assertTrue(self.node.maintenance)
@ -256,7 +275,7 @@ class TestOneViewAgentDeploy(db_base.DbTestCase):
post_deploy_get_power_state_retries=GET_POWER_STATE_RETRIES, post_deploy_get_power_state_retries=GET_POWER_STATE_RETRIES,
group='agent') group='agent')
mgr_utils.mock_the_extension_manager(driver="agent_pxe_oneview") mgr_utils.mock_the_extension_manager(driver="agent_pxe_oneview")
self.driver = driver_factory.get_driver("agent_pxe_oneview")
self.node = obj_utils.create_test_node( self.node = obj_utils.create_test_node(
self.context, driver='agent_pxe_oneview', self.context, driver='agent_pxe_oneview',
properties=db_utils.get_test_oneview_properties(), properties=db_utils.get_test_oneview_properties(),
@ -301,18 +320,24 @@ class TestOneViewAgentDeploy(db_base.DbTestCase):
def test_reboot_and_finish_deploy_soft_poweroff_doesnt_complete( def test_reboot_and_finish_deploy_soft_poweroff_doesnt_complete(
self, power_off_mock, get_power_state_mock, self, power_off_mock, get_power_state_mock,
node_power_action_mock, mock_get_ov_client): node_power_action_mock, mock_get_ov_client):
client = mock_get_ov_client.return_value oneview_client = mock_get_ov_client.return_value
self.driver.management.oneview_client = oneview_client
fake_server_hardware = oneview_models.ServerHardware() fake_server_hardware = oneview_models.ServerHardware()
fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/' fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/'
client.get_server_hardware_by_uuid.return_value = fake_server_hardware oneview_client.get_server_hardware_by_uuid.return_value = (
mock_get_ov_client.return_value = client fake_server_hardware
)
mock_get_ov_client.return_value = oneview_client
self.node.provision_state = states.DEPLOYING self.node.provision_state = states.DEPLOYING
self.node.target_provision_state = states.ACTIVE self.node.target_provision_state = states.ACTIVE
driver_info = self.node.driver_info driver_info = self.node.driver_info
driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/' driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/'
self.node.driver_info = driver_info self.node.driver_info = driver_info
self.node.save() self.node.save()
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
get_power_state_mock.return_value = states.POWER_ON get_power_state_mock.return_value = states.POWER_ON
@ -333,19 +358,27 @@ class TestOneViewAgentDeploy(db_base.DbTestCase):
def test_reboot_and_finish_deploy_soft_poweroff_fails( def test_reboot_and_finish_deploy_soft_poweroff_fails(
self, power_off_mock, node_power_action_mock, self, power_off_mock, node_power_action_mock,
mock_get_ov_client): mock_get_ov_client):
client = mock_get_ov_client.return_value oneview_client = mock_get_ov_client.return_value
self.driver.management.oneview_client = oneview_client
fake_server_hardware = oneview_models.ServerHardware() fake_server_hardware = oneview_models.ServerHardware()
fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/' fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/'
client.get_server_hardware_by_uuid.return_value = fake_server_hardware oneview_client.get_server_hardware_by_uuid.return_value = (
mock_get_ov_client.return_value = client fake_server_hardware
)
mock_get_ov_client.return_value = oneview_client
power_off_mock.side_effect = RuntimeError("boom") power_off_mock.side_effect = RuntimeError("boom")
self.node.provision_state = states.DEPLOYING self.node.provision_state = states.DEPLOYING
self.node.target_provision_state = states.ACTIVE self.node.target_provision_state = states.ACTIVE
driver_info = self.node.driver_info driver_info = self.node.driver_info
driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/' driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/'
self.node.driver_info = driver_info self.node.driver_info = driver_info
self.node.save() self.node.save()
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
task.driver.deploy.reboot_and_finish_deploy(task) task.driver.deploy.reboot_and_finish_deploy(task)
@ -366,18 +399,24 @@ class TestOneViewAgentDeploy(db_base.DbTestCase):
def test_reboot_and_finish_deploy_get_power_state_fails( def test_reboot_and_finish_deploy_get_power_state_fails(
self, power_off_mock, get_power_state_mock, self, power_off_mock, get_power_state_mock,
node_power_action_mock, mock_get_ov_client): node_power_action_mock, mock_get_ov_client):
client = mock_get_ov_client.return_value oneview_client = mock_get_ov_client.return_value
self.driver.management.oneview_client = oneview_client
fake_server_hardware = oneview_models.ServerHardware() fake_server_hardware = oneview_models.ServerHardware()
fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/' fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/'
client.get_server_hardware_by_uuid.return_value = fake_server_hardware oneview_client.get_server_hardware_by_uuid.return_value = (
mock_get_ov_client.return_value = client fake_server_hardware
)
mock_get_ov_client.return_value = oneview_client
self.node.provision_state = states.DEPLOYING self.node.provision_state = states.DEPLOYING
self.node.target_provision_state = states.ACTIVE self.node.target_provision_state = states.ACTIVE
driver_info = self.node.driver_info driver_info = self.node.driver_info
driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/' driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/'
self.node.driver_info = driver_info self.node.driver_info = driver_info
self.node.save() self.node.save()
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
get_power_state_mock.side_effect = RuntimeError("boom") get_power_state_mock.side_effect = RuntimeError("boom")
@ -436,18 +475,24 @@ class TestOneViewAgentDeploy(db_base.DbTestCase):
node_power_action_mock, mock_get_ov_client): node_power_action_mock, mock_get_ov_client):
check_deploy_mock.return_value = None check_deploy_mock.return_value = None
client = mock_get_ov_client.return_value oneview_client = mock_get_ov_client.return_value
self.driver.management.oneview_client = oneview_client
fake_server_hardware = oneview_models.ServerHardware() fake_server_hardware = oneview_models.ServerHardware()
fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/' fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/'
client.get_server_hardware_by_uuid.return_value = fake_server_hardware oneview_client.get_server_hardware_by_uuid.return_value = (
mock_get_ov_client.return_value = client fake_server_hardware
)
mock_get_ov_client.return_value = oneview_client
self.node.provision_state = states.DEPLOYWAIT self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE self.node.target_provision_state = states.ACTIVE
driver_info = self.node.driver_info driver_info = self.node.driver_info
driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/' driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/'
self.node.driver_info = driver_info self.node.driver_info = driver_info
self.node.save() self.node.save()
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
get_power_state_mock.return_value = states.POWER_OFF get_power_state_mock.return_value = states.POWER_OFF
@ -478,20 +523,26 @@ class TestOneViewAgentDeploy(db_base.DbTestCase):
get_power_state_mock, get_power_state_mock,
node_power_action_mock, node_power_action_mock,
mock_get_ov_client): mock_get_ov_client):
client = mock_get_ov_client.return_value oneview_client = mock_get_ov_client.return_value
self.driver.management.oneview_client = oneview_client
fake_server_hardware = oneview_models.ServerHardware() fake_server_hardware = oneview_models.ServerHardware()
fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/' fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/'
client.get_server_hardware_by_uuid.return_value = fake_server_hardware oneview_client.get_server_hardware_by_uuid.return_value = (
mock_get_ov_client.return_value = client fake_server_hardware
)
mock_get_ov_client.return_value = oneview_client
check_deploy_mock.return_value = None check_deploy_mock.return_value = None
self.node.provision_state = states.DEPLOYWAIT self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE self.node.target_provision_state = states.ACTIVE
driver_info = self.node.driver_info driver_info = self.node.driver_info
driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/' driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/'
self.node.driver_info = driver_info self.node.driver_info = driver_info
self.node.save() self.node.save()
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
get_power_state_mock.return_value = states.POWER_OFF get_power_state_mock.return_value = states.POWER_OFF
@ -508,3 +559,354 @@ class TestOneViewAgentDeploy(db_base.DbTestCase):
task, states.POWER_ON) task, states.POWER_ON)
self.assertEqual(states.ACTIVE, task.node.provision_state) self.assertEqual(states.ACTIVE, task.node.provision_state)
self.assertEqual(states.NOSTATE, task.node.target_provision_state) self.assertEqual(states.NOSTATE, task.node.target_provision_state)
@mock.patch.object(common, 'get_oneview_client', spec_set=True, autospec=True)
class OneViewIscsiDeployTestCase(db_base.DbTestCase):
def setUp(self):
super(OneViewIscsiDeployTestCase, self).setUp()
self.config(manager_url='https://1.2.3.4', group='oneview')
self.config(username='user', group='oneview')
self.config(password='password', group='oneview')
mgr_utils.mock_the_extension_manager(driver='iscsi_pxe_oneview')
self.driver = driver_factory.get_driver('iscsi_pxe_oneview')
OV_DRV_INFO_DICT = db_utils.get_test_oneview_driver_info()
OV_DRV_INFO_DICT.update(PXE_DRV_INFO_DICT)
self.node = obj_utils.create_test_node(
self.context, driver='iscsi_pxe_oneview',
properties=db_utils.get_test_oneview_properties(),
driver_info=OV_DRV_INFO_DICT,
instance_info=PXE_INST_INFO_DICT,
)
self.port = obj_utils.create_test_port(self.context,
node_id=self.node.id)
self.info = common.get_oneview_info(self.node)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'validate',
spec_set=True, autospec=True)
def test_validate(self, iscsi_deploy_validate_mock, mock_get_ov_client):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.validate(task)
iscsi_deploy_validate_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'prepare',
spec_set=True, autospec=True)
def test_prepare(self, iscsi_deploy_prepare_mock, mock_get_ov_client):
self.node.provision_state = states.DEPLOYING
self.node.save()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.prepare(task)
iscsi_deploy_prepare_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'prepare',
spec_set=True, autospec=True)
def test_prepare_active_node(self, iscsi_deploy_prepare_mock,
mock_get_ov_client):
"""Ensure nodes in running states are not inadvertently changed"""
test_states = list(states.STABLE_STATES)
test_states.extend([states.CLEANING,
states.CLEANWAIT,
states.INSPECTING])
for state in test_states:
self.node.provision_state = state
self.node.save()
iscsi_deploy_prepare_mock.reset_mock()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.prepare(task)
iscsi_deploy_prepare_mock.assert_called_once_with(
mock.ANY, task)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'prepare',
spec_set=True, autospec=True)
@mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic')
def test_prepare_with_dynamic_allocation_enabled(
self, allocate_server_hardware_mock,
iscsi_deploy_prepare_mock, mock_get_ov_client
):
driver_info = self.node.driver_info
driver_info['dynamic_allocation'] = True
self.node.driver_info = driver_info
self.node.provision_state = states.DEPLOYING
self.node.save()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.prepare(task)
iscsi_deploy_prepare_mock.assert_called_once_with(mock.ANY, task)
self.assertTrue(allocate_server_hardware_mock.called)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'deploy',
spec_set=True, autospec=True)
def test_deploy(self, iscsi_deploy_mock, mock_get_ov_client):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) 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', spec_set=True,
autospec=True)
def test_tear_down(self, iscsi_tear_down_mock, mock_get_ov_client):
iscsi_tear_down_mock.return_value = states.DELETED
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.tear_down(task)
iscsi_tear_down_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'tear_down', spec_set=True,
autospec=True)
@mock.patch.object(deploy_utils, 'deallocate_server_hardware_from_ironic')
def test_tear_down_with_dynamic_allocation_enabled(
self, deallocate_server_hardware_mock,
iscsi_tear_down_mock, mock_get_ov_client
):
driver_info = self.node.driver_info
driver_info['dynamic_allocation'] = True
self.node.driver_info = driver_info
self.node.save()
CONF.conductor.automated_clean = False
iscsi_tear_down_mock.return_value = states.DELETED
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.tear_down(task)
iscsi_tear_down_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'prepare_cleaning',
spec_set=True, autospec=True)
def test_prepare_cleaning(self, iscsi_prep_clean_mock, mock_get_ov_client):
iscsi_prep_clean_mock.return_value = states.CLEANWAIT
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
ret = task.driver.deploy.prepare_cleaning(task)
self.assertEqual(states.CLEANWAIT, ret)
iscsi_prep_clean_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'prepare_cleaning',
spec_set=True, autospec=True)
@mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic')
def test_prepare_cleaning_with_dynamic_allocation_enabled(
self, allocate_server_hardware_mock,
iscsi_prep_clean_mock, mock_get_ov_client
):
driver_info = self.node.driver_info
driver_info['dynamic_allocation'] = True
self.node.driver_info = driver_info
self.node.save()
iscsi_prep_clean_mock.return_value = states.CLEANWAIT
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
ret = task.driver.deploy.prepare_cleaning(task)
self.assertEqual(states.CLEANWAIT, ret)
iscsi_prep_clean_mock.assert_called_once_with(mock.ANY, task)
self.assertTrue(allocate_server_hardware_mock.called)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'tear_down_cleaning',
spec_set=True, autospec=True)
def test_tear_down_cleaning(self, iscsi_tear_down_clean_mock,
mock_get_ov_client):
iscsi_tear_down_clean_mock.return_value = states.CLEANWAIT
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.tear_down_cleaning(task)
iscsi_tear_down_clean_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(iscsi_deploy.ISCSIDeploy, 'tear_down_cleaning',
spec_set=True, autospec=True)
@mock.patch.object(deploy_utils, 'deallocate_server_hardware_from_ironic')
def test_tear_down_cleaning_with_dynamic_allocation_enabled(
self, deallocate_server_hardware_mock,
iscsi_tear_down_clean_mock, mock_get_ov_client
):
driver_info = self.node.driver_info
driver_info['dynamic_allocation'] = True
self.node.driver_info = driver_info
self.node.save()
iscsi_tear_down_clean_mock.return_value = states.CLEANWAIT
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.tear_down_cleaning(task)
iscsi_tear_down_clean_mock.assert_called_once_with(mock.ANY, task)
self.assertTrue(deallocate_server_hardware_mock.called)
@mock.patch.object(common, 'get_oneview_client', spec_set=True, autospec=True)
class OneViewAgentDeployTestCase(db_base.DbTestCase):
def setUp(self):
super(OneViewAgentDeployTestCase, self).setUp()
self.config(manager_url='https://1.2.3.4', group='oneview')
self.config(username='user', group='oneview')
self.config(password='password', group='oneview')
mgr_utils.mock_the_extension_manager(driver='agent_pxe_oneview')
self.driver = driver_factory.get_driver('agent_pxe_oneview')
OV_DRV_INFO_DICT = db_utils.get_test_oneview_driver_info()
OV_DRV_INFO_DICT.update(PXE_DRV_INFO_DICT)
self.node = obj_utils.create_test_node(
self.context, driver='agent_pxe_oneview',
properties=db_utils.get_test_oneview_properties(),
driver_info=OV_DRV_INFO_DICT,
instance_info=PXE_INST_INFO_DICT,
)
self.port = obj_utils.create_test_port(self.context,
node_id=self.node.id)
self.info = common.get_oneview_info(self.node)
@mock.patch.object(agent.AgentDeploy, 'validate',
spec_set=True, autospec=True)
def test_validate(self, agent_deploy_validate_mock, mock_get_ov_client):
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)
@mock.patch.object(agent.AgentDeploy, 'prepare',
spec_set=True, autospec=True)
def test_prepare(self, agent_deploy_prepare_mock, mock_get_ov_client):
self.node.provision_state = states.DEPLOYING
self.node.save()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.prepare(task)
agent_deploy_prepare_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(agent.AgentDeploy, 'prepare',
spec_set=True, autospec=True)
def test_prepare_active_node(self, agent_deploy_prepare_mock,
mock_get_ov_client):
"""Ensure nodes in running states are not inadvertently changed"""
test_states = list(states.STABLE_STATES)
test_states.extend([states.CLEANING,
states.CLEANWAIT,
states.INSPECTING])
for state in test_states:
self.node.provision_state = state
self.node.save()
agent_deploy_prepare_mock.reset_mock()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.prepare(task)
agent_deploy_prepare_mock.assert_called_once_with(
mock.ANY, task)
@mock.patch.object(agent.AgentDeploy, 'prepare',
spec_set=True, autospec=True)
@mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic')
def test_prepare_with_dynamic_allocation_enabled(
self, allocate_server_hardware_mock,
agent_deploy_prepare_mock, mock_get_ov_client
):
driver_info = self.node.driver_info
driver_info['dynamic_allocation'] = True
self.node.driver_info = driver_info
self.node.provision_state = states.DEPLOYING
self.node.save()
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.prepare(task)
agent_deploy_prepare_mock.assert_called_once_with(mock.ANY, task)
self.assertTrue(allocate_server_hardware_mock.called)
@mock.patch.object(agent.AgentDeploy, 'deploy',
spec_set=True, autospec=True)
def test_deploy(self, agent_deploy_mock, mock_get_ov_client):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.deploy(task)
agent_deploy_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(agent.AgentDeploy, 'tear_down', spec_set=True,
autospec=True)
def test_tear_down(self, agent_tear_down_mock, mock_get_ov_client):
agent_tear_down_mock.return_value = states.DELETED
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.tear_down(task)
agent_tear_down_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(agent.AgentDeploy, 'tear_down', spec_set=True,
autospec=True)
@mock.patch.object(deploy_utils, 'deallocate_server_hardware_from_ironic')
def test_tear_down_with_dynamic_allocation_enabled(
self, deallocate_server_hardware_mock,
agent_tear_down_mock, mock_get_ov_client
):
driver_info = self.node.driver_info
driver_info['dynamic_allocation'] = True
self.node.driver_info = driver_info
self.node.save()
CONF.conductor.automated_clean = False
agent_tear_down_mock.return_value = states.DELETED
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.tear_down(task)
agent_tear_down_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(agent.AgentDeploy, 'prepare_cleaning',
spec_set=True, autospec=True)
def test_prepare_cleaning(self, agent_prep_clean_mock, mock_get_ov_client):
agent_prep_clean_mock.return_value = states.CLEANWAIT
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
ret = task.driver.deploy.prepare_cleaning(task)
self.assertEqual(states.CLEANWAIT, ret)
agent_prep_clean_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(agent.AgentDeploy, 'prepare_cleaning',
spec_set=True, autospec=True)
@mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic')
def test_prepare_cleaning_with_dynamic_allocation_enabled(
self, allocate_server_hardware_mock,
agent_prep_clean_mock, mock_get_ov_client
):
driver_info = self.node.driver_info
driver_info['dynamic_allocation'] = True
self.node.driver_info = driver_info
self.node.save()
agent_prep_clean_mock.return_value = states.CLEANWAIT
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
ret = task.driver.deploy.prepare_cleaning(task)
self.assertEqual(states.CLEANWAIT, ret)
agent_prep_clean_mock.assert_called_once_with(mock.ANY, task)
self.assertTrue(allocate_server_hardware_mock.called)
@mock.patch.object(agent.AgentDeploy, 'tear_down_cleaning',
spec_set=True, autospec=True)
def test_tear_down_cleaning(self, agent_tear_down_clean_mock,
mock_get_ov_client):
agent_tear_down_clean_mock.return_value = states.CLEANWAIT
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.tear_down_cleaning(task)
agent_tear_down_clean_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(agent.AgentDeploy, 'tear_down_cleaning',
spec_set=True, autospec=True)
@mock.patch.object(deploy_utils, 'deallocate_server_hardware_from_ironic')
def test_tear_down_cleaning_with_dynamic_allocation_enabled(
self, deallocate_server_hardware_mock,
agent_tear_down_clean_mock, mock_get_ov_client
):
driver_info = self.node.driver_info
driver_info['dynamic_allocation'] = True
self.node.driver_info = driver_info
self.node.save()
agent_tear_down_clean_mock.return_value = states.CLEANWAIT
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.tear_down_cleaning(task)
agent_tear_down_clean_mock.assert_called_once_with(mock.ANY, task)
self.assertTrue(deallocate_server_hardware_mock.called)

View File

@ -58,6 +58,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
""" """
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
fake_server_hardware = oneview_models.ServerHardware() fake_server_hardware = oneview_models.ServerHardware()
fake_server_hardware.server_profile_uri = "/any/sp_uri" fake_server_hardware.server_profile_uri = "/any/sp_uri"
oneview_client.get_server_hardware.return_value = fake_server_hardware oneview_client.get_server_hardware.return_value = fake_server_hardware
@ -70,6 +71,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
self.assertRaises( self.assertRaises(
exception.InstanceDeployFailure, exception.InstanceDeployFailure,
deploy_utils.prepare, deploy_utils.prepare,
oneview_client,
task task
) )
@ -80,22 +82,24 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
"""`prepare` behavior when the node is free from OneView standpoint. """`prepare` behavior when the node is free from OneView standpoint.
""" """
ov_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
fake_sh = oneview_models.ServerHardware() fake_sh = oneview_models.ServerHardware()
fake_sh.server_profile_uri = None fake_sh.server_profile_uri = None
ov_client.get_server_hardware_by_uuid.return_value = fake_sh oneview_client.get_server_hardware_by_uuid.return_value = fake_sh
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
task.node.provision_state = states.DEPLOYING task.node.provision_state = states.DEPLOYING
deploy_utils.prepare(task) deploy_utils.prepare(oneview_client, task)
self.assertTrue(ov_client.clone_template_and_apply.called) self.assertTrue(oneview_client.clone_template_and_apply.called)
self.assertTrue(ov_client.get_server_profile_from_hardware) self.assertTrue(oneview_client.get_server_profile_from_hardware)
# Tests for tear_down # Tests for tear_down
def test_tear_down(self, mock_get_ov_client): def test_tear_down(self, mock_get_ov_client):
"""`tear_down` behavior when node already has Profile applied """`tear_down` behavior when node already has Profile applied
""" """
ov_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
driver_info = task.node.driver_info driver_info = task.node.driver_info
driver_info['applied_server_profile_uri'] = \ driver_info['applied_server_profile_uri'] = \
@ -105,12 +109,12 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
self.assertTrue( self.assertTrue(
'applied_server_profile_uri' in task.node.driver_info 'applied_server_profile_uri' in task.node.driver_info
) )
deploy_utils.tear_down(task) deploy_utils.tear_down(oneview_client, task)
self.assertFalse( self.assertFalse(
'applied_server_profile_uri' in task.node.driver_info 'applied_server_profile_uri' in task.node.driver_info
) )
self.assertTrue( self.assertTrue(
ov_client.delete_server_profile.called oneview_client.delete_server_profile.called
) )
# Tests for prepare_cleaning # Tests for prepare_cleaning
@ -121,13 +125,14 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
"""`prepare_cleaning` behavior when node is free """`prepare_cleaning` behavior when node is free
""" """
ov_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
fake_sh = oneview_models.ServerHardware() fake_sh = oneview_models.ServerHardware()
fake_sh.server_profile_uri = None fake_sh.server_profile_uri = None
ov_client.get_server_hardware_by_uuid.return_value = fake_sh oneview_client.get_server_hardware_by_uuid.return_value = fake_sh
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
deploy_utils.prepare_cleaning(task) deploy_utils.prepare_cleaning(oneview_client, task)
self.assertTrue(ov_client.clone_template_and_apply.called) self.assertTrue(oneview_client.clone_template_and_apply.called)
@mock.patch.object(objects.Node, 'save') @mock.patch.object(objects.Node, 'save')
def test_prepare_cleaning_when_node_has_sp_applied( def test_prepare_cleaning_when_node_has_sp_applied(
@ -136,18 +141,19 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
"""`prepare_cleaning` behavior when node already has Profile applied """`prepare_cleaning` behavior when node already has Profile applied
""" """
ov_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
fake_sh = oneview_models.ServerHardware() fake_sh = oneview_models.ServerHardware()
fake_sh.server_profile_uri = 'same/sp_applied' fake_sh.server_profile_uri = 'same/sp_applied'
ov_client.get_server_hardware_by_uuid.return_value = fake_sh oneview_client.get_server_hardware_by_uuid.return_value = fake_sh
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
driver_info = task.node.driver_info driver_info = task.node.driver_info
driver_info['applied_server_profile_uri'] = 'same/sp_applied' driver_info['applied_server_profile_uri'] = 'same/sp_applied'
task.node.driver_info = driver_info task.node.driver_info = driver_info
deploy_utils.prepare_cleaning(task) deploy_utils.prepare_cleaning(oneview_client, task)
self.assertFalse(ov_client.clone_template_and_apply.called) self.assertFalse(oneview_client.clone_template_and_apply.called)
def test_prepare_cleaning_node_is_in_use_by_oneview( def test_prepare_cleaning_node_is_in_use_by_oneview(
self, mock_get_ov_client self, mock_get_ov_client
@ -156,6 +162,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
""" """
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
fake_server_hardware = oneview_models.ServerHardware() fake_server_hardware = oneview_models.ServerHardware()
fake_server_hardware.server_profile_uri = "/any/sp_uri" fake_server_hardware.server_profile_uri = "/any/sp_uri"
oneview_client.get_server_hardware.return_value = fake_server_hardware oneview_client.get_server_hardware.return_value = fake_server_hardware
@ -168,6 +175,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
self.assertRaises( self.assertRaises(
exception.NodeCleaningFailure, exception.NodeCleaningFailure,
deploy_utils.prepare_cleaning, deploy_utils.prepare_cleaning,
oneview_client,
task task
) )
@ -176,7 +184,8 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
"""Checks if Server Profile was deleted and its uri removed """Checks if Server Profile was deleted and its uri removed
""" """
ov_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
driver_info = task.node.driver_info driver_info = task.node.driver_info
driver_info['applied_server_profile_uri'] = \ driver_info['applied_server_profile_uri'] = \
@ -184,16 +193,18 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
task.node.driver_info = driver_info task.node.driver_info = driver_info
self.assertIn('applied_server_profile_uri', task.node.driver_info) self.assertIn('applied_server_profile_uri', task.node.driver_info)
deploy_utils.tear_down_cleaning(task) deploy_utils.tear_down_cleaning(oneview_client, task)
self.assertNotIn('applied_server_profile_uri', self.assertNotIn('applied_server_profile_uri',
task.node.driver_info) task.node.driver_info)
self.assertTrue(ov_client.delete_server_profile.called) self.assertTrue(oneview_client.delete_server_profile.called)
# Tests for is_node_in_use_by_oneview # Tests for is_node_in_use_by_oneview
def test_is_node_in_use_by_oneview(self, mock_get_ov_client): def test_is_node_in_use_by_oneview(self, mock_get_ov_client):
"""Node has a Server Profile applied by a third party user. """Node has a Server Profile applied by a third party user.
""" """
oneview_client = mock_get_ov_client()
fake_server_hardware = oneview_models.ServerHardware() fake_server_hardware = oneview_models.ServerHardware()
fake_server_hardware.server_profile_uri = "/any/sp_uri" fake_server_hardware.server_profile_uri = "/any/sp_uri"
@ -202,7 +213,8 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
driver_info['dynamic_allocation'] = True driver_info['dynamic_allocation'] = True
task.node.driver_info = driver_info task.node.driver_info = driver_info
self.assertTrue( self.assertTrue(
deploy_utils.is_node_in_use_by_oneview(task.node) deploy_utils.is_node_in_use_by_oneview(oneview_client,
task.node)
) )
def test_is_node_in_use_by_oneview_no_server_profile( def test_is_node_in_use_by_oneview_no_server_profile(
@ -211,15 +223,15 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
"""Node has no Server Profile. """Node has no Server Profile.
""" """
oneview_client = mock_get_ov_client()
fake_sh = oneview_models.ServerHardware() fake_sh = oneview_models.ServerHardware()
fake_sh.server_profile_uri = None fake_sh.server_profile_uri = None
oneview_client.get_server_hardware_by_uuid.return_value = fake_sh
ov_client = mock_get_ov_client.return_value
ov_client.get_server_hardware_by_uuid.return_value = fake_sh
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertFalse( self.assertFalse(
deploy_utils.is_node_in_use_by_oneview(task.node) deploy_utils.is_node_in_use_by_oneview(oneview_client,
task.node)
) )
def test_is_node_in_use_by_oneview_same_server_profile_applied( def test_is_node_in_use_by_oneview_same_server_profile_applied(
@ -228,18 +240,19 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
"""Node's Server Profile uri is the same applied by ironic. """Node's Server Profile uri is the same applied by ironic.
""" """
oneview_client = mock_get_ov_client()
fake_sh = oneview_models.ServerHardware() fake_sh = oneview_models.ServerHardware()
fake_sh.server_profile_uri = 'same/applied_sp_uri/' fake_sh.server_profile_uri = 'same/applied_sp_uri/'
oneview_client.get_server_hardware_by_uuid.return_value = fake_sh
ov_client = mock_get_ov_client.return_value
ov_client.get_server_hardware_by_uuid.return_value = fake_sh
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
driver_info = task.node.driver_info driver_info = task.node.driver_info
driver_info['applied_server_profile_uri'] = 'same/applied_sp_uri/' driver_info['applied_server_profile_uri'] = 'same/applied_sp_uri/'
task.node.driver_info = driver_info task.node.driver_info = driver_info
self.assertFalse( self.assertFalse(
deploy_utils.is_node_in_use_by_oneview(task.node) deploy_utils.is_node_in_use_by_oneview(oneview_client,
task.node)
) )
# Tests for is_node_in_use_by_oneview # Tests for is_node_in_use_by_oneview
@ -259,7 +272,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
driver_info['applied_server_profile_uri'] = 'same/applied_sp_uri/' driver_info['applied_server_profile_uri'] = 'same/applied_sp_uri/'
task.node.driver_info = driver_info task.node.driver_info = driver_info
self.assertTrue( self.assertTrue(
deploy_utils.is_node_in_use_by_ironic(task.node) deploy_utils.is_node_in_use_by_ironic(ov_client, task.node)
) )
def test_is_node_in_use_by_ironic_no_server_profile( def test_is_node_in_use_by_ironic_no_server_profile(
@ -276,7 +289,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertFalse( self.assertFalse(
deploy_utils.is_node_in_use_by_ironic(task.node) deploy_utils.is_node_in_use_by_ironic(ov_client, task.node)
) )
# Tests for _add_applied_server_profile_uri_field # Tests for _add_applied_server_profile_uri_field
@ -321,17 +334,17 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
"""Checks if a Server Profile was created and its uri is in driver_info. """Checks if a Server Profile was created and its uri is in driver_info.
""" """
ov_client = mock_get_ov_client.return_value oneview_client = mock_get_ov_client()
fake_sh = oneview_models.ServerHardware() fake_sh = oneview_models.ServerHardware()
fake_sh.server_profile_uri = None fake_sh.server_profile_uri = None
ov_client.get_server_hardware_by_uuid.return_value = fake_sh oneview_client.get_server_hardware_by_uuid.return_value = fake_sh
mock_get_ov_client.return_value = ov_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
deploy_utils.allocate_server_hardware_to_ironic( deploy_utils.allocate_server_hardware_to_ironic(
task.node, 'serverProfileName' oneview_client, task.node, 'serverProfileName'
) )
self.assertTrue(ov_client.clone_template_and_apply.called) self.assertTrue(oneview_client.clone_template_and_apply.called)
self.assertIn('applied_server_profile_uri', task.node.driver_info) self.assertIn('applied_server_profile_uri', task.node.driver_info)
@mock.patch.object(objects.Node, 'save') @mock.patch.object(objects.Node, 'save')
@ -347,11 +360,11 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
the conductor should remove the value and apply a new server profile to the conductor should remove the value and apply a new server profile to
use the node. use the node.
""" """
ov_client = mock_get_ov_client.return_value oneview_client = mock_get_ov_client()
fake_sh = oneview_models.ServerHardware() fake_sh = oneview_models.ServerHardware()
fake_sh.server_profile_uri = None fake_sh.server_profile_uri = None
ov_client.get_server_hardware_by_uuid.return_value = fake_sh oneview_client.get_server_hardware_by_uuid.return_value = fake_sh
mock_get_ov_client.return_value = ov_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
driver_info = task.node.driver_info driver_info = task.node.driver_info
@ -359,7 +372,7 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
task.node.driver_info = driver_info task.node.driver_info = driver_info
deploy_utils.allocate_server_hardware_to_ironic( deploy_utils.allocate_server_hardware_to_ironic(
task.node, 'serverProfileName' oneview_client, task.node, 'serverProfileName'
) )
self.assertTrue(mock_delete_applied_sp.called) self.assertTrue(mock_delete_applied_sp.called)
@ -368,19 +381,22 @@ class OneViewDeployUtilsTestCase(db_base.DbTestCase):
def test_deallocate_server_hardware_from_ironic( def test_deallocate_server_hardware_from_ironic(
self, mock_node_save, mock_get_ov_client self, mock_node_save, mock_get_ov_client
): ):
ov_client = mock_get_ov_client.return_value oneview_client = mock_get_ov_client()
fake_sh = oneview_models.ServerHardware() fake_sh = oneview_models.ServerHardware()
fake_sh.server_profile_uri = 'any/applied_sp_uri/' fake_sh.server_profile_uri = 'any/applied_sp_uri/'
ov_client.get_server_hardware_by_uuid.return_value = fake_sh oneview_client.get_server_hardware_by_uuid.return_value = fake_sh
mock_get_ov_client.return_value = ov_client mock_get_ov_client.return_value = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
driver_info = task.node.driver_info driver_info = task.node.driver_info
driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/' driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/'
task.node.driver_info = driver_info task.node.driver_info = driver_info
deploy_utils.deallocate_server_hardware_from_ironic(task.node) deploy_utils.deallocate_server_hardware_from_ironic(
self.assertTrue(ov_client.delete_server_profile.called) oneview_client, task.node
)
self.assertTrue(oneview_client.delete_server_profile.called)
self.assertTrue( self.assertTrue(
'applied_server_profile_uri' not in task.node.driver_info 'applied_server_profile_uri' not in task.node.driver_info
) )

View File

@ -25,6 +25,8 @@ from ironic.tests.unit.db import utils as db_utils
from ironic.tests.unit.objects import utils as obj_utils from ironic.tests.unit.objects import utils as obj_utils
@mock.patch.object(
oneview_common, 'get_oneview_client', spec_set=True, autospec=True)
class AgentPXEOneViewInspectTestCase(db_base.DbTestCase): class AgentPXEOneViewInspectTestCase(db_base.DbTestCase):
def setUp(self): def setUp(self):
@ -37,15 +39,15 @@ class AgentPXEOneViewInspectTestCase(db_base.DbTestCase):
driver_info=db_utils.get_test_oneview_driver_info(), driver_info=db_utils.get_test_oneview_driver_info(),
) )
def test_get_properties(self): def test_get_properties(self, mock_get_ov_client):
expected = oneview_common.COMMON_PROPERTIES expected = deploy_utils.get_properties()
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task: shared=True) as task:
self.assertEqual(expected, task.driver.inspect.get_properties()) self.assertEqual(expected, task.driver.inspect.get_properties())
@mock.patch.object(oneview_common, 'verify_node_info', spec_set=True, @mock.patch.object(oneview_common, 'verify_node_info', spec_set=True,
autospec=True) autospec=True)
def test_validate(self, mock_verify_node_info): def test_validate(self, mock_verify_node_info, mock_get_ov_client):
self.config(enabled=False, group='inspector') self.config(enabled=False, group='inspector')
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
@ -53,13 +55,16 @@ class AgentPXEOneViewInspectTestCase(db_base.DbTestCase):
mock_verify_node_info.assert_called_once_with(task.node) mock_verify_node_info.assert_called_once_with(task.node)
@mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic') @mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic')
def test_inspect_hardware(self, mock_allocate_server_hardware_to_ironic): def test_inspect_hardware(self, mock_allocate_server_hardware_to_ironic,
mock_get_ov_client):
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
task.driver.inspect.inspect_hardware(task) task.driver.inspect.inspect_hardware(task)
self.assertTrue(mock_allocate_server_hardware_to_ironic.called) self.assertTrue(mock_allocate_server_hardware_to_ironic.called)
@mock.patch.object(
oneview_common, 'get_oneview_client', spec_set=True, autospec=True)
class ISCSIPXEOneViewInspectTestCase(db_base.DbTestCase): class ISCSIPXEOneViewInspectTestCase(db_base.DbTestCase):
def setUp(self): def setUp(self):
@ -72,15 +77,15 @@ class ISCSIPXEOneViewInspectTestCase(db_base.DbTestCase):
driver_info=db_utils.get_test_oneview_driver_info(), driver_info=db_utils.get_test_oneview_driver_info(),
) )
def test_get_properties(self): def test_get_properties(self, mock_get_ov_client):
expected = oneview_common.COMMON_PROPERTIES expected = deploy_utils.get_properties()
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task: shared=True) as task:
self.assertEqual(expected, task.driver.inspect.get_properties()) self.assertEqual(expected, task.driver.inspect.get_properties())
@mock.patch.object(oneview_common, 'verify_node_info', spec_set=True, @mock.patch.object(oneview_common, 'verify_node_info', spec_set=True,
autospec=True) autospec=True)
def test_validate(self, mock_verify_node_info): def test_validate(self, mock_verify_node_info, mock_get_ov_client):
self.config(enabled=False, group='inspector') self.config(enabled=False, group='inspector')
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
@ -88,7 +93,8 @@ class ISCSIPXEOneViewInspectTestCase(db_base.DbTestCase):
mock_verify_node_info.assert_called_once_with(task.node) mock_verify_node_info.assert_called_once_with(task.node)
@mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic') @mock.patch.object(deploy_utils, 'allocate_server_hardware_to_ironic')
def test_inspect_hardware(self, mock_allocate_server_hardware_to_ironic): def test_inspect_hardware(self, mock_allocate_server_hardware_to_ironic,
mock_get_ov_client):
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
task.driver.inspect.inspect_hardware(task) task.driver.inspect.inspect_hardware(task)

View File

@ -57,15 +57,23 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
@mock.patch.object(common, 'validate_oneview_resources_compatibility', @mock.patch.object(common, 'validate_oneview_resources_compatibility',
spect_set=True, autospec=True) spect_set=True, autospec=True)
def test_validate(self, mock_validate, mock_get_ov_client): def test_validate(self, mock_validate, mock_get_ov_client):
client = mock_get_ov_client.return_value oneview_client = mock_get_ov_client()
self.driver.management.oneview_client = oneview_client
fake_server_hardware = oneview_models.ServerHardware() fake_server_hardware = oneview_models.ServerHardware()
fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/' fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/'
client.get_server_hardware_by_uuid.return_value = fake_server_hardware
mock_get_ov_client.return_value = client oneview_client.get_server_hardware_by_uuid.return_value = (
fake_server_hardware
)
mock_get_ov_client.return_value = oneview_client
driver_info = self.node.driver_info driver_info = self.node.driver_info
driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/' driver_info['applied_server_profile_uri'] = 'any/applied_sp_uri/'
self.node.driver_info = driver_info self.node.driver_info = driver_info
self.node.save() self.node.save()
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
task.driver.management.validate(task) task.driver.management.validate(task)
self.assertTrue(mock_validate.called) self.assertTrue(mock_validate.called)
@ -75,15 +83,22 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
def test_validate_for_node_not_in_use_by_ironic(self, def test_validate_for_node_not_in_use_by_ironic(self,
mock_validate, mock_validate,
mock_get_ov_client): mock_get_ov_client):
client = mock_get_ov_client.return_value oneview_client = mock_get_ov_client()
fake_server_hardware = oneview_models.ServerHardware() fake_server_hardware = oneview_models.ServerHardware()
fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/' fake_server_hardware.server_profile_uri = 'any/applied_sp_uri/'
client.get_server_hardware_by_uuid.return_value = fake_server_hardware
mock_get_ov_client.return_value = client oneview_client.get_server_hardware_by_uuid.return_value = (
fake_server_hardware
)
mock_get_ov_client.return_value = oneview_client
driver_info = self.node.driver_info driver_info = self.node.driver_info
driver_info['applied_server_profile_uri'] = 'other/applied_sp_uri/' driver_info['applied_server_profile_uri'] = 'other/applied_sp_uri/'
self.node.driver_info = driver_info self.node.driver_info = driver_info
self.node.save() self.node.save()
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.InvalidParameterValue, self.assertRaises(exception.InvalidParameterValue,
task.driver.management.validate, task) task.driver.management.validate, task)
@ -113,6 +128,8 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
def test_set_boot_device(self, mock_get_ov_client): def test_set_boot_device(self, mock_get_ov_client):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
self.driver.management.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.management.set_boot_device(task, boot_devices.PXE) self.driver.management.set_boot_device(task, boot_devices.PXE)
oneview_client.set_boot_device.assert_called_once_with( oneview_client.set_boot_device.assert_called_once_with(
@ -122,6 +139,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
def test_set_boot_device_invalid_device(self, mock_get_ov_client): def test_set_boot_device_invalid_device(self, mock_get_ov_client):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
self.driver.management.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.InvalidParameterValue, self.assertRaises(exception.InvalidParameterValue,
self.driver.management.set_boot_device, self.driver.management.set_boot_device,
@ -131,9 +149,10 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
def test_set_boot_device_fail_to_get_server_profile(self, def test_set_boot_device_fail_to_get_server_profile(self,
mock_get_ov_client): mock_get_ov_client):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.get_server_profile_from_hardware.side_effect = \ oneview_client.get_server_profile_from_hardware.side_effect = \
oneview_exceptions.OneViewException() oneview_exceptions.OneViewException()
self.driver.management.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.OneViewError, self.assertRaises(exception.OneViewError,
self.driver.management.set_boot_device, self.driver.management.set_boot_device,
@ -143,6 +162,8 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
def test_set_boot_device_without_server_profile(self, mock_get_ov_client): def test_set_boot_device_without_server_profile(self, mock_get_ov_client):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.get_server_profile_from_hardware.return_value = False oneview_client.get_server_profile_from_hardware.return_value = False
self.driver.management.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
expected_msg = ( expected_msg = (
'A Server Profile is not associated with node %s.' 'A Server Profile is not associated with node %s.'
@ -168,6 +189,7 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
def test_get_boot_device(self, mock_get_ov_client): def test_get_boot_device(self, mock_get_ov_client):
device_mapping = management.BOOT_DEVICE_MAPPING_TO_OV device_mapping = management.BOOT_DEVICE_MAPPING_TO_OV
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
self.driver.management.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
# For each known device on OneView, Ironic should return its # For each known device on OneView, Ironic should return its
@ -186,6 +208,8 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.get_boot_order.side_effect = \ oneview_client.get_boot_order.side_effect = \
oneview_exceptions.OneViewException() oneview_exceptions.OneViewException()
self.driver.management.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.OneViewError, self.assertRaises(exception.OneViewError,
self.driver.management.get_boot_device, self.driver.management.get_boot_device,
@ -196,6 +220,8 @@ class OneViewManagementDriverTestCase(db_base.DbTestCase):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.get_boot_order.return_value = ["spam", oneview_client.get_boot_order.return_value = ["spam",
"bacon"] "bacon"]
self.driver.management.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises( self.assertRaises(
exception.InvalidParameterValue, exception.InvalidParameterValue,

View File

@ -89,6 +89,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
def test_get_power_state(self, mock_get_ov_client): def test_get_power_state(self, mock_get_ov_client):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.get_node_power_state.return_value = POWER_ON oneview_client.get_node_power_state.return_value = POWER_ON
self.driver.power.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.power.get_power_state(task) self.driver.power.get_power_state(task)
oneview_client.get_node_power_state.assert_called_once_with(self.info) oneview_client.get_node_power_state.assert_called_once_with(self.info)
@ -97,6 +99,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.get_node_power_state.side_effect = \ oneview_client.get_node_power_state.side_effect = \
oneview_exceptions.OneViewException() oneview_exceptions.OneViewException()
self.driver.power.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises( self.assertRaises(
exception.OneViewError, exception.OneViewError,
@ -107,6 +111,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
def test_set_power_on(self, mock_get_ov_client): def test_set_power_on(self, mock_get_ov_client):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.power_on.return_value = POWER_ON oneview_client.power_on.return_value = POWER_ON
self.driver.power.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.power.set_power_state(task, states.POWER_ON) self.driver.power.set_power_state(task, states.POWER_ON)
oneview_client.power_on.assert_called_once_with(self.info) oneview_client.power_on.assert_called_once_with(self.info)
@ -114,6 +120,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
def test_set_power_off(self, mock_get_ov_client): def test_set_power_off(self, mock_get_ov_client):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.power_off.return_value = POWER_OFF oneview_client.power_off.return_value = POWER_OFF
self.driver.power.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.power.set_power_state(task, states.POWER_OFF) self.driver.power.set_power_state(task, states.POWER_OFF)
oneview_client.power_off.assert_called_once_with(self.info) oneview_client.power_off.assert_called_once_with(self.info)
@ -122,6 +130,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.power_on.side_effect = \ oneview_client.power_on.side_effect = \
oneview_exceptions.OneViewException() oneview_exceptions.OneViewException()
self.driver.power.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.OneViewError, self.assertRaises(exception.OneViewError,
self.driver.power.set_power_state, task, self.driver.power.set_power_state, task,
@ -132,6 +142,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.power_off.side_effect = \ oneview_client.power_off.side_effect = \
oneview_exceptions.OneViewException() oneview_exceptions.OneViewException()
self.driver.power.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.OneViewError, self.assertRaises(exception.OneViewError,
self.driver.power.set_power_state, task, self.driver.power.set_power_state, task,
@ -148,6 +160,8 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.power_off.return_value = POWER_OFF oneview_client.power_off.return_value = POWER_OFF
oneview_client.power_on.return_value = POWER_ON oneview_client.power_on.return_value = POWER_ON
self.driver.power.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.power.set_power_state(task, states.REBOOT) self.driver.power.set_power_state(task, states.REBOOT)
oneview_client.power_off.assert_called_once_with(self.info) oneview_client.power_off.assert_called_once_with(self.info)
@ -155,9 +169,9 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
def test_reboot(self, mock_get_ov_client): def test_reboot(self, mock_get_ov_client):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.power_off.return_value = POWER_OFF oneview_client.power_off.return_value = POWER_OFF
oneview_client.power_on.return_value = POWER_ON oneview_client.power_on.return_value = POWER_ON
self.driver.power.oneview_client = oneview_client
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.power.reboot(task) self.driver.power.reboot(task)
@ -169,6 +183,7 @@ class OneViewPowerDriverTestCase(db_base.DbTestCase):
oneview_client = mock_get_ov_client() oneview_client = mock_get_ov_client()
oneview_client.power_off.side_effect = \ oneview_client.power_off.side_effect = \
oneview_exceptions.OneViewException() oneview_exceptions.OneViewException()
self.driver.power.oneview_client = oneview_client
with task_manager.acquire(self.context, with task_manager.acquire(self.context,
self.node.uuid) as task: self.node.uuid) as task:

View File

@ -0,0 +1,4 @@
---
fixes:
- Fixes a bug where OneView drivers creates a new instance of the
oneview_client for each request made.