Merge "Set consts NAME_PREFIX & SANDBOX_NAME_PREFIX"
This commit is contained in:
commit
315cf165a5
@ -40,3 +40,7 @@ RESOURCE_CLASSES = (
|
||||
)
|
||||
|
||||
ALLOCATED = 'allocated'
|
||||
|
||||
# The name of Docker container is of the form NAME_PREFIX-<uuid>
|
||||
NAME_PREFIX = 'zun-'
|
||||
SANDBOX_NAME_PREFIX = 'zun-sandbox-'
|
||||
|
@ -44,7 +44,7 @@ CONF = zun.conf.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
NETWORK_ATTACH_EXTERNAL = 'network:attach_external_network'
|
||||
|
||||
synchronized = lockutils.synchronized_with_prefix('zun-')
|
||||
synchronized = lockutils.synchronized_with_prefix(consts.NAME_PREFIX)
|
||||
|
||||
VALID_STATES = {
|
||||
'commit': [consts.RUNNING, consts.STOPPED, consts.PAUSED],
|
||||
|
@ -334,7 +334,7 @@ class DockerDriver(driver.ContainerDriver):
|
||||
|
||||
def _get_container_uuids(self, containers):
|
||||
# The name of Docker container is of the form '/zun-<uuid>'
|
||||
name_prefix = '/zun-'
|
||||
name_prefix = '/' + consts.NAME_PREFIX
|
||||
uuids = [c['Names'][0].replace(name_prefix, '', 1)
|
||||
for c in containers]
|
||||
return [u for u in uuids if uuidutils.is_uuid_like(u)]
|
||||
@ -862,10 +862,10 @@ class DockerDriver(driver.ContainerDriver):
|
||||
docker.stop(sandbox_id)
|
||||
|
||||
def get_sandbox_name(self, container):
|
||||
return 'zun-sandbox-' + container.uuid
|
||||
return consts.SANDBOX_NAME_PREFIX + container.uuid
|
||||
|
||||
def get_container_name(self, container):
|
||||
return 'zun-' + container.uuid
|
||||
return consts.NAME_PREFIX + container.uuid
|
||||
|
||||
def get_host_info(self):
|
||||
with docker_utils.docker_client() as docker:
|
||||
|
@ -20,6 +20,7 @@ from docker import errors
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import encodeutils
|
||||
|
||||
from zun.common import consts
|
||||
from zun.common import exception
|
||||
from zun.common.i18n import _
|
||||
import zun.conf
|
||||
@ -73,7 +74,7 @@ class DockerHTTPClient(docker.APIClient):
|
||||
)
|
||||
|
||||
def list_containers(self):
|
||||
return self.containers(all=True, filters={'name': 'zun-'})
|
||||
return self.containers(all=True, filters={'name': consts.NAME_PREFIX})
|
||||
|
||||
def read_tar_image(self, image):
|
||||
image_path = image['path']
|
||||
|
@ -127,7 +127,8 @@ class TestDockerDriver(base.DriverTestCase):
|
||||
**host_config)
|
||||
|
||||
kwargs = {
|
||||
'name': 'zun-ea8e2a25-2901-438d-8157-de7ffd68d051',
|
||||
'name': '%sea8e2a25-2901-438d-8157-de7ffd68d051' %
|
||||
consts.NAME_PREFIX,
|
||||
'command': 'fake_command',
|
||||
'environment': {'key1': 'val1', 'key2': 'val2'},
|
||||
'working_dir': '/home/ubuntu',
|
||||
@ -186,9 +187,10 @@ class TestDockerDriver(base.DriverTestCase):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
uuid2 = uuidutils.generate_uuid()
|
||||
mock_container_list = [
|
||||
{'Names': ['/zun-%s' % uuid]},
|
||||
{'Names': ['/zun-sandbox-%s' % uuidutils.generate_uuid()]},
|
||||
{'Names': ['/zun-%s' % uuid2]}]
|
||||
{'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))
|
||||
|
||||
@ -555,16 +557,19 @@ class TestDockerDriver(base.DriverTestCase):
|
||||
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,
|
||||
'zun-sandbox-ea8e2a25-2901-438d-8157-de7ffd68d051')
|
||||
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')
|
||||
result_container_name = self.driver.get_container_name(
|
||||
mock_container)
|
||||
self.assertEqual(result_container_name,
|
||||
'zun-ea8e2a25-2901-438d-8157-de7ffd68d051')
|
||||
self.assertEqual(
|
||||
result_container_name,
|
||||
'%sea8e2a25-2901-438d-8157-de7ffd68d051' % consts.NAME_PREFIX)
|
||||
|
||||
def test_execute_resize(self):
|
||||
self.mock_docker.exec_resize = mock.Mock()
|
||||
|
Loading…
Reference in New Issue
Block a user