Query docker_root_dir from docker API
In before, we retrieve docker_root_dir from config file. However, this infomation is available by docker API so it is unnecessary to have such config. This commit remove the config docker_data_dir and switch to get such information from docker API. Change-Id: Iafe070c6743a37444386cd431a2e310fd89620d8
This commit is contained in:
parent
d71af9ea44
commit
8ea4e611a5
@ -55,6 +55,7 @@ docker_opts = [
|
||||
'container.'),
|
||||
cfg.StrOpt('docker_data_root',
|
||||
default='/var/lib/docker',
|
||||
deprecated_for_removal=True,
|
||||
help='Root directory of persistent Docker state.'),
|
||||
]
|
||||
|
||||
|
@ -125,9 +125,12 @@ class DockerDriver(driver.ContainerDriver):
|
||||
self.volume_drivers[driver_name] = driver
|
||||
|
||||
def _get_host_storage_info(self):
|
||||
host_info = self.get_host_info()
|
||||
self.docker_root_dir = host_info['docker_root_dir']
|
||||
storage_info = self._host.get_storage_info()
|
||||
self.base_device_size = storage_info['default_base_size']
|
||||
self.support_disk_quota = self._host.check_supported_disk_quota()
|
||||
self.support_disk_quota = self._host.check_supported_disk_quota(
|
||||
host_info)
|
||||
|
||||
def load_image(self, image_path=None):
|
||||
with docker_utils.docker_client() as docker:
|
||||
@ -1114,13 +1117,24 @@ class DockerDriver(driver.ContainerDriver):
|
||||
runtimes.append(key)
|
||||
else:
|
||||
runtimes = ['runc']
|
||||
return (total, running, paused, stopped, cpus,
|
||||
architecture, os_type, os, kernel_version, labels,
|
||||
runtimes)
|
||||
docker_root_dir = info['DockerRootDir']
|
||||
|
||||
return {'total_containers': total,
|
||||
'running_containers': running,
|
||||
'paused_containers': paused,
|
||||
'stopped_containers': stopped,
|
||||
'cpus': cpus,
|
||||
'architecture': architecture,
|
||||
'os_type': os_type,
|
||||
'os': os,
|
||||
'kernel_version': kernel_version,
|
||||
'labels': labels,
|
||||
'runtimes': runtimes,
|
||||
'docker_root_dir': docker_root_dir}
|
||||
|
||||
def get_total_disk_for_container(self):
|
||||
try:
|
||||
disk_usage = psutil.disk_usage(CONF.docker.docker_data_root)
|
||||
disk_usage = psutil.disk_usage(self.docker_root_dir)
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
|
@ -63,7 +63,7 @@ class Host(object):
|
||||
'default_base_size': default_base_size
|
||||
}
|
||||
|
||||
def check_supported_disk_quota(self):
|
||||
def check_supported_disk_quota(self, host_info):
|
||||
"""Check your system be supported disk quota or not"""
|
||||
storage_info = self.get_storage_info()
|
||||
sp_disk_quota = True
|
||||
@ -76,7 +76,7 @@ class Host(object):
|
||||
if backing_filesystem == 'xfs':
|
||||
# Check project quota mount option
|
||||
try:
|
||||
cmd = "mount |grep $(df " + CONF.docker.docker_data_root + \
|
||||
cmd = "mount |grep $(df " + host_info['docker_root_dir'] + \
|
||||
" |awk 'FNR==2 {print $1}') | grep 'xfs'" \
|
||||
" |grep -E 'pquota|prjquota'"
|
||||
utils.execute(cmd, shell=True)
|
||||
|
@ -233,26 +233,23 @@ class ContainerDriver(object):
|
||||
node.mem_available = mem_ava // units.Ki
|
||||
node.mem_used = mem_used // units.Ki
|
||||
info = self.get_host_info()
|
||||
(total, running, paused, stopped, cpus,
|
||||
architecture, os_type, os, kernel_version, labels,
|
||||
runtimes) = info
|
||||
node.total_containers = total
|
||||
node.running_containers = running
|
||||
node.paused_containers = paused
|
||||
node.stopped_containers = stopped
|
||||
node.cpus = cpus
|
||||
node.architecture = architecture
|
||||
node.os_type = os_type
|
||||
node.os = os
|
||||
node.kernel_version = kernel_version
|
||||
node.total_containers = info['total_containers']
|
||||
node.running_containers = info['running_containers']
|
||||
node.paused_containers = info['paused_containers']
|
||||
node.stopped_containers = info['stopped_containers']
|
||||
node.cpus = info['cpus']
|
||||
node.architecture = info['architecture']
|
||||
node.os_type = info['os_type']
|
||||
node.os = info['os']
|
||||
node.kernel_version = info['kernel_version']
|
||||
cpu_used = self.get_cpu_used()
|
||||
node.cpu_used = cpu_used
|
||||
node.labels = labels
|
||||
node.labels = info['labels']
|
||||
disk_total = self.get_total_disk_for_container()
|
||||
node.disk_total = disk_total
|
||||
disk_quota_supported = self.node_support_disk_quota()
|
||||
node.disk_quota_supported = disk_quota_supported
|
||||
node.runtimes = runtimes
|
||||
node.runtimes = info['runtimes']
|
||||
|
||||
def node_is_available(self, nodename):
|
||||
"""Return whether this compute service manages a particular node."""
|
||||
|
@ -862,19 +862,20 @@ class TestDockerDriver(base.DriverTestCase):
|
||||
'KernelVersion': '3.10.0-123',
|
||||
'Labels': ['dev.type=product'],
|
||||
'Runtimes': {'runc': {'path':
|
||||
'docker-runc'}}}
|
||||
(total, running, paused, stopped, cpus, architecture, os_type,
|
||||
os, kernel_version, labels, runtimes) = self.driver.get_host_info()
|
||||
self.assertEqual(10, total)
|
||||
self.assertEqual(8, running)
|
||||
self.assertEqual(0, paused)
|
||||
self.assertEqual(2, stopped)
|
||||
self.assertEqual(48, cpus)
|
||||
self.assertEqual('x86_64', architecture)
|
||||
self.assertEqual('linux', os_type)
|
||||
self.assertEqual('CentOS', os)
|
||||
self.assertEqual('3.10.0-123', kernel_version)
|
||||
self.assertEqual({"dev.type": "product"}, labels)
|
||||
'docker-runc'}},
|
||||
'DockerRootDir': 'fake-dir'}
|
||||
host_info = self.driver.get_host_info()
|
||||
self.assertEqual(10, host_info['total_containers'])
|
||||
self.assertEqual(8, host_info['running_containers'])
|
||||
self.assertEqual(0, host_info['paused_containers'])
|
||||
self.assertEqual(2, host_info['stopped_containers'])
|
||||
self.assertEqual(48, host_info['cpus'])
|
||||
self.assertEqual('x86_64', host_info['architecture'])
|
||||
self.assertEqual('linux', host_info['os_type'])
|
||||
self.assertEqual('CentOS', host_info['os'])
|
||||
self.assertEqual('3.10.0-123', host_info['kernel_version'])
|
||||
self.assertEqual({"dev.type": "product"}, host_info['labels'])
|
||||
self.assertEqual('fake-dir', host_info['docker_root_dir'])
|
||||
|
||||
def test_get_cpu_used(self):
|
||||
self.mock_docker.containers = mock.Mock()
|
||||
@ -1002,10 +1003,18 @@ class TestDockerDriver(base.DriverTestCase):
|
||||
conf.CONF.set_override('floating_cpu_set', "0")
|
||||
mock_mem.return_value = (100 * units.Ki, 50 * units.Ki, 50 * units.Ki,
|
||||
50 * units.Ki)
|
||||
mock_info.return_value = (10, 8, 0, 2, 48, 'x86_64', 'linux',
|
||||
'CentOS', '3.10.0-123',
|
||||
{'dev.type': 'product'},
|
||||
['runc'])
|
||||
mock_info.return_value = {'total_containers': 10,
|
||||
'running_containers': 8,
|
||||
'paused_containers': 0,
|
||||
'stopped_containers': 2,
|
||||
'cpus': 48,
|
||||
'architecture': 'x86_64',
|
||||
'os_type': 'linux',
|
||||
'os': 'CentOS',
|
||||
'kernel_version': '3.10.0-123',
|
||||
'labels': {'dev.type': 'product'},
|
||||
'runtimes': ['runc'],
|
||||
'docker_root_dir': '/var/lib/docker'}
|
||||
mock_cpu_used.return_value = 1.0
|
||||
mock_disk.return_value = 80
|
||||
node_obj = objects.ComputeNode()
|
||||
|
Loading…
x
Reference in New Issue
Block a user