From f6e78cc5609af581e2aa3ddc0eaba32afb212034 Mon Sep 17 00:00:00 2001 From: Xavier Vello Date: Wed, 10 May 2017 16:00:14 +0200 Subject: [PATCH] [docker] use DockerUtil.image_name_extractor for all code paths (#3334) * use image_name_extractor for _get_checks_to_refresh too * use image_name_extractor for flares too * use image_name_extractor for unit test --- tests/core/test_service_discovery.py | 3 ++- utils/configcheck.py | 7 ++++--- utils/service_discovery/sd_docker_backend.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/core/test_service_discovery.py b/tests/core/test_service_discovery.py index 52ab0b5fa7..21ee46541b 100644 --- a/tests/core/test_service_discovery.py +++ b/tests/core/test_service_discovery.py @@ -17,6 +17,7 @@ _TemplateCache, CONFIG_FROM_KUBE, CONFIG_FROM_TEMPLATE, CONFIG_FROM_AUTOCONF from utils.service_discovery.sd_backend import get_sd_backend from utils.service_discovery.sd_docker_backend import SDDockerBackend, _SDDockerBackendConfigFetchState +from utils.dockerutil import DockerUtil def clear_singletons(agentConfig): @@ -587,7 +588,7 @@ def test_get_config_id(self, mock_get_auto_confd_path): for c_ins, _, _, _, expected_ident in self.container_inspects: sd_backend = get_sd_backend(agentConfig=self.auto_conf_agentConfig) self.assertEqual( - sd_backend.get_config_id(c_ins.get('Image'), c_ins.get('Config', {}).get('Labels', {})), + sd_backend.get_config_id(DockerUtil().image_name_extractor(c_ins), c_ins.get('Config', {}).get('Labels', {})), expected_ident) clear_singletons(self.auto_conf_agentConfig) diff --git a/utils/configcheck.py b/utils/configcheck.py index a42ae93e61..cad7572138 100644 --- a/utils/configcheck.py +++ b/utils/configcheck.py @@ -72,13 +72,14 @@ def get_sd_configcheck(agentConfig, configs): def print_containers(): - containers = DockerUtil().client.containers() + dockerutil = DockerUtil() + containers = dockerutil.client.containers() print("\nContainers info:\n") print("Number of containers found: %s" % len(containers)) for co in containers: c_id = 'ID: %s' % co.get('Id')[:12] - c_image = 'image: %s' % co.get('Image') - c_name = 'name: %s' % DockerUtil.container_name_extractor(co)[0] + c_image = 'image: %s' % dockerutil.image_name_extractor(co) + c_name = 'name: %s' % dockerutil.container_name_extractor(co)[0] print("\t- %s %s %s" % (c_id, c_image, c_name)) print('\n') diff --git a/utils/service_discovery/sd_docker_backend.py b/utils/service_discovery/sd_docker_backend.py index 2dc49e2ba3..9df87ca207 100644 --- a/utils/service_discovery/sd_docker_backend.py +++ b/utils/service_discovery/sd_docker_backend.py @@ -144,7 +144,7 @@ def _get_checks_to_refresh(self, state, c_id): return identifier = inspect.get('Config', {}).get('Labels', {}).get(DATADOG_ID) or \ - inspect.get('Config', {}).get('Image') + self.dockerutil.image_name_extractor(inspect) platform_kwargs = {} if Platform.is_k8s():