Changes container_execute to container_exec
This is more consistent with the "docker exec" command, and causes the user to do less typing, which they will appreciate. Closes-Bug: #1459877 Change-Id: I721059e01fa617dcf63c6205ca63b3f1d7def089
This commit is contained in:
parent
b3c4c444ea
commit
8ad2e89e90
|
@ -243,9 +243,9 @@ class ExecuteController(object):
|
||||||
% pecan.request.method))
|
% pecan.request.method))
|
||||||
container_uuid = api_utils.get_rpc_resource('Container',
|
container_uuid = api_utils.get_rpc_resource('Container',
|
||||||
container_ident).uuid
|
container_ident).uuid
|
||||||
LOG.debug('Calling conductor.container_execute with %s command %s'
|
LOG.debug('Calling conductor.container_exec with %s command %s'
|
||||||
% (container_uuid, command))
|
% (container_uuid, command))
|
||||||
return pecan.request.rpcapi.container_execute(container_uuid, command)
|
return pecan.request.rpcapi.container_exec(container_uuid, command)
|
||||||
|
|
||||||
|
|
||||||
class ContainersController(rest.RestController):
|
class ContainersController(rest.RestController):
|
||||||
|
|
|
@ -150,8 +150,8 @@ class API(rpc_service.API):
|
||||||
def container_logs(self, container_uuid):
|
def container_logs(self, container_uuid):
|
||||||
return self._call('container_logs', container_uuid=container_uuid)
|
return self._call('container_logs', container_uuid=container_uuid)
|
||||||
|
|
||||||
def container_execute(self, container_uuid, command):
|
def container_exec(self, container_uuid, command):
|
||||||
return self._call('container_execute', container_uuid=container_uuid,
|
return self._call('container_exec', container_uuid=container_uuid,
|
||||||
command=command)
|
command=command)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -222,8 +222,8 @@ class Handler(object):
|
||||||
"Docker API Error : %s" % str(api_error))
|
"Docker API Error : %s" % str(api_error))
|
||||||
|
|
||||||
@wrap_container_exception
|
@wrap_container_exception
|
||||||
def container_execute(self, context, container_uuid, command):
|
def container_exec(self, context, container_uuid, command):
|
||||||
LOG.debug("container_execute %s command %s" %
|
LOG.debug("container_exec %s command %s" %
|
||||||
(container_uuid, command))
|
(container_uuid, command))
|
||||||
docker = self.get_docker_client(context, container_uuid)
|
docker = self.get_docker_client(context, container_uuid)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -358,10 +358,10 @@ class TestContainerController(db_base.DbTestCase):
|
||||||
'/v1/containers/%s/logs' % container_uuid)
|
'/v1/containers/%s/logs' % container_uuid)
|
||||||
self.assertFalse(mock_container_logs.called)
|
self.assertFalse(mock_container_logs.called)
|
||||||
|
|
||||||
@patch('magnum.conductor.api.API.container_execute')
|
@patch('magnum.conductor.api.API.container_exec')
|
||||||
@patch('magnum.objects.Container.get_by_uuid')
|
@patch('magnum.objects.Container.get_by_uuid')
|
||||||
def test_execute_command_by_uuid(self, mock_get_by_uuid,
|
def test_execute_command_by_uuid(self, mock_get_by_uuid,
|
||||||
mock_container_execute):
|
mock_container_exec):
|
||||||
test_container = utils.get_test_container()
|
test_container = utils.get_test_container()
|
||||||
test_container_obj = objects.Container(self.context, **test_container)
|
test_container_obj = objects.Container(self.context, **test_container)
|
||||||
mock_get_by_uuid.return_value = test_container_obj
|
mock_get_by_uuid.return_value = test_container_obj
|
||||||
|
@ -371,12 +371,12 @@ class TestContainerController(db_base.DbTestCase):
|
||||||
cmd = {'command': 'ls'}
|
cmd = {'command': 'ls'}
|
||||||
response = self.app.put(url, cmd)
|
response = self.app.put(url, cmd)
|
||||||
self.assertEqual(response.status_int, 200)
|
self.assertEqual(response.status_int, 200)
|
||||||
mock_container_execute.assert_called_one_with(container_uuid, cmd)
|
mock_container_exec.assert_called_one_with(container_uuid, cmd)
|
||||||
|
|
||||||
@patch('magnum.conductor.api.API.container_execute')
|
@patch('magnum.conductor.api.API.container_exec')
|
||||||
@patch('magnum.objects.Container.get_by_name')
|
@patch('magnum.objects.Container.get_by_name')
|
||||||
def test_execute_command_by_name(self, mock_get_by_name,
|
def test_execute_command_by_name(self, mock_get_by_name,
|
||||||
mock_container_execute):
|
mock_container_exec):
|
||||||
test_container = utils.get_test_container()
|
test_container = utils.get_test_container()
|
||||||
test_container_obj = objects.Container(self.context, **test_container)
|
test_container_obj = objects.Container(self.context, **test_container)
|
||||||
mock_get_by_name.return_value = test_container_obj
|
mock_get_by_name.return_value = test_container_obj
|
||||||
|
@ -387,7 +387,7 @@ class TestContainerController(db_base.DbTestCase):
|
||||||
cmd = {'command': 'ls'}
|
cmd = {'command': 'ls'}
|
||||||
response = self.app.put(url, cmd)
|
response = self.app.put(url, cmd)
|
||||||
self.assertEqual(response.status_int, 200)
|
self.assertEqual(response.status_int, 200)
|
||||||
mock_container_execute.assert_called_one_with(container_uuid, cmd)
|
mock_container_exec.assert_called_one_with(container_uuid, cmd)
|
||||||
|
|
||||||
@patch('magnum.conductor.api.API.container_delete')
|
@patch('magnum.conductor.api.API.container_delete')
|
||||||
@patch('magnum.objects.Container.get_by_uuid')
|
@patch('magnum.objects.Container.get_by_uuid')
|
||||||
|
|
|
@ -610,8 +610,8 @@ class TestDockerConductor(base.BaseTestCase):
|
||||||
|
|
||||||
@patch.object(docker_conductor.Handler, '_find_container_by_name')
|
@patch.object(docker_conductor.Handler, '_find_container_by_name')
|
||||||
@mock.patch.object(docker_conductor.Handler, 'get_docker_client')
|
@mock.patch.object(docker_conductor.Handler, 'get_docker_client')
|
||||||
def test_container_execute(self, mock_get_docker_client,
|
def test_container_exec(self, mock_get_docker_client,
|
||||||
mock_find_container):
|
mock_find_container):
|
||||||
mock_docker = mock.MagicMock()
|
mock_docker = mock.MagicMock()
|
||||||
mock_get_docker_client.return_value = mock_docker
|
mock_get_docker_client.return_value = mock_docker
|
||||||
mock_container_uuid = 'd545a92d-609a-428f-8edb-16b02ad20ca1'
|
mock_container_uuid = 'd545a92d-609a-428f-8edb-16b02ad20ca1'
|
||||||
|
@ -620,7 +620,7 @@ class TestDockerConductor(base.BaseTestCase):
|
||||||
mock_find_container.return_value = mock_docker_id
|
mock_find_container.return_value = mock_docker_id
|
||||||
mock_create_res = mock.MagicMock()
|
mock_create_res = mock.MagicMock()
|
||||||
mock_docker.exec_create.return_value = mock_create_res
|
mock_docker.exec_create.return_value = mock_create_res
|
||||||
self.conductor.container_execute(None, mock_container_uuid, 'ls')
|
self.conductor.container_exec(None, mock_container_uuid, 'ls')
|
||||||
mock_docker.exec_create.assert_called_once_with(mock_docker_id, 'ls',
|
mock_docker.exec_create.assert_called_once_with(mock_docker_id, 'ls',
|
||||||
True, True, False)
|
True, True, False)
|
||||||
|
|
||||||
|
@ -631,8 +631,8 @@ class TestDockerConductor(base.BaseTestCase):
|
||||||
|
|
||||||
@patch.object(docker_conductor.Handler, '_find_container_by_name')
|
@patch.object(docker_conductor.Handler, '_find_container_by_name')
|
||||||
@mock.patch.object(docker_conductor.Handler, 'get_docker_client')
|
@mock.patch.object(docker_conductor.Handler, 'get_docker_client')
|
||||||
def test_container_execute_deprecated(self, mock_get_docker_client,
|
def test_container_exec_deprecated(self, mock_get_docker_client,
|
||||||
mock_find_container):
|
mock_find_container):
|
||||||
mock_docker = mock.MagicMock()
|
mock_docker = mock.MagicMock()
|
||||||
mock_get_docker_client.return_value = mock_docker
|
mock_get_docker_client.return_value = mock_docker
|
||||||
mock_container_uuid = 'd545a92d-609a-428f-8edb-16b02ad20ca1'
|
mock_container_uuid = 'd545a92d-609a-428f-8edb-16b02ad20ca1'
|
||||||
|
@ -641,16 +641,16 @@ class TestDockerConductor(base.BaseTestCase):
|
||||||
mock_find_container.return_value = mock_docker_id
|
mock_find_container.return_value = mock_docker_id
|
||||||
mock_create_res = mock.MagicMock()
|
mock_create_res = mock.MagicMock()
|
||||||
mock_docker.exec_create.return_value = mock_create_res
|
mock_docker.exec_create.return_value = mock_create_res
|
||||||
self.conductor.container_execute(None, mock_container_uuid, 'ls')
|
self.conductor.container_exec(None, mock_container_uuid, 'ls')
|
||||||
mock_docker.execute.assert_called_once_with(mock_docker_id, 'ls')
|
mock_docker.execute.assert_called_once_with(mock_docker_id, 'ls')
|
||||||
mock_find_container.assert_called_once_with(mock_docker,
|
mock_find_container.assert_called_once_with(mock_docker,
|
||||||
mock_container_uuid)
|
mock_container_uuid)
|
||||||
|
|
||||||
@patch.object(docker_conductor.Handler, '_find_container_by_name')
|
@patch.object(docker_conductor.Handler, '_find_container_by_name')
|
||||||
@mock.patch.object(docker_conductor.Handler, 'get_docker_client')
|
@mock.patch.object(docker_conductor.Handler, 'get_docker_client')
|
||||||
def test_container_execute_with_failure(self,
|
def test_container_exec_with_failure(self,
|
||||||
mock_get_docker_client,
|
mock_get_docker_client,
|
||||||
mock_find_container):
|
mock_find_container):
|
||||||
mock_docker = mock.MagicMock()
|
mock_docker = mock.MagicMock()
|
||||||
mock_get_docker_client.return_value = mock_docker
|
mock_get_docker_client.return_value = mock_docker
|
||||||
mock_container_uuid = 'd545a92d-609a-428f-8edb-16b02ad20ca1'
|
mock_container_uuid = 'd545a92d-609a-428f-8edb-16b02ad20ca1'
|
||||||
|
@ -662,7 +662,7 @@ class TestDockerConductor(base.BaseTestCase):
|
||||||
mock_docker.exec_create = mock.Mock(
|
mock_docker.exec_create = mock.Mock(
|
||||||
side_effect=errors.APIError('Error', '', ''))
|
side_effect=errors.APIError('Error', '', ''))
|
||||||
self.assertRaises(exception.ContainerException,
|
self.assertRaises(exception.ContainerException,
|
||||||
self.conductor.container_execute,
|
self.conductor.container_exec,
|
||||||
None, mock_container_uuid, 'ls')
|
None, mock_container_uuid, 'ls')
|
||||||
mock_docker.exec_create.assert_called_once_with(mock_docker_id,
|
mock_docker.exec_create.assert_called_once_with(mock_docker_id,
|
||||||
'ls', True, True,
|
'ls', True, True,
|
||||||
|
@ -673,9 +673,9 @@ class TestDockerConductor(base.BaseTestCase):
|
||||||
|
|
||||||
@patch.object(docker_conductor.Handler, '_find_container_by_name')
|
@patch.object(docker_conductor.Handler, '_find_container_by_name')
|
||||||
@mock.patch.object(docker_conductor.Handler, 'get_docker_client')
|
@mock.patch.object(docker_conductor.Handler, 'get_docker_client')
|
||||||
def test_container_execute_deprecated_with_failure(self,
|
def test_container_exec_deprecated_with_failure(self,
|
||||||
mock_get_docker_client,
|
mock_get_docker_client,
|
||||||
mock_find_container):
|
mock_find_container):
|
||||||
mock_docker = mock.MagicMock()
|
mock_docker = mock.MagicMock()
|
||||||
mock_get_docker_client.return_value = mock_docker
|
mock_get_docker_client.return_value = mock_docker
|
||||||
mock_container_uuid = 'd545a92d-609a-428f-8edb-16b02ad20ca1'
|
mock_container_uuid = 'd545a92d-609a-428f-8edb-16b02ad20ca1'
|
||||||
|
@ -687,7 +687,7 @@ class TestDockerConductor(base.BaseTestCase):
|
||||||
mock_docker.execute = mock.Mock(
|
mock_docker.execute = mock.Mock(
|
||||||
side_effect=errors.APIError('Error', '', ''))
|
side_effect=errors.APIError('Error', '', ''))
|
||||||
self.assertRaises(exception.ContainerException,
|
self.assertRaises(exception.ContainerException,
|
||||||
self.conductor.container_execute,
|
self.conductor.container_exec,
|
||||||
None, mock_container_uuid, 'ls')
|
None, mock_container_uuid, 'ls')
|
||||||
mock_docker.execute.assert_called_once_with(mock_docker_id, 'ls')
|
mock_docker.execute.assert_called_once_with(mock_docker_id, 'ls')
|
||||||
mock_find_container.assert_called_once_with(mock_docker,
|
mock_find_container.assert_called_once_with(mock_docker,
|
||||||
|
@ -732,7 +732,7 @@ class TestDockerConductor(base.BaseTestCase):
|
||||||
mock_init.assert_called_once_with()
|
mock_init.assert_called_once_with()
|
||||||
|
|
||||||
def test_container_common_exception(self):
|
def test_container_common_exception(self):
|
||||||
for action in ('container_execute', 'container_logs', 'container_show',
|
for action in ('container_exec', 'container_logs', 'container_show',
|
||||||
'container_delete', 'container_create',
|
'container_delete', 'container_create',
|
||||||
'_container_action'):
|
'_container_action'):
|
||||||
func = getattr(self.conductor, action)
|
func = getattr(self.conductor, action)
|
||||||
|
|
Loading…
Reference in New Issue