|
3 | 3 | import mock |
4 | 4 | import unittest |
5 | 5 |
|
| 6 | +# 3p |
| 7 | +from nose.plugins.attrib import attr |
| 8 | + |
6 | 9 | # project |
7 | 10 | from utils.service_discovery.config_stores import get_config_store |
8 | 11 | from utils.service_discovery.consul_config_store import ConsulStore |
@@ -64,6 +67,7 @@ def issue_read(identifier): |
64 | 67 | return TestServiceDiscovery.mock_tpls.get(identifier) |
65 | 68 |
|
66 | 69 |
|
| 70 | +@attr('unix') |
67 | 71 | class TestServiceDiscovery(unittest.TestCase): |
68 | 72 | docker_container_inspect = { |
69 | 73 | u'Id': u'69ff25598b2314d1cdb7752cc3a659fb1c1352b32546af4f1454321550e842c0', |
@@ -91,11 +95,11 @@ class TestServiceDiscovery(unittest.TestCase): |
91 | 95 | u'Name': u'/nginx' |
92 | 96 | } |
93 | 97 | container_inspects = [ |
94 | | - # (inspect_dict, expected_ip, expected_port, expected_ident) |
95 | | - (docker_container_inspect, '172.17.0.21', ['80', '443'], 'nginx'), |
96 | | - (docker_container_inspect_with_label, '172.17.0.21', ['80', '443'], 'custom-nginx'), |
97 | | - (kubernetes_container_inspect, None, ['6379'], 'foo'), # arbitrarily defined in the mocked pod_list |
98 | | - (malformed_container_inspect, None, KeyError, 'foo') |
| 98 | + # (inspect_dict, expected_ip, tpl_var, expected_port, expected_ident) |
| 99 | + (docker_container_inspect, '172.17.0.21', 'port', '443', 'nginx'), |
| 100 | + (docker_container_inspect_with_label, '172.17.0.21', 'port', '443', 'custom-nginx'), |
| 101 | + (kubernetes_container_inspect, None, 'port', '6379', 'foo'), # arbitrarily defined in the mocked pod_list |
| 102 | + (malformed_container_inspect, None, 'port', KeyError, 'foo') |
99 | 103 | ] |
100 | 104 |
|
101 | 105 | # templates with variables already extracted |
@@ -224,22 +228,22 @@ def test_get_host_address(self, mock_check_yaml, mock_get): |
224 | 228 | mock_check_yaml.return_value = kubernetes_config |
225 | 229 | mock_get.return_value = Response(pod_list) |
226 | 230 |
|
227 | | - for c_ins, expected_ip, _, _ in self.container_inspects: |
| 231 | + for c_ins, tpl_var, expected_ip in ip_address_inspects: |
228 | 232 | with mock.patch.object(AbstractConfigStore, '__init__', return_value=None): |
229 | 233 | with mock.patch('utils.dockerutil.DockerUtil.client', return_value=None): |
230 | 234 | with mock.patch('utils.kubeutil.get_conf_path', return_value=None): |
231 | 235 | sd_backend = get_sd_backend(agentConfig=self.auto_conf_agentConfig) |
232 | | - self.assertEqual(sd_backend._get_host(c_ins), expected_ip) |
| 236 | + self.assertEquals(sd_backend._get_host_address(c_ins, tpl_var), expected_ip) |
233 | 237 | clear_singletons(self.auto_conf_agentConfig) |
234 | 238 |
|
235 | 239 | def test_get_port(self): |
236 | 240 | with mock.patch('utils.dockerutil.DockerUtil.client', return_value=None): |
237 | | - for c_ins, _, expected_ports, _ in self.container_inspects: |
| 241 | + for c_ins, _, var_tpl, expected_ports, _ in self.container_inspects: |
238 | 242 | sd_backend = get_sd_backend(agentConfig=self.auto_conf_agentConfig) |
239 | | - if isinstance(expected_ports, list): |
240 | | - self.assertEqual(sd_backend._get_ports(c_ins), expected_ports) |
| 243 | + if isinstance(expected_ports, str): |
| 244 | + self.assertEquals(sd_backend._get_port(c_ins, var_tpl), expected_ports) |
241 | 245 | else: |
242 | | - self.assertRaises(expected_ports, sd_backend._get_ports, c_ins) |
| 246 | + self.assertRaises(expected_ports, sd_backend._get_port, c_ins, var_tpl) |
243 | 247 | clear_singletons(self.auto_conf_agentConfig) |
244 | 248 |
|
245 | 249 | @mock.patch('docker.Client.inspect_container', side_effect=_get_container_inspect) |
@@ -519,7 +523,7 @@ def test_get_check_tpls(self, mock_client_read): |
519 | 523 | def test_get_config_id(self): |
520 | 524 | """Test get_config_id""" |
521 | 525 | with mock.patch('utils.dockerutil.DockerUtil.client', return_value=None): |
522 | | - for c_ins, _, _, expected_ident in self.container_inspects: |
| 526 | + for c_ins, _, _, _, expected_ident in self.container_inspects: |
523 | 527 | sd_backend = get_sd_backend(agentConfig=self.auto_conf_agentConfig) |
524 | 528 | self.assertEqual( |
525 | 529 | sd_backend.get_config_id(c_ins.get('Image'), c_ins.get('Labels', {})), |
|
0 commit comments