Add profile type ops cli
Change-Id: I40c4da6fc7f449397748a098aa0cb7cd786b0603 Closes-Bug: #1709574
This commit is contained in:
@@ -93,3 +93,40 @@ class TestProfileTypeShow(TestProfileType):
|
||||
parsed_args)
|
||||
self.assertEqual('Profile Type not found: os.heat.stack-1.1',
|
||||
str(error))
|
||||
|
||||
|
||||
class TestProfileTypeOperations(TestProfileType):
|
||||
def setUp(self):
|
||||
super(TestProfileTypeOperations, self).setUp()
|
||||
self.cmd = osc_profile_type.ProfileTypeOperations(self.app, None)
|
||||
fake_profile_type_ops = mock.Mock(
|
||||
{
|
||||
'options': {
|
||||
'abandon': {
|
||||
'required': False,
|
||||
'type': 'Map',
|
||||
'description': 'Abandon a heat stack node.',
|
||||
'updatable': False
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
self.mock_client.list_profile_type_operations = mock.Mock(
|
||||
return_value=fake_profile_type_ops)
|
||||
|
||||
def test_profile_type_operations(self):
|
||||
arglist = ['os.heat.stack-1.0']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.mock_client.list_profile_type_operations.assert_called_once_with(
|
||||
'os.heat.stack-1.0')
|
||||
|
||||
def test_profile_type_operations_not_found(self):
|
||||
arglist = ['os.heat.stack-1.1']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.mock_client.list_profile_type_operations.side_effect = (
|
||||
sdk_exc.ResourceNotFound())
|
||||
error = self.assertRaises(exc.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertEqual('Profile Type not found: os.heat.stack-1.1',
|
||||
str(error))
|
||||
|
||||
@@ -131,6 +131,39 @@ class ShellTest(testtools.TestCase):
|
||||
self.assertEqual(_('Profile Type not found: wrong_type'),
|
||||
six.text_type(ex))
|
||||
|
||||
@mock.patch.object(utils, 'format_output')
|
||||
def test_do_profile_type_operations(self, mock_format):
|
||||
service = mock.Mock()
|
||||
fake_pto = {'foo': 'bar'}
|
||||
service.list_profile_type_operations = mock.Mock(return_value=fake_pto)
|
||||
args_dict = {
|
||||
'format': 'json',
|
||||
'type_name': 'os.nova.server-1.0'
|
||||
}
|
||||
args = self._make_args(args_dict)
|
||||
sh.do_profile_type_ops(service, args)
|
||||
mock_format.assert_called_with({'foo': 'bar'}, format=args.format)
|
||||
service.list_profile_type_operations.assert_called_with(
|
||||
'os.nova.server-1.0')
|
||||
args.format = None
|
||||
sh.do_profile_type_ops(service, args)
|
||||
mock_format.assert_called_with({'foo': 'bar'})
|
||||
|
||||
def test_do_profile_type_operations_type_not_found(self):
|
||||
service = mock.Mock()
|
||||
args = {
|
||||
'type_name': 'wrong_type',
|
||||
'format': 'json'
|
||||
}
|
||||
args = self._make_args(args)
|
||||
ex = oexc.ResourceNotFound
|
||||
service.list_profile_type_operations = mock.Mock(side_effect=ex)
|
||||
ex = self.assertRaises(exc.CommandError,
|
||||
sh.do_profile_type_ops,
|
||||
service, args)
|
||||
self.assertEqual(_('Profile Type not found: wrong_type'),
|
||||
six.text_type(ex))
|
||||
|
||||
@mock.patch.object(utils, 'print_list')
|
||||
def test_do_profile_list(self, mock_print):
|
||||
service = mock.Mock()
|
||||
|
||||
@@ -44,6 +44,15 @@ class Client(object):
|
||||
"""
|
||||
return self.service.get_profile_type(profile_type)
|
||||
|
||||
def list_profile_type_operations(self, profile_type):
|
||||
"""Show profile type operations
|
||||
|
||||
Doc link:
|
||||
https://developer.openstack.org/api-ref/clustering/
|
||||
#show-profile-type-details
|
||||
"""
|
||||
return self.service.list_profile_type_operations(profile_type)
|
||||
|
||||
def profiles(self, **query):
|
||||
"""List profiles
|
||||
|
||||
|
||||
@@ -77,3 +77,31 @@ class ProfileTypeShow(format_utils.YamlFormat):
|
||||
rows = data.values()
|
||||
columns = data.keys()
|
||||
return columns, rows
|
||||
|
||||
|
||||
class ProfileTypeOperations(format_utils.YamlFormat):
|
||||
"""Show the operations about a profile type."""
|
||||
log = logging.getLogger(__name__ + ".ProfileTypeOperations")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ProfileTypeOperations, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'type_name',
|
||||
metavar='<type-name>',
|
||||
help=_('Profile type to retrieve')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
senlin_client = self.app.client_manager.clustering
|
||||
|
||||
try:
|
||||
ops = senlin_client.list_profile_type_operations(
|
||||
parsed_args.type_name)
|
||||
except sdk_exc.ResourceNotFound:
|
||||
raise exc.CommandError(_('Profile Type not found: %s')
|
||||
% parsed_args.type_name)
|
||||
rows = ops.values()
|
||||
columns = ops.keys()
|
||||
return columns, rows
|
||||
|
||||
@@ -96,6 +96,28 @@ def do_profile_type_show(service, args):
|
||||
print(utils.format_output(pt))
|
||||
|
||||
|
||||
@utils.arg('type_name', metavar='<TYPE_NAME>',
|
||||
help=_('Profile type to retrieve.'))
|
||||
@utils.arg('-F', '--format', metavar='<FORMAT>',
|
||||
choices=utils.supported_formats.keys(),
|
||||
help=_("The template output format, one of: %s.")
|
||||
% ', '.join(utils.supported_formats.keys()))
|
||||
def do_profile_type_ops(service, args):
|
||||
"""Show the operations about a policy type."""
|
||||
show_deprecated('senlin profile-type-ops',
|
||||
'openstack cluster profile type ops')
|
||||
try:
|
||||
ops = service.list_profile_type_operations(args.type_name)
|
||||
except sdk_exc.ResourceNotFound:
|
||||
raise exc.CommandError(_('Profile Type not found: %s')
|
||||
% args.type_name)
|
||||
|
||||
if args.format:
|
||||
print(utils.format_output(ops, format=args.format))
|
||||
else:
|
||||
print(utils.format_output(ops))
|
||||
|
||||
|
||||
# PROFILES
|
||||
|
||||
@utils.arg('-f', '--filters', metavar='<"KEY1=VALUE1;KEY2=VALUE2...">',
|
||||
|
||||
@@ -68,6 +68,7 @@ openstack.clustering.v1 =
|
||||
cluster_profile_delete = senlinclient.v1.profile:DeleteProfile
|
||||
cluster_profile_list = senlinclient.v1.profile:ListProfile
|
||||
cluster_profile_show = senlinclient.v1.profile:ShowProfile
|
||||
cluster_profile_type_ops = senlinclient.v1.profile_type:ProfileTypeOperations
|
||||
cluster_profile_type_list = senlinclient.v1.profile_type:ProfileTypeList
|
||||
cluster_profile_type_show = senlinclient.v1.profile_type:ProfileTypeShow
|
||||
cluster_profile_update = senlinclient.v1.profile:UpdateProfile
|
||||
|
||||
Reference in New Issue
Block a user