Add the missing task states
Adding tthe following missing task states: * CONTAINER_PAUSING * CONTAINER_UNPAUSING * CONTAINER_KILLING * CONTAINER_ADDING_SG * CONTAINER_REMOVING_SG * NETWORK_ATTACHING * NETWORK_DETACHING Change-Id: Ida0de94ea0db7314e6892cd55e479fca7bbedeaf Closes-Bug:#1748349
This commit is contained in:
parent
80cbb24bd8
commit
26fad638e9
@ -13,8 +13,8 @@ if test "x$1" = "x-HEAD" ; then
|
||||
shift
|
||||
files=$(git diff --name-only HEAD~1 | tr '\n' ' ')
|
||||
echo "Running flake8 on ${files}"
|
||||
diff -u --from-file /dev/null ${files} | flake8 --max-complexity 20 --diff "$@"
|
||||
diff -u --from-file /dev/null ${files} | flake8 --max-complexity 34 --diff "$@"
|
||||
else
|
||||
echo "Running flake8 on all files"
|
||||
exec flake8 --max-complexity 20 "$@"
|
||||
exec flake8 --max-complexity 34 "$@"
|
||||
fi
|
||||
|
@ -28,12 +28,17 @@ CAPSULE_STATUSES = (
|
||||
TASK_STATES = (
|
||||
IMAGE_PULLING, CONTAINER_CREATING, SANDBOX_CREATING,
|
||||
CONTAINER_STARTING, CONTAINER_DELETING, SANDBOX_DELETING,
|
||||
CONTAINER_STOPPING, CONTAINER_REBOOTING,
|
||||
CONTAINER_STOPPING, CONTAINER_REBOOTING, CONTAINER_PAUSING,
|
||||
CONTAINER_UNPAUSING, CONTAINER_KILLING, CONTAINER_ADDING_SG,
|
||||
CONTAINER_REMOVING_SG, NETWORK_ATTACHING,
|
||||
NETWORK_DETACHING
|
||||
) = (
|
||||
'image_pulling', 'container_creating', 'sandbox_creating',
|
||||
'container_starting', 'container_deleting', 'sandbox_deleting',
|
||||
'container_stopping', 'container_rebooting',
|
||||
)
|
||||
'container_stopping', 'container_rebooting', 'container_pausing',
|
||||
'container_unpausing', 'container_killing', 'container_adding_sg',
|
||||
'container_removing_sg', 'network_attaching', 'network_detaching'
|
||||
)
|
||||
|
||||
RESOURCE_CLASSES = (
|
||||
VCPU, MEMORY_MB, DISK_GB, PCI_DEVICE, SRIOV_NET_VF,
|
||||
|
@ -88,7 +88,7 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
current_status)
|
||||
|
||||
def _init_container(self, context, container):
|
||||
'''Initialize this container during zun-compute init.'''
|
||||
"""Initialize this container during zun-compute init."""
|
||||
|
||||
if (container.status == consts.CREATING or
|
||||
container.task_state in [consts.CONTAINER_CREATING,
|
||||
@ -133,6 +133,34 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
self.container_start(context, container)
|
||||
return
|
||||
|
||||
if container.task_state == consts.CONTAINER_PAUSING:
|
||||
self.container_pause(context, container)
|
||||
return
|
||||
|
||||
if container.task_state == consts.CONTAINER_UNPAUSING:
|
||||
self.container_unpause(context, container)
|
||||
return
|
||||
|
||||
if container.task_state == consts.CONTAINER_KILLING:
|
||||
self.container_kill(context, container)
|
||||
return
|
||||
|
||||
if container.task_state == consts.NETWORK_ATTACHING:
|
||||
self.network_attach(context, container)
|
||||
return
|
||||
|
||||
if container.task_state == consts.NETWORK_DETACHING:
|
||||
self.network_detach(context, container)
|
||||
return
|
||||
|
||||
if container.task_state == consts.CONTAINER_ADDING_SG:
|
||||
self.add_security_group(context, container)
|
||||
return
|
||||
|
||||
if container.task_state == consts.CONTAINER_REMOVING_SG:
|
||||
self.remove_security_group(context, container)
|
||||
return
|
||||
|
||||
def _fail_container(self, context, container, error, unset_host=False):
|
||||
try:
|
||||
self._detach_volumes(context, container)
|
||||
@ -453,7 +481,10 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _add_security_group(self, context, container, security_group):
|
||||
LOG.debug('Adding security_group to container: %s', container.uuid)
|
||||
self._update_task_state(context, container,
|
||||
consts.CONTAINER_ADDING_SG)
|
||||
self.driver.add_security_group(context, container, security_group)
|
||||
self._update_task_state(context, container, None)
|
||||
container.security_groups += [security_group]
|
||||
container.save(context)
|
||||
|
||||
@ -468,8 +499,11 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _remove_security_group(self, context, container, security_group):
|
||||
LOG.debug('Removing security_group from container: %s', container.uuid)
|
||||
self._update_task_state(context, container,
|
||||
consts.CONTAINER_REMOVING_SG)
|
||||
self.driver.remove_security_group(context, container,
|
||||
security_group)
|
||||
self._update_task_state(context, container, None)
|
||||
security_groups = (set(container.security_groups)
|
||||
- set([security_group]))
|
||||
container.security_groups = list(security_groups)
|
||||
@ -534,7 +568,9 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _do_container_pause(self, context, container):
|
||||
LOG.debug('Pausing container: %s', container.uuid)
|
||||
self._update_task_state(context, container, consts.CONTAINER_PAUSING)
|
||||
container = self.driver.pause(context, container)
|
||||
self._update_task_state(context, container, None)
|
||||
container.save(context)
|
||||
return container
|
||||
|
||||
@ -549,7 +585,9 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _do_container_unpause(self, context, container):
|
||||
LOG.debug('Unpausing container: %s', container.uuid)
|
||||
self._update_task_state(context, container, consts.CONTAINER_UNPAUSING)
|
||||
container = self.driver.unpause(context, container)
|
||||
self._update_task_state(context, container, None)
|
||||
container.save(context)
|
||||
return container
|
||||
|
||||
@ -615,7 +653,9 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
@wrap_container_event(prefix='compute')
|
||||
def _do_container_kill(self, context, container, signal):
|
||||
LOG.debug('Killing a container: %s', container.uuid)
|
||||
self._update_task_state(context, container, consts.CONTAINER_KILLING)
|
||||
container = self.driver.kill(context, container, signal)
|
||||
self._update_task_state(context, container, None)
|
||||
container.save(context)
|
||||
return container
|
||||
|
||||
@ -1024,11 +1064,17 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
def network_detach(self, context, container, network):
|
||||
LOG.debug('Detach network: %(network)s from container: %(container)s.',
|
||||
{'container': container, 'network': network})
|
||||
self._update_task_state(context, container,
|
||||
consts.NETWORK_DETACHING)
|
||||
self.driver.network_detach(context, container, network)
|
||||
self._update_task_state(context, container, None)
|
||||
|
||||
@wrap_exception()
|
||||
@wrap_container_event(prefix='compute')
|
||||
def network_attach(self, context, container, network):
|
||||
LOG.debug('Attach network: %(network)s to container: %(container)s.',
|
||||
{'container': container, 'network': network})
|
||||
self._update_task_state(context, container,
|
||||
consts.NETWORK_ATTACHING)
|
||||
self.driver.network_attach(context, container, network)
|
||||
self._update_task_state(context, container, None)
|
||||
|
@ -813,12 +813,14 @@ class TestManager(base.TestCase):
|
||||
|
||||
@mock.patch.object(ContainerActionEvent, 'event_start')
|
||||
@mock.patch.object(ContainerActionEvent, 'event_finish')
|
||||
@mock.patch.object(Container, 'save')
|
||||
@mock.patch.object(fake_driver, 'pause')
|
||||
def test_container_pause(self, mock_pause, mock_event_finish,
|
||||
mock_event_start):
|
||||
def test_container_pause(self, mock_pause, mock_save,
|
||||
mock_event_finish, mock_event_start):
|
||||
container = Container(self.context, **utils.get_test_container())
|
||||
self.compute_manager._do_container_pause(self.context, container)
|
||||
mock_pause.assert_called_once_with(self.context, container)
|
||||
mock_save.assert_called_with(self.context)
|
||||
mock_event_start.assert_called_once()
|
||||
mock_event_finish.assert_called_once()
|
||||
self.assertEqual(
|
||||
@ -830,13 +832,15 @@ class TestManager(base.TestCase):
|
||||
@mock.patch.object(ContainerActionEvent, 'event_start')
|
||||
@mock.patch.object(ContainerActionEvent, 'event_finish')
|
||||
@mock.patch.object(manager.Manager, '_fail_container')
|
||||
@mock.patch.object(Container, 'save')
|
||||
@mock.patch.object(fake_driver, 'pause')
|
||||
def test_container_pause_failed(self, mock_pause, mock_fail,
|
||||
def test_container_pause_failed(self, mock_pause, mock_save, mock_fail,
|
||||
mock_event_finish, mock_event_start):
|
||||
container = Container(self.context, **utils.get_test_container())
|
||||
mock_pause.side_effect = exception.DockerError(
|
||||
message="Docker Error occurred")
|
||||
self.compute_manager._do_container_pause(self.context, container)
|
||||
mock_save.assert_called_with(self.context)
|
||||
mock_fail.assert_called_with(self.context,
|
||||
container, 'Docker Error occurred')
|
||||
mock_event_start.assert_called_once()
|
||||
@ -849,12 +853,14 @@ class TestManager(base.TestCase):
|
||||
|
||||
@mock.patch.object(ContainerActionEvent, 'event_start')
|
||||
@mock.patch.object(ContainerActionEvent, 'event_finish')
|
||||
@mock.patch.object(Container, 'save')
|
||||
@mock.patch.object(fake_driver, 'unpause')
|
||||
def test_container_unpause(self, mock_unpause, mock_event_finish,
|
||||
mock_event_start):
|
||||
def test_container_unpause(self, mock_unpause, mock_save,
|
||||
mock_event_finish, mock_event_start):
|
||||
container = Container(self.context, **utils.get_test_container())
|
||||
self.compute_manager._do_container_unpause(self.context, container)
|
||||
mock_unpause.assert_called_once_with(self.context, container)
|
||||
mock_save.assert_called_with(self.context)
|
||||
mock_event_start.assert_called_once()
|
||||
mock_event_finish.assert_called_once()
|
||||
self.assertEqual(
|
||||
@ -866,13 +872,16 @@ class TestManager(base.TestCase):
|
||||
@mock.patch.object(ContainerActionEvent, 'event_start')
|
||||
@mock.patch.object(ContainerActionEvent, 'event_finish')
|
||||
@mock.patch.object(manager.Manager, '_fail_container')
|
||||
@mock.patch.object(Container, 'save')
|
||||
@mock.patch.object(fake_driver, 'unpause')
|
||||
def test_container_unpause_failed(self, mock_unpause, mock_fail,
|
||||
mock_event_finish, mock_event_start):
|
||||
def test_container_unpause_failed(self, mock_unpause, mock_save,
|
||||
mock_fail, mock_event_finish,
|
||||
mock_event_start):
|
||||
container = Container(self.context, **utils.get_test_container())
|
||||
mock_unpause.side_effect = exception.DockerError(
|
||||
message="Docker Error occurred")
|
||||
self.compute_manager._do_container_unpause(self.context, container)
|
||||
mock_save.assert_called_with(self.context)
|
||||
mock_fail.assert_called_with(self.context,
|
||||
container, 'Docker Error occurred')
|
||||
mock_event_start.assert_called_once()
|
||||
@ -923,12 +932,14 @@ class TestManager(base.TestCase):
|
||||
|
||||
@mock.patch.object(ContainerActionEvent, 'event_start')
|
||||
@mock.patch.object(ContainerActionEvent, 'event_finish')
|
||||
@mock.patch.object(Container, 'save')
|
||||
@mock.patch.object(fake_driver, 'kill')
|
||||
def test_container_kill(self, mock_kill, mock_event_finish,
|
||||
mock_event_start):
|
||||
def test_container_kill(self, mock_kill, mock_save,
|
||||
mock_event_finish, mock_event_start):
|
||||
container = Container(self.context, **utils.get_test_container())
|
||||
self.compute_manager._do_container_kill(self.context, container, None)
|
||||
mock_kill.assert_called_once_with(self.context, container, None)
|
||||
mock_save.assert_called_with(self.context)
|
||||
mock_event_start.assert_called_once()
|
||||
mock_event_finish.assert_called_once()
|
||||
self.assertEqual(
|
||||
@ -940,13 +951,16 @@ class TestManager(base.TestCase):
|
||||
@mock.patch.object(ContainerActionEvent, 'event_start')
|
||||
@mock.patch.object(ContainerActionEvent, 'event_finish')
|
||||
@mock.patch.object(manager.Manager, '_fail_container')
|
||||
@mock.patch.object(Container, 'save')
|
||||
@mock.patch.object(fake_driver, 'kill')
|
||||
def test_container_kill_failed(self, mock_kill, mock_fail,
|
||||
mock_event_finish, mock_event_start):
|
||||
def test_container_kill_failed(self, mock_kill, mock_save,
|
||||
mock_fail, mock_event_finish,
|
||||
mock_event_start):
|
||||
container = Container(self.context, **utils.get_test_container())
|
||||
mock_kill.side_effect = exception.DockerError(
|
||||
message="Docker Error occurred")
|
||||
self.compute_manager._do_container_kill(self.context, container, None)
|
||||
mock_save.assert_called_with(self.context)
|
||||
mock_fail.assert_called_with(self.context,
|
||||
container, 'Docker Error occurred')
|
||||
mock_event_start.assert_called_once()
|
||||
@ -1149,12 +1163,14 @@ class TestManager(base.TestCase):
|
||||
|
||||
@mock.patch.object(ContainerActionEvent, 'event_start')
|
||||
@mock.patch.object(ContainerActionEvent, 'event_finish')
|
||||
@mock.patch.object(Container, 'save')
|
||||
@mock.patch.object(fake_driver, 'network_detach')
|
||||
def test_container_network_detach(self, mock_detach, mock_event_finish,
|
||||
mock_event_start):
|
||||
def test_container_network_detach(self, mock_detach, mock_save,
|
||||
mock_event_finish, mock_event_start):
|
||||
container = Container(self.context, **utils.get_test_container())
|
||||
self.compute_manager.network_detach(self.context, container, 'network')
|
||||
mock_detach.assert_called_once_with(self.context, container, mock.ANY)
|
||||
mock_save.assert_called_with(self.context)
|
||||
mock_event_start.assert_called_once()
|
||||
mock_event_finish.assert_called_once()
|
||||
self.assertEqual(
|
||||
@ -1165,11 +1181,13 @@ class TestManager(base.TestCase):
|
||||
|
||||
@mock.patch.object(ContainerActionEvent, 'event_start')
|
||||
@mock.patch.object(ContainerActionEvent, 'event_finish')
|
||||
@mock.patch.object(Container, 'save')
|
||||
@mock.patch.object(fake_driver, 'network_attach')
|
||||
def test_container_network_attach(self, mock_attach, mock_event_finish,
|
||||
mock_event_start):
|
||||
def test_container_network_attach(self, mock_attach, mock_save,
|
||||
mock_event_finish, mock_event_start):
|
||||
container = Container(self.context, **utils.get_test_container())
|
||||
self.compute_manager.network_attach(self.context, container, 'network')
|
||||
mock_save.assert_called_with(self.context)
|
||||
mock_event_start.assert_called_once()
|
||||
mock_event_finish.assert_called_once()
|
||||
self.assertEqual(
|
||||
|
@ -344,7 +344,7 @@ class TestObject(test_base.TestCase, _TestObject):
|
||||
# For more information on object version testing, read
|
||||
# https://docs.openstack.org/zun/latest/
|
||||
object_data = {
|
||||
'Container': '1.24-bd8b0f179b62157772955f0a76735a39',
|
||||
'Container': '1.24-e9230fe84ef146c80f996d55febc5b4d',
|
||||
'VolumeMapping': '1.1-50df6202f7846a136a91444c38eba841',
|
||||
'Image': '1.0-0b976be24f4f6ee0d526e5c981ce0633',
|
||||
'MyObj': '1.0-34c4b1aadefd177b13f9a2f894cc23cd',
|
||||
|
Loading…
Reference in New Issue
Block a user