Merge "Set consts NAME_PREFIX & SANDBOX_NAME_PREFIX"
This commit is contained in:
commit
315cf165a5
@ -17,7 +17,7 @@ CONTAINER_STATUSES = (
|
|||||||
) = (
|
) = (
|
||||||
'Error', 'Running', 'Stopped', 'Paused', 'Unknown', 'Creating', 'Created',
|
'Error', 'Running', 'Stopped', 'Paused', 'Unknown', 'Creating', 'Created',
|
||||||
'Deleted', 'Deleting'
|
'Deleted', 'Deleting'
|
||||||
)
|
)
|
||||||
|
|
||||||
TASK_STATES = (
|
TASK_STATES = (
|
||||||
IMAGE_PULLING, CONTAINER_CREATING, SANDBOX_CREATING,
|
IMAGE_PULLING, CONTAINER_CREATING, SANDBOX_CREATING,
|
||||||
@ -27,7 +27,7 @@ TASK_STATES = (
|
|||||||
'image_pulling', 'container_creating', 'sandbox_creating',
|
'image_pulling', 'container_creating', 'sandbox_creating',
|
||||||
'container_starting', 'container_deleting', 'sandbox_deleting',
|
'container_starting', 'container_deleting', 'sandbox_deleting',
|
||||||
'container_stopping', 'container_rebooting',
|
'container_stopping', 'container_rebooting',
|
||||||
)
|
)
|
||||||
|
|
||||||
RESOURCE_CLASSES = (
|
RESOURCE_CLASSES = (
|
||||||
VCPU, MEMORY_MB, DISK_GB, PCI_DEVICE, SRIOV_NET_VF,
|
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',
|
'VCPU', 'MEMORY_MB', 'DISK_GB', 'PCI_DEVICE', 'SRIOV_NET_VF',
|
||||||
'NUMA_SOCKET', 'NUMA_CORE', 'NUMA_THREAD', 'NUMA_MEMORY_MB',
|
'NUMA_SOCKET', 'NUMA_CORE', 'NUMA_THREAD', 'NUMA_MEMORY_MB',
|
||||||
'IPV4_ADDRESS'
|
'IPV4_ADDRESS'
|
||||||
)
|
)
|
||||||
|
|
||||||
ALLOCATED = 'allocated'
|
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__)
|
LOG = logging.getLogger(__name__)
|
||||||
NETWORK_ATTACH_EXTERNAL = 'network:attach_external_network'
|
NETWORK_ATTACH_EXTERNAL = 'network:attach_external_network'
|
||||||
|
|
||||||
synchronized = lockutils.synchronized_with_prefix('zun-')
|
synchronized = lockutils.synchronized_with_prefix(consts.NAME_PREFIX)
|
||||||
|
|
||||||
VALID_STATES = {
|
VALID_STATES = {
|
||||||
'commit': [consts.RUNNING, consts.STOPPED, consts.PAUSED],
|
'commit': [consts.RUNNING, consts.STOPPED, consts.PAUSED],
|
||||||
|
@ -334,7 +334,7 @@ class DockerDriver(driver.ContainerDriver):
|
|||||||
|
|
||||||
def _get_container_uuids(self, containers):
|
def _get_container_uuids(self, containers):
|
||||||
# The name of Docker container is of the form '/zun-<uuid>'
|
# 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)
|
uuids = [c['Names'][0].replace(name_prefix, '', 1)
|
||||||
for c in containers]
|
for c in containers]
|
||||||
return [u for u in uuids if uuidutils.is_uuid_like(u)]
|
return [u for u in uuids if uuidutils.is_uuid_like(u)]
|
||||||
@ -862,10 +862,10 @@ class DockerDriver(driver.ContainerDriver):
|
|||||||
docker.stop(sandbox_id)
|
docker.stop(sandbox_id)
|
||||||
|
|
||||||
def get_sandbox_name(self, container):
|
def get_sandbox_name(self, container):
|
||||||
return 'zun-sandbox-' + container.uuid
|
return consts.SANDBOX_NAME_PREFIX + container.uuid
|
||||||
|
|
||||||
def get_container_name(self, container):
|
def get_container_name(self, container):
|
||||||
return 'zun-' + container.uuid
|
return consts.NAME_PREFIX + container.uuid
|
||||||
|
|
||||||
def get_host_info(self):
|
def get_host_info(self):
|
||||||
with docker_utils.docker_client() as docker:
|
with docker_utils.docker_client() as docker:
|
||||||
|
@ -20,6 +20,7 @@ from docker import errors
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import encodeutils
|
from oslo_utils import encodeutils
|
||||||
|
|
||||||
|
from zun.common import consts
|
||||||
from zun.common import exception
|
from zun.common import exception
|
||||||
from zun.common.i18n import _
|
from zun.common.i18n import _
|
||||||
import zun.conf
|
import zun.conf
|
||||||
@ -73,7 +74,7 @@ class DockerHTTPClient(docker.APIClient):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def list_containers(self):
|
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):
|
def read_tar_image(self, image):
|
||||||
image_path = image['path']
|
image_path = image['path']
|
||||||
|
@ -127,7 +127,8 @@ class TestDockerDriver(base.DriverTestCase):
|
|||||||
**host_config)
|
**host_config)
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'name': 'zun-ea8e2a25-2901-438d-8157-de7ffd68d051',
|
'name': '%sea8e2a25-2901-438d-8157-de7ffd68d051' %
|
||||||
|
consts.NAME_PREFIX,
|
||||||
'command': 'fake_command',
|
'command': 'fake_command',
|
||||||
'environment': {'key1': 'val1', 'key2': 'val2'},
|
'environment': {'key1': 'val1', 'key2': 'val2'},
|
||||||
'working_dir': '/home/ubuntu',
|
'working_dir': '/home/ubuntu',
|
||||||
@ -186,9 +187,10 @@ class TestDockerDriver(base.DriverTestCase):
|
|||||||
uuid = uuidutils.generate_uuid()
|
uuid = uuidutils.generate_uuid()
|
||||||
uuid2 = uuidutils.generate_uuid()
|
uuid2 = uuidutils.generate_uuid()
|
||||||
mock_container_list = [
|
mock_container_list = [
|
||||||
{'Names': ['/zun-%s' % uuid]},
|
{'Names': ['/%s%s' % (consts.NAME_PREFIX, uuid)]},
|
||||||
{'Names': ['/zun-sandbox-%s' % uuidutils.generate_uuid()]},
|
{'Names': ['/%s%s' % (consts.SANDBOX_NAME_PREFIX,
|
||||||
{'Names': ['/zun-%s' % uuid2]}]
|
uuidutils.generate_uuid())]},
|
||||||
|
{'Names': ['/%s%s' % (consts.NAME_PREFIX, uuid2)]}]
|
||||||
uuids = self.driver._get_container_uuids(mock_container_list)
|
uuids = self.driver._get_container_uuids(mock_container_list)
|
||||||
self.assertEqual(sorted([uuid, uuid2]), sorted(uuids))
|
self.assertEqual(sorted([uuid, uuid2]), sorted(uuids))
|
||||||
|
|
||||||
@ -555,16 +557,19 @@ class TestDockerDriver(base.DriverTestCase):
|
|||||||
mock_container = mock.MagicMock(
|
mock_container = mock.MagicMock(
|
||||||
uuid='ea8e2a25-2901-438d-8157-de7ffd68d051')
|
uuid='ea8e2a25-2901-438d-8157-de7ffd68d051')
|
||||||
result_sanbox_name = self.driver.get_sandbox_name(mock_container)
|
result_sanbox_name = self.driver.get_sandbox_name(mock_container)
|
||||||
self.assertEqual(result_sanbox_name,
|
self.assertEqual(
|
||||||
'zun-sandbox-ea8e2a25-2901-438d-8157-de7ffd68d051')
|
result_sanbox_name,
|
||||||
|
'%sea8e2a25-2901-438d-8157-de7ffd68d051' %
|
||||||
|
consts.SANDBOX_NAME_PREFIX)
|
||||||
|
|
||||||
def test_get_container_name(self):
|
def test_get_container_name(self):
|
||||||
mock_container = mock.MagicMock(
|
mock_container = mock.MagicMock(
|
||||||
uuid='ea8e2a25-2901-438d-8157-de7ffd68d051')
|
uuid='ea8e2a25-2901-438d-8157-de7ffd68d051')
|
||||||
result_container_name = self.driver.get_container_name(
|
result_container_name = self.driver.get_container_name(
|
||||||
mock_container)
|
mock_container)
|
||||||
self.assertEqual(result_container_name,
|
self.assertEqual(
|
||||||
'zun-ea8e2a25-2901-438d-8157-de7ffd68d051')
|
result_container_name,
|
||||||
|
'%sea8e2a25-2901-438d-8157-de7ffd68d051' % consts.NAME_PREFIX)
|
||||||
|
|
||||||
def test_execute_resize(self):
|
def test_execute_resize(self):
|
||||||
self.mock_docker.exec_resize = mock.Mock()
|
self.mock_docker.exec_resize = mock.Mock()
|
||||||
@ -630,7 +635,7 @@ class TestDockerDriver(base.DriverTestCase):
|
|||||||
'memory_stats': {'usage': 104857600,
|
'memory_stats': {'usage': 104857600,
|
||||||
'limit': 1048576000},
|
'limit': 1048576000},
|
||||||
'networks': {'eth0':
|
'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,
|
'tx_errors': 0, 'rx_errors': 0, 'tx_bytes': 200,
|
||||||
'rx_dropped': 0, 'tx_packets': 2}}}
|
'rx_dropped': 0, 'tx_packets': 2}}}
|
||||||
stats_info = self.driver.stats(self.context, mock_container)
|
stats_info = self.driver.stats(self.context, mock_container)
|
||||||
|
Loading…
Reference in New Issue
Block a user