Merge "Set consts NAME_PREFIX & SANDBOX_NAME_PREFIX"

This commit is contained in:
Zuul 2018-02-27 09:18:41 +00:00 committed by Gerrit Code Review
commit 315cf165a5
5 changed files with 27 additions and 17 deletions

View File

@ -17,7 +17,7 @@ CONTAINER_STATUSES = (
) = (
'Error', 'Running', 'Stopped', 'Paused', 'Unknown', 'Creating', 'Created',
'Deleted', 'Deleting'
)
)
TASK_STATES = (
IMAGE_PULLING, CONTAINER_CREATING, SANDBOX_CREATING,
@ -27,7 +27,7 @@ TASK_STATES = (
'image_pulling', 'container_creating', 'sandbox_creating',
'container_starting', 'container_deleting', 'sandbox_deleting',
'container_stopping', 'container_rebooting',
)
)
RESOURCE_CLASSES = (
VCPU, MEMORY_MB, DISK_GB, PCI_DEVICE, SRIOV_NET_VF,
@ -37,6 +37,10 @@ RESOURCE_CLASSES = (
'VCPU', 'MEMORY_MB', 'DISK_GB', 'PCI_DEVICE', 'SRIOV_NET_VF',
'NUMA_SOCKET', 'NUMA_CORE', 'NUMA_THREAD', 'NUMA_MEMORY_MB',
'IPV4_ADDRESS'
)
)
ALLOCATED = 'allocated'
# The name of Docker container is of the form NAME_PREFIX-<uuid>
NAME_PREFIX = 'zun-'
SANDBOX_NAME_PREFIX = 'zun-sandbox-'

View File

@ -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],

View File

@ -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:

View File

@ -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']

View File

@ -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()
@ -630,7 +635,7 @@ class TestDockerDriver(base.DriverTestCase):
'memory_stats': {'usage': 104857600,
'limit': 1048576000},
'networks': {'eth0':
{'tx_dropped': 0, 'rx_packets': 2, 'rx_bytes': 200,
{'tx_dropped': 0, 'rx_packets': 2, 'rx_bytes': 200,
'tx_errors': 0, 'rx_errors': 0, 'tx_bytes': 200,
'rx_dropped': 0, 'tx_packets': 2}}}
stats_info = self.driver.stats(self.context, mock_container)