Adds Plan List Action

This patch adds a mistral action for retrieving a list of tripleo
deployment plans.  A tripleo deployment plan consists of a container
and a mistral environment with the same name.

Change-Id: Ie2d1109d4ca6c04a5e06246e753006a7331041ea
Implements: blueprint plan-list-action
This commit is contained in:
Ryan Brady
2016-03-31 17:25:18 -04:00
parent e7377aaeb1
commit 1e963236c2
3 changed files with 81 additions and 0 deletions

View File

@@ -58,6 +58,7 @@ mistral.actions =
tripleo.create_container = tripleo_common.actions.plan:CreateContainerAction
tripleo.create_plan = tripleo_common.actions.plan:CreatePlanAction
tripleo.deploy_config = tripleo_common.actions.deployment:OrchestrationDeployAction
tripleo.list_plans = tripleo_common.actions.plan:ListPlansAction
tripleo.get_capabilities = tripleo_common.actions.heat_capabilities:GetCapabilitiesAction
tripleo.update_capabilities = tripleo_common.actions.heat_capabilities:UpdateCapabilitiesAction
tripleo.register_or_update_nodes = tripleo_common.actions.baremetal:RegisterOrUpdateNodes

View File

@@ -30,6 +30,11 @@ default_container_headers = {
class CreateContainerAction(base.TripleOAction):
"""Creates an object container
This action creates an object container for a given name. If a container
with the same name already exists an exception is raised.
"""
def __init__(self, container):
super(CreateContainerAction, self).__init__()
@@ -50,6 +55,12 @@ class CreateContainerAction(base.TripleOAction):
class CreatePlanAction(base.TripleOAction):
"""Creates a plan
Given a container, creates a Mistral environment with the same name,
parses the capabilities map file and sets initial plan template and
environment files.
"""
def __init__(self, container):
super(CreatePlanAction, self).__init__()
@@ -88,3 +99,30 @@ class CreatePlanAction(base.TripleOAction):
if error_text:
return mistral_workflow_utils.Result(error=error_text)
class ListPlansAction(base.TripleOAction):
"""Lists deployment plans
This action lists all deployment plans residing in the undercloud. A
deployment plan consists of a container marked with metadata
'x-container-meta-usage-tripleo' and a mistral environment with the same
name as the container.
"""
def __init__(self):
super(ListPlansAction, self).__init__()
def run(self):
# 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()
for item in oc.get_account()[1]:
container = oc.get_container(item['name'])[0]
if constants.TRIPLEO_META_USAGE_KEY in container.keys():
plan_list.append(item['name'])
return list(set(plan_list).intersection(
[env.name for env in mc.environments.list()]))

View File

@@ -206,3 +206,45 @@ class CreatePlanActionTest(base.TestCase):
error_str = "capabilities-map.yaml missing key: 'root_template'"
self.assertEqual(result.error, error_str)
class ListPlansActionTest(base.TestCase):
def setUp(self):
super(ListPlansActionTest, self).setUp()
self.container = 'overcloud'
@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):
# setup swift
swift = mock.MagicMock()
swift.get_account.return_value = ({}, [
{
'count': 1,
'bytes': 55,
'name': 'overcloud'
},
])
swift.get_container.return_value = ({
'x-container-meta-usage-tripleo': 'plan',
}, [])
get_obj_client_mock.return_value = swift
# setup mistral
mistral = mock.MagicMock()
env_item = mock.Mock()
env_item.name = self.container
mistral.environments.list.return_value = [env_item]
get_workflow_client_mock.return_value = mistral
# Test
action = plan.ListPlansAction()
action.run()
# verify
self.assertEqual([self.container], action.run())
swift.get_account.assert_called()
swift.get_container.assert_called_with(self.container)