Merge "Support update a service"

This commit is contained in:
Jenkins
2015-04-17 06:03:38 +00:00
committed by Gerrit Code Review
3 changed files with 53 additions and 0 deletions

View File

@@ -526,6 +526,17 @@ class TestCommandLineArgument(utils.TestCase):
self._test_arg_failure('service-show', self._few_argument_error)
self.assertFalse(mock_show.called)
@mock.patch('magnumclient.v1.services.ServiceManager.update')
def test_service_update_success(self, mock_update):
self._test_arg_success('service-update xxx replace xxx=xxx')
self.assertTrue(mock_update.called)
self.assertEqual(1, mock_update.call_count)
@mock.patch('magnumclient.v1.services.ServiceManager.update')
def test_service_update_failure_no_arg(self, mock_update):
self._test_arg_failure('service-update', self._few_argument_error)
self.assertFalse(mock_update.called)
@mock.patch('magnumclient.v1.containers.ContainerManager.list')
def test_container_list_success(self, mock_list):
self._test_arg_success('container-list')

View File

@@ -301,6 +301,22 @@ class ShellTest(base.TestCase):
client_mock.services.create.assert_called_once_with(
manifest_url=manifest_url, bay_uuid=bay.uuid)
def test_do_service_update(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()
service_id = 'id'
args.service = service_id
op = 'replace'
args.op = op
attributes = 'manifest={}'
args.attributes = attributes
shell.magnum_utils.args_array_to_patch = mock.MagicMock()
patch = [{'path': '/manifest', 'value': '{}', 'op': 'replace'}]
shell.magnum_utils.args_array_to_patch.return_value = patch
shell.do_service_update(client_mock, args)
client_mock.services.update.assert_called_once_with(service_id, patch)
def test_do_service_delete(self):
client_mock = mock.MagicMock()
args = mock.MagicMock()

View File

@@ -425,6 +425,32 @@ def do_service_create(cs, args):
_show_service(service)
@utils.arg('service', metavar='<service>', help="UUID or name of service")
@utils.arg(
'op',
metavar='<op>',
choices=['add', 'replace', 'remove'],
help="Operations: 'add', 'replace' or 'remove'")
@utils.arg(
'attributes',
metavar='<path=value>',
nargs='+',
action='append',
default=[],
help="Attributes to add/replace or remove "
"(only PATH is necessary on remove)")
def do_service_update(cs, args):
"""Update information about the given service."""
patch = magnum_utils.args_array_to_patch(args.op, args.attributes[0])
p = patch[0]
if p['path'] == '/manifest' and os.path.isfile(p['value']):
with open(p['value'], 'r') as f:
p['value'] = f.read()
service = cs.services.update(args.service, patch)
_show_service(service)
@utils.arg('services',
metavar='<services>',
nargs='+',