def test_extract_ports(self):
     ports = ServiceRegistrator.extract_ports(self.container)
     self.assertEqual(
         set(ports),
         set([
             Ports(internal=80, external=80, protocol='tcp', ip='0.0.0.0'),
             Ports(internal=180, external=180, protocol='udp',
                   ip='0.0.0.0'),
         ]))
Beispiel #2
0
 def test_names_count_multiple_services_same_name(self):
     self.container_info.metadata = ContainerMetadata(
         {'name': 'dummyservice_name'})
     self.container_info.metadata_with_port = {}
     self.container_info.ports = [
         Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0'),
         Ports(internal=81, external=8087, protocol='tcp', ip='0.0.0.0'),
     ]
     counts = self.container_info.names_count()
     self.assertIn('dummyservice_name', counts)
     self.assertEqual(counts['dummyservice_name'], 2)
Beispiel #3
0
 def test_build_service_name_multiple_services_same_name_udp(self):
     self.container_info.metadata = ContainerMetadata(
         {'name': 'dummyservice_name'})
     self.container_info.metadata_with_port = {}
     self.container_info.ports = [
         Ports(internal=80, external=8086, protocol='udp', ip='0.0.0.0'),
         Ports(internal=81, external=8087, protocol='tcp', ip='0.0.0.0'),
     ]
     name = self.container_info.build_service_name(
         self.container_info.ports[0])
     self.assertEqual(name, 'dummyservice_name-8086-udp')
Beispiel #4
0
 def test_services_multiple(self):
     self.container_info.metadata = ContainerMetadata(
         {'name': 'dummyservice_name'})
     self.container_info.metadata_with_port = {}
     self.container_info.ports = [
         Ports(internal=80, external=8086, protocol='udp', ip='0.0.0.0'),
         Ports(internal=81, external=8087, protocol='tcp', ip='0.0.0.0'),
     ]
     identifiers = self.container_info.service_identifiers()
     id1 = self.container_info.SERVICE_ID_SEPARATOR.join(
         ('my_host_name', 'dummyservice', '8086', 'udp'))
     id2 = self.container_info.SERVICE_ID_SEPARATOR.join(
         ('my_host_name', 'dummyservice', '8087'))
     self.assertIn(id1, identifiers)
     self.assertIn(id2, identifiers)
Beispiel #5
0
 def test_build_service_id_udp(self):
     port = Ports(internal=80, external=8086, protocol='udp', ip='0.0.0.0')
     service_id = self.container_info.build_service_id(port)
     self.assertEqual(
         service_id,
         self.container_info.SERVICE_ID_SEPARATOR.join(
             ('my_host_name', 'dummyservice', '8086', 'udp')))
Beispiel #6
0
 def test_get_name_service_prefix(self):
     self.container_info.service_prefix = 'x'
     port = Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0')
     value = self.container_info.get_name(port)
     self.assertEqual(value,
                      (self.container_info.service_prefix +
                       self.container_info.SERVICE_PREFIX_NAME_SEPARATOR +
                       'dummyservice_80_name'))
Beispiel #7
0
 def test_names_count_no_name(self):
     self.container_info.metadata = ContainerMetadata()
     self.container_info.ports = [
         Ports(internal=81, external=8086, protocol='tcp', ip='0.0.0.0')
     ]
     counts = self.container_info.names_count()
     self.assertNotIn('dummyservice_80_name', counts)
     self.assertEqual(counts, {})
Beispiel #8
0
    def test_build_service_ip_metadata_port(self):
        self.container_info.metadata_with_port = {
            80: ContainerMetadata({'ip': '4.3.2.1'})
        }

        port = Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0')
        ip = self.container_info.build_service_ip(port)
        self.assertEqual(ip, '4.3.2.1')
Beispiel #9
0
 def test_build_service_attrs_metadata(self):
     self.container_info.metadata_with_port = {
         80: ContainerMetadata({'attrs': {
             'k': 'v'
         }})
     }
     port = Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0')
     attrs = self.container_info.build_service_attrs(port)
     self.assertEqual(attrs, {'k': 'v'})
 def test_extract_ports_no_port_but_bindings(self):
     self.container.attrs['HostConfig'][
         'PortBindings'] = self.container.attrs['NetworkSettings'][
             'Ports'].copy()
     self.container.attrs['NetworkSettings']['Ports'] = {}
     ports = ServiceRegistrator.extract_ports(self.container)
     self.assertEqual(
         set(ports),
         set([
             Ports(internal=180,
                   external=18082,
                   protocol='udp',
                   ip='127.0.0.1'),
             Ports(internal=80,
                   external=28082,
                   protocol='tcp',
                   ip='0.0.0.0'),
             Ports(internal=80, external=8082, protocol='tcp', ip='0.0.0.0')
         ]))
Beispiel #11
0
 def setUp(self):
     ports = [
         Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0')
     ]
     metadata = ContainerMetadata({'name': 'dummyservice_name'})
     metadata_with_port = {
         80: ContainerMetadata({'name': 'dummyservice_80_name'})
     }
     container_id = 'deadbeef'
     service_name = 'dummyservice'
     hostname = 'my_host_name'
     ip = '127.6.6.6'
     tags = ['tag1', 'tag2']
     self.container_info = ContainerInfo(container_id, service_name, ports,
                                         metadata, metadata_with_port,
                                         hostname, ip, tags)
Beispiel #12
0
 def test_get_name_none(self):
     self.container_info.metadata = ContainerMetadata()
     port = Ports(internal=81, external=8086, protocol='tcp', ip='0.0.0.0')
     value = self.container_info.get_name(port)
     self.assertIsNone(value)
Beispiel #13
0
 def test_get_name(self):
     port = Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0')
     value = self.container_info.get_name(port)
     self.assertEqual(value, 'dummyservice_80_name')
Beispiel #14
0
 def test_build_service_name(self):
     port = Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0')
     name = self.container_info.build_service_name(port)
     self.assertEqual(name, 'dummyservice_80_name')
Beispiel #15
0
    def test_build_service_ip_metadata(self):
        self.container_info.metadata = ContainerMetadata({'ip': '1.2.3.4'})

        port = Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0')
        ip = self.container_info.build_service_ip(port)
        self.assertEqual(ip, '1.2.3.4')
Beispiel #16
0
 def test_build_service_ip(self):
     port = Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0')
     ip = self.container_info.build_service_ip(port)
     self.assertEqual(ip, '127.6.6.6')
Beispiel #17
0
 def test_build_service_attrs(self):
     port = Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0')
     attrs = self.container_info.build_service_attrs(port)
     self.assertEqual(attrs, {})
Beispiel #18
0
 def test_services_tags_udp(self):
     port = Ports(internal=80, external=8086, protocol='udp', ip='0.0.0.0')
     tags = self.container_info.build_service_tags(port)
     self.assertEqual(set(tags), set(['tag2', 'tag1', 'udp']))
Beispiel #19
0
 def test_services_tags_metadata_notags(self):
     self.container_info.tags = []
     self.container_info.metadata = ContainerMetadata({'tags': 'tag3,tag4'})
     port = Ports(internal=80, external=8086, protocol='tcp', ip='0.0.0.0')
     tags = self.container_info.build_service_tags(port)
     self.assertEqual(set(tags), set(['tag4', 'tag3']))
Beispiel #20
0
 def test_build_service_name_no_matching_port(self):
     port = Ports(internal=81, external=8086, protocol='tcp', ip='0.0.0.0')
     name = self.container_info.build_service_name(port)
     self.assertIsNone(name)