Remove sandbox-related logic

The 'sandbox' code path in compute manager and driver is only
used to create/delete capsule. After the consolidation of
capsule and container code [1][2], the sandbox logic is not
used anymore. This commit removes these unused code.

[1] https://review.openstack.org/#/c/636070/
[2] https://review.openstack.org/#/c/633371/

Change-Id: Ib8d2dff699a816686be4b1a53bf1463ffce02cdf
This commit is contained in:
Hongbin Lu 2019-02-18 23:01:38 +00:00
parent a18ae456af
commit 9f03c3e941
12 changed files with 40 additions and 395 deletions

View File

@ -26,14 +26,14 @@ CAPSULE_STATUSES = (
)
TASK_STATES = (
IMAGE_PULLING, CONTAINER_CREATING, SANDBOX_CREATING,
CONTAINER_STARTING, CONTAINER_DELETING, SANDBOX_DELETING,
IMAGE_PULLING, CONTAINER_CREATING,
CONTAINER_STARTING, CONTAINER_DELETING,
CONTAINER_STOPPING, CONTAINER_REBOOTING, CONTAINER_PAUSING,
CONTAINER_UNPAUSING, CONTAINER_KILLING, SG_ADDING,
SG_REMOVING, NETWORK_ATTACHING, NETWORK_DETACHING
) = (
'image_pulling', 'container_creating', 'sandbox_creating',
'container_starting', 'container_deleting', 'sandbox_deleting',
'image_pulling', 'container_creating',
'container_starting', 'container_deleting',
'container_stopping', 'container_rebooting', 'container_pausing',
'container_unpausing', 'container_killing', 'sg_adding',
'sg_removing', 'network_attaching', 'network_detaching'
@ -53,7 +53,6 @@ ALLOCATED = 'allocated'
# The name of Docker container is of the form NAME_PREFIX-<uuid>
NAME_PREFIX = 'zun-'
SANDBOX_NAME_PREFIX = 'zun-sandbox-'
# Storage drivers that support disk quota feature
SUPPORTED_STORAGE_DRIVERS = \

View File

@ -52,10 +52,6 @@ class Manager(periodic_task.PeriodicTasks):
self.driver = driver.load_container_driver(container_driver)
self.host = CONF.host
self._resource_tracker = None
if self._use_sandbox():
self.use_sandbox = True
else:
self.use_sandbox = False
def restore_running_container(self, context, container, current_status):
if (container.status == consts.RUNNING and
@ -87,7 +83,6 @@ class Manager(periodic_task.PeriodicTasks):
if (container.status == consts.CREATING or
container.task_state in [consts.CONTAINER_CREATING,
consts.IMAGE_PULLING,
consts.SANDBOX_CREATING,
consts.NETWORK_ATTACHING,
consts.NETWORK_DETACHING,
consts.SG_ADDING,
@ -261,24 +256,13 @@ class Manager(periodic_task.PeriodicTasks):
utils.spawn_n(do_container_create)
def _do_sandbox_cleanup(self, context, container):
sandbox_id = container.get_sandbox_id()
if sandbox_id is None:
return
try:
self.driver.delete_sandbox(context, container)
except Exception as e:
LOG.error("Error occurred while deleting sandbox: %s",
six.text_type(e))
def _update_task_state(self, context, container, task_state):
if container.task_state != task_state:
container.task_state = task_state
container.save(context)
def _do_container_create_base(self, context, container, requested_networks,
requested_volumes, sandbox=None,
requested_volumes,
limits=None):
self._update_task_state(context, container, consts.IMAGE_PULLING)
image_driver_name = container.image_driver
@ -296,19 +280,16 @@ class Manager(periodic_task.PeriodicTasks):
except exception.ImageNotFound as e:
with excutils.save_and_reraise_exception():
LOG.error(six.text_type(e))
self._do_sandbox_cleanup(context, container)
self._fail_container(context, container, six.text_type(e))
except exception.DockerError as e:
with excutils.save_and_reraise_exception():
LOG.error("Error occurred while calling Docker image API: %s",
six.text_type(e))
self._do_sandbox_cleanup(context, container)
self._fail_container(context, container, six.text_type(e))
except Exception as e:
with excutils.save_and_reraise_exception():
LOG.exception("Unexpected exception: %s",
six.text_type(e))
self._do_sandbox_cleanup(context, container)
self._fail_container(context, container, six.text_type(e))
container.task_state = consts.CONTAINER_CREATING
@ -334,14 +315,12 @@ class Manager(periodic_task.PeriodicTasks):
with excutils.save_and_reraise_exception():
LOG.error("Error occurred while calling Docker create API: %s",
six.text_type(e))
self._do_sandbox_cleanup(context, container)
self._fail_container(context, container, six.text_type(e),
unset_host=True)
except Exception as e:
with excutils.save_and_reraise_exception():
LOG.exception("Unexpected exception: %s",
six.text_type(e))
self._do_sandbox_cleanup(context, container)
self._fail_container(context, container, six.text_type(e),
unset_host=True)
@ -353,17 +332,10 @@ class Manager(periodic_task.PeriodicTasks):
try:
rt = self._get_resource_tracker()
# As sriov port also need to claim, we need claim pci port before
# create sandbox.
with rt.container_claim(context, container, pci_requests, limits):
sandbox = None
if self.use_sandbox:
sandbox = self._create_sandbox(context, container,
requested_networks)
created_container = self._do_container_create_base(
context, container, requested_networks, requested_volumes,
sandbox, limits)
limits)
return created_container
except exception.ResourcesUnavailable as e:
with excutils.save_and_reraise_exception():
@ -437,43 +409,6 @@ class Manager(periodic_task.PeriodicTasks):
'container_id': volmap.container_uuid})
volmap.destroy()
def _use_sandbox(self):
if CONF.use_sandbox and self.driver.capabilities["support_sandbox"]:
return True
elif (not CONF.use_sandbox and
self.driver.capabilities["support_standalone"]):
return False
else:
raise exception.ZunException(_(
"The configuration of use_sandbox '%(use_sandbox)s' is not "
"supported by driver '%(driver)s'.") %
{'use_sandbox': CONF.use_sandbox,
'driver': self.driver})
def _create_sandbox(self, context, container, requested_networks):
self._update_task_state(context, container, consts.SANDBOX_CREATING)
sandbox_image = CONF.sandbox_image
sandbox_image_driver = CONF.sandbox_image_driver
sandbox_image_pull_policy = CONF.sandbox_image_pull_policy
repo, tag = utils.parse_image_name(sandbox_image,
sandbox_image_driver)
try:
image, image_loaded = self.driver.pull_image(
context, repo, tag, sandbox_image_pull_policy,
sandbox_image_driver)
if not image_loaded:
self.driver.load_image(image['path'])
sandbox_id = self.driver.create_sandbox(
context, container, image=sandbox_image,
requested_networks=requested_networks,
requested_volumes=[])
return sandbox_id
except Exception as e:
with excutils.save_and_reraise_exception():
LOG.exception("Unexpected exception: %s",
six.text_type(e))
self._fail_container(context, container, six.text_type(e))
@wrap_container_event(prefix='compute')
def _do_container_start(self, context, container):
LOG.debug('Starting container: %s', container.uuid)
@ -512,9 +447,6 @@ class Manager(periodic_task.PeriodicTasks):
self.driver.delete_capsule(context, container, force)
elif isinstance(container, objects.Container):
self.driver.delete(context, container, force)
if self.use_sandbox:
self._delete_sandbox(context, container, reraise)
except exception.DockerError as e:
with excutils.save_and_reraise_exception(reraise=reraise):
LOG.error("Error occurred while calling Docker "
@ -535,18 +467,6 @@ class Manager(periodic_task.PeriodicTasks):
rt = self._get_resource_tracker()
rt.remove_usage_from_container(context, container, True)
def _delete_sandbox(self, context, container, reraise=False):
sandbox_id = container.get_sandbox_id()
if sandbox_id:
self._update_task_state(context, container,
consts.SANDBOX_DELETING)
try:
self.driver.delete_sandbox(context, container)
except Exception as e:
with excutils.save_and_reraise_exception(reraise=reraise):
LOG.exception("Unexpected exception: %s", six.text_type(e))
self._fail_container(context, container, six.text_type(e))
def add_security_group(self, context, container, security_group):
@utils.synchronized(container.uuid)
def do_add_security_group():
@ -1140,7 +1060,7 @@ class Manager(periodic_task.PeriodicTasks):
"""Delete container with status DELETED"""
# NOTE(kiennt): Need to filter with both status (DELETED) and
# task_state (None). If task_state in
# [CONTAINER_DELETING, SANDBOX_DELETING] it may
# [CONTAINER_DELETING] it may
# raise some errors when try to delete container.
filters = {
'auto_remove': True,

View File

@ -36,16 +36,6 @@ Interdependencies to other options:
cfg.StrOpt('floating_cpu_set',
default="",
help='Define the cpusets to be excluded from pinning'),
cfg.BoolOpt('use_sandbox',
default=False,
help="""Whether to use infra container. If set to True,
Zun will create an infra container that serves as a placeholder of a few
Linux namespaces (i.e. network namespace). Then, one or multiple containers
could join the namespaces of the infra container thus sharing resources inside
the sandbox (i.e. the network interface). This is typically used to group
a set of high-coupled containers into a unit. If set to False, infra container
won't be created.
"""),
cfg.StrOpt('container_runtime', default='runc',
help="""Define the runtime to create container with. Default value
in Zun is ``runc``."""),

View File

@ -106,10 +106,6 @@ def wrap_docker_error(function):
class DockerDriver(driver.ContainerDriver):
"""Implementation of container drivers for Docker."""
capabilities = {
"support_sandbox": True,
"support_standalone": True,
}
def __init__(self):
super(DockerDriver, self).__init__()
@ -252,8 +248,6 @@ class DockerDriver(driver.ContainerDriver):
def create(self, context, container, image, requested_networks,
requested_volumes):
sandbox_id = container.get_sandbox_id()
with docker_utils.docker_client() as docker:
network_api = zun_network.api(context=context, docker_api=docker)
name = container.name
@ -269,11 +263,8 @@ class DockerDriver(driver.ContainerDriver):
'labels': container.labels,
'tty': container.interactive,
'stdin_open': container.interactive,
'hostname': container.hostname,
}
if not sandbox_id:
# Sandbox is not used so it is legitimate to customize
# the container's hostname
kwargs['hostname'] = container.hostname
if not self._is_runtime_supported():
if container.runtime:
@ -288,17 +279,10 @@ class DockerDriver(driver.ContainerDriver):
host_config['runtime'] = runtime
host_config['binds'] = binds
kwargs['volumes'] = [b['bind'] for b in binds.values()]
if sandbox_id:
host_config['network_mode'] = 'container:%s' % sandbox_id
# TODO(hongbin): Uncomment this after docker-py add support for
# container mode for pid namespace.
# host_config['pid_mode'] = 'container:%s' % sandbox_id
host_config['ipc_mode'] = 'container:%s' % sandbox_id
else:
self._process_exposed_ports(network_api.neutron_api, container)
self._process_networking_config(
context, container, requested_networks, host_config,
kwargs, docker)
self._process_exposed_ports(network_api.neutron_api, container)
self._process_networking_config(
context, container, requested_networks, host_config,
kwargs, docker)
if container.auto_remove:
host_config['auto_remove'] = container.auto_remove
if container.memory is not None:
@ -438,17 +422,13 @@ class DockerDriver(driver.ContainerDriver):
return addresses
def delete(self, context, container, force):
teardown_network = True
if container.get_sandbox_id():
teardown_network = False
with docker_utils.docker_client() as docker:
try:
if teardown_network:
network_api = zun_network.api(context=context,
docker_api=docker)
self._cleanup_network_for_container(container, network_api)
self._cleanup_exposed_ports(network_api.neutron_api,
container)
network_api = zun_network.api(context=context,
docker_api=docker)
self._cleanup_network_for_container(container, network_api)
self._cleanup_exposed_ports(network_api.neutron_api,
container)
if container.container_id:
docker.remove_container(container.container_id,
force=force)
@ -1004,40 +984,6 @@ class DockerDriver(driver.ContainerDriver):
value = six.text_type(value)
return value.encode('utf-8')
def create_sandbox(self, context, container, requested_networks,
requested_volumes,
image='kubernetes/pause'):
with docker_utils.docker_client() as docker:
network_api = zun_network.api(context=context, docker_api=docker)
self._provision_network(context, network_api, requested_networks)
binds = self._get_binds(context, requested_volumes)
host_config = {'binds': binds}
name = self.get_sandbox_name(container)
volumes = [b['bind'] for b in binds.values()]
kwargs = {
'name': name,
'hostname': name[:63],
'volumes': volumes,
}
self._process_exposed_ports(network_api.neutron_api, container)
self._process_networking_config(
context, container, requested_networks, host_config,
kwargs, docker)
kwargs['host_config'] = docker.create_host_config(**host_config)
sandbox = docker.create_container(image, **kwargs)
container.set_sandbox_id(sandbox['Id'])
addresses = self._setup_network_for_container(
context, container, requested_networks, network_api)
if not addresses:
raise exception.ZunException(_(
"Unexpected missing of addresses"))
container.addresses = addresses
container.save(context)
docker.start(sandbox['Id'])
return sandbox['Id']
def _get_volume_driver(self, volume_mapping):
driver_name = volume_mapping.volume_provider
driver = self.volume_drivers.get(driver_name)
@ -1082,26 +1028,6 @@ class DockerDriver(driver.ContainerDriver):
# so it will not be duplicated across projects.
return neutron_net_id
def delete_sandbox(self, context, container):
sandbox_id = container.get_sandbox_id()
with docker_utils.docker_client() as docker:
network_api = zun_network.api(context=context, docker_api=docker)
self._cleanup_network_for_container(container, network_api)
self._cleanup_exposed_ports(network_api.neutron_api, container)
try:
docker.remove_container(sandbox_id, force=True)
except errors.APIError as api_error:
if is_not_found(api_error):
return
raise
def stop_sandbox(self, context, sandbox_id):
with docker_utils.docker_client() as docker:
docker.stop(sandbox_id)
def get_sandbox_name(self, container):
return consts.SANDBOX_NAME_PREFIX + container.uuid
def get_container_name(self, container):
return consts.NAME_PREFIX + container.uuid

View File

@ -149,26 +149,8 @@ class ContainerDriver(object):
"""Display stats of the container."""
raise NotImplementedError()
def create_sandbox(self, context, *args, **kwargs):
"""Create a sandbox."""
raise NotImplementedError()
def delete_sandbox(self, context, container, sandbox_id):
"""Delete a sandbox."""
raise NotImplementedError()
# Note: This is not currently used, but
# may be used later
def stop_sandbox(self, context, sandbox_id):
"""Stop a sandbox."""
raise NotImplementedError()
def get_sandbox_name(self, container):
"""Retrieve sandbox name."""
raise NotImplementedError()
def get_container_name(self, container):
"""Retrieve sandbox name."""
"""Retrieve container name."""
raise NotImplementedError()
def get_addresses(self, context, container):

View File

@ -281,9 +281,7 @@ class KuryrNetwork(network.Network):
This method will create a neutron port, retrieve the ip address(es)
of the port, and pass them to docker.connect_container_to_network.
"""
container_id = container.get_sandbox_id()
if not container_id:
container_id = container.container_id
container_id = container.container_id
addresses, original_port = self.create_or_update_port(
container, network_name, requested_network, security_groups)
@ -338,9 +336,7 @@ class KuryrNetwork(network.Network):
def disconnect_container_from_network(self, container, network_name,
neutron_network_id=None):
container_id = container.get_sandbox_id()
if not container_id:
container_id = container.container_id
container_id = container.container_id
addrs_list = []
if container.addresses and neutron_network_id:
@ -413,10 +409,6 @@ class KuryrNetwork(network.Network):
port_id)
def add_security_groups_to_ports(self, container, security_group_ids):
container_id = container.get_sandbox_id()
if not container_id:
container_id = container.container_id
port_ids = set()
for addrs_list in container.addresses.values():
for addr in addrs_list:
@ -452,10 +444,6 @@ class KuryrNetwork(network.Network):
LOG.exception("Neutron Error:")
def remove_security_groups_from_ports(self, container, security_group_ids):
container_id = container.get_sandbox_id()
if not container_id:
container_id = container.container_id
port_ids = set()
for addrs_list in container.addresses.values():
for addr in addrs_list:

View File

@ -270,19 +270,6 @@ class ContainerBase(base.ZunPersistentObject, base.ZunObject):
getattr(self, field) != getattr(current, field):
setattr(self, field, getattr(current, field))
def get_sandbox_id(self):
if self.meta:
return self.meta.get('sandbox_id', None)
else:
return None
def set_sandbox_id(self, sandbox_id):
if self.meta is None:
self.meta = {'sandbox_id': sandbox_id}
else:
self.meta['sandbox_id'] = sandbox_id
self._changed_fields.add('meta')
def obj_load_attr(self, attrname):
if attrname not in CONTAINER_OPTIONAL_ATTRS:
raise exception.ObjectActionError(

View File

@ -685,57 +685,6 @@ class TestManager(base.TestCase):
mock_remove_usage.assert_called_once_with(self.context, container,
True)
@mock.patch.object(FakeResourceTracker,
'remove_usage_from_container')
@mock.patch.object(Container, 'destroy')
@mock.patch.object(manager.Manager, '_fail_container')
@mock.patch.object(manager.Manager, '_delete_sandbox')
@mock.patch.object(Container, 'save')
@mock.patch.object(fake_driver, 'delete')
def test_container_delete_sandbox_failed(self, mock_delete, mock_save,
mock_delete_sandbox,
mock_fail, mock_destroy,
mock_remove_usage):
self.compute_manager.use_sandbox = True
container = Container(self.context, **utils.get_test_container())
container.set_sandbox_id("sandbox_id")
mock_delete_sandbox.side_effect = exception.ZunException(
message="Unexpected exception")
self.assertRaises(exception.ZunException,
self.compute_manager._do_container_delete,
self.context, container, False)
mock_save.assert_called_with(self.context)
mock_fail.assert_called_with(self.context,
container, 'Unexpected exception')
mock_destroy.assert_not_called()
mock_remove_usage.assert_not_called()
@mock.patch.object(FakeResourceTracker,
'remove_usage_from_container')
@mock.patch.object(Container, 'destroy')
@mock.patch.object(manager.Manager, '_fail_container')
@mock.patch.object(manager.Manager, '_delete_sandbox')
@mock.patch.object(Container, 'save')
@mock.patch.object(VolumeMapping, 'list_by_container')
@mock.patch.object(fake_driver, 'delete')
def test_container_delete_sandbox_failed_force(self, mock_delete,
mock_list_by_container,
mock_save,
mock_delete_sandbox,
mock_fail, mock_destroy,
mock_remove_usage):
mock_list_by_container.return_value = []
self.compute_manager.use_sandbox = True
container = Container(self.context, **utils.get_test_container())
container.set_sandbox_id("sandbox_id")
mock_delete_sandbox.side_effect = exception.ZunException(
message="Unexpected exception")
self.compute_manager._do_container_delete(self.context, container,
True)
mock_save.assert_called_with(self.context)
mock_fail.assert_called_with(self.context,
container, 'Unexpected exception')
@mock.patch.object(fake_driver, 'show')
def test_container_show(self, mock_show):
container = Container(self.context, **utils.get_test_container())

View File

@ -368,18 +368,30 @@ class TestDockerDriver(base.DriverTestCase):
self.mock_docker.remove_container.assert_called_once_with(
mock_container.container_id, force=True)
def test_delete_fail_no_result(self):
@mock.patch('zun.container.docker.driver.DockerDriver'
'._cleanup_network_for_container')
@mock.patch('zun.container.docker.driver.DockerDriver'
'._cleanup_exposed_ports')
def test_delete_fail_no_result(self, mock_cleanup_network_for_container,
mock_cleanup_exposed_ports):
with mock.patch.object(errors.APIError, '__str__',
return_value='404 Not Found') as mock_init:
self.mock_docker.remove_container = mock.Mock(
side_effect=errors.APIError('Error', '', ''))
mock_container = mock.MagicMock()
self.driver.delete(self.context, mock_container, True)
self.assertTrue(mock_cleanup_network_for_container.called)
self.assertTrue(mock_cleanup_exposed_ports.called)
self.mock_docker.remove_container.assert_called_once_with(
mock_container.container_id, force=True)
self.assertEqual(1, mock_init.call_count)
def test_delete_fail_raise_error(self):
@mock.patch('zun.container.docker.driver.DockerDriver'
'._cleanup_network_for_container')
@mock.patch('zun.container.docker.driver.DockerDriver'
'._cleanup_exposed_ports')
def test_delete_fail_raise_error(self, mock_cleanup_network_for_container,
mock_cleanup_exposed_ports):
with mock.patch.object(errors.APIError, '__str__',
return_value='test') as mock_init:
self.mock_docker.remove_container = mock.Mock(
@ -388,6 +400,8 @@ class TestDockerDriver(base.DriverTestCase):
self.assertRaises(errors.APIError, self.driver.delete,
self.context, mock_container,
True)
self.assertTrue(mock_cleanup_network_for_container.called)
self.assertTrue(mock_cleanup_exposed_ports.called)
self.mock_docker.remove_container.assert_called_once_with(
mock_container.container_id, force=True)
self.assertEqual(2, mock_init.call_count)
@ -402,8 +416,6 @@ class TestDockerDriver(base.DriverTestCase):
uuid2 = uuidutils.generate_uuid()
mock_container_list = [
{'Names': ['/%s%s' % (consts.NAME_PREFIX, uuid)]},
{'Names': ['/%s%s' % (consts.SANDBOX_NAME_PREFIX,
uuidutils.generate_uuid())]},
{'Names': ['/%s%s' % (consts.NAME_PREFIX, uuid2)]}]
uuids = self.driver._get_container_uuids(mock_container_list)
self.assertEqual(sorted([uuid, uuid2]), sorted(uuids))
@ -739,103 +751,6 @@ class TestDockerDriver(base.DriverTestCase):
self.mock_docker.commit.assert_called_once_with(
mock_container.container_id, "repo", "tag")
@mock.patch('neutronclient.v2_0.client.Client.create_security_group')
@mock.patch('zun.network.neutron.NeutronAPI.expose_ports')
@mock.patch('zun.network.kuryr_network.KuryrNetwork'
'.connect_container_to_network')
@mock.patch('zun.network.kuryr_network.KuryrNetwork'
'.create_or_update_port')
@mock.patch('zun.container.docker.driver.DockerDriver.get_sandbox_name')
@mock.patch('zun.common.utils.get_security_group_ids')
def test_create_sandbox(self, mock_get_security_group_ids,
mock_get_sandbox_name, mock_create_or_update_port,
mock_connect, mock_expose_ports,
mock_create_security_group):
sandbox_name = 'my_test_sandbox'
mock_get_sandbox_name.return_value = sandbox_name
self.mock_docker.create_container = mock.Mock(
return_value={'Id': 'val1', 'key1': 'val2'})
self.mock_docker.create_networking_config = mock.Mock(
return_value={'Id': 'val1', 'key1': 'val2'})
fake_host_config = mock.Mock()
self.mock_docker.create_host_config.return_value = fake_host_config
mock_container = mock.MagicMock()
hostname = 'my_hostname'
mock_container.hostname = hostname
requested_networks = [{'network': 'fake-network'}]
requested_volumes = []
fake_port = {'mac_address': 'fake_mac'}
mock_create_or_update_port.return_value = ([], fake_port)
result_sandbox_id = self.driver.create_sandbox(
self.context, mock_container, requested_networks,
requested_volumes, 'kubernetes/pause')
self.mock_docker.create_container.assert_called_once_with(
'kubernetes/pause', name=sandbox_name, hostname=sandbox_name,
host_config=fake_host_config, volumes=[], mac_address='fake_mac',
networking_config={'Id': 'val1', 'key1': 'val2'})
self.assertEqual(result_sandbox_id, 'val1')
@mock.patch('neutronclient.v2_0.client.Client.create_security_group')
@mock.patch('zun.network.neutron.NeutronAPI.expose_ports')
@mock.patch('zun.network.kuryr_network.KuryrNetwork'
'.connect_container_to_network')
@mock.patch('zun.network.kuryr_network.KuryrNetwork'
'.create_or_update_port')
@mock.patch('zun.container.docker.driver.DockerDriver.get_sandbox_name')
@mock.patch('zun.common.utils.get_security_group_ids')
def test_create_sandbox_with_long_name(self, mock_get_security_group_ids,
mock_get_sandbox_name,
mock_create_or_update_port,
mock_connect,
mock_expose_ports,
mock_create_security_group):
sandbox_name = 'x' * 100
mock_get_sandbox_name.return_value = sandbox_name
self.mock_docker.create_container = mock.Mock(
return_value={'Id': 'val1', 'key1': 'val2'})
self.mock_docker.create_networking_config = mock.Mock(
return_value={'Id': 'val1', 'key1': 'val2'})
fake_host_config = mock.Mock()
self.mock_docker.create_host_config.return_value = fake_host_config
mock_container = mock.MagicMock()
mock_container.hostname = None
requested_networks = [{'network': 'fake-network'}]
requested_volumes = []
fake_port = {'mac_address': 'fake_mac'}
mock_create_or_update_port.return_value = ([], fake_port)
result_sandbox_id = self.driver.create_sandbox(
self.context, mock_container, requested_networks,
requested_volumes, 'kubernetes/pause')
self.mock_docker.create_container.assert_called_once_with(
'kubernetes/pause', name=sandbox_name, hostname=sandbox_name[:63],
host_config=fake_host_config, volumes=[], mac_address='fake_mac',
networking_config={'Id': 'val1', 'key1': 'val2'})
self.assertEqual(result_sandbox_id, 'val1')
@mock.patch('neutronclient.v2_0.client.Client.delete_security_group')
def test_delete_sandbox(self, mock_delete_security_group):
self.mock_docker.remove_container = mock.Mock()
mock_container = mock.MagicMock()
mock_container.get_sandbox_id.return_value = 'test_sandbox_id'
self.driver.delete_sandbox(self.context, mock_container)
self.mock_docker.remove_container.assert_called_once_with(
'test_sandbox_id', force=True)
def test_stop_sandbox(self):
self.mock_docker.stop = mock.Mock()
self.driver.stop_sandbox(context=self.context,
sandbox_id='test_sandbox_id')
self.mock_docker.stop.assert_called_once_with('test_sandbox_id')
def test_get_sandbox_name(self):
mock_container = mock.MagicMock(
uuid='ea8e2a25-2901-438d-8157-de7ffd68d051')
result_sanbox_name = self.driver.get_sandbox_name(mock_container)
self.assertEqual(
result_sanbox_name,
'%sea8e2a25-2901-438d-8157-de7ffd68d051' %
consts.SANDBOX_NAME_PREFIX)
def test_get_container_name(self):
mock_container = mock.MagicMock(
uuid='ea8e2a25-2901-438d-8157-de7ffd68d051')

View File

@ -18,10 +18,6 @@ from zun.container import driver
class FakeDriver(driver.ContainerDriver):
"""Fake driver for testing."""
capabilities = {
"support_sandbox": True,
"support_standalone": True,
}
def __init__(self):
super(FakeDriver, self).__init__()
@ -103,12 +99,6 @@ class FakeDriver(driver.ContainerDriver):
def resize(self, context, container, height, weight):
pass
def create_sandbox(self, context, name, **kwargs):
pass
def delete_sandbox(self, context, id):
pass
def get_addresses(self, context, container):
pass

View File

@ -48,7 +48,6 @@ class TestTaskState(test_fields.TestField):
self.coerce_good_values = [
('image_pulling', 'image_pulling'),
('container_creating', 'container_creating'),
('sandbox_creating', 'sandbox_creating'),
]
self.coerce_bad_values = ['bad_value']
self.to_primitive_values = self.coerce_good_values[0:1]

View File

@ -344,10 +344,10 @@ class TestObject(test_base.TestCase, _TestObject):
# For more information on object version testing, read
# https://docs.openstack.org/zun/latest/
object_data = {
'Capsule': '1.0-c8709325f8076186c120f0e1fb981896',
'CapsuleContainer': '1.0-ae9d952955ee38aa3bdc62a1f395a98b',
'CapsuleInitContainer': '1.0-ae9d952955ee38aa3bdc62a1f395a98b',
'Container': '1.39-e7d3ea52fad6c978bc01979afff98444',
'Capsule': '1.0-f2adba2460c55f8bb6f8cdb548cf691d',
'CapsuleContainer': '1.0-64f11ebe03a0f7d5e74e4876b1f5a98f',
'CapsuleInitContainer': '1.0-64f11ebe03a0f7d5e74e4876b1f5a98f',
'Container': '1.39-dd75db8ef7f620f9781de1f484b9e5d0',
'Cpuset': '1.0-06c4e6335683c18b87e2e54080f8c341',
'Volume': '1.0-4ec18c39ea49f898cc354f9ca178dfb7',
'VolumeMapping': '1.5-57febc66526185a75a744637e7a387c7',