Skip to content

Commit

Permalink
[docker] use DockerUtil.image_name_extractor for all code paths (#3334)
Browse files Browse the repository at this point in the history
* use image_name_extractor for _get_checks_to_refresh too

* use image_name_extractor for flares too

* use image_name_extractor for unit test
  • Loading branch information
xvello authored and truthbk committed May 10, 2017
1 parent 5959dc4 commit f6e78cc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion tests/core/test_service_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions utils/configcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion utils/service_discovery/sd_docker_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit f6e78cc

Please sign in to comment.