Add OpenstackClient plugin for cluster profile update
This change implements the "openstack cluster profile update" command Based on the existing senlin command: senlin profile-update Change-Id: I2120a55cf0dddaa3a87c6a9444fd6d6fab79b489 Blueprint: senlin-support-python-openstackclient
This commit is contained in:
@@ -252,3 +252,50 @@ class CreateProfile(show.ShowOne):
|
||||
|
||||
profile = senlin_client.create_profile(**params)
|
||||
return _show_profile(senlin_client, profile_id=profile.id)
|
||||
|
||||
|
||||
class UpdateProfile(show.ShowOne):
|
||||
"""Update a profile."""
|
||||
|
||||
log = logging.getLogger(__name__ + ".UpdateProfile")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(UpdateProfile, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar='<NAME>',
|
||||
help=_('The new name for the profile')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--metadata',
|
||||
metavar='<KEY1=VALUE1;KEY2=VALUE2...>',
|
||||
help=_('Metadata values to be attached to the profile. '
|
||||
'This can be specified multiple times, or once with '
|
||||
'key-value pairs separated by a semicolon'),
|
||||
action='append'
|
||||
)
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar='<PROFILE_ID>',
|
||||
help=_('Name or ID of the profile to update')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
senlin_client = self.app.client_manager.clustering
|
||||
|
||||
params = {
|
||||
'name': parsed_args.name,
|
||||
}
|
||||
if parsed_args.metadata:
|
||||
params['metadata'] = senlin_utils.format_parameters(
|
||||
parsed_args.metadata)
|
||||
|
||||
# Find the profile first, we need its id
|
||||
try:
|
||||
profile = senlin_client.get_profile(parsed_args.id)
|
||||
except sdk_exc.ResourceNotFound:
|
||||
raise exc.CommandError(_('Profile not found: %s') % parsed_args.id)
|
||||
senlin_client.update_profile(profile.id, **params)
|
||||
return _show_profile(senlin_client, profile_id=profile.id)
|
||||
|
||||
@@ -330,3 +330,62 @@ class TestProfileCreate(TestProfile):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.mock_client.create_profile.assert_called_with(**kwargs)
|
||||
|
||||
|
||||
class TestProfileUpdate(TestProfile):
|
||||
|
||||
response = {"profile": {
|
||||
"created_at": "2016-02-17T12:10:57",
|
||||
"domain": None,
|
||||
"id": "e3057c77-a178-4265-bafd-16b2fae50eea",
|
||||
"metadata": {
|
||||
"nk1": "nv1",
|
||||
"nk2": "nv2",
|
||||
},
|
||||
"name": "new_profile",
|
||||
"project": "5f1cc92b578e4e25a3b284179cf20a9b",
|
||||
"spec": {"properties": {
|
||||
"flavor": 1,
|
||||
"image": "cirros-0.3.4-x86_64-uec",
|
||||
"name": "cirros_server"},
|
||||
"type": "os.nova.server",
|
||||
"version": 1.0},
|
||||
"type": "os.nova.server-1.0",
|
||||
"updated_at": None,
|
||||
"user": "2d7aca950f3e465d8ef0c81720faf6ff"}}
|
||||
|
||||
defaults = {
|
||||
"name": "new_profile",
|
||||
"metadata": {
|
||||
"nk1": "nv1",
|
||||
"nk2": "nv2",
|
||||
}
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super(TestProfileUpdate, self).setUp()
|
||||
self.cmd = osc_profile.UpdateProfile(self.app, None)
|
||||
self.mock_client.update_profile = mock.Mock(
|
||||
return_value=sdk_profile.Profile(None, self.response))
|
||||
self.mock_client.get_profile = mock.Mock(
|
||||
return_value=sdk_profile.Profile(None, self.response))
|
||||
utils.get_dict_properties = mock.Mock(return_value='')
|
||||
|
||||
def test_profile_update_defaults(self):
|
||||
arglist = ['--name', 'new_profile', '--metadata', 'nk1=nv1;nk2=nv2',
|
||||
'c6b8b252']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.mock_client.update_profile.assert_called_with(None,
|
||||
**self.defaults)
|
||||
|
||||
def test_profile_update_not_found(self):
|
||||
arglist = ['--name', 'new_profile', '--metadata', 'nk1=nv1;nk2=nv2',
|
||||
'c6b8b252']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.mock_client.get_profile.side_effect = sdk_exc.ResourceNotFound()
|
||||
error = self.assertRaises(
|
||||
exc.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertIn('Profile not found: c6b8b252', str(error))
|
||||
|
||||
@@ -37,6 +37,7 @@ openstack.clustering.v1 =
|
||||
cluster_profile_show = senlinclient.osc.v1.profile:ShowProfile
|
||||
cluster_profile_type_list = senlinclient.osc.v1.profile_type:ProfileTypeList
|
||||
cluster_profile_type_show = senlinclient.osc.v1.profile_type:ProfileTypeShow
|
||||
cluster_profile_update = senlinclient.osc.v1.profile:UpdateProfile
|
||||
|
||||
[global]
|
||||
setup-hooks =
|
||||
|
||||
Reference in New Issue
Block a user