Allows fetching of deployments from all environments.
Murano Dashboard uses Murano Client to fetch data from Murano. In order to improve log browsing for deployments in Murano Dashboard, which requires showing all deployments for all environments, the deployments API had to be changed to support this. Includes client support for OSC as well as old murano client. Change-Id: I80c02a8cfd82260f097474bb512f693aa6734655 Partially-implements: blueprint improve-deployment-log-browsing Depends-On: I1b6a313af1a0c4aa57bd4e6f51da92b396b35165
This commit is contained in:
parent
40075056ef
commit
792ce5249e
|
@ -16,6 +16,8 @@ from osc_lib.command import command
|
|||
from osc_lib import utils
|
||||
from oslo_log import log as logging
|
||||
|
||||
from muranoclient.apiclient import exceptions
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -27,8 +29,16 @@ class ListDeployment(command.Lister):
|
|||
parser.add_argument(
|
||||
"id",
|
||||
metavar="<ID>",
|
||||
nargs="?",
|
||||
default=None,
|
||||
help=("Environment ID for which to list deployments."),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--all-environments",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="List all deployments for all environments in user's tenant."
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
@ -36,9 +46,22 @@ class ListDeployment(command.Lister):
|
|||
LOG.debug("take_action({0})".format(parsed_args))
|
||||
client = self.app.client_manager.application_catalog
|
||||
|
||||
environment = utils.find_resource(client.environments,
|
||||
parsed_args.id)
|
||||
data = client.deployments.list(environment.id)
|
||||
all_environments = getattr(parsed_args, 'all_environments', False)
|
||||
env_id = getattr(parsed_args, 'id', None)
|
||||
|
||||
if env_id and all_environments:
|
||||
raise exceptions.CommandError(
|
||||
'Environment ID and all-environments flag cannot both be set.')
|
||||
elif not env_id and not all_environments:
|
||||
raise exceptions.CommandError(
|
||||
'Either environment ID or all-environments flag must be set.')
|
||||
|
||||
if all_environments:
|
||||
data = client.deployments.list(None, all_environments)
|
||||
else:
|
||||
environment = utils.find_resource(client.environments,
|
||||
env_id)
|
||||
data = client.deployments.list(environment.id)
|
||||
|
||||
columns = ('id', 'state', 'created', 'updated', 'finished')
|
||||
column_headers = [c.capitalize() for c in columns]
|
||||
|
|
|
@ -19,6 +19,10 @@ from muranoclient.v1 import deployments as api_deployment
|
|||
DEPLOYMENT_COLUMNS = ('id', 'state', 'created', 'updated', 'finished')
|
||||
DEPLOYMENT_DATA = ('xyz123', 'success', '2016-06-25T12:21:37',
|
||||
'2016-06-25T12:21:47', '2016-06-25T12:21:47')
|
||||
ALL_DEPLOYMENT_DATA = (('abc123', 'success', '2016-06-25T12:21:37',
|
||||
'2016-06-25T12:21:47', '2016-06-25T12:21:47'),
|
||||
('xyz456', 'success', '2017-01-31T11:22:35',
|
||||
'2017-01-31T11:22:47', '2017-01-31T11:22:47'))
|
||||
|
||||
|
||||
class TestDeployment(fakes.TestApplicationCatalog):
|
||||
|
@ -42,7 +46,7 @@ class TestListDeployment(TestDeployment):
|
|||
self.cmd = osc_deployment.ListDeployment(self.app, None)
|
||||
|
||||
@mock.patch('osc_lib.utils.get_item_properties')
|
||||
def test_category_list(self, mock_util):
|
||||
def test_deployment_list(self, mock_util):
|
||||
arglist = ['xyz123']
|
||||
verifylist = [('id', 'xyz123')]
|
||||
mock_util.return_value = DEPLOYMENT_DATA
|
||||
|
@ -58,3 +62,21 @@ class TestListDeployment(TestDeployment):
|
|||
# Check that data is correct
|
||||
expected_data = [DEPLOYMENT_DATA]
|
||||
self.assertEqual(expected_data, data)
|
||||
|
||||
@mock.patch('osc_lib.utils.get_item_properties', autospec=True)
|
||||
def test_deployment_list_all_environments(self, mock_util):
|
||||
arglist = ['--all-environments']
|
||||
verifylist = [('id', None), ('all_environments', True)]
|
||||
mock_util.return_value = ALL_DEPLOYMENT_DATA
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
# Check that columns are correct
|
||||
expected_columns = [c.title() for c in DEPLOYMENT_COLUMNS]
|
||||
self.assertEqual(expected_columns, columns)
|
||||
|
||||
# Check that data is correct
|
||||
expected_data = [ALL_DEPLOYMENT_DATA]
|
||||
self.assertEqual(expected_data, data)
|
||||
|
|
|
@ -18,6 +18,7 @@ import testtools
|
|||
|
||||
from muranoclient import client
|
||||
from muranoclient.v1 import actions
|
||||
from muranoclient.v1 import deployments
|
||||
import muranoclient.v1.environments as environments
|
||||
from muranoclient.v1 import packages
|
||||
import muranoclient.v1.sessions as sessions
|
||||
|
@ -331,3 +332,24 @@ class UnitTestsForClassesAndFunctions(testtools.TestCase):
|
|||
result = manager.get('test')
|
||||
|
||||
self.assertIsNotNone(result.manager)
|
||||
|
||||
def test_deployment_manager_list(self):
|
||||
manager = deployments.DeploymentManager(api)
|
||||
manager._list = mock.Mock(return_value=mock.sentinel.deployments)
|
||||
|
||||
result = manager.list(mock.sentinel.environment_id)
|
||||
self.assertEqual(mock.sentinel.deployments, result)
|
||||
|
||||
manager._list.assert_called_once_with(
|
||||
'/v1/environments/sentinel.environment_id/deployments',
|
||||
'deployments')
|
||||
|
||||
def test_deployment_manager_list_all_environments(self):
|
||||
manager = deployments.DeploymentManager(api)
|
||||
manager._list = mock.Mock(return_value=mock.sentinel.deployments)
|
||||
|
||||
result = manager.list(mock.sentinel.environment_id,
|
||||
all_environments=True)
|
||||
self.assertEqual(mock.sentinel.deployments, result)
|
||||
|
||||
manager._list.assert_called_once_with('/v1/deployments', 'deployments')
|
||||
|
|
|
@ -816,6 +816,44 @@ class ShellCommandTest(ShellTest):
|
|||
name='env-id-or-name')
|
||||
self.assertEqual(1, self.client.deployments.list.call_count)
|
||||
|
||||
@mock.patch('muranoclient.v1.deployments.DeploymentManager')
|
||||
@requests_mock.mock()
|
||||
def test_deployments_list_all_environments(self, mock_deployment_manager,
|
||||
m_requests):
|
||||
self.client.deployments = mock_deployment_manager()
|
||||
self.make_env()
|
||||
self.register_keystone_discovery_fixture(m_requests)
|
||||
self.register_keystone_token_fixture(m_requests)
|
||||
self.shell('deployment-list --all-environments')
|
||||
self.client.deployments.list.assert_called_once_with(
|
||||
None, True)
|
||||
|
||||
@mock.patch('muranoclient.v1.deployments.DeploymentManager')
|
||||
@requests_mock.mock()
|
||||
def test_deployments_list_negative(self, mock_deployment_manager,
|
||||
m_requests):
|
||||
self.client.deployments = mock_deployment_manager()
|
||||
self.make_env()
|
||||
self.register_keystone_discovery_fixture(m_requests)
|
||||
self.register_keystone_token_fixture(m_requests)
|
||||
e = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.shell,
|
||||
'deployment-list env-id --all-environments')
|
||||
self.assertIn(
|
||||
'Environment ID and all-environments flag cannot both be set.',
|
||||
e.__str__())
|
||||
self.assertFalse(self.client.deployments.list.called)
|
||||
|
||||
e = self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.shell,
|
||||
'deployment-list')
|
||||
self.assertIn(
|
||||
'Either environment ID or all-environments flag must be set.',
|
||||
e.__str__())
|
||||
self.assertFalse(self.client.deployments.list.called)
|
||||
|
||||
@mock.patch('muranoclient.v1.services.ServiceManager')
|
||||
@mock.patch('muranoclient.v1.environments.EnvironmentManager')
|
||||
@requests_mock.mock()
|
||||
|
|
|
@ -34,9 +34,12 @@ class Status(base.Resource):
|
|||
class DeploymentManager(base.Manager):
|
||||
resource_class = Deployment
|
||||
|
||||
def list(self, environment_id):
|
||||
return self._list('/v1/environments/{id}/deployments'.
|
||||
format(id=environment_id), 'deployments')
|
||||
def list(self, environment_id, all_environments=False):
|
||||
if all_environments:
|
||||
return self._list('/v1/deployments', 'deployments')
|
||||
else:
|
||||
return self._list('/v1/environments/{id}/deployments'.
|
||||
format(id=environment_id), 'deployments')
|
||||
|
||||
def reports(self, environment_id, deployment_id, *service_ids):
|
||||
path = '/v1/environments/{id}/deployments/{deployment_id}'
|
||||
|
|
|
@ -523,15 +523,32 @@ def do_env_template_clone(mc, args):
|
|||
utils.print_dict(env_template.to_dict(), formatters=formatters)
|
||||
|
||||
|
||||
@utils.arg("id", metavar="<ID>",
|
||||
@utils.arg("id", metavar="<ID>", nargs='?', default=None,
|
||||
help="Environment ID for which to list deployments.")
|
||||
@utils.arg('--all-environments', action='store_true', default=False,
|
||||
help="Lists all deployments for all environments in user's tenant.")
|
||||
def do_deployment_list(mc, args):
|
||||
"""List deployments for an environment."""
|
||||
"""List deployments for an environment or multiple environments."""
|
||||
all_environments = getattr(args, 'all_environments', False)
|
||||
env_id = getattr(args, 'id', None)
|
||||
if env_id and all_environments:
|
||||
raise exceptions.CommandError(
|
||||
'Environment ID and all-environments flag cannot both be set.')
|
||||
elif not env_id and not all_environments:
|
||||
raise exceptions.CommandError(
|
||||
'Either environment ID or all-environments flag must be set.')
|
||||
try:
|
||||
environment = utils.find_resource(mc.environments, args.id)
|
||||
deployments = mc.deployments.list(environment.id)
|
||||
if all_environments:
|
||||
deployments = mc.deployments.list(None, all_environments)
|
||||
else:
|
||||
environment = utils.find_resource(mc.environments, env_id)
|
||||
deployments = mc.deployments.list(environment.id)
|
||||
except exceptions.NotFound:
|
||||
raise exceptions.CommandError("Environment %s not found" % args.id)
|
||||
if env_id:
|
||||
msg = "Environment %s not found" % env_id
|
||||
else:
|
||||
msg = "Environments not found"
|
||||
raise exceptions.CommandError(msg)
|
||||
else:
|
||||
field_labels = ["ID", "State", "Created", "Updated", "Finished"]
|
||||
fields = ["id", "state", "created", "updated", "finished"]
|
||||
|
|
Loading…
Reference in New Issue