move mistral base action dependency to mistral_lib
mistral_lib base TripleoAction has a context in the run method signature. These changes remove the mistral.context and make use of the one provide by the default executor Change-Id: Ib1a5aa8d5735b05f5308dc943ac088b5eeeec253
This commit is contained in:
@@ -15,6 +15,7 @@ python-glanceclient>=2.5.0 # Apache-2.0
|
||||
python-ironicclient>=1.11.0 # Apache-2.0
|
||||
six>=1.9.0 # MIT
|
||||
mistral!=2015.1.0,>=3.0.0 # Apache-2.0
|
||||
mistral-lib>=0.1.0 # Apache-2.0
|
||||
python-ironic-inspector-client>=1.5.0 # Apache-2.0
|
||||
Jinja2!=2.9.0,!=2.9.1,!=2.9.2,!=2.9.3,!=2.9.4,>=2.8 # BSD License (3 clause)
|
||||
python-novaclient>=7.1.0 # Apache-2.0
|
||||
|
@@ -48,15 +48,15 @@ class RegisterOrUpdateNodes(base.TripleOAction):
|
||||
self.kernel_name = kernel_name
|
||||
self.ramdisk_name = ramdisk_name
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
for node in self.nodes_json:
|
||||
caps = node.get('capabilities', {})
|
||||
caps = nodes.capabilities_to_dict(caps)
|
||||
caps.setdefault('boot_option', self.instance_boot_option)
|
||||
node['capabilities'] = nodes.dict_to_capabilities(caps)
|
||||
|
||||
baremetal_client = self.get_baremetal_client()
|
||||
image_client = self.get_image_client()
|
||||
baremetal_client = self.get_baremetal_client(context)
|
||||
image_client = self.get_image_client(context)
|
||||
|
||||
try:
|
||||
return nodes.register_all_nodes(
|
||||
@@ -81,7 +81,7 @@ class ValidateNodes(base.TripleOAction):
|
||||
super(ValidateNodes, self).__init__()
|
||||
self.nodes_json = nodes_json
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
try:
|
||||
nodes.validate_nodes(self.nodes_json)
|
||||
except exception.InvalidNode as err:
|
||||
@@ -110,9 +110,9 @@ class ConfigureBootAction(base.TripleOAction):
|
||||
self.ramdisk_name = ramdisk_name
|
||||
self.instance_boot_option = instance_boot_option
|
||||
|
||||
def run(self):
|
||||
baremetal_client = self.get_baremetal_client()
|
||||
image_client = self.get_image_client()
|
||||
def run(self, context):
|
||||
baremetal_client = self.get_baremetal_client(context)
|
||||
image_client = self.get_image_client(context)
|
||||
|
||||
try:
|
||||
image_ids = {'kernel': None, 'ramdisk': None}
|
||||
@@ -176,17 +176,21 @@ class ConfigureRootDeviceAction(base.TripleOAction):
|
||||
self.minimum_size = minimum_size
|
||||
self.overwrite = overwrite
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
if not self.root_device:
|
||||
return
|
||||
|
||||
baremetal_client = self.get_baremetal_client()
|
||||
baremetal_client = self.get_baremetal_client(context)
|
||||
node = baremetal_client.node.get(self.node_uuid)
|
||||
self._apply_root_device_strategy(
|
||||
node, self.root_device, self.minimum_size, self.overwrite)
|
||||
node,
|
||||
self.root_device,
|
||||
self.minimum_size,
|
||||
self.overwrite,
|
||||
context=context)
|
||||
|
||||
def _apply_root_device_strategy(self, node, strategy, minimum_size,
|
||||
overwrite=False):
|
||||
overwrite=False, context=None):
|
||||
if node.properties.get('root_device') and not overwrite:
|
||||
# This is a correct situation, we still want to allow people to
|
||||
# fine-tune the root device setting for a subset of nodes.
|
||||
@@ -200,7 +204,7 @@ class ConfigureRootDeviceAction(base.TripleOAction):
|
||||
node.uuid)
|
||||
return
|
||||
|
||||
inspector_client = self.get_baremetal_introspection_client()
|
||||
inspector_client = self.get_baremetal_introspection_client(context)
|
||||
try:
|
||||
data = inspector_client.get_data(node.uuid)
|
||||
except ironic_inspector_client.ClientError:
|
||||
@@ -266,7 +270,7 @@ class ConfigureRootDeviceAction(base.TripleOAction):
|
||||
# This -1 is what we always do to account for partitioning
|
||||
new_size -= 1
|
||||
|
||||
bm_client = self.get_baremetal_client()
|
||||
bm_client = self.get_baremetal_client(context)
|
||||
bm_client.node.update(
|
||||
node.uuid,
|
||||
[{'op': 'add', 'path': '/properties/root_device', 'value': hint},
|
||||
@@ -294,8 +298,8 @@ class UpdateNodeCapability(base.TripleOAction):
|
||||
self.capability = capability
|
||||
self.value = value
|
||||
|
||||
def run(self):
|
||||
baremetal_client = self.get_baremetal_client()
|
||||
def run(self, context):
|
||||
baremetal_client = self.get_baremetal_client(context)
|
||||
|
||||
try:
|
||||
return nodes.update_node_capability(
|
||||
@@ -318,7 +322,7 @@ class CellV2DiscoverHostsAction(base.TripleOAction):
|
||||
|
||||
"""
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
try:
|
||||
result = nodes.run_nova_cell_v2_discovery()
|
||||
LOG.info(
|
||||
@@ -340,7 +344,7 @@ class GetProfileAction(base.TripleOAction):
|
||||
super(GetProfileAction, self).__init__()
|
||||
self.node = node
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
result = {}
|
||||
result['profile'] = nodes.get_node_profile(self.node)
|
||||
result['uuid'] = self.node.get('uuid')
|
||||
|
@@ -19,9 +19,8 @@ from glanceclient.v2 import client as glanceclient
|
||||
from heatclient.v1 import client as heatclient
|
||||
import ironic_inspector_client
|
||||
from ironicclient.v1 import client as ironicclient
|
||||
from mistral.actions import base
|
||||
from mistral import context
|
||||
from mistral.utils.openstack import keystone as keystone_utils
|
||||
from mistral_lib import actions
|
||||
from mistralclient.api import client as mistral_client
|
||||
from novaclient.client import Client as nova_client
|
||||
from swiftclient import client as swift_client
|
||||
@@ -29,18 +28,17 @@ from swiftclient import exceptions as swiftexceptions
|
||||
from tripleo_common import constants
|
||||
|
||||
|
||||
class TripleOAction(base.Action):
|
||||
class TripleOAction(actions.Action):
|
||||
|
||||
def __init__(self):
|
||||
super(TripleOAction, self).__init__()
|
||||
|
||||
def get_object_client(self):
|
||||
ctx = context.ctx()
|
||||
def get_object_client(self, context):
|
||||
obj_ep = keystone_utils.get_endpoint_for_project('swift')
|
||||
|
||||
kwargs = {
|
||||
'preauthurl': obj_ep.url % {'tenant_id': ctx.project_id},
|
||||
'preauthtoken': ctx.auth_token,
|
||||
'preauthurl': obj_ep.url % {'tenant_id': context.project_id},
|
||||
'preauthtoken': context.auth_token,
|
||||
'retries': 10,
|
||||
'starting_backoff': 3,
|
||||
'max_backoff': 120
|
||||
@@ -48,9 +46,7 @@ class TripleOAction(base.Action):
|
||||
|
||||
return swift_client.Connection(**kwargs)
|
||||
|
||||
def get_baremetal_client(self):
|
||||
ctx = context.ctx()
|
||||
|
||||
def get_baremetal_client(self, context):
|
||||
ironic_endpoint = keystone_utils.get_endpoint_for_project('ironic')
|
||||
|
||||
# FIXME(lucasagomes): Use ironicclient.get_client() instead
|
||||
@@ -59,7 +55,7 @@ class TripleOAction(base.Action):
|
||||
# prefered way
|
||||
return ironicclient.Client(
|
||||
ironic_endpoint.url,
|
||||
token=ctx.auth_token,
|
||||
token=context.auth_token,
|
||||
region_name=ironic_endpoint.region,
|
||||
os_ironic_api_version='1.15',
|
||||
# FIXME(lucasagomes):Paramtetize max_retries and
|
||||
@@ -71,9 +67,7 @@ class TripleOAction(base.Action):
|
||||
retry_interval=5,
|
||||
)
|
||||
|
||||
def get_baremetal_introspection_client(self):
|
||||
ctx = context.ctx()
|
||||
|
||||
def get_baremetal_introspection_client(self, context):
|
||||
bmi_endpoint = keystone_utils.get_endpoint_for_project(
|
||||
'ironic-inspector')
|
||||
|
||||
@@ -81,46 +75,41 @@ class TripleOAction(base.Action):
|
||||
api_version='1.2',
|
||||
inspector_url=bmi_endpoint.url,
|
||||
region_name=bmi_endpoint.region,
|
||||
auth_token=ctx.auth_token
|
||||
auth_token=context.auth_token
|
||||
)
|
||||
|
||||
def get_image_client(self):
|
||||
ctx = context.ctx()
|
||||
|
||||
def get_image_client(self, context):
|
||||
glance_endpoint = keystone_utils.get_endpoint_for_project('glance')
|
||||
return glanceclient.Client(
|
||||
glance_endpoint.url,
|
||||
token=ctx.auth_token,
|
||||
token=context.auth_token,
|
||||
region_name=glance_endpoint.region
|
||||
)
|
||||
|
||||
def get_orchestration_client(self):
|
||||
ctx = context.ctx()
|
||||
def get_orchestration_client(self, context):
|
||||
heat_endpoint = keystone_utils.get_endpoint_for_project('heat')
|
||||
|
||||
endpoint_url = keystone_utils.format_url(
|
||||
heat_endpoint.url,
|
||||
{'tenant_id': ctx.project_id}
|
||||
{'tenant_id': context.project_id}
|
||||
)
|
||||
|
||||
return heatclient.Client(
|
||||
endpoint_url,
|
||||
region_name=heat_endpoint.region,
|
||||
token=ctx.auth_token,
|
||||
username=ctx.user_name
|
||||
token=context.auth_token,
|
||||
username=context.user_name
|
||||
)
|
||||
|
||||
def get_workflow_client(self):
|
||||
ctx = context.ctx()
|
||||
def get_workflow_client(self, context):
|
||||
mistral_endpoint = keystone_utils.get_endpoint_for_project('mistral')
|
||||
|
||||
mc = mistral_client.client(auth_token=ctx.auth_token,
|
||||
mc = mistral_client.client(auth_token=context.auth_token,
|
||||
mistral_url=mistral_endpoint.url)
|
||||
|
||||
return mc
|
||||
|
||||
def get_compute_client(self):
|
||||
ctx = context.ctx()
|
||||
def get_compute_client(self, context):
|
||||
keystone_endpoint = keystone_utils.get_endpoint_for_project('keystone')
|
||||
nova_endpoint = keystone_utils.get_endpoint_for_project('nova')
|
||||
|
||||
@@ -129,16 +118,16 @@ class TripleOAction(base.Action):
|
||||
username=None,
|
||||
api_key=None,
|
||||
service_type='compute',
|
||||
auth_token=ctx.auth_token,
|
||||
tenant_id=ctx.project_id,
|
||||
auth_token=context.auth_token,
|
||||
tenant_id=context.project_id,
|
||||
region_name=keystone_endpoint.region,
|
||||
auth_url=keystone_endpoint.url,
|
||||
insecure=ctx.insecure
|
||||
insecure=context.insecure
|
||||
)
|
||||
|
||||
client.client.management_url = keystone_utils.format_url(
|
||||
nova_endpoint.url,
|
||||
{'tenant_id': ctx.project_id}
|
||||
{'tenant_id': context.project_id}
|
||||
)
|
||||
|
||||
return client
|
||||
@@ -146,14 +135,14 @@ class TripleOAction(base.Action):
|
||||
def _cache_key(self, plan_name, key_name):
|
||||
return "__cache_{}_{}".format(plan_name, key_name)
|
||||
|
||||
def cache_get(self, plan_name, key):
|
||||
def cache_get(self, context, plan_name, key):
|
||||
"""Retrieves the stored objects
|
||||
|
||||
Returns None if there are any issues or no objects found
|
||||
|
||||
"""
|
||||
|
||||
swift_client = self.get_object_client()
|
||||
swift_client = self.get_object_client(context)
|
||||
try:
|
||||
headers, body = swift_client.get_object(
|
||||
constants.TRIPLEO_CACHE_CONTAINER,
|
||||
@@ -166,10 +155,10 @@ class TripleOAction(base.Action):
|
||||
pass
|
||||
except ValueError:
|
||||
# the stored json is invalid. Deleting
|
||||
self.cache_delete(plan_name, key)
|
||||
self.cache_delete(context, plan_name, key)
|
||||
return
|
||||
|
||||
def cache_set(self, plan_name, key, contents):
|
||||
def cache_set(self, context, plan_name, key, contents):
|
||||
"""Stores an object
|
||||
|
||||
Allows the storage of jsonable objects except for None
|
||||
@@ -177,9 +166,9 @@ class TripleOAction(base.Action):
|
||||
|
||||
"""
|
||||
|
||||
swift_client = self.get_object_client()
|
||||
swift_client = self.get_object_client(context)
|
||||
if contents is None:
|
||||
self.cache_delete(plan_name, key)
|
||||
self.cache_delete(context, plan_name, key)
|
||||
return
|
||||
|
||||
try:
|
||||
@@ -192,8 +181,8 @@ class TripleOAction(base.Action):
|
||||
self._cache_key(plan_name, key),
|
||||
zlib.compress(json.dumps(contents).encode()))
|
||||
|
||||
def cache_delete(self, plan_name, key):
|
||||
swift_client = self.get_object_client()
|
||||
def cache_delete(self, context, plan_name, key):
|
||||
swift_client = self.get_object_client(context)
|
||||
try:
|
||||
swift_client.delete_object(
|
||||
constants.TRIPLEO_CACHE_CONTAINER,
|
||||
|
@@ -65,10 +65,10 @@ class OrchestrationDeployAction(base.TripleOAction):
|
||||
signal_id=swift_url
|
||||
)
|
||||
|
||||
def _wait_for_data(self, container_name, object_name):
|
||||
def _wait_for_data(self, container_name, object_name, context):
|
||||
body = None
|
||||
count_check = 0
|
||||
swift_client = self.get_object_client()
|
||||
swift_client = self.get_object_client(context)
|
||||
while not body:
|
||||
headers, body = swift_client.get_object(
|
||||
container_name,
|
||||
@@ -81,9 +81,9 @@ class OrchestrationDeployAction(base.TripleOAction):
|
||||
|
||||
return body
|
||||
|
||||
def run(self):
|
||||
heat = self.get_orchestration_client()
|
||||
swift_client = self.get_object_client()
|
||||
def run(self, context):
|
||||
heat = self.get_orchestration_client(context)
|
||||
swift_client = self.get_object_client(context)
|
||||
|
||||
swift_url = deployment_utils.create_temp_url(swift_client,
|
||||
self.name,
|
||||
@@ -102,7 +102,7 @@ class OrchestrationDeployAction(base.TripleOAction):
|
||||
status='IN_PROGRESS'
|
||||
)
|
||||
|
||||
body = self._wait_for_data(container_name, object_name)
|
||||
body = self._wait_for_data(container_name, object_name, context)
|
||||
|
||||
# cleanup
|
||||
try:
|
||||
@@ -134,9 +134,9 @@ class DeployStackAction(templates.ProcessTemplatesAction):
|
||||
self.timeout_mins = timeout
|
||||
self.skip_deploy_identifier = skip_deploy_identifier
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
# check to see if the stack exists
|
||||
heat = self.get_orchestration_client()
|
||||
heat = self.get_orchestration_client(context)
|
||||
try:
|
||||
stack = heat.stacks.get(self.container)
|
||||
except heat_exc.HTTPNotFound:
|
||||
@@ -145,7 +145,7 @@ class DeployStackAction(templates.ProcessTemplatesAction):
|
||||
stack_is_new = stack is None
|
||||
|
||||
# update StackAction, DeployIdentifier and UpdateIdentifier
|
||||
wc = self.get_workflow_client()
|
||||
wc = self.get_workflow_client(context)
|
||||
wf_env = wc.environments.get(self.container)
|
||||
|
||||
parameters = dict()
|
||||
@@ -165,7 +165,7 @@ class DeployStackAction(templates.ProcessTemplatesAction):
|
||||
wc.environments.update(**env_kwargs)
|
||||
|
||||
# process all plan files and create or update a stack
|
||||
processed_data = super(DeployStackAction, self).run()
|
||||
processed_data = super(DeployStackAction, self).run(context)
|
||||
|
||||
# If we receive a 'Result' instance it is because the parent action
|
||||
# had an error.
|
||||
@@ -176,7 +176,7 @@ class DeployStackAction(templates.ProcessTemplatesAction):
|
||||
stack_args['timeout_mins'] = self.timeout_mins
|
||||
|
||||
if stack_is_new:
|
||||
swift_client = self.get_object_client()
|
||||
swift_client = self.get_object_client(context)
|
||||
try:
|
||||
swift_client.copy_object(
|
||||
"%s-swift-rings" % self.container, "swift-rings.tar.gz",
|
||||
@@ -209,9 +209,9 @@ class OvercloudRcAction(base.TripleOAction):
|
||||
self.container = container
|
||||
self.no_proxy = no_proxy
|
||||
|
||||
def run(self):
|
||||
orchestration_client = self.get_orchestration_client()
|
||||
workflow_client = self.get_workflow_client()
|
||||
def run(self, context):
|
||||
orchestration_client = self.get_orchestration_client(context)
|
||||
workflow_client = self.get_workflow_client(context)
|
||||
|
||||
try:
|
||||
stack = orchestration_client.stacks.get(self.container)
|
||||
|
@@ -38,9 +38,9 @@ class GetCapabilitiesAction(base.TripleOAction):
|
||||
super(GetCapabilitiesAction, self).__init__()
|
||||
self.container = container
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
try:
|
||||
swift_client = self.get_object_client()
|
||||
swift_client = self.get_object_client(context)
|
||||
map_file = swift_client.get_object(
|
||||
self.container, 'capabilities-map.yaml')
|
||||
capabilities = yaml.safe_load(map_file[1])
|
||||
@@ -58,7 +58,7 @@ class GetCapabilitiesAction(base.TripleOAction):
|
||||
LOG.exception(err_msg)
|
||||
return mistral_workflow_utils.Result(error=err_msg)
|
||||
try:
|
||||
mistral_client = self.get_workflow_client()
|
||||
mistral_client = self.get_workflow_client(context)
|
||||
mistral_env = mistral_client.environments.get(self.container)
|
||||
except Exception as mistral_err:
|
||||
err_msg = ("Error retrieving mistral "
|
||||
@@ -162,8 +162,8 @@ class UpdateCapabilitiesAction(base.TripleOAction):
|
||||
self.environments = environments
|
||||
self.purge_missing = purge_missing
|
||||
|
||||
def run(self):
|
||||
mistral_client = self.get_workflow_client()
|
||||
def run(self, context):
|
||||
mistral_client = self.get_workflow_client(context)
|
||||
mistral_env = None
|
||||
try:
|
||||
mistral_env = mistral_client.environments.get(self.container)
|
||||
@@ -192,7 +192,7 @@ class UpdateCapabilitiesAction(base.TripleOAction):
|
||||
if env.get('path') not in self.environments:
|
||||
mistral_env.variables['environments'].remove(env)
|
||||
|
||||
self.cache_delete(self.container, "tripleo.parameters.get")
|
||||
self.cache_delete(context, self.container, "tripleo.parameters.get")
|
||||
|
||||
env_kwargs = {
|
||||
'name': mistral_env.name,
|
||||
|
@@ -33,9 +33,9 @@ class ClearBreakpointsAction(base.TripleOAction):
|
||||
self.stack_id = stack_id
|
||||
self.refs = refs
|
||||
|
||||
def run(self):
|
||||
heat = self.get_orchestration_client()
|
||||
nova = self.get_compute_client()
|
||||
def run(self, context):
|
||||
heat = self.get_orchestration_client(context)
|
||||
nova = self.get_compute_client(context)
|
||||
update_manager = PackageUpdateManager(
|
||||
heat, nova, self.stack_id, stack_fields={})
|
||||
update_manager.clear_breakpoints(self.refs)
|
||||
@@ -47,9 +47,9 @@ class UpdateStackAction(templates.ProcessTemplatesAction):
|
||||
super(UpdateStackAction, self).__init__(container)
|
||||
self.timeout_mins = timeout
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
# get the stack. Error if doesn't exist
|
||||
heat = self.get_orchestration_client()
|
||||
heat = self.get_orchestration_client(context)
|
||||
try:
|
||||
stack = heat.stacks.get(self.container)
|
||||
except heat_exc.HTTPNotFound:
|
||||
@@ -63,7 +63,7 @@ class UpdateStackAction(templates.ProcessTemplatesAction):
|
||||
parameters['UpdateIdentifier'] = timestamp
|
||||
parameters['StackAction'] = 'UPDATE'
|
||||
|
||||
wc = self.get_workflow_client()
|
||||
wc = self.get_workflow_client(context)
|
||||
try:
|
||||
wf_env = wc.environments.get(self.container)
|
||||
except Exception:
|
||||
@@ -83,7 +83,7 @@ class UpdateStackAction(templates.ProcessTemplatesAction):
|
||||
wc.environments.update(**env_kwargs)
|
||||
|
||||
# process all plan files and create or update a stack
|
||||
processed_data = super(UpdateStackAction, self).run()
|
||||
processed_data = super(UpdateStackAction, self).run(context)
|
||||
|
||||
# If we receive a 'Result' instance it is because the parent action
|
||||
# had an error.
|
||||
|
@@ -45,14 +45,16 @@ LOG = logging.getLogger(__name__)
|
||||
class GetParametersAction(templates.ProcessTemplatesAction):
|
||||
"""Gets list of available heat parameters."""
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
|
||||
cached = self.cache_get(self.container, "tripleo.parameters.get")
|
||||
cached = self.cache_get(context,
|
||||
self.container,
|
||||
"tripleo.parameters.get")
|
||||
|
||||
if cached is not None:
|
||||
return cached
|
||||
|
||||
processed_data = super(GetParametersAction, self).run()
|
||||
processed_data = super(GetParametersAction, self).run(context)
|
||||
|
||||
# If we receive a 'Result' instance it is because the parent action
|
||||
# had an error.
|
||||
@@ -62,9 +64,9 @@ class GetParametersAction(templates.ProcessTemplatesAction):
|
||||
processed_data['show_nested'] = True
|
||||
|
||||
# respect previously user set param values
|
||||
wc = self.get_workflow_client()
|
||||
wc = self.get_workflow_client(context)
|
||||
wf_env = wc.environments.get(self.container)
|
||||
orc = self.get_orchestration_client()
|
||||
orc = self.get_orchestration_client(context)
|
||||
|
||||
params = wf_env.variables.get('parameter_defaults')
|
||||
|
||||
@@ -78,7 +80,10 @@ class GetParametersAction(templates.ProcessTemplatesAction):
|
||||
'heat_resource_tree': orc.stacks.validate(**fields),
|
||||
'mistral_environment_parameters': params,
|
||||
}
|
||||
self.cache_set(self.container, "tripleo.parameters.get", result)
|
||||
self.cache_set(context,
|
||||
self.container,
|
||||
"tripleo.parameters.get",
|
||||
result)
|
||||
return result
|
||||
|
||||
|
||||
@@ -89,8 +94,8 @@ class ResetParametersAction(base.TripleOAction):
|
||||
super(ResetParametersAction, self).__init__()
|
||||
self.container = container
|
||||
|
||||
def run(self):
|
||||
wc = self.get_workflow_client()
|
||||
def run(self, context):
|
||||
wc = self.get_workflow_client(context)
|
||||
wf_env = wc.environments.get(self.container)
|
||||
|
||||
if 'parameter_defaults' in wf_env.variables:
|
||||
@@ -101,7 +106,9 @@ class ResetParametersAction(base.TripleOAction):
|
||||
'variables': wf_env.variables
|
||||
}
|
||||
wc.environments.update(**env_kwargs)
|
||||
self.cache_delete(self.container, "tripleo.parameters.get")
|
||||
self.cache_delete(context,
|
||||
self.container,
|
||||
"tripleo.parameters.get")
|
||||
return wf_env
|
||||
|
||||
|
||||
@@ -114,8 +121,8 @@ class UpdateParametersAction(base.TripleOAction):
|
||||
self.container = container
|
||||
self.parameters = parameters
|
||||
|
||||
def run(self):
|
||||
wc = self.get_workflow_client()
|
||||
def run(self, context):
|
||||
wc = self.get_workflow_client(context)
|
||||
wf_env = wc.environments.get(self.container)
|
||||
if 'parameter_defaults' not in wf_env.variables:
|
||||
wf_env.variables['parameter_defaults'] = {}
|
||||
@@ -125,7 +132,9 @@ class UpdateParametersAction(base.TripleOAction):
|
||||
'variables': wf_env.variables
|
||||
}
|
||||
wc.environments.update(**env_kwargs)
|
||||
self.cache_delete(self.container, "tripleo.parameters.get")
|
||||
self.cache_delete(context,
|
||||
self.container,
|
||||
"tripleo.parameters.get")
|
||||
return wf_env
|
||||
|
||||
|
||||
@@ -137,12 +146,12 @@ class UpdateRoleParametersAction(UpdateParametersAction):
|
||||
container=container)
|
||||
self.role = role
|
||||
|
||||
def run(self):
|
||||
baremetal_client = self.get_baremetal_client()
|
||||
compute_client = self.get_compute_client()
|
||||
def run(self, context):
|
||||
baremetal_client = self.get_baremetal_client(context)
|
||||
compute_client = self.get_compute_client(context)
|
||||
self.parameters = parameters.set_count_and_flavor_params(
|
||||
self.role, baremetal_client, compute_client)
|
||||
return super(UpdateRoleParametersAction, self).run()
|
||||
return super(UpdateRoleParametersAction, self).run(context)
|
||||
|
||||
|
||||
class GeneratePasswordsAction(base.TripleOAction):
|
||||
@@ -157,10 +166,10 @@ class GeneratePasswordsAction(base.TripleOAction):
|
||||
super(GeneratePasswordsAction, self).__init__()
|
||||
self.container = container
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
|
||||
orchestration = self.get_orchestration_client()
|
||||
wc = self.get_workflow_client()
|
||||
orchestration = self.get_orchestration_client(context)
|
||||
wc = self.get_workflow_client(context)
|
||||
try:
|
||||
wf_env = wc.environments.get(self.container)
|
||||
except Exception:
|
||||
@@ -192,7 +201,9 @@ class GeneratePasswordsAction(base.TripleOAction):
|
||||
}
|
||||
|
||||
wc.environments.update(**env_kwargs)
|
||||
self.cache_delete(self.container, "tripleo.parameters.get")
|
||||
self.cache_delete(context,
|
||||
self.container,
|
||||
"tripleo.parameters.get")
|
||||
|
||||
return wf_env.variables['passwords']
|
||||
|
||||
@@ -209,8 +220,8 @@ class GetPasswordsAction(base.TripleOAction):
|
||||
super(GetPasswordsAction, self).__init__()
|
||||
self.container = container
|
||||
|
||||
def run(self):
|
||||
wc = self.get_workflow_client()
|
||||
def run(self, context):
|
||||
wc = self.get_workflow_client(context)
|
||||
try:
|
||||
wf_env = wc.environments.get(self.container)
|
||||
except Exception:
|
||||
@@ -250,10 +261,10 @@ class GenerateFencingParametersAction(base.TripleOAction):
|
||||
self.ipmi_cipher = ipmi_cipher
|
||||
self.ipmi_lanplus = ipmi_lanplus
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
"""Returns the parameters for fencing controller nodes"""
|
||||
hostmap = nodes.generate_hostmap(self.get_baremetal_client(),
|
||||
self.get_compute_client())
|
||||
hostmap = nodes.generate_hostmap(self.get_baremetal_client(context),
|
||||
self.get_compute_client(context))
|
||||
fence_params = {"EnableFencing": True, "FencingConfig": {}}
|
||||
devices = []
|
||||
|
||||
@@ -369,9 +380,9 @@ class GetFlattenedParametersAction(GetParametersAction):
|
||||
flattened['resources'][key] = value
|
||||
return {key: value}
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
# process all plan files and create or update a stack
|
||||
processed_data = super(GetFlattenedParametersAction, self).run()
|
||||
processed_data = super(GetFlattenedParametersAction, self).run(context)
|
||||
|
||||
# If we receive a 'Result' instance it is because the parent action
|
||||
# had an error.
|
||||
|
@@ -104,8 +104,8 @@ class CreateContainerAction(base.TripleOAction):
|
||||
super(CreateContainerAction, self).__init__()
|
||||
self.container = container
|
||||
|
||||
def run(self):
|
||||
oc = self.get_object_client()
|
||||
def run(self, context):
|
||||
oc = self.get_object_client(context)
|
||||
|
||||
# checks to see if a container has a valid name
|
||||
if not pattern_validator(constants.PLAN_NAME_PATTERN, self.container):
|
||||
@@ -135,9 +135,9 @@ class CreatePlanAction(base.TripleOAction, PlanEnvMixin):
|
||||
super(CreatePlanAction, self).__init__()
|
||||
self.container = container
|
||||
|
||||
def run(self):
|
||||
swift = self.get_object_client()
|
||||
mistral = self.get_workflow_client()
|
||||
def run(self, context):
|
||||
swift = self.get_object_client(context)
|
||||
mistral = self.get_workflow_client(context)
|
||||
env_data = {
|
||||
'name': self.container,
|
||||
}
|
||||
@@ -202,9 +202,9 @@ class UpdatePlanAction(base.TripleOAction, PlanEnvMixin):
|
||||
super(UpdatePlanAction, self).__init__()
|
||||
self.container = container
|
||||
|
||||
def run(self):
|
||||
swift = self.get_object_client()
|
||||
mistral = self.get_workflow_client()
|
||||
def run(self, context):
|
||||
swift = self.get_object_client(context)
|
||||
mistral = self.get_workflow_client(context)
|
||||
|
||||
# Get plan environment from Swift
|
||||
try:
|
||||
@@ -215,7 +215,7 @@ class UpdatePlanAction(base.TripleOAction, PlanEnvMixin):
|
||||
|
||||
# Update mistral environment with contents from plan environment file
|
||||
variables = json.dumps(plan_env_dict, sort_keys=True)
|
||||
self.cache_delete(self.container, "tripleo.parameters.get")
|
||||
self.cache_delete(context, self.container, "tripleo.parameters.get")
|
||||
try:
|
||||
mistral.environments.update(
|
||||
name=self.container, variables=variables)
|
||||
@@ -248,13 +248,13 @@ class ListPlansAction(base.TripleOAction):
|
||||
name as the container.
|
||||
"""
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
# plans consist of a container object and mistral environment
|
||||
# with the same name. The container is marked with metadata
|
||||
# to ensure it isn't confused with another container
|
||||
plan_list = []
|
||||
oc = self.get_object_client()
|
||||
mc = self.get_workflow_client()
|
||||
oc = self.get_object_client(context)
|
||||
mc = self.get_workflow_client(context)
|
||||
for item in oc.get_account()[1]:
|
||||
container = oc.get_container(item['name'])[0]
|
||||
if constants.TRIPLEO_META_USAGE_KEY in container.keys():
|
||||
@@ -277,11 +277,13 @@ class DeletePlanAction(base.TripleOAction):
|
||||
super(DeletePlanAction, self).__init__()
|
||||
self.container = container
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
error_text = None
|
||||
# heat throws HTTPNotFound if the stack is not found
|
||||
try:
|
||||
stack = self.get_orchestration_client().stacks.get(self.container)
|
||||
stack = self.get_orchestration_client(context).stacks.get(
|
||||
self.container
|
||||
)
|
||||
except heatexceptions.HTTPNotFound:
|
||||
pass
|
||||
else:
|
||||
@@ -289,11 +291,11 @@ class DeletePlanAction(base.TripleOAction):
|
||||
raise exception.StackInUseError(name=self.container)
|
||||
|
||||
try:
|
||||
swift = self.get_object_client()
|
||||
swift = self.get_object_client(context)
|
||||
swiftutils.delete_container(swift, self.container)
|
||||
|
||||
# if mistral environment exists, delete it too
|
||||
mistral = self.get_workflow_client()
|
||||
mistral = self.get_workflow_client(context)
|
||||
if self.container in [env.name for env in
|
||||
mistral.environments.list()]:
|
||||
# deletes environment
|
||||
@@ -323,13 +325,13 @@ class ListRolesAction(base.TripleOAction):
|
||||
super(ListRolesAction, self).__init__()
|
||||
self.container = container
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
try:
|
||||
mc = self.get_workflow_client()
|
||||
mc = self.get_workflow_client(context)
|
||||
mistral_env = mc.environments.get(self.container)
|
||||
template_name = mistral_env.variables['template']
|
||||
|
||||
oc = self.get_object_client()
|
||||
oc = self.get_object_client(context)
|
||||
resources = yaml.safe_load(
|
||||
oc.get_object(self.container, template_name)[1])['resources']
|
||||
except Exception as mistral_err:
|
||||
@@ -403,9 +405,9 @@ class ExportPlanAction(base.TripleOAction):
|
||||
swift.put_object(self.exports_container, tarball_name, tmp_tarball,
|
||||
headers=headers)
|
||||
|
||||
def run(self):
|
||||
swift = self.get_object_client()
|
||||
mistral = self.get_workflow_client()
|
||||
def run(self, context):
|
||||
swift = self.get_object_client(context)
|
||||
mistral = self.get_workflow_client(context)
|
||||
tmp_dir = tempfile.mkdtemp()
|
||||
|
||||
try:
|
||||
|
@@ -63,18 +63,19 @@ class ScaleDownAction(templates.ProcessTemplatesAction):
|
||||
super(ScaleDownAction, self).__init__(container)
|
||||
|
||||
def _update_stack(self, parameters={},
|
||||
timeout_mins=constants.STACK_TIMEOUT_DEFAULT):
|
||||
timeout_mins=constants.STACK_TIMEOUT_DEFAULT,
|
||||
context=None):
|
||||
# TODO(rbrady): migrate _update_stack to it's own action and update
|
||||
# the workflow for scale down
|
||||
|
||||
# update the plan parameters with the scaled down parameters
|
||||
update_params_action = parameters_actions.UpdateParametersAction(
|
||||
parameters, self.container)
|
||||
updated_plan = update_params_action.run()
|
||||
updated_plan = update_params_action.run(context)
|
||||
if isinstance(updated_plan, mistral_workflow_utils.Result):
|
||||
return updated_plan
|
||||
|
||||
processed_data = super(ScaleDownAction, self).run()
|
||||
processed_data = super(ScaleDownAction, self).run(context)
|
||||
if isinstance(processed_data, mistral_workflow_utils.Result):
|
||||
return processed_data
|
||||
|
||||
@@ -85,8 +86,8 @@ class ScaleDownAction(templates.ProcessTemplatesAction):
|
||||
fields['existing'] = True
|
||||
|
||||
LOG.debug('stack update params: %s', fields)
|
||||
self.get_orchestration_client().stacks.update(self.container,
|
||||
**fields)
|
||||
self.get_orchestration_client(context).stacks.update(self.container,
|
||||
**fields)
|
||||
|
||||
def _get_removal_params_from_heat(self, resources_by_role, resources):
|
||||
stack_params = {}
|
||||
@@ -110,8 +111,8 @@ class ScaleDownAction(templates.ProcessTemplatesAction):
|
||||
|
||||
return stack_params
|
||||
|
||||
def run(self):
|
||||
heatclient = self.get_orchestration_client()
|
||||
def run(self, context):
|
||||
heatclient = self.get_orchestration_client(context)
|
||||
resources = heatclient.resources.list(self.container, nested_depth=5)
|
||||
resources_by_role = collections.defaultdict(list)
|
||||
instance_list = list(self.nodes)
|
||||
@@ -144,4 +145,4 @@ class ScaleDownAction(templates.ProcessTemplatesAction):
|
||||
stack_params = self._get_removal_params_from_heat(
|
||||
resources_by_role, resources)
|
||||
|
||||
self._update_stack(parameters=stack_params)
|
||||
self._update_stack(parameters=stack_params, context=context)
|
||||
|
@@ -30,8 +30,8 @@ class SwiftTempUrlAction(base.TripleOAction):
|
||||
self.method = method
|
||||
self.valid = valid
|
||||
|
||||
def run(self):
|
||||
swift_client = self.get_object_client()
|
||||
def run(self, context):
|
||||
swift_client = self.get_object_client(context)
|
||||
|
||||
try:
|
||||
cont_stat = swift_client.head_container(self.container)
|
||||
|
@@ -22,7 +22,6 @@ import tempfile as tf
|
||||
import yaml
|
||||
|
||||
from heatclient.common import template_utils
|
||||
from mistral import context
|
||||
from mistral.workflow import utils as mistral_workflow_utils
|
||||
from swiftclient import exceptions as swiftexceptions
|
||||
|
||||
@@ -84,11 +83,11 @@ class UploadTemplatesAction(base.TripleOAction):
|
||||
self.container = container
|
||||
self.templates_path = templates_path
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
with tf.NamedTemporaryFile() as tmp_tarball:
|
||||
tarball.create_tarball(self.templates_path, tmp_tarball.name)
|
||||
tarball.tarball_extract_to_swift_container(
|
||||
self.get_object_client(),
|
||||
self.get_object_client(context),
|
||||
tmp_tarball.name,
|
||||
self.container)
|
||||
|
||||
@@ -104,8 +103,12 @@ class ProcessTemplatesAction(base.TripleOAction):
|
||||
super(ProcessTemplatesAction, self).__init__()
|
||||
self.container = container
|
||||
|
||||
def _j2_render_and_put(self, j2_template, j2_data, outfile_name=None):
|
||||
swift = self.get_object_client()
|
||||
def _j2_render_and_put(self,
|
||||
j2_template,
|
||||
j2_data,
|
||||
outfile_name=None,
|
||||
context=None):
|
||||
swift = self.get_object_client(context)
|
||||
yaml_f = outfile_name or j2_template.replace('.j2.yaml', '.yaml')
|
||||
|
||||
# Search for templates relative to the current template path first
|
||||
@@ -125,7 +128,9 @@ class ProcessTemplatesAction(base.TripleOAction):
|
||||
try:
|
||||
# write the template back to the plan container
|
||||
LOG.info("Writing rendered template %s" % yaml_f)
|
||||
self.cache_delete(self.container, "tripleo.parameters.get")
|
||||
self.cache_delete(context,
|
||||
self.container,
|
||||
"tripleo.parameters.get")
|
||||
swift.put_object(
|
||||
self.container, yaml_f, r_template)
|
||||
except swiftexceptions.ClientException as ex:
|
||||
@@ -134,8 +139,8 @@ class ProcessTemplatesAction(base.TripleOAction):
|
||||
LOG.error(error_msg)
|
||||
raise Exception(error_msg)
|
||||
|
||||
def _get_j2_excludes_file(self):
|
||||
swift = self.get_object_client()
|
||||
def _get_j2_excludes_file(self, context):
|
||||
swift = self.get_object_client(context)
|
||||
try:
|
||||
j2_excl_file = swift.get_object(
|
||||
self.container, constants.OVERCLOUD_J2_EXCLUDES)[1]
|
||||
@@ -151,8 +156,8 @@ class ProcessTemplatesAction(base.TripleOAction):
|
||||
"the J2 excludes list to: %s" % j2_excl_data)
|
||||
return j2_excl_data
|
||||
|
||||
def _process_custom_roles(self):
|
||||
swift = self.get_object_client()
|
||||
def _process_custom_roles(self, context):
|
||||
swift = self.get_object_client(context)
|
||||
|
||||
try:
|
||||
j2_role_file = swift.get_object(
|
||||
@@ -173,7 +178,7 @@ class ProcessTemplatesAction(base.TripleOAction):
|
||||
% constants.OVERCLOUD_J2_ROLES_NAME)
|
||||
network_data = []
|
||||
|
||||
j2_excl_data = self._get_j2_excludes_file()
|
||||
j2_excl_data = self._get_j2_excludes_file(context)
|
||||
|
||||
try:
|
||||
# Iterate over all files in the plan container
|
||||
@@ -215,7 +220,8 @@ class ProcessTemplatesAction(base.TripleOAction):
|
||||
if not (out_f_path in excl_templates):
|
||||
self._j2_render_and_put(j2_template,
|
||||
j2_data,
|
||||
out_f_path)
|
||||
out_f_path,
|
||||
context=context)
|
||||
else:
|
||||
LOG.info("Skipping rendering of %s, defined in %s" %
|
||||
(out_f_path, j2_excl_data))
|
||||
@@ -225,13 +231,16 @@ class ProcessTemplatesAction(base.TripleOAction):
|
||||
j2_template = swift.get_object(self.container, f)[1]
|
||||
j2_data = {'roles': role_data, 'networks': network_data}
|
||||
out_f = f.replace('.j2.yaml', '.yaml')
|
||||
self._j2_render_and_put(j2_template, j2_data, out_f)
|
||||
self._j2_render_and_put(j2_template,
|
||||
j2_data,
|
||||
out_f,
|
||||
context=context)
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
error_text = None
|
||||
ctx = context.ctx()
|
||||
swift = self.get_object_client()
|
||||
mistral = self.get_workflow_client()
|
||||
self.context = context
|
||||
swift = self.get_object_client(context)
|
||||
mistral = self.get_workflow_client(context)
|
||||
try:
|
||||
mistral_environment = mistral.environments.get(self.container)
|
||||
except Exception as mistral_err:
|
||||
@@ -247,7 +256,7 @@ class ProcessTemplatesAction(base.TripleOAction):
|
||||
# not found in swift, but if they are found and an exception
|
||||
# occurs during processing, that exception will cause the
|
||||
# ProcessTemplatesAction to return an error result.
|
||||
self._process_custom_roles()
|
||||
self._process_custom_roles(context)
|
||||
except Exception as err:
|
||||
LOG.exception("Error occurred while processing custom roles.")
|
||||
return mistral_workflow_utils.Result(error=six.text_type(err))
|
||||
@@ -294,7 +303,7 @@ class ProcessTemplatesAction(base.TripleOAction):
|
||||
LOG.debug('_env_path_is_object %s: %s' % (env_path, retval))
|
||||
return retval
|
||||
|
||||
def _object_request(method, url, token=ctx.auth_token):
|
||||
def _object_request(method, url, token=context.auth_token):
|
||||
return requests.request(
|
||||
method, url, headers={'X-Auth-Token': token}).content
|
||||
|
||||
|
@@ -25,8 +25,8 @@ from tripleo_common.utils import validations as utils
|
||||
|
||||
class GetPubkeyAction(base.TripleOAction):
|
||||
|
||||
def run(self):
|
||||
mc = self.get_workflow_client()
|
||||
def run(self, context):
|
||||
mc = self.get_workflow_client(context)
|
||||
try:
|
||||
env = mc.environments.get('ssh_keys')
|
||||
public_key = env.variables['public_key']
|
||||
@@ -47,9 +47,9 @@ class GetPubkeyAction(base.TripleOAction):
|
||||
class Enabled(base.TripleOAction):
|
||||
"""Indicate whether the validations have been enabled."""
|
||||
|
||||
def _validations_enabled(self):
|
||||
def _validations_enabled(self, context):
|
||||
"""Detect whether the validations are enabled on the undercloud."""
|
||||
mistral = self.get_workflow_client()
|
||||
mistral = self.get_workflow_client(context)
|
||||
try:
|
||||
# NOTE: the `ssh_keys` environment is created by
|
||||
# instack-undercloud only when the validations are enabled on the
|
||||
@@ -60,9 +60,9 @@ class Enabled(base.TripleOAction):
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
return_value = {'stderr': ''}
|
||||
if self._validations_enabled():
|
||||
if self._validations_enabled(context):
|
||||
return_value['stdout'] = 'Validations are enabled'
|
||||
mistral_result = {"data": return_value}
|
||||
else:
|
||||
@@ -77,14 +77,14 @@ class ListValidationsAction(base.TripleOAction):
|
||||
super(ListValidationsAction, self).__init__()
|
||||
self.groups = groups
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
return utils.load_validations(groups=self.groups)
|
||||
|
||||
|
||||
class ListGroupsAction(base.TripleOAction):
|
||||
"""Return a set of TripleO validation groups"""
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
validations = utils.load_validations()
|
||||
return {
|
||||
group for validation in validations
|
||||
@@ -99,8 +99,8 @@ class RunValidationAction(base.TripleOAction):
|
||||
self.validation = validation
|
||||
self.plan = plan
|
||||
|
||||
def run(self):
|
||||
mc = self.get_workflow_client()
|
||||
def run(self, context):
|
||||
mc = self.get_workflow_client(context)
|
||||
identity_file = None
|
||||
try:
|
||||
env = mc.environments.get('ssh_keys')
|
||||
@@ -109,7 +109,8 @@ class RunValidationAction(base.TripleOAction):
|
||||
|
||||
stdout, stderr = utils.run_validation(self.validation,
|
||||
identity_file,
|
||||
self.plan)
|
||||
self.plan,
|
||||
context)
|
||||
return_value = {'stdout': stdout, 'stderr': stderr}
|
||||
mistral_result = {"data": return_value}
|
||||
except mistralclient_api.APIException as e:
|
||||
@@ -138,7 +139,7 @@ class CheckBootImagesAction(base.TripleOAction):
|
||||
self.deploy_kernel_name = deploy_kernel_name
|
||||
self.deploy_ramdisk_name = deploy_ramdisk_name
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
messages = []
|
||||
kernel_id = self._check_for_image(self.deploy_kernel_name, messages)
|
||||
ramdisk_id = self._check_for_image(self.deploy_ramdisk_name, messages)
|
||||
@@ -189,7 +190,7 @@ class CheckFlavorsAction(base.TripleOAction):
|
||||
super(CheckFlavorsAction, self).__init__()
|
||||
self.roles_info = roles_info
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
"""Validate and collect nova flavors in use.
|
||||
|
||||
Ensure that selected flavors (--ROLE-flavor) are valid in nova.
|
||||
@@ -197,7 +198,7 @@ class CheckFlavorsAction(base.TripleOAction):
|
||||
|
||||
:returns: dictionary flavor name -> (flavor object, scale)
|
||||
"""
|
||||
compute_client = self.get_compute_client()
|
||||
compute_client = self.get_compute_client(context)
|
||||
flavors = {f.name: {'name': f.name, 'keys': f.get_keys()}
|
||||
for f in compute_client.flavors.list()}
|
||||
|
||||
@@ -261,7 +262,7 @@ class CheckNodeBootConfigurationAction(base.TripleOAction):
|
||||
self.kernel_id = kernel_id
|
||||
self.ramdisk_id = ramdisk_id
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
warnings = []
|
||||
errors = []
|
||||
message = ("Node {uuid} has an incorrectly configured "
|
||||
@@ -314,7 +315,7 @@ class VerifyProfilesAction(base.TripleOAction):
|
||||
self.nodes = nodes
|
||||
self.flavors = flavors
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
errors = []
|
||||
warnings = []
|
||||
|
||||
@@ -410,7 +411,7 @@ class CheckNodesCountAction(base.TripleOAction):
|
||||
self.parameters = parameters
|
||||
self.default_role_counts = default_role_counts
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
errors = []
|
||||
warnings = []
|
||||
|
||||
|
@@ -20,13 +20,13 @@ import tempfile
|
||||
from git import Repo
|
||||
import six
|
||||
|
||||
from mistral.actions import base
|
||||
from mistral.workflow import utils as mistral_workflow_utils
|
||||
from mistral_lib import actions
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GitCloneAction(base.Action):
|
||||
class GitCloneAction(actions.Action):
|
||||
"""Clones a remote git repository
|
||||
|
||||
:param container: name of the container associated with the plan
|
||||
@@ -42,7 +42,7 @@ class GitCloneAction(base.Action):
|
||||
def _checkout_reference(self, repo, ref):
|
||||
return repo.git.checkout(repo.refs[ref])
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
# make a temp directory to contain the repo
|
||||
local_dir_path = tempfile.mkdtemp(
|
||||
suffix="_%s_import" % self.container)
|
||||
@@ -75,7 +75,7 @@ class GitCloneAction(base.Action):
|
||||
return local_dir_path
|
||||
|
||||
|
||||
class GitCleanupAction(base.Action):
|
||||
class GitCleanupAction(actions.Action):
|
||||
"""Removes temporary files associated with GitCloneAction operations
|
||||
|
||||
:param container: name of the container associated with the plan
|
||||
@@ -85,7 +85,7 @@ class GitCleanupAction(base.Action):
|
||||
def __init__(self, container):
|
||||
self.container = container
|
||||
|
||||
def run(self):
|
||||
def run(self, context):
|
||||
try:
|
||||
temp_dir = tempfile.gettempdir()
|
||||
target_path = '%s/*_%s_import' % (temp_dir, self.container)
|
||||
|
@@ -57,11 +57,12 @@ class TestConfigureBootAction(base.TestCase):
|
||||
elif name == 'bm-deploy-ramdisk':
|
||||
return mock.MagicMock(id='r_id')
|
||||
self.glance.images.find = mock_find
|
||||
self.context = mock.MagicMock()
|
||||
|
||||
def test_run_instance_boot_option(self):
|
||||
action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID',
|
||||
instance_boot_option='netboot')
|
||||
result = action.run()
|
||||
result = action.run(self.context)
|
||||
self.assertEqual(result, None)
|
||||
|
||||
self.node_update[0].update({'value': 'boot_option:netboot'})
|
||||
@@ -70,7 +71,7 @@ class TestConfigureBootAction(base.TestCase):
|
||||
|
||||
def test_run_instance_boot_option_not_set(self):
|
||||
action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID')
|
||||
result = action.run()
|
||||
result = action.run(self.context)
|
||||
self.assertEqual(result, None)
|
||||
|
||||
self.node_update[0].update({'value': 'boot_option:local'})
|
||||
@@ -83,7 +84,7 @@ class TestConfigureBootAction(base.TestCase):
|
||||
self.ironic.node.get.return_value = node_mock
|
||||
|
||||
action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID')
|
||||
result = action.run()
|
||||
result = action.run(self.context)
|
||||
self.assertEqual(result, None)
|
||||
|
||||
self.node_update[0].update({'value': 'boot_option:netboot'})
|
||||
@@ -97,7 +98,7 @@ class TestConfigureBootAction(base.TestCase):
|
||||
|
||||
action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID',
|
||||
instance_boot_option='local')
|
||||
result = action.run()
|
||||
result = action.run(self.context)
|
||||
self.assertEqual(result, None)
|
||||
|
||||
self.node_update[0].update({'value': 'boot_option:local'})
|
||||
@@ -113,7 +114,7 @@ class TestConfigureBootAction(base.TestCase):
|
||||
action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID',
|
||||
kernel_name='test_kernel',
|
||||
ramdisk_name='test_ramdisk')
|
||||
result = action.run()
|
||||
result = action.run(self.context)
|
||||
|
||||
self.assertEqual(result, None)
|
||||
|
||||
@@ -129,14 +130,14 @@ class TestConfigureBootAction(base.TestCase):
|
||||
action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID',
|
||||
kernel_name='unknown_kernel',
|
||||
ramdisk_name='unknown_ramdisk')
|
||||
result = action.run()
|
||||
result = action.run(self.context)
|
||||
self.assertIn("not found", str(result.error))
|
||||
|
||||
def test_run_exception_on_node_update(self):
|
||||
self.ironic.node.update.side_effect = Exception("Update error")
|
||||
|
||||
action = baremetal.ConfigureBootAction(node_uuid='MOCK_UUID')
|
||||
result = action.run()
|
||||
result = action.run(self.context)
|
||||
|
||||
self.assertIn("Update error", str(result.error))
|
||||
|
||||
@@ -185,11 +186,12 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
self.inspector.get_data.return_value = {
|
||||
'inventory': {'disks': self.disks}
|
||||
}
|
||||
self.context = mock.MagicMock()
|
||||
|
||||
def test_smallest(self):
|
||||
action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID',
|
||||
root_device='smallest')
|
||||
action.run()
|
||||
action.run(self.context)
|
||||
|
||||
self.assertEqual(self.ironic.node.update.call_count, 1)
|
||||
root_device_args = self.ironic.node.update.call_args_list[0]
|
||||
@@ -203,7 +205,7 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
def test_largest(self):
|
||||
action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID',
|
||||
root_device='largest')
|
||||
action.run()
|
||||
action.run(self.context)
|
||||
|
||||
self.assertEqual(self.ironic.node.update.call_count, 1)
|
||||
root_device_args = self.ironic.node.update.call_args_list[0]
|
||||
@@ -219,7 +221,7 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
|
||||
action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID',
|
||||
root_device='smallest')
|
||||
action.run()
|
||||
action.run(self.context)
|
||||
|
||||
self.assertEqual(self.ironic.node.update.call_count, 0)
|
||||
|
||||
@@ -229,7 +231,7 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID',
|
||||
root_device='smallest',
|
||||
overwrite=True)
|
||||
action.run()
|
||||
action.run(self.context)
|
||||
|
||||
self.assertEqual(self.ironic.node.update.call_count, 1)
|
||||
root_device_args = self.ironic.node.update.call_args_list[0]
|
||||
@@ -244,7 +246,7 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID',
|
||||
root_device='smallest',
|
||||
minimum_size=10)
|
||||
action.run()
|
||||
action.run(self.context)
|
||||
|
||||
self.assertEqual(self.ironic.node.update.call_count, 1)
|
||||
root_device_args = self.ironic.node.update.call_args_list[0]
|
||||
@@ -262,7 +264,8 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
root_device='smallest')
|
||||
self.assertRaisesRegexp(exception.RootDeviceDetectionError,
|
||||
"Malformed introspection data",
|
||||
action.run)
|
||||
action.run,
|
||||
self.context)
|
||||
|
||||
self.assertEqual(self.ironic.node.update.call_count, 0)
|
||||
|
||||
@@ -277,7 +280,8 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
root_device='smallest')
|
||||
self.assertRaisesRegexp(exception.RootDeviceDetectionError,
|
||||
"No suitable disks",
|
||||
action.run)
|
||||
action.run,
|
||||
self.context)
|
||||
|
||||
self.assertEqual(self.ironic.node.update.call_count, 0)
|
||||
|
||||
@@ -289,7 +293,8 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
root_device='smallest')
|
||||
self.assertRaisesRegexp(exception.RootDeviceDetectionError,
|
||||
"No introspection data",
|
||||
action.run)
|
||||
action.run,
|
||||
self.context)
|
||||
|
||||
self.assertEqual(self.ironic.node.update.call_count, 0)
|
||||
|
||||
@@ -304,7 +309,8 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
root_device='smallest')
|
||||
self.assertRaisesRegexp(exception.RootDeviceDetectionError,
|
||||
"Neither WWN nor serial number are known",
|
||||
action.run)
|
||||
action.run,
|
||||
self.context)
|
||||
|
||||
self.assertEqual(self.ironic.node.update.call_count, 0)
|
||||
|
||||
@@ -312,7 +318,7 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
action = baremetal.ConfigureRootDeviceAction(
|
||||
node_uuid='MOCK_UUID',
|
||||
root_device='hda,sda,sdb,sdc')
|
||||
action.run()
|
||||
action.run(self.context)
|
||||
|
||||
self.assertEqual(self.ironic.node.update.call_count, 1)
|
||||
root_device_args = self.ironic.node.update.call_args_list[0]
|
||||
@@ -329,7 +335,8 @@ class TestConfigureRootDeviceAction(base.TestCase):
|
||||
|
||||
self.assertRaisesRegexp(exception.RootDeviceDetectionError,
|
||||
"Cannot find a disk",
|
||||
action.run)
|
||||
action.run,
|
||||
self.context)
|
||||
self.assertEqual(self.ironic.node.update.call_count, 0)
|
||||
|
||||
|
||||
@@ -338,7 +345,7 @@ class TestCellV2DiscoverHostsAction(base.TestCase):
|
||||
@mock.patch('tripleo_common.utils.nodes.run_nova_cell_v2_discovery')
|
||||
def test_run(self, mock_command):
|
||||
action = baremetal.CellV2DiscoverHostsAction()
|
||||
action.run()
|
||||
action.run(mock.MagicMock())
|
||||
mock_command.assert_called_once()
|
||||
|
||||
@mock.patch('tripleo_common.utils.nodes.run_nova_cell_v2_discovery')
|
||||
@@ -350,7 +357,7 @@ class TestCellV2DiscoverHostsAction(base.TestCase):
|
||||
cmd='command'
|
||||
)
|
||||
action = baremetal.CellV2DiscoverHostsAction()
|
||||
result = action.run()
|
||||
result = action.run(mock.MagicMock())
|
||||
self.assertTrue(result.is_error())
|
||||
mock_command.assert_called_once()
|
||||
|
||||
@@ -358,6 +365,7 @@ class TestCellV2DiscoverHostsAction(base.TestCase):
|
||||
class TestGetProfileAction(base.TestCase):
|
||||
|
||||
def test_run(self):
|
||||
mock_ctx = mock.MagicMock()
|
||||
node = {
|
||||
'uuid': 'abcd1',
|
||||
'properties': {
|
||||
@@ -365,7 +373,7 @@ class TestGetProfileAction(base.TestCase):
|
||||
}
|
||||
}
|
||||
action = baremetal.GetProfileAction(node=node)
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
expected_result = {
|
||||
'uuid': 'abcd1',
|
||||
'profile': 'compute'
|
||||
|
@@ -17,7 +17,6 @@ import zlib
|
||||
import mock
|
||||
|
||||
from ironicclient.v1 import client as ironicclient
|
||||
from mistral import context
|
||||
from mistral.utils.openstack import keystone as keystone_utils
|
||||
|
||||
from tripleo_common.actions import base
|
||||
@@ -26,7 +25,6 @@ from tripleo_common.tests import base as tests_base
|
||||
from swiftclient.exceptions import ClientException
|
||||
|
||||
|
||||
@mock.patch.object(context, 'ctx')
|
||||
@mock.patch.object(keystone_utils, 'get_endpoint_for_project')
|
||||
class TestActionsBase(tests_base.TestCase):
|
||||
|
||||
@@ -35,17 +33,18 @@ class TestActionsBase(tests_base.TestCase):
|
||||
self.action = base.TripleOAction()
|
||||
|
||||
@mock.patch.object(ironicclient, 'Client')
|
||||
def test__get_baremetal_client(self, mock_client, mock_endpoint, mock_cxt):
|
||||
def test__get_baremetal_client(self, mock_client, mock_endpoint):
|
||||
mock_cxt = mock.MagicMock()
|
||||
mock_endpoint.return_value = mock.Mock(
|
||||
url='http://ironic/v1', region='ironic-region')
|
||||
self.action.get_baremetal_client()
|
||||
self.action.get_baremetal_client(mock_cxt)
|
||||
mock_client.assert_called_once_with(
|
||||
'http://ironic/v1', max_retries=12, os_ironic_api_version='1.15',
|
||||
region_name='ironic-region', retry_interval=5, token=mock.ANY)
|
||||
mock_endpoint.assert_called_once_with('ironic')
|
||||
mock_cxt.assert_called_once_with()
|
||||
mock_cxt.assert_not_called()
|
||||
|
||||
def test_cache_key(self, mock_client, mock_endpoint):
|
||||
def test_cache_key(self, mock_endpoint):
|
||||
container = "TestContainer"
|
||||
key = "testkey"
|
||||
cache_key = "__cache_TestContainer_testkey"
|
||||
@@ -56,7 +55,8 @@ class TestActionsBase(tests_base.TestCase):
|
||||
)
|
||||
|
||||
@mock.patch("tripleo_common.actions.base.swift_client.Connection")
|
||||
def test_cache_set(self, mock_conn, mock_client, mock_endpoint):
|
||||
def test_cache_set(self, mock_conn, mock_endpoint):
|
||||
mock_ctx = mock.Mock()
|
||||
mock_swift = mock.Mock()
|
||||
mock_conn.return_value = mock_swift
|
||||
|
||||
@@ -66,7 +66,7 @@ class TestActionsBase(tests_base.TestCase):
|
||||
cache_key = "__cache_TestContainer_testkey"
|
||||
compressed_json = zlib.compress("{\"foo\": 1}".encode())
|
||||
|
||||
self.action.cache_set(container, key, {"foo": 1})
|
||||
self.action.cache_set(mock_ctx, container, key, {"foo": 1})
|
||||
mock_swift.put_object.assert_called_once_with(
|
||||
cache_container,
|
||||
cache_key,
|
||||
@@ -75,7 +75,8 @@ class TestActionsBase(tests_base.TestCase):
|
||||
mock_swift.delete_object.assert_not_called()
|
||||
|
||||
@mock.patch("tripleo_common.actions.base.swift_client.Connection")
|
||||
def test_cache_set_none(self, mock_conn, mock_client, mock_endpoint):
|
||||
def test_cache_set_none(self, mock_conn, mock_endpoint):
|
||||
mock_ctx = mock.Mock()
|
||||
mock_swift = mock.Mock()
|
||||
mock_conn.return_value = mock_swift
|
||||
|
||||
@@ -84,7 +85,7 @@ class TestActionsBase(tests_base.TestCase):
|
||||
key = "testkey"
|
||||
cache_key = "__cache_TestContainer_testkey"
|
||||
|
||||
self.action.cache_set(container, key, None)
|
||||
self.action.cache_set(mock_ctx, container, key, None)
|
||||
mock_swift.put_object.assert_not_called()
|
||||
mock_swift.delete_object.called_once_with(
|
||||
cache_container,
|
||||
@@ -92,7 +93,8 @@ class TestActionsBase(tests_base.TestCase):
|
||||
)
|
||||
|
||||
@mock.patch("tripleo_common.actions.base.swift_client.Connection")
|
||||
def test_cache_get_filled(self, mock_conn, mock_client, mock_endpoint):
|
||||
def test_cache_get_filled(self, mock_conn, mock_endpoint):
|
||||
mock_ctx = mock.Mock()
|
||||
mock_swift = mock.Mock()
|
||||
mock_conn.return_value = mock_swift
|
||||
|
||||
@@ -101,11 +103,12 @@ class TestActionsBase(tests_base.TestCase):
|
||||
compressed_json = zlib.compress("{\"foo\": 1}".encode())
|
||||
# test if cache has something in it
|
||||
mock_swift.get_object.return_value = ([], compressed_json)
|
||||
result = self.action.cache_get(container, key)
|
||||
result = self.action.cache_get(mock_ctx, container, key)
|
||||
self.assertEqual(result, {"foo": 1})
|
||||
|
||||
@mock.patch("tripleo_common.actions.base.swift_client.Connection")
|
||||
def test_cache_empty(self, mock_conn, mock_client, mock_endpoint):
|
||||
def test_cache_empty(self, mock_conn, mock_endpoint):
|
||||
mock_ctx = mock.Mock()
|
||||
mock_swift = mock.Mock()
|
||||
mock_conn.return_value = mock_swift
|
||||
|
||||
@@ -117,18 +120,19 @@ class TestActionsBase(tests_base.TestCase):
|
||||
mock_swift.get_object.side_effect = ClientException(
|
||||
"Foo"
|
||||
)
|
||||
result = self.action.cache_get(container, key)
|
||||
result = self.action.cache_get(mock_ctx, container, key)
|
||||
self.assertFalse(result)
|
||||
|
||||
# delete cache if we have a value
|
||||
self.action.cache_delete(container, key)
|
||||
self.action.cache_delete(mock_ctx, container, key)
|
||||
mock_swift.delete_object.assert_called_once_with(
|
||||
cache_container,
|
||||
cache_key
|
||||
)
|
||||
|
||||
@mock.patch("tripleo_common.actions.base.swift_client.Connection")
|
||||
def test_cache_delete(self, mock_conn, mock_client, mock_endpoint):
|
||||
def test_cache_delete(self, mock_conn, mock_endpoint):
|
||||
mock_ctx = mock.Mock()
|
||||
mock_swift = mock.Mock()
|
||||
mock_conn.return_value = mock_swift
|
||||
|
||||
@@ -139,7 +143,7 @@ class TestActionsBase(tests_base.TestCase):
|
||||
mock_swift.delete_object.side_effect = ClientException(
|
||||
"Foo"
|
||||
)
|
||||
self.action.cache_delete(container, key)
|
||||
self.action.cache_delete(mock_ctx, container, key)
|
||||
mock_swift.delete_object.assert_called_once_with(
|
||||
cache_container,
|
||||
cache_key
|
||||
|
@@ -59,19 +59,24 @@ class OrchestrationDeployActionTest(base.TestCase):
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
def test_wait_for_data(self, get_obj_client_mock):
|
||||
mock_ctx = mock.MagicMock()
|
||||
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object.return_value = ({}, 'body')
|
||||
get_obj_client_mock.return_value = swift
|
||||
|
||||
action = deployment.OrchestrationDeployAction(self.server_id,
|
||||
self.config, self.name)
|
||||
self.assertEqual('body', action._wait_for_data('container', 'object'))
|
||||
self.assertEqual('body', action._wait_for_data('container',
|
||||
'object',
|
||||
context=mock_ctx))
|
||||
get_obj_client_mock.assert_called_once()
|
||||
swift.get_object.assert_called_once_with('container', 'object')
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('time.sleep')
|
||||
def test_wait_for_data_timeout(self, sleep, get_obj_client_mock):
|
||||
mock_ctx = mock.MagicMock()
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object.return_value = ({}, None)
|
||||
get_obj_client_mock.return_value = swift
|
||||
@@ -79,7 +84,9 @@ class OrchestrationDeployActionTest(base.TestCase):
|
||||
action = deployment.OrchestrationDeployAction(self.server_id,
|
||||
self.config, self.name,
|
||||
timeout=10)
|
||||
self.assertEqual(None, action._wait_for_data('container', 'object'))
|
||||
self.assertEqual(None, action._wait_for_data('container',
|
||||
'object',
|
||||
context=mock_ctx))
|
||||
get_obj_client_mock.assert_called_once()
|
||||
swift.get_object.assert_called_with('container', 'object')
|
||||
# Trying every 3 seconds, so 4 times for a timeout of 10 seconds
|
||||
@@ -99,6 +106,7 @@ class OrchestrationDeployActionTest(base.TestCase):
|
||||
extract_from_swift_url_mock, create_temp_url_mock,
|
||||
get_heat_mock, get_obj_client_mock):
|
||||
extract_from_swift_url_mock.return_value = ('container', 'object')
|
||||
mock_ctx = mock.MagicMock()
|
||||
build_sc_params_mock.return_value = {'foo': 'bar'}
|
||||
config = mock.MagicMock()
|
||||
sd = mock.MagicMock()
|
||||
@@ -111,7 +119,7 @@ class OrchestrationDeployActionTest(base.TestCase):
|
||||
expected = mistral_workflow_utils.Result(
|
||||
data={"deploy_status_code": 0},
|
||||
error=None)
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(context=mock_ctx))
|
||||
create_temp_url_mock.assert_called_once()
|
||||
extract_from_swift_url_mock.assert_called_once()
|
||||
build_sc_params_mock.assert_called_once()
|
||||
@@ -138,6 +146,7 @@ class OrchestrationDeployActionTest(base.TestCase):
|
||||
extract_from_swift_url_mock, create_temp_url_mock,
|
||||
get_heat_mock, get_obj_client_mock):
|
||||
extract_from_swift_url_mock.return_value = ('container', 'object')
|
||||
mock_ctx = mock.MagicMock()
|
||||
config = mock.MagicMock()
|
||||
sd = mock.MagicMock()
|
||||
get_heat_mock().software_configs.create.return_value = config
|
||||
@@ -149,7 +158,7 @@ class OrchestrationDeployActionTest(base.TestCase):
|
||||
expected = mistral_workflow_utils.Result(
|
||||
data={},
|
||||
error="Timeout for heat deployment 'name'")
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(mock_ctx))
|
||||
|
||||
sd.delete.assert_called_once()
|
||||
config.delete.assert_called_once()
|
||||
@@ -171,6 +180,7 @@ class OrchestrationDeployActionTest(base.TestCase):
|
||||
extract_from_swift_url_mock, create_temp_url_mock,
|
||||
get_heat_mock, get_obj_client_mock):
|
||||
extract_from_swift_url_mock.return_value = ('container', 'object')
|
||||
mock_ctx = mock.MagicMock()
|
||||
config = mock.MagicMock()
|
||||
sd = mock.MagicMock()
|
||||
get_heat_mock().software_configs.create.return_value = config
|
||||
@@ -182,7 +192,7 @@ class OrchestrationDeployActionTest(base.TestCase):
|
||||
expected = mistral_workflow_utils.Result(
|
||||
data={"deploy_status_code": 1},
|
||||
error="Heat deployment failed for 'name'")
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(mock_ctx))
|
||||
|
||||
sd.delete.assert_called_once()
|
||||
config.delete.assert_called_once()
|
||||
@@ -205,14 +215,13 @@ class DeployStackActionTest(base.TestCase):
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.base.TripleOAction.get_orchestration_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run(self, mock_ctx, get_orchestration_client_mock,
|
||||
def test_run(self, get_orchestration_client_mock,
|
||||
mock_get_object_client, mock_get_workflow_client,
|
||||
mock_get_template_contents,
|
||||
mock_process_multiple_environments_and_files,
|
||||
mock_time):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
# setup swift
|
||||
swift = mock.MagicMock(url="http://test.com")
|
||||
swift.get_object.side_effect = swiftexceptions.ClientException(
|
||||
@@ -243,7 +252,7 @@ class DeployStackActionTest(base.TestCase):
|
||||
mock_time.time.return_value = 1473366264
|
||||
|
||||
action = deployment.DeployStackAction(1, 'overcloud')
|
||||
action.run()
|
||||
action.run(mock_ctx)
|
||||
|
||||
# verify parameters are as expected
|
||||
expected_defaults = {'DeployIdentifier': 1473366264,
|
||||
@@ -275,15 +284,14 @@ class DeployStackActionTest(base.TestCase):
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.base.TripleOAction.get_orchestration_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run_skip_deploy_identifier(
|
||||
self, mock_ctx, get_orchestration_client_mock,
|
||||
self, get_orchestration_client_mock,
|
||||
mock_get_object_client, mock_get_workflow_client,
|
||||
mock_get_template_contents,
|
||||
mock_process_multiple_environments_and_files,
|
||||
mock_time):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
# setup swift
|
||||
swift = mock.MagicMock(url="http://test.com")
|
||||
swift.get_object.side_effect = swiftexceptions.ClientException(
|
||||
@@ -315,7 +323,7 @@ class DeployStackActionTest(base.TestCase):
|
||||
|
||||
action = deployment.DeployStackAction(1, 'overcloud',
|
||||
skip_deploy_identifier=True)
|
||||
action.run()
|
||||
action.run(mock_ctx)
|
||||
|
||||
# verify parameters are as expected
|
||||
expected_defaults = {'StackAction': 'CREATE',
|
||||
@@ -344,15 +352,16 @@ class OvercloudRcActionTestCase(base.TestCase):
|
||||
'get_workflow_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_orchestration_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_no_stack(self, mock_context, mock_get_orchestration,
|
||||
def test_no_stack(self, mock_get_orchestration,
|
||||
mock_get_workflow):
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
|
||||
not_found = heat_exc.HTTPNotFound()
|
||||
mock_get_orchestration.return_value.stacks.get.side_effect = not_found
|
||||
|
||||
action = deployment.OvercloudRcAction("overcast")
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
self.assertEqual(result.error, (
|
||||
"The Heat stack overcast could not be found. Make sure you have "
|
||||
@@ -363,15 +372,16 @@ class OvercloudRcActionTestCase(base.TestCase):
|
||||
'get_workflow_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_orchestration_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_no_env(self, mock_context, mock_get_orchestration,
|
||||
def test_no_env(self, mock_get_orchestration,
|
||||
mock_get_workflow):
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
|
||||
not_found = mistralclient_exc.APIException()
|
||||
mock_get_workflow.return_value.environments.get.side_effect = not_found
|
||||
|
||||
action = deployment.OvercloudRcAction("overcast")
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
self.assertEqual(
|
||||
result.error,
|
||||
@@ -381,15 +391,15 @@ class OvercloudRcActionTestCase(base.TestCase):
|
||||
'get_workflow_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_orchestration_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_no_password(self, mock_context, mock_get_orchestration,
|
||||
def test_no_password(self, mock_get_orchestration,
|
||||
mock_get_workflow):
|
||||
mock_ctx = mock.MagicMock()
|
||||
|
||||
mock_env = mock.MagicMock(variables={})
|
||||
mock_get_workflow.return_value.environments.get.return_value = mock_env
|
||||
|
||||
action = deployment.OvercloudRcAction("overcast")
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
self.assertEqual(
|
||||
result.error,
|
||||
@@ -400,9 +410,9 @@ class OvercloudRcActionTestCase(base.TestCase):
|
||||
'get_workflow_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_orchestration_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_no_success(self, mock_context, mock_get_orchestration,
|
||||
def test_no_success(self, mock_get_orchestration,
|
||||
mock_get_workflow, mock_create_overcloudrc):
|
||||
mock_ctx = mock.MagicMock()
|
||||
|
||||
mock_create_overcloudrc.return_value = {
|
||||
"overcloudrc": "fake overcloudrc"
|
||||
@@ -414,6 +424,6 @@ class OvercloudRcActionTestCase(base.TestCase):
|
||||
mock_get_workflow.return_value.environments.get.return_value = mock_env
|
||||
|
||||
action = deployment.OvercloudRcAction("overcast")
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
self.assertEqual(result, {"overcloudrc": "fake overcloudrc"})
|
||||
|
@@ -141,6 +141,8 @@ class GetCapabilitiesActionTest(base.TestCase):
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
def test_run_yaml_error(self, get_obj_client_mock):
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
# setup swift
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object.return_value = mock.Mock(side_effect=ValueError)
|
||||
@@ -150,7 +152,7 @@ class GetCapabilitiesActionTest(base.TestCase):
|
||||
expected = mistral_workflow_utils.Result(
|
||||
data=None,
|
||||
error="Error parsing capabilities-map.yaml.")
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(mock_ctx))
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch(
|
||||
@@ -158,6 +160,7 @@ class GetCapabilitiesActionTest(base.TestCase):
|
||||
def test_run_mistral_error(self, get_workflow_client_mock,
|
||||
get_obj_client_mock):
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
# setup swift
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object.return_value = ({}, MAPPING_YAML_CONTENTS)
|
||||
@@ -173,13 +176,14 @@ class GetCapabilitiesActionTest(base.TestCase):
|
||||
expected = mistral_workflow_utils.Result(
|
||||
data=None,
|
||||
error="Error retrieving mistral environment. ")
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(mock_ctx))
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.base.TripleOAction.get_workflow_client')
|
||||
def test_run(self, get_workflow_client_mock, get_obj_client_mock):
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
# setup swift
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object.return_value = ({}, MAPPING_YAML_CONTENTS)
|
||||
@@ -227,7 +231,7 @@ class GetCapabilitiesActionTest(base.TestCase):
|
||||
|
||||
action = heat_capabilities.GetCapabilitiesAction(self.container_name)
|
||||
yaml_mapping = yaml.safe_load(MAPPING_JSON_CONTENTS)
|
||||
self.assertEqual(yaml_mapping, action.run())
|
||||
self.assertEqual(yaml_mapping, action.run(mock_ctx))
|
||||
|
||||
|
||||
class UpdateCapabilitiesActionTest(base.TestCase):
|
||||
@@ -242,6 +246,8 @@ class UpdateCapabilitiesActionTest(base.TestCase):
|
||||
'tripleo_common.actions.base.TripleOAction.get_workflow_client')
|
||||
def test_run(self, get_workflow_client_mock, mock_cache):
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
|
||||
# setup mistral
|
||||
mistral = mock.MagicMock()
|
||||
mocked_env = mock.MagicMock()
|
||||
@@ -267,9 +273,10 @@ class UpdateCapabilitiesActionTest(base.TestCase):
|
||||
{'path': '/path/to/overcloud-default-env.yaml'},
|
||||
{'path': '/path/to/poc-custom-env.yaml'}
|
||||
]},
|
||||
action.run())
|
||||
action.run(mock_ctx))
|
||||
|
||||
mock_cache.assert_called_once_with(
|
||||
mock_ctx,
|
||||
self.container_name,
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
@@ -280,6 +287,8 @@ class UpdateCapabilitiesActionTest(base.TestCase):
|
||||
'tripleo_common.actions.base.TripleOAction.get_workflow_client')
|
||||
def test_run_purge_missing(self, get_workflow_client_mock, mock_cache):
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
|
||||
# setup mistral
|
||||
mistral = mock.MagicMock()
|
||||
mocked_env = mock.MagicMock()
|
||||
@@ -305,8 +314,9 @@ class UpdateCapabilitiesActionTest(base.TestCase):
|
||||
{'path': '/path/to/overcloud-default-env.yaml'},
|
||||
{'path': '/path/to/poc-custom-env.yaml'}
|
||||
]},
|
||||
action.run())
|
||||
action.run(mock_ctx))
|
||||
mock_cache.assert_called_once_with(
|
||||
mock_ctx,
|
||||
self.container_name,
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
@@ -318,6 +328,7 @@ class UpdateCapabilitiesActionTest(base.TestCase):
|
||||
def test_run_mistral_error(self, get_workflow_client_mock,
|
||||
get_obj_client_mock):
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
# setup swift
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object.return_value = ({}, MAPPING_YAML_CONTENTS)
|
||||
@@ -334,4 +345,4 @@ class UpdateCapabilitiesActionTest(base.TestCase):
|
||||
expected = mistral_workflow_utils.Result(
|
||||
data=None,
|
||||
error="Error retrieving mistral environment. ")
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(mock_ctx))
|
||||
|
@@ -33,9 +33,10 @@ class ClearBreakpointsActionTest(base.TestCase):
|
||||
def test_run(self, mock_compute_client,
|
||||
mock_orchestration_client,
|
||||
mock_update_manager):
|
||||
mock_ctx = mock.MagicMock()
|
||||
action = package_update.ClearBreakpointsAction(self.stack_id,
|
||||
self.refs)
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
self.assertEqual(None, result)
|
||||
mock_compute_client.assert_called_once()
|
||||
mock_orchestration_client.assert_called_once()
|
||||
@@ -55,7 +56,6 @@ class UpdateStackActionTest(base.TestCase):
|
||||
self.timeout = 1
|
||||
self.container = 'container'
|
||||
|
||||
@mock.patch('mistral.context.ctx')
|
||||
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction.run')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@@ -70,9 +70,9 @@ class UpdateStackActionTest(base.TestCase):
|
||||
mock_compute_client,
|
||||
mock_orchestration_client,
|
||||
mock_workflow_client,
|
||||
mock_templates_run,
|
||||
mock_ctx,):
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_templates_run
|
||||
):
|
||||
mock_ctx = mock.MagicMock()
|
||||
heat = mock.MagicMock()
|
||||
heat.stacks.get.return_value = mock.MagicMock(
|
||||
stack_name='stack', id='stack_id')
|
||||
@@ -103,7 +103,7 @@ class UpdateStackActionTest(base.TestCase):
|
||||
|
||||
action = package_update.UpdateStackAction(self.timeout,
|
||||
container=self.container)
|
||||
action.run()
|
||||
action.run(mock_ctx)
|
||||
|
||||
# verify parameters are as expected
|
||||
expected_defaults = {
|
||||
|
@@ -149,15 +149,14 @@ class GetParametersActionTest(base.TestCase):
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run(self, mock_ctx, mock_get_object_client,
|
||||
def test_run(self, mock_get_object_client,
|
||||
mock_get_workflow_client, mock_get_orchestration_client,
|
||||
mock_get_template_contents,
|
||||
mock_process_multiple_environments_and_files,
|
||||
mock_cache_get,
|
||||
mock_cache_set):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
swift = mock.MagicMock(url="http://test.com")
|
||||
swift.get_object.side_effect = swiftexceptions.ClientException(
|
||||
'atest2')
|
||||
@@ -185,7 +184,7 @@ class GetParametersActionTest(base.TestCase):
|
||||
mock_cache_get.return_value = None
|
||||
# Test
|
||||
action = parameters.GetParametersAction()
|
||||
action.run()
|
||||
action.run(mock_ctx)
|
||||
mock_heat.stacks.validate.assert_called_once_with(
|
||||
environment={},
|
||||
files={},
|
||||
@@ -193,10 +192,12 @@ class GetParametersActionTest(base.TestCase):
|
||||
template={'heat_template_version': '2016-04-30'},
|
||||
)
|
||||
mock_cache_get.assert_called_once_with(
|
||||
mock_ctx,
|
||||
"overcloud",
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
mock_cache_set.assert_called_once_with(
|
||||
mock_ctx,
|
||||
"overcloud",
|
||||
"tripleo.parameters.get",
|
||||
{'heat_resource_tree': {}, 'mistral_environment_parameters': None}
|
||||
@@ -209,11 +210,10 @@ class ResetParametersActionTest(base.TestCase):
|
||||
'cache_delete')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run(self, mock_ctx, mock_get_workflow_client,
|
||||
def test_run(self, mock_get_workflow_client,
|
||||
mock_cache):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_mistral = mock.MagicMock()
|
||||
mock_env = mock.MagicMock()
|
||||
mock_env.name = constants.DEFAULT_CONTAINER_NAME
|
||||
@@ -226,7 +226,7 @@ class ResetParametersActionTest(base.TestCase):
|
||||
mock_get_workflow_client.return_value = mock_mistral
|
||||
# Test
|
||||
action = parameters.ResetParametersAction()
|
||||
action.run()
|
||||
action.run(mock_ctx)
|
||||
mock_mistral.environments.update.assert_called_once_with(
|
||||
name=constants.DEFAULT_CONTAINER_NAME,
|
||||
variables={
|
||||
@@ -235,6 +235,7 @@ class ResetParametersActionTest(base.TestCase):
|
||||
}
|
||||
)
|
||||
mock_cache.assert_called_once_with(
|
||||
mock_ctx,
|
||||
"overcloud",
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
@@ -246,10 +247,9 @@ class UpdateParametersActionTest(base.TestCase):
|
||||
'cache_delete')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run(self, mock_ctx, mock_get_workflow_client, mock_cache):
|
||||
def test_run(self, mock_get_workflow_client, mock_cache):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_mistral = mock.MagicMock()
|
||||
mock_env = mock.MagicMock()
|
||||
mock_env.name = constants.DEFAULT_CONTAINER_NAME
|
||||
@@ -264,7 +264,7 @@ class UpdateParametersActionTest(base.TestCase):
|
||||
# Test
|
||||
test_parameters = {'SomeTestParameter': 42}
|
||||
action = parameters.UpdateParametersAction(test_parameters)
|
||||
action.run()
|
||||
action.run(mock_ctx)
|
||||
|
||||
mock_mistral.environments.update.assert_called_once_with(
|
||||
name=constants.DEFAULT_CONTAINER_NAME,
|
||||
@@ -275,6 +275,7 @@ class UpdateParametersActionTest(base.TestCase):
|
||||
'parameter_defaults': {'SomeTestParameter': 42}}
|
||||
)
|
||||
mock_cache.assert_called_once_with(
|
||||
mock_ctx,
|
||||
"overcloud",
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
@@ -291,12 +292,11 @@ class UpdateRoleParametersActionTest(base.TestCase):
|
||||
'get_compute_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run(self, mock_ctx, mock_get_workflow_client,
|
||||
def test_run(self, mock_get_workflow_client,
|
||||
mock_get_compute_client, mock_get_baremetal_client,
|
||||
mock_set_count_and_flavor, mock_cache):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_mistral = mock.MagicMock()
|
||||
mock_env = mock.MagicMock()
|
||||
mock_env.name = 'overcast'
|
||||
@@ -310,11 +310,12 @@ class UpdateRoleParametersActionTest(base.TestCase):
|
||||
|
||||
action = parameters.UpdateRoleParametersAction('ceph-storage',
|
||||
'overcast')
|
||||
action.run()
|
||||
action.run(mock_ctx)
|
||||
|
||||
mock_mistral.environments.update.assert_called_once_with(
|
||||
name='overcast', variables={'parameter_defaults': params})
|
||||
mock_cache.assert_called_once_with(
|
||||
mock_ctx,
|
||||
"overcast",
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
@@ -330,14 +331,13 @@ class GeneratePasswordsActionTest(base.TestCase):
|
||||
'get_snmpd_readonly_user_password')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client', return_value="TestPassword")
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run(self, mock_ctx, mock_get_workflow_client,
|
||||
def test_run(self, mock_get_workflow_client,
|
||||
mock_get_snmpd_readonly_user_password,
|
||||
mock_get_orchestration_client, mock_cache):
|
||||
|
||||
mock_get_snmpd_readonly_user_password.return_value = "TestPassword"
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_mistral = mock.MagicMock()
|
||||
mock_env = mock.MagicMock()
|
||||
mock_env.name = constants.DEFAULT_CONTAINER_NAME
|
||||
@@ -356,12 +356,13 @@ class GeneratePasswordsActionTest(base.TestCase):
|
||||
mock_get_orchestration_client.return_value = mock_orchestration
|
||||
|
||||
action = parameters.GeneratePasswordsAction()
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
for password_param_name in constants.PASSWORD_PARAMETER_NAMES:
|
||||
self.assertTrue(password_param_name in result,
|
||||
"%s is not in %s" % (password_param_name, result))
|
||||
mock_cache.assert_called_once_with(
|
||||
mock_ctx,
|
||||
"overcloud",
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
@@ -376,8 +377,7 @@ class GeneratePasswordsActionTest(base.TestCase):
|
||||
'get_snmpd_readonly_user_password')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run_passwords_exist(self, mock_ctx, mock_get_workflow_client,
|
||||
def test_run_passwords_exist(self, mock_get_workflow_client,
|
||||
mock_get_snmpd_readonly_user_password,
|
||||
mock_create_ssh_keypair,
|
||||
mock_get_orchestration_client,
|
||||
@@ -387,7 +387,7 @@ class GeneratePasswordsActionTest(base.TestCase):
|
||||
mock_create_ssh_keypair.return_value = {'public_key': 'Foo',
|
||||
'private_key': 'Bar'}
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_mistral = mock.MagicMock()
|
||||
mock_env = mock.MagicMock()
|
||||
mock_env.name = constants.DEFAULT_CONTAINER_NAME
|
||||
@@ -407,11 +407,12 @@ class GeneratePasswordsActionTest(base.TestCase):
|
||||
mock_get_orchestration_client.return_value = mock_orchestration
|
||||
|
||||
action = parameters.GeneratePasswordsAction()
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
# ensure old passwords used and no new generation
|
||||
self.assertEqual(_EXISTING_PASSWORDS, result)
|
||||
mock_cache.assert_called_once_with(
|
||||
mock_ctx,
|
||||
"overcloud",
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
@@ -426,8 +427,7 @@ class GeneratePasswordsActionTest(base.TestCase):
|
||||
'get_snmpd_readonly_user_password')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_passwords_exist_in_heat(self, mock_ctx, mock_get_workflow_client,
|
||||
def test_passwords_exist_in_heat(self, mock_get_workflow_client,
|
||||
mock_get_snmpd_readonly_user_password,
|
||||
mock_create_ssh_keypair,
|
||||
mock_get_orchestration_client,
|
||||
@@ -440,7 +440,7 @@ class GeneratePasswordsActionTest(base.TestCase):
|
||||
existing_passwords = _EXISTING_PASSWORDS.copy()
|
||||
existing_passwords.pop("AdminPassword")
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_mistral = mock.MagicMock()
|
||||
mock_env = mock.MagicMock()
|
||||
mock_env.name = constants.DEFAULT_CONTAINER_NAME
|
||||
@@ -462,12 +462,13 @@ class GeneratePasswordsActionTest(base.TestCase):
|
||||
mock_get_orchestration_client.return_value = mock_orchestration
|
||||
|
||||
action = parameters.GeneratePasswordsAction()
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
existing_passwords["AdminPassword"] = "ExistingPasswordInHeat"
|
||||
# ensure old passwords used and no new generation
|
||||
self.assertEqual(existing_passwords, result)
|
||||
mock_cache.assert_called_once_with(
|
||||
mock_ctx,
|
||||
"overcloud",
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
@@ -479,12 +480,11 @@ class GetPasswordsActionTest(base.TestCase):
|
||||
'get_orchestration_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_password_from_parameter_defaults(self, mock_ctx,
|
||||
def test_password_from_parameter_defaults(self,
|
||||
mock_get_workflow_client,
|
||||
mock_get_orchestration_client):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_mistral = mock.MagicMock()
|
||||
mock_env = mock.MagicMock()
|
||||
mock_env.name = constants.DEFAULT_CONTAINER_NAME
|
||||
@@ -499,7 +499,7 @@ class GetPasswordsActionTest(base.TestCase):
|
||||
mock_get_orchestration_client.return_value = mock_orchestration
|
||||
|
||||
action = parameters.GetPasswordsAction()
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
# ensure old passwords used and no new generation
|
||||
self.assertEqual(_EXISTING_PASSWORDS, result)
|
||||
@@ -508,12 +508,11 @@ class GetPasswordsActionTest(base.TestCase):
|
||||
'get_orchestration_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_password_from_generated_passwords(self, mock_ctx,
|
||||
def test_password_from_generated_passwords(self,
|
||||
mock_get_workflow_client,
|
||||
mock_get_orchestration_client):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_mistral = mock.MagicMock()
|
||||
mock_env = mock.MagicMock()
|
||||
mock_env.name = constants.DEFAULT_CONTAINER_NAME
|
||||
@@ -530,7 +529,7 @@ class GetPasswordsActionTest(base.TestCase):
|
||||
mock_get_orchestration_client.return_value = mock_orchestration
|
||||
|
||||
action = parameters.GetPasswordsAction()
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
# ensure old passwords used and no new generation
|
||||
self.assertEqual(_EXISTING_PASSWORDS, result)
|
||||
@@ -539,15 +538,14 @@ class GetPasswordsActionTest(base.TestCase):
|
||||
'get_orchestration_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_password_merging_passwords(self, mock_ctx,
|
||||
def test_password_merging_passwords(self,
|
||||
mock_get_workflow_client,
|
||||
mock_get_orchestration_client):
|
||||
|
||||
parameter_defaults = _EXISTING_PASSWORDS.copy()
|
||||
passwords = {"AdminPassword": parameter_defaults.pop("AdminPassword")}
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_mistral = mock.MagicMock()
|
||||
mock_env = mock.MagicMock()
|
||||
mock_env.name = constants.DEFAULT_CONTAINER_NAME
|
||||
@@ -563,7 +561,7 @@ class GetPasswordsActionTest(base.TestCase):
|
||||
mock_get_orchestration_client.return_value = mock_orchestration
|
||||
|
||||
action = parameters.GetPasswordsAction()
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
# ensure old passwords used and no new generation
|
||||
self.assertEqual(_EXISTING_PASSWORDS, result)
|
||||
@@ -581,10 +579,10 @@ class GenerateFencingParametersActionTestCase(base.TestCase):
|
||||
'get_workflow_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_orchestration_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_no_success(self, mock_ctx, mock_get_orchestration,
|
||||
def test_no_success(self, mock_get_orchestration,
|
||||
mock_get_workflow, mock_get_baremetal,
|
||||
mock_get_compute, mock_generate_hostmap):
|
||||
mock_ctx = mock.MagicMock()
|
||||
test_hostmap = {
|
||||
"00:11:22:33:44:55": {
|
||||
"compute_name": "compute_name_0",
|
||||
@@ -643,7 +641,7 @@ class GenerateFencingParametersActionTestCase(base.TestCase):
|
||||
0,
|
||||
True)
|
||||
|
||||
result = action.run()["parameter_defaults"]
|
||||
result = action.run(mock_ctx)["parameter_defaults"]
|
||||
|
||||
self.assertTrue(result["EnableFencing"])
|
||||
self.assertEqual(len(result["FencingConfig"]["devices"]), 2)
|
||||
@@ -687,14 +685,13 @@ class GetFlattenedParametersActionTest(base.TestCase):
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_empty_resource_tree(self, mock_ctx, mock_get_object_client,
|
||||
def test_empty_resource_tree(self, mock_get_object_client,
|
||||
mock_get_workflow_client,
|
||||
mock_get_orchestration_client,
|
||||
mock_get_template_contents,
|
||||
mock_process_multiple_environments_and_files):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
swift = mock.MagicMock(url="http://test.com")
|
||||
swift.get_object.side_effect = swiftexceptions.ClientException(
|
||||
'atest2')
|
||||
@@ -727,7 +724,7 @@ class GetFlattenedParametersActionTest(base.TestCase):
|
||||
|
||||
# Test
|
||||
action = parameters.GetFlattenedParametersAction()
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
mock_heat.stacks.validate.assert_called_once_with(
|
||||
environment={},
|
||||
files={},
|
||||
@@ -745,15 +742,14 @@ class GetFlattenedParametersActionTest(base.TestCase):
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_valid_resource_tree(self, mock_ctx, mock_get_object_client,
|
||||
def test_valid_resource_tree(self, mock_get_object_client,
|
||||
mock_get_workflow_client,
|
||||
mock_get_orchestration_client,
|
||||
mock_get_template_contents,
|
||||
mock_process_multiple_environments_and_files,
|
||||
mock_uuid):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
swift = mock.MagicMock(url="http://test.com")
|
||||
swift.get_object.side_effect = swiftexceptions.ClientException(
|
||||
'atest2')
|
||||
@@ -824,5 +820,5 @@ class GetFlattenedParametersActionTest(base.TestCase):
|
||||
|
||||
# Test
|
||||
action = parameters.GetFlattenedParametersAction()
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
self.assertEqual(result, expected_value)
|
||||
|
@@ -88,6 +88,7 @@ class CreateContainerActionTest(base.TestCase):
|
||||
# A container that name enforces all validation rules
|
||||
self.container_name = 'Test-container-7'
|
||||
self.expected_list = ['', [{'name': 'test1'}, {'name': 'test2'}]]
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
def test_run(self, get_obj_client_mock):
|
||||
@@ -99,7 +100,7 @@ class CreateContainerActionTest(base.TestCase):
|
||||
|
||||
# Test
|
||||
action = plan.CreateContainerAction(self.container_name)
|
||||
action.run()
|
||||
action.run(self.ctx)
|
||||
|
||||
# Verify
|
||||
swift.put_container.assert_called_once_with(
|
||||
@@ -118,7 +119,7 @@ class CreateContainerActionTest(base.TestCase):
|
||||
|
||||
# Test
|
||||
action = plan.CreateContainerAction(self.container_name)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = ('A container with the name %s already'
|
||||
' exists.') % self.container_name
|
||||
@@ -133,7 +134,7 @@ class CreateContainerActionTest(base.TestCase):
|
||||
|
||||
# Test
|
||||
action = plan.CreateContainerAction("invalid_underscore")
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = ("Unable to create plan. The plan name must only contain "
|
||||
"letters, numbers or dashes")
|
||||
@@ -166,10 +167,11 @@ class CreatePlanActionTest(base.TestCase):
|
||||
return_value=self.mistral)
|
||||
mistral_patcher.start()
|
||||
self.addCleanup(mistral_patcher.stop)
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
def test_run_success(self):
|
||||
action = plan.CreatePlanAction(self.container_name)
|
||||
action.run()
|
||||
action.run(self.ctx)
|
||||
|
||||
self.swift.get_object.assert_called_once_with(
|
||||
self.container_name,
|
||||
@@ -185,7 +187,7 @@ class CreatePlanActionTest(base.TestCase):
|
||||
|
||||
def test_run_invalid_plan_name(self):
|
||||
action = plan.CreatePlanAction("invalid_underscore")
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = ("Unable to create plan. The plan name must only contain "
|
||||
"letters, numbers or dashes")
|
||||
@@ -197,7 +199,7 @@ class CreatePlanActionTest(base.TestCase):
|
||||
self.mistral.environments.get.return_value = 'test-env'
|
||||
|
||||
action = plan.CreatePlanAction(self.container_name)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = ("Unable to create plan. The Mistral environment already "
|
||||
"exists")
|
||||
@@ -209,7 +211,7 @@ class CreatePlanActionTest(base.TestCase):
|
||||
self.plan_environment_name)
|
||||
|
||||
action = plan.CreatePlanAction(self.container_name)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = ('File missing from container: %s' %
|
||||
self.plan_environment_name)
|
||||
@@ -219,7 +221,7 @@ class CreatePlanActionTest(base.TestCase):
|
||||
self.swift.get_object.return_value = ({}, YAML_CONTENTS_INVALID)
|
||||
|
||||
action = plan.CreatePlanAction(self.container_name)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = 'Error parsing the yaml file'
|
||||
self.assertEqual(result.error.split(':')[0], error_str)
|
||||
@@ -228,7 +230,7 @@ class CreatePlanActionTest(base.TestCase):
|
||||
self.swift.get_object.return_value = ({}, YAML_CONTENTS_MISSING_KEY)
|
||||
|
||||
action = plan.CreatePlanAction(self.container_name)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = ("%s missing key: environments" %
|
||||
self.plan_environment_name)
|
||||
@@ -258,11 +260,12 @@ class UpdatePlanActionTest(base.TestCase):
|
||||
return_value=self.mistral)
|
||||
mistral_patcher.start()
|
||||
self.addCleanup(mistral_patcher.stop)
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.cache_delete')
|
||||
def test_run_success(self, mock_cache):
|
||||
action = plan.UpdatePlanAction(self.container_name)
|
||||
action.run()
|
||||
action.run(self.ctx)
|
||||
|
||||
self.swift.get_object.assert_called_once_with(
|
||||
self.container_name,
|
||||
@@ -271,6 +274,7 @@ class UpdatePlanActionTest(base.TestCase):
|
||||
|
||||
self.swift.delete_object.assert_called_once()
|
||||
mock_cache.assert_called_once_with(
|
||||
self.ctx,
|
||||
"Test-container-3",
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
@@ -286,13 +290,14 @@ class UpdatePlanActionTest(base.TestCase):
|
||||
mistral_base.APIException)
|
||||
|
||||
action = plan.UpdatePlanAction(self.container_name)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = ("Error updating mistral environment: %s" %
|
||||
self.container_name)
|
||||
self.assertEqual(result.error, error_str)
|
||||
self.swift.delete_object.assert_not_called()
|
||||
mock_cache.assert_called_once_with(
|
||||
self.ctx,
|
||||
"Test-container-3",
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
@@ -302,7 +307,7 @@ class UpdatePlanActionTest(base.TestCase):
|
||||
self.plan_environment_name)
|
||||
|
||||
action = plan.UpdatePlanAction(self.container_name)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = ('File missing from container: %s' %
|
||||
self.plan_environment_name)
|
||||
@@ -312,7 +317,7 @@ class UpdatePlanActionTest(base.TestCase):
|
||||
self.swift.get_object.return_value = ({}, YAML_CONTENTS_INVALID)
|
||||
|
||||
action = plan.UpdatePlanAction(self.container_name)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = 'Error parsing the yaml file'
|
||||
self.assertEqual(result.error.split(':')[0], error_str)
|
||||
@@ -321,7 +326,7 @@ class UpdatePlanActionTest(base.TestCase):
|
||||
self.swift.get_object.return_value = ({}, YAML_CONTENTS_MISSING_KEY)
|
||||
|
||||
action = plan.UpdatePlanAction(self.container_name)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error_str = ("%s missing key: environments" %
|
||||
self.plan_environment_name)
|
||||
@@ -333,6 +338,7 @@ class ListPlansActionTest(base.TestCase):
|
||||
def setUp(self):
|
||||
super(ListPlansActionTest, self).setUp()
|
||||
self.container = 'overcloud'
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch(
|
||||
@@ -362,10 +368,10 @@ class ListPlansActionTest(base.TestCase):
|
||||
|
||||
# Test
|
||||
action = plan.ListPlansAction()
|
||||
action.run()
|
||||
action.run(self.ctx)
|
||||
|
||||
# verify
|
||||
self.assertEqual([self.container], action.run())
|
||||
self.assertEqual([self.container], action.run(self.ctx))
|
||||
swift.get_account.assert_called()
|
||||
swift.get_container.assert_called_with(self.container)
|
||||
|
||||
@@ -380,6 +386,7 @@ class DeletePlanActionTest(base.TestCase):
|
||||
status='CREATE_COMPLETE',
|
||||
stack_name=self.container_name
|
||||
)
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.base.TripleOAction.get_orchestration_client')
|
||||
@@ -392,7 +399,7 @@ class DeletePlanActionTest(base.TestCase):
|
||||
|
||||
# test that stack exists
|
||||
action = plan.DeletePlanAction(self.container_name)
|
||||
self.assertRaises(exception.StackInUseError, action.run)
|
||||
self.assertRaises(exception.StackInUseError, action.run, self.ctx)
|
||||
heat.stacks.get.assert_called_with(self.container_name)
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@@ -436,7 +443,7 @@ class DeletePlanActionTest(base.TestCase):
|
||||
get_orchestration_client.return_value = heat
|
||||
|
||||
action = plan.DeletePlanAction(self.container_name)
|
||||
action.run()
|
||||
action.run(self.ctx)
|
||||
|
||||
mock_calls = [
|
||||
mock.call('overcloud', 'some-name.yaml'),
|
||||
@@ -457,6 +464,7 @@ class RoleListActionTest(base.TestCase):
|
||||
def setUp(self):
|
||||
super(RoleListActionTest, self).setUp()
|
||||
self.container = 'overcloud'
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch(
|
||||
@@ -492,7 +500,7 @@ class RoleListActionTest(base.TestCase):
|
||||
|
||||
# Test
|
||||
action = plan.ListRolesAction()
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
# verify
|
||||
expected = ['Compute', 'Controller']
|
||||
@@ -545,6 +553,7 @@ class ExportPlanActionTest(base.TestCase):
|
||||
return_value=self.mistral)
|
||||
mistral_patcher.start()
|
||||
self.addCleanup(mistral_patcher.stop)
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
@mock.patch('tripleo_common.utils.tarball.create_tarball')
|
||||
@mock.patch('tempfile.mkdtemp')
|
||||
@@ -560,7 +569,7 @@ class ExportPlanActionTest(base.TestCase):
|
||||
|
||||
action = plan.ExportPlanAction(self.plan, self.delete_after,
|
||||
self.exports_container)
|
||||
action.run()
|
||||
action.run(self.ctx)
|
||||
|
||||
self.swift.get_container.assert_has_calls(get_container_mock_calls)
|
||||
self.swift.get_object.assert_has_calls(
|
||||
@@ -575,7 +584,7 @@ class ExportPlanActionTest(base.TestCase):
|
||||
|
||||
action = plan.ExportPlanAction(self.plan, self.delete_after,
|
||||
self.exports_container)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error = "Error attempting an operation on container: %s" % self.plan
|
||||
self.assertIn(error, result.error)
|
||||
@@ -585,7 +594,7 @@ class ExportPlanActionTest(base.TestCase):
|
||||
|
||||
action = plan.ExportPlanAction(self.plan, self.delete_after,
|
||||
self.exports_container)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error = "The Mistral environment %s could not be found." % self.plan
|
||||
self.assertEqual(error, result.error)
|
||||
@@ -596,7 +605,7 @@ class ExportPlanActionTest(base.TestCase):
|
||||
|
||||
action = plan.ExportPlanAction(self.plan, self.delete_after,
|
||||
self.exports_container)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
error = "Error while creating a tarball"
|
||||
self.assertIn(error, result.error)
|
||||
|
@@ -50,8 +50,7 @@ class ScaleDownActionTest(base.TestCase):
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run(self, mock_ctx, mock_get_object_client,
|
||||
def test_run(self, mock_get_object_client,
|
||||
mock_get_workflow_client, mock_get_template_contents,
|
||||
mock_env_files, mock_get_heat_client,
|
||||
mock_cache):
|
||||
@@ -84,7 +83,7 @@ class ScaleDownActionTest(base.TestCase):
|
||||
heatclient.stacks.get.return_value = mock_stack()
|
||||
mock_get_heat_client.return_value = heatclient
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
swift = mock.MagicMock(url="http://test.com")
|
||||
swift.get_object.side_effect = swiftexceptions.ClientException(
|
||||
'atest2')
|
||||
@@ -113,7 +112,7 @@ class ScaleDownActionTest(base.TestCase):
|
||||
# Test
|
||||
action = scale.ScaleDownAction(
|
||||
constants.STACK_TIMEOUT_DEFAULT, ['resource_id'], 'stack')
|
||||
action.run()
|
||||
action.run(mock_ctx)
|
||||
|
||||
heatclient.stacks.update.assert_called_once_with(
|
||||
'stack',
|
||||
@@ -125,6 +124,7 @@ class ScaleDownActionTest(base.TestCase):
|
||||
timeout_mins=240)
|
||||
|
||||
mock_cache.assert_called_once_with(
|
||||
mock_ctx,
|
||||
"stack",
|
||||
"tripleo.parameters.get"
|
||||
)
|
||||
|
@@ -22,10 +22,9 @@ class SwiftTempUrlActionTest(base.TestCase):
|
||||
@mock.patch('time.time')
|
||||
@mock.patch('uuid.uuid4')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def _test_get_tempurl(self, secret, mock_ctx, mock_get_object_client,
|
||||
def _test_get_tempurl(self, secret, mock_get_object_client,
|
||||
mock_uuid, mock_time):
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
|
||||
url = "http://swift:8080/v1/AUTH_test"
|
||||
swiftclient = mock.MagicMock(url=url)
|
||||
@@ -39,7 +38,7 @@ class SwiftTempUrlActionTest(base.TestCase):
|
||||
mock_time.return_value = 1500000000
|
||||
|
||||
action = swifthelper.SwiftTempUrlAction("container", "obj")
|
||||
tempurl = action.run()
|
||||
tempurl = action.run(mock_ctx)
|
||||
|
||||
expected = "%s/container/obj?temp_url_sig=%s&temp_url_expires=%d" % (
|
||||
url, "ea8fdc57e2b2b1fbb7210bddd40029a7c8d5e2ed", 1500086400)
|
||||
|
@@ -108,11 +108,11 @@ class UploadTemplatesActionTest(base.TestCase):
|
||||
@mock.patch('tripleo_common.utils.tarball.create_tarball')
|
||||
def test_run(self, mock_create_tar, mock_extract_tar, mock_get_swift,
|
||||
tempfile):
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
tempfile.return_value.__enter__.return_value.name = "test"
|
||||
|
||||
action = templates.UploadTemplatesAction(container='tar-container')
|
||||
action.run()
|
||||
action.run(mock_ctx)
|
||||
|
||||
mock_create_tar.assert_called_once_with(
|
||||
constants.DEFAULT_TEMPLATES_PATH, 'test')
|
||||
@@ -191,12 +191,11 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||
'get_workflow_client')
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run(self, mock_ctx, mock_get_object_client,
|
||||
def test_run(self, mock_get_object_client,
|
||||
mock_get_workflow_client, mock_get_template_contents,
|
||||
mock_process_multiple_environments_and_files):
|
||||
|
||||
mock_ctx.return_value = mock.MagicMock()
|
||||
mock_ctx = mock.MagicMock()
|
||||
swift = mock.MagicMock(url="http://test.com")
|
||||
swift.get_object.side_effect = swiftexceptions.ClientException(
|
||||
'atest2')
|
||||
@@ -219,7 +218,7 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
|
||||
# Test
|
||||
action = templates.ProcessTemplatesAction()
|
||||
result = action.run()
|
||||
result = action.run(mock_ctx)
|
||||
|
||||
# Verify the values we get out
|
||||
self.assertEqual(result, {
|
||||
@@ -232,8 +231,7 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
})
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_process_custom_roles(self, ctx_mock, get_obj_client_mock):
|
||||
def test_process_custom_roles(self, get_obj_client_mock):
|
||||
|
||||
def return_multiple_files(*args):
|
||||
if args[1] == constants.OVERCLOUD_J2_NAME:
|
||||
@@ -254,6 +252,7 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
{'name': constants.OVERCLOUD_J2_ROLES_NAME},
|
||||
{'name': constants.OVERCLOUD_J2_NETWORKS_NAME}])
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
# setup swift
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object = mock.MagicMock(side_effect=return_multiple_files)
|
||||
@@ -263,7 +262,7 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
|
||||
# Test
|
||||
action = templates.ProcessTemplatesAction()
|
||||
action._process_custom_roles()
|
||||
action._process_custom_roles(mock_ctx)
|
||||
|
||||
get_object_mock_calls = [
|
||||
mock.call('overcloud', constants.OVERCLOUD_J2_NAME),
|
||||
@@ -285,9 +284,8 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
put_object_mock_calls, any_order=True)
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_process_custom_roles_disable_constraints(
|
||||
self, ctx_mock, get_obj_client_mock):
|
||||
self, get_obj_client_mock):
|
||||
|
||||
def return_multiple_files(*args):
|
||||
if args[1] == constants.OVERCLOUD_J2_NAME:
|
||||
@@ -308,6 +306,7 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
{'name': constants.OVERCLOUD_J2_ROLES_NAME},
|
||||
{'name': constants.OVERCLOUD_J2_NETWORKS_NAME}])
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
# setup swift
|
||||
swift = mock.MagicMock()
|
||||
swift.get_object = mock.MagicMock(side_effect=return_multiple_files)
|
||||
@@ -317,7 +316,7 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
|
||||
# Test
|
||||
action = templates.ProcessTemplatesAction()
|
||||
action._process_custom_roles()
|
||||
action._process_custom_roles(mock_ctx)
|
||||
|
||||
put_object_mock_call = mock.call(
|
||||
constants.DEFAULT_CONTAINER_NAME,
|
||||
@@ -327,8 +326,7 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
put_object_mock_call)
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_j2_render_and_put(self, ctx_mock, get_obj_client_mock):
|
||||
def test_j2_render_and_put(self, get_obj_client_mock):
|
||||
|
||||
# setup swift
|
||||
swift = mock.MagicMock()
|
||||
@@ -347,8 +345,7 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
self.assertTrue("CustomRole" in str(action_result))
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_j2_render_and_put_include(self, ctx_mock, get_obj_client_mock):
|
||||
def test_j2_render_and_put_include(self, get_obj_client_mock):
|
||||
|
||||
def return_multiple_files(*args):
|
||||
if args[1] == 'foo.yaml':
|
||||
@@ -375,10 +372,8 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
self.assertTrue("CustomRole" in str(action_result))
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_j2_render_and_put_include_relative(
|
||||
self,
|
||||
ctx_mock,
|
||||
get_obj_client_mock):
|
||||
|
||||
def return_multiple_files(*args):
|
||||
@@ -406,9 +401,9 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
self.assertTrue("CustomRole" in str(action_result))
|
||||
|
||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_get_j2_excludes_file(self, ctx_mock, get_obj_client_mock):
|
||||
def test_get_j2_excludes_file(self, get_obj_client_mock):
|
||||
|
||||
mock_ctx = mock.MagicMock()
|
||||
swift = mock.MagicMock()
|
||||
get_obj_client_mock.return_value = swift
|
||||
|
||||
@@ -419,7 +414,7 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
# Test - J2 exclude file with valid templates
|
||||
action = templates.ProcessTemplatesAction()
|
||||
self.assertTrue({'name': ['puppet/controller-role.yaml']} ==
|
||||
action._get_j2_excludes_file())
|
||||
action._get_j2_excludes_file(mock_ctx))
|
||||
|
||||
def return_multiple_files(*args):
|
||||
if args[1] == constants.OVERCLOUD_J2_EXCLUDES:
|
||||
@@ -427,7 +422,7 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
swift.get_object = mock.MagicMock(side_effect=return_multiple_files)
|
||||
# Test - J2 exclude file with no template to exlude
|
||||
action = templates.ProcessTemplatesAction()
|
||||
self.assertTrue({'name': []} == action._get_j2_excludes_file())
|
||||
self.assertTrue({'name': []} == action._get_j2_excludes_file(mock_ctx))
|
||||
|
||||
def return_multiple_files(*args):
|
||||
if args[1] == constants.OVERCLOUD_J2_EXCLUDES:
|
||||
@@ -435,4 +430,4 @@ class ProcessTemplatesActionTest(base.TestCase):
|
||||
swift.get_object = mock.MagicMock(side_effect=return_multiple_files)
|
||||
# Test - J2 exclude file empty
|
||||
action = templates.ProcessTemplatesAction()
|
||||
self.assertTrue({'name': []} == action._get_j2_excludes_file())
|
||||
self.assertTrue({'name': []} == action._get_j2_excludes_file(mock_ctx))
|
||||
|
@@ -31,6 +31,7 @@ class GetPubkeyActionTest(base.TestCase):
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.base.TripleOAction.get_workflow_client')
|
||||
def test_run_existing_pubkey(self, get_workflow_client_mock):
|
||||
mock_ctx = mock.MagicMock()
|
||||
mistral = mock.MagicMock()
|
||||
get_workflow_client_mock.return_value = mistral
|
||||
environment = collections.namedtuple('environment', ['variables'])
|
||||
@@ -38,13 +39,14 @@ class GetPubkeyActionTest(base.TestCase):
|
||||
'public_key': 'existing_pubkey'
|
||||
})
|
||||
action = validations.GetPubkeyAction()
|
||||
self.assertEqual('existing_pubkey', action.run())
|
||||
self.assertEqual('existing_pubkey', action.run(mock_ctx))
|
||||
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.base.TripleOAction.get_workflow_client')
|
||||
@mock.patch('tripleo_common.utils.passwords.create_ssh_keypair')
|
||||
def test_run_no_pubkey(self, mock_create_keypair,
|
||||
get_workflow_client_mock):
|
||||
mock_ctx = mock.MagicMock()
|
||||
mistral = mock.MagicMock()
|
||||
get_workflow_client_mock.return_value = mistral
|
||||
mistral.environments.get.side_effect = 'nope, sorry'
|
||||
@@ -54,7 +56,7 @@ class GetPubkeyActionTest(base.TestCase):
|
||||
}
|
||||
|
||||
action = validations.GetPubkeyAction()
|
||||
self.assertEqual('public_key', action.run())
|
||||
self.assertEqual('public_key', action.run(mock_ctx))
|
||||
|
||||
|
||||
class Enabled(base.TestCase):
|
||||
@@ -62,21 +64,23 @@ class Enabled(base.TestCase):
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.base.TripleOAction.get_workflow_client')
|
||||
def test_validations_enabled(self, get_workflow_client_mock):
|
||||
mock_ctx = mock.MagicMock()
|
||||
mistral = mock.MagicMock()
|
||||
get_workflow_client_mock.return_value = mistral
|
||||
mistral.environments.get.return_value = {}
|
||||
action = validations.Enabled()
|
||||
result = action._validations_enabled()
|
||||
result = action._validations_enabled(mock_ctx)
|
||||
self.assertEqual(result, True)
|
||||
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.base.TripleOAction.get_workflow_client')
|
||||
def test_validations_disabled(self, get_workflow_client_mock):
|
||||
mock_ctx = mock.MagicMock()
|
||||
mistral = mock.MagicMock()
|
||||
get_workflow_client_mock.return_value = mistral
|
||||
mistral.environments.get.side_effect = Exception()
|
||||
action = validations.Enabled()
|
||||
result = action._validations_enabled()
|
||||
result = action._validations_enabled(mock_ctx)
|
||||
self.assertEqual(result, False)
|
||||
|
||||
@mock.patch(
|
||||
@@ -85,9 +89,10 @@ class Enabled(base.TestCase):
|
||||
'tripleo_common.actions.base.TripleOAction.get_workflow_client')
|
||||
def test_success_with_validations_enabled(self, get_workflow_client_mock,
|
||||
validations_enabled_mock):
|
||||
mock_ctx = mock.MagicMock()
|
||||
validations_enabled_mock.return_value = True
|
||||
action = validations.Enabled()
|
||||
action_result = action.run()
|
||||
action_result = action.run(mock_ctx)
|
||||
self.assertEqual(None, action_result.error)
|
||||
self.assertEqual('Validations are enabled',
|
||||
action_result.data['stdout'])
|
||||
@@ -98,9 +103,10 @@ class Enabled(base.TestCase):
|
||||
'tripleo_common.actions.base.TripleOAction.get_workflow_client')
|
||||
def test_success_with_validations_disabled(self, get_workflow_client_mock,
|
||||
validations_enabled_mock):
|
||||
mock_ctx = mock.MagicMock()
|
||||
validations_enabled_mock.return_value = False
|
||||
action = validations.Enabled()
|
||||
action_result = action.run()
|
||||
action_result = action.run(mock_ctx)
|
||||
self.assertEqual(None, action_result.data)
|
||||
self.assertEqual('Validations are disabled',
|
||||
action_result.error['stdout'])
|
||||
@@ -110,17 +116,19 @@ class ListValidationsActionTest(base.TestCase):
|
||||
|
||||
@mock.patch('tripleo_common.utils.validations.load_validations')
|
||||
def test_run_default(self, mock_load_validations):
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_load_validations.return_value = 'list of validations'
|
||||
action = validations.ListValidationsAction()
|
||||
self.assertEqual('list of validations', action.run())
|
||||
self.assertEqual('list of validations', action.run(mock_ctx))
|
||||
mock_load_validations.assert_called_once_with(groups=None)
|
||||
|
||||
@mock.patch('tripleo_common.utils.validations.load_validations')
|
||||
def test_run_groups(self, mock_load_validations):
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_load_validations.return_value = 'list of validations'
|
||||
action = validations.ListValidationsAction(groups=['group1',
|
||||
'group2'])
|
||||
self.assertEqual('list of validations', action.run())
|
||||
self.assertEqual('list of validations', action.run(mock_ctx))
|
||||
mock_load_validations.assert_called_once_with(groups=['group1',
|
||||
'group2'])
|
||||
|
||||
@@ -129,12 +137,13 @@ class ListGroupsActionTest(base.TestCase):
|
||||
|
||||
@mock.patch('tripleo_common.utils.validations.load_validations')
|
||||
def test_run(self, mock_load_validations):
|
||||
mock_ctx = mock.MagicMock()
|
||||
mock_load_validations.return_value = [
|
||||
test_validations.VALIDATION_GROUPS_1_2_PARSED,
|
||||
test_validations.VALIDATION_GROUP_1_PARSED,
|
||||
test_validations.VALIDATION_WITH_METADATA_PARSED]
|
||||
action = validations.ListGroupsAction()
|
||||
self.assertEqual(set(['group1', 'group2']), action.run())
|
||||
self.assertEqual(set(['group1', 'group2']), action.run(mock_ctx))
|
||||
mock_load_validations.assert_called_once_with()
|
||||
|
||||
|
||||
@@ -147,6 +156,7 @@ class RunValidationActionTest(base.TestCase):
|
||||
@mock.patch('tripleo_common.utils.validations.run_validation')
|
||||
def test_run(self, mock_run_validation, mock_cleanup_identity_file,
|
||||
mock_write_identity_file, get_workflow_client_mock):
|
||||
mock_ctx = mock.MagicMock()
|
||||
mistral = mock.MagicMock()
|
||||
get_workflow_client_mock.return_value = mistral
|
||||
environment = collections.namedtuple('environment', ['variables'])
|
||||
@@ -162,12 +172,13 @@ class RunValidationActionTest(base.TestCase):
|
||||
'stderr': 'error'
|
||||
},
|
||||
error=None)
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(mock_ctx))
|
||||
mock_write_identity_file.assert_called_once_with('shhhh')
|
||||
mock_run_validation.assert_called_once_with(
|
||||
'validation',
|
||||
'identity_file_path',
|
||||
constants.DEFAULT_CONTAINER_NAME)
|
||||
constants.DEFAULT_CONTAINER_NAME,
|
||||
mock_ctx)
|
||||
mock_cleanup_identity_file.assert_called_once_with(
|
||||
'identity_file_path')
|
||||
|
||||
@@ -178,6 +189,7 @@ class RunValidationActionTest(base.TestCase):
|
||||
@mock.patch('tripleo_common.utils.validations.run_validation')
|
||||
def test_run_failing(self, mock_run_validation, mock_cleanup_identity_file,
|
||||
mock_write_identity_file, get_workflow_client_mock):
|
||||
mock_ctx = mock.MagicMock()
|
||||
mistral = mock.MagicMock()
|
||||
get_workflow_client_mock.return_value = mistral
|
||||
environment = collections.namedtuple('environment', ['variables'])
|
||||
@@ -194,12 +206,13 @@ class RunValidationActionTest(base.TestCase):
|
||||
'stdout': 'output',
|
||||
'stderr': 'error'
|
||||
})
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(mock_ctx))
|
||||
mock_write_identity_file.assert_called_once_with('shhhh')
|
||||
mock_run_validation.assert_called_once_with(
|
||||
'validation',
|
||||
'identity_file_path',
|
||||
constants.DEFAULT_CONTAINER_NAME)
|
||||
constants.DEFAULT_CONTAINER_NAME,
|
||||
mock_ctx)
|
||||
mock_cleanup_identity_file.assert_called_once_with(
|
||||
'identity_file_path')
|
||||
|
||||
@@ -211,6 +224,7 @@ class TestCheckBootImagesAction(base.TestCase):
|
||||
{'id': '67890', 'name': 'ramdisk'},
|
||||
{'id': '12345', 'name': 'kernel'},
|
||||
]
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
@mock.patch(
|
||||
'tripleo_common.actions.validations.CheckBootImagesAction'
|
||||
@@ -229,7 +243,7 @@ class TestCheckBootImagesAction(base.TestCase):
|
||||
'deploy_ramdisk_name': 'ramdisk'
|
||||
}
|
||||
action = validations.CheckBootImagesAction(**action_args)
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(self.ctx))
|
||||
mock_check_for_image.assert_has_calls([
|
||||
mock.call('kernel', []),
|
||||
mock.call('ramdisk', [])
|
||||
@@ -320,6 +334,7 @@ class TestCheckFlavorsAction(base.TestCase):
|
||||
]
|
||||
self.mock_flavors.attach_mock(
|
||||
mock.Mock(return_value=self.mock_flavor_list), 'list')
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
def test_run_success(self):
|
||||
roles_info = {
|
||||
@@ -344,7 +359,7 @@ class TestCheckFlavorsAction(base.TestCase):
|
||||
'roles_info': roles_info
|
||||
}
|
||||
action = validations.CheckFlavorsAction(**action_args)
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(self.ctx))
|
||||
|
||||
def test_run_boot_option_is_netboot(self):
|
||||
roles_info = {
|
||||
@@ -381,7 +396,7 @@ class TestCheckFlavorsAction(base.TestCase):
|
||||
'roles_info': roles_info
|
||||
}
|
||||
action = validations.CheckFlavorsAction(**action_args)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_run_flavor_does_not_exist(self):
|
||||
@@ -404,7 +419,7 @@ class TestCheckFlavorsAction(base.TestCase):
|
||||
'roles_info': roles_info
|
||||
}
|
||||
action = validations.CheckFlavorsAction(**action_args)
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(self.ctx))
|
||||
|
||||
|
||||
class TestCheckNodeBootConfigurationAction(base.TestCase):
|
||||
@@ -422,6 +437,7 @@ class TestCheckNodeBootConfigurationAction(base.TestCase):
|
||||
'capabilities': 'boot_option:local',
|
||||
}
|
||||
}
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
def test_run_success(self):
|
||||
expected = mistral_workflow_utils.Result(
|
||||
@@ -434,7 +450,7 @@ class TestCheckNodeBootConfigurationAction(base.TestCase):
|
||||
'ramdisk_id': self.ramdisk_id,
|
||||
}
|
||||
action = validations.CheckNodeBootConfigurationAction(**action_args)
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(self.ctx))
|
||||
|
||||
def test_run_invalid_ramdisk(self):
|
||||
expected = mistral_workflow_utils.Result(
|
||||
@@ -454,7 +470,7 @@ class TestCheckNodeBootConfigurationAction(base.TestCase):
|
||||
'ramdisk_id': self.ramdisk_id,
|
||||
}
|
||||
action = validations.CheckNodeBootConfigurationAction(**action_args)
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(self.ctx))
|
||||
|
||||
def test_no_boot_option_local(self):
|
||||
expected = mistral_workflow_utils.Result(
|
||||
@@ -479,7 +495,7 @@ class TestCheckNodeBootConfigurationAction(base.TestCase):
|
||||
}
|
||||
|
||||
action = validations.CheckNodeBootConfigurationAction(**action_args)
|
||||
self.assertEqual(expected, action.run())
|
||||
self.assertEqual(expected, action.run(self.ctx))
|
||||
|
||||
|
||||
class TestVerifyProfilesAction(base.TestCase):
|
||||
@@ -489,6 +505,7 @@ class TestVerifyProfilesAction(base.TestCase):
|
||||
self.nodes = []
|
||||
self.flavors = {name: (self._get_fake_flavor(name), 1)
|
||||
for name in ('compute', 'control')}
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
def _get_fake_node(self, profile=None, possible_profiles=[],
|
||||
provision_state='available'):
|
||||
@@ -516,7 +533,7 @@ class TestVerifyProfilesAction(base.TestCase):
|
||||
|
||||
def _test(self, expected_result):
|
||||
action = validations.VerifyProfilesAction(self.nodes, self.flavors)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
@@ -594,7 +611,7 @@ class TestVerifyProfilesAction(base.TestCase):
|
||||
'warnings': []})
|
||||
|
||||
action = validations.VerifyProfilesAction(self.nodes, self.flavors)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
self.assertEqual(expected.error['errors'].sort(),
|
||||
result.error['errors'].sort())
|
||||
self.assertEqual(expected.error['warnings'], result.error['warnings'])
|
||||
@@ -656,7 +673,7 @@ class TestVerifyProfilesAction(base.TestCase):
|
||||
})
|
||||
|
||||
action = validations.VerifyProfilesAction(self.nodes, self.flavors)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
self.assertEqual(expected.error['errors'].sort(),
|
||||
result.error['errors'].sort())
|
||||
self.assertEqual(expected.error['warnings'], result.error['warnings'])
|
||||
@@ -702,6 +719,7 @@ class TestCheckNodesCountAction(base.TestCase):
|
||||
'default_role_counts': self.defaults,
|
||||
'statistics': {'count': 3, 'memory_mb': 1, 'vcpus': 1},
|
||||
}
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
def _ironic_node_list(self, associated, maintenance):
|
||||
if associated:
|
||||
@@ -714,7 +732,7 @@ class TestCheckNodesCountAction(base.TestCase):
|
||||
action_args = self.action_args.copy()
|
||||
|
||||
action = validations.CheckNodesCountAction(**action_args)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
expected = mistral_workflow_utils.Result(
|
||||
data={
|
||||
@@ -736,7 +754,7 @@ class TestCheckNodesCountAction(base.TestCase):
|
||||
action_args.update({'statistics': statistics})
|
||||
|
||||
action = validations.CheckNodesCountAction(**action_args)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
expected = mistral_workflow_utils.Result(
|
||||
error={
|
||||
@@ -759,7 +777,7 @@ class TestCheckNodesCountAction(base.TestCase):
|
||||
action_args['parameters'] = {'ControllerCount': 2}
|
||||
|
||||
action = validations.CheckNodesCountAction(**action_args)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
expected = mistral_workflow_utils.Result(
|
||||
data={
|
||||
@@ -779,7 +797,7 @@ class TestCheckNodesCountAction(base.TestCase):
|
||||
action_args['parameters'] = {'ControllerCount': 3}
|
||||
|
||||
action = validations.CheckNodesCountAction(**action_args)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
expected = mistral_workflow_utils.Result(
|
||||
error={
|
||||
@@ -801,7 +819,7 @@ class TestCheckNodesCountAction(base.TestCase):
|
||||
action_args['stack'] = {'parameters': self.defaults.copy()}
|
||||
|
||||
action = validations.CheckNodesCountAction(**action_args)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
expected = mistral_workflow_utils.Result(
|
||||
data={
|
||||
@@ -822,7 +840,7 @@ class TestCheckNodesCountAction(base.TestCase):
|
||||
action_args['stack'] = {'parameters': self.defaults.copy()}
|
||||
|
||||
action = validations.CheckNodesCountAction(**action_args)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
expected = mistral_workflow_utils.Result(
|
||||
error={
|
||||
@@ -846,7 +864,7 @@ class TestCheckNodesCountAction(base.TestCase):
|
||||
del action_args['stack']['parameters'][missing_param]
|
||||
|
||||
action = validations.CheckNodesCountAction(**action_args)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
expected = mistral_workflow_utils.Result(
|
||||
error={
|
||||
|
@@ -34,6 +34,7 @@ class GitCloneActionTest(base.TestCase):
|
||||
self.git_url = "https://github.com/openstack/tripleo-common.git"
|
||||
self.tag_ref = "some.test.ref"
|
||||
self.container = "overcloudtest"
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
@mock.patch('tempfile.mkdtemp')
|
||||
@mock.patch('git.Repo.clone_from')
|
||||
@@ -41,7 +42,7 @@ class GitCloneActionTest(base.TestCase):
|
||||
|
||||
mock_mkdtemp.return_value = self.temp_url
|
||||
action = vcs.GitCloneAction(self.container, self.git_url)
|
||||
action.run()
|
||||
action.run(self.ctx)
|
||||
|
||||
mock_mkdtemp.assert_called()
|
||||
mock_repo_clone.assert_called_with(self.git_url, self.temp_url)
|
||||
@@ -53,7 +54,7 @@ class GitCloneActionTest(base.TestCase):
|
||||
mock_mkdtemp.return_value = self.temp_url
|
||||
mock_repo_clone.side_effect = git.exc.GitCommandError
|
||||
action = vcs.GitCloneAction(self.container, self.git_url)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
expected = mistral_workflow_utils.Result(
|
||||
error="Error cloning remote repository: %s " % self.git_url
|
||||
@@ -76,7 +77,7 @@ class GitCloneActionTest(base.TestCase):
|
||||
self.container,
|
||||
"{url}@{tag}".format(url=self.git_url, tag=self.tag_ref)
|
||||
)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
err_msg = ("Error finding %s reference from remote repository" %
|
||||
self.tag_ref)
|
||||
@@ -101,7 +102,7 @@ class GitCloneActionTest(base.TestCase):
|
||||
self.container,
|
||||
"{url}@{tag}".format(url=self.git_url, tag=self.tag_ref)
|
||||
)
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
|
||||
err_msg = ("Error checking out %s reference from remote "
|
||||
"repository %s" % (self.tag_ref, self.git_url))
|
||||
@@ -121,6 +122,7 @@ class GitCleanupActionTest(base.TestCase):
|
||||
self.container = "overcloud"
|
||||
self.temp_test_dir = tempfile.mkdtemp(
|
||||
suffix="_%s_import" % self.container)
|
||||
self.ctx = mock.MagicMock()
|
||||
|
||||
def tearDown(self):
|
||||
super(GitCleanupActionTest, self).tearDown()
|
||||
@@ -129,10 +131,10 @@ class GitCleanupActionTest(base.TestCase):
|
||||
|
||||
def test_run(self):
|
||||
action = vcs.GitCleanupAction(self.container)
|
||||
action.run()
|
||||
action.run(self.ctx)
|
||||
self.assertFalse(os.path.exists(self.temp_test_dir))
|
||||
|
||||
def test_run_with_error(self):
|
||||
action = vcs.GitCleanupAction(str(uuid.uuid4()))
|
||||
result = action.run()
|
||||
result = action.run(self.ctx)
|
||||
self.assertIn("list index", str(result.error))
|
||||
|
@@ -174,11 +174,10 @@ class RunValidationTest(base.TestCase):
|
||||
|
||||
@mock.patch('tripleo_common.utils.validations.find_validation')
|
||||
@mock.patch('oslo_concurrency.processutils.execute')
|
||||
@mock.patch('mistral.context.ctx')
|
||||
def test_run_validation(self, mock_ctx, mock_execute,
|
||||
def test_run_validation(self, mock_execute,
|
||||
mock_find_validation):
|
||||
Ctx = namedtuple('Ctx', 'auth_uri user_name auth_token project_name')
|
||||
mock_ctx.return_value = Ctx(
|
||||
mock_ctx = Ctx(
|
||||
auth_uri='auth_uri',
|
||||
user_name='user_name',
|
||||
auth_token='auth_token',
|
||||
@@ -188,7 +187,7 @@ class RunValidationTest(base.TestCase):
|
||||
mock_find_validation.return_value = 'validation_path'
|
||||
|
||||
result = validations.run_validation('validation', 'identity_file',
|
||||
'plan')
|
||||
'plan', mock_ctx)
|
||||
self.assertEqual('output', result)
|
||||
mock_execute.assert_called_once_with(
|
||||
'/usr/bin/sudo', '-u', 'validations',
|
||||
|
@@ -19,7 +19,6 @@ import re
|
||||
import tempfile
|
||||
import yaml
|
||||
|
||||
from mistral import context
|
||||
from oslo_concurrency import processutils
|
||||
|
||||
from tripleo_common import constants
|
||||
@@ -78,14 +77,13 @@ def find_validation(validation):
|
||||
return '{}/{}.yaml'.format(constants.DEFAULT_VALIDATIONS_PATH, validation)
|
||||
|
||||
|
||||
def run_validation(validation, identity_file, plan):
|
||||
ctx = context.ctx()
|
||||
def run_validation(validation, identity_file, plan, context):
|
||||
return processutils.execute(
|
||||
'/usr/bin/sudo', '-u', 'validations',
|
||||
'OS_AUTH_URL={}'.format(ctx.auth_uri),
|
||||
'OS_USERNAME={}'.format(ctx.user_name),
|
||||
'OS_AUTH_TOKEN={}'.format(ctx.auth_token),
|
||||
'OS_TENANT_NAME={}'.format(ctx.project_name),
|
||||
'OS_AUTH_URL={}'.format(context.auth_uri),
|
||||
'OS_USERNAME={}'.format(context.user_name),
|
||||
'OS_AUTH_TOKEN={}'.format(context.auth_token),
|
||||
'OS_TENANT_NAME={}'.format(context.project_name),
|
||||
'/usr/bin/run-validation',
|
||||
find_validation(validation),
|
||||
identity_file,
|
||||
|
Reference in New Issue
Block a user