Beispiel #1
0
 def test_get_port_mappings_string_list_case(self):
     p = portmappings.PortMappings()
     expected = [{
         'labels': {
             'VIP_0': '1.1.1.1:8080',
             'VIP_2': u'www.contoso.com.external:80'
         },
         'protocol': 'tcp',
         'containerPort': 8080,
         'hostPort': 0
     }, {
         'labels': {
             'VIP_0': '1.1.1.1:8081',
             'VIP_2': u'api.contoso.com.external:80'
         },
         'protocol': 'tcp',
         'containerPort': 8081,
         'hostPort': 0
     }]
     service_data = {
         'labels': {
             "com.microsoft.acs.DCOS.marathon.vhosts=[\"www.contoso.com:8080\", \"api.contoso.com:8081\"]"
         }
     }
     actual = p.get_port_mappings('1.1.1.1', service_data, 'myvipname')
     self.assertEquals(actual, expected)
Beispiel #2
0
 def test_get_port_mappings_port_range_pair(self):
     p = portmappings.PortMappings()
     expected = [{
         'labels': {
             'VIP_1': 'myvipname.internal:5000',
             'VIP_0': '1.1.1.1:6000'
         },
         'protocol': 'tcp',
         'containerPort': 6000,
         'hostPort': 0
     }, {
         'labels': {
             'VIP_1': 'myvipname.internal:5001',
             'VIP_0': '1.1.1.1:6001'
         },
         'protocol': 'tcp',
         'containerPort': 6001,
         'hostPort': 0
     }, {
         'labels': {
             'VIP_1': 'myvipname.internal:5002',
             'VIP_0': '1.1.1.1:6002'
         },
         'protocol': 'tcp',
         'containerPort': 6002,
         'hostPort': 0
     }]
     service_data = {'ports': ["5000-5002:6000-6002"]}
     self.assertEquals(
         p.get_port_mappings('1.1.1.1', service_data, 'myvipname'),
         expected)
Beispiel #3
0
 def test_get_port_mappings_multiple_externals_case(self):
     p = portmappings.PortMappings()
     expected = [{
         'labels': {
             'VIP_0': '1.1.1.1:8080',
             'VIP_2': u'www.contoso.com.external:80'
         },
         'protocol': 'tcp',
         'containerPort': 8080,
         'hostPort': 0
     }, {
         'labels': {
             'VIP_0': '1.1.1.1:8081',
             'VIP_2': u'api.contoso.com.external:80'
         },
         'protocol': 'tcp',
         'containerPort': 8081,
         'hostPort': 0
     }]
     service_data = {
         'labels': {
             'com.microsoft.acs.dcos.marathon.VHOSTS':
             '["www.contoso.com:8080", "api.contoso.com:8081"]'
         }
     }
     actual = p.get_port_mappings('1.1.1.1', service_data, 'myvipname')
     self.assertEquals(actual, expected)
Beispiel #4
0
 def test_get_all_vhosts_single_json_case(self):
     p = portmappings.PortMappings()
     service_data = {
         'labels': {'com.microsoft.ACS.dcos.marathon.vhost=example.com:80'}
     }
     expected = {'example.com': 80}
     actual = p._get_all_vhosts(service_data)
     self.assertEquals(actual, expected)
Beispiel #5
0
 def test_get_all_vhosts_single_dict_case(self):
     p = portmappings.PortMappings()
     service_data = {
         'labels': {
             'com.microsoft.acs.dcos.MARATHON.vhost': 'example.com:80'
         }
     }
     expected = {'example.com': 80}
     actual = p._get_all_vhosts(service_data)
     self.assertEquals(actual, expected)
Beispiel #6
0
 def test_get_port_mappings_single_exposed_port(self):
     p = portmappings.PortMappings()
     expected = [{
         'labels': {
             'VIP_0': '1.1.1.1:5000'
         },
         'protocol': 'tcp',
         'containerPort': 5000,
         'hostPort': 0
     }]
     service_data = {'expose': ["5000"]}
     self.assertEquals(
         p.get_port_mappings('1.1.1.1', service_data, 'myvipname'),
         expected)
Beispiel #7
0
 def test_get_port_mappings_string_case(self):
     p = portmappings.PortMappings()
     expected = [{
         'labels': {
             'VIP_0': '1.1.1.1:5000',
             'VIP_2': 'www.example.com.external:80'
         },
         'protocol': 'tcp',
         'containerPort': 5000,
         'hostPort': 0
     }]
     service_data = {
         'labels':
         {'com.microsoft.ACS.dcos.MARATHON.vhost=www.example.com:5000'}
     }
     self.assertEquals(
         p.get_port_mappings('1.1.1.1', service_data, 'myvipname'),
         expected)
    def __init__(self,
                 compose_file,
                 master_url,
                 acs_host,
                 acs_port,
                 acs_username,
                 acs_password,
                 acs_private_key,
                 group_name,
                 group_qualifier,
                 group_version,
                 registry_host,
                 registry_username,
                 registry_password,
                 minimum_health_capacity,
                 check_dcos_version=False):

        self.cleanup_needed = False
        self._ensure_docker_compose(compose_file)
        with open(compose_file, 'r') as compose_stream:
            self.compose_data = yaml.load(compose_stream)

        self.acs_info = acsinfo.AcsInfo(acs_host, acs_port, acs_username,
                                        acs_password, acs_private_key,
                                        master_url)

        self.group_name = group_name
        self.group_qualifier = group_qualifier
        self.group_version = group_version

        self.registry_host = registry_host
        self.registry_username = registry_username
        self.registry_password = registry_password

        self.minimum_health_capacity = minimum_health_capacity

        self.acs_client = acsclient.ACSClient(self.acs_info)
        if check_dcos_version:
            self.acs_client.ensure_dcos_version()
        self.marathon_helper = marathon.Marathon(self.acs_client)
        self.exhibitor_helper = Exhibitor(self.marathon_helper)
        self.nginx_helper = LoadBalancerApp(self.marathon_helper)

        self.portmappings_helper = portmappings.PortMappings()
Beispiel #9
0
 def test_get_port_mappings_external_port_case(self):
     p = portmappings.PortMappings()
     expected = [{
         'labels': {
             'VIP_1': 'myvipname.internal:5000',
             'VIP_0': '1.1.1.1:5000',
             'VIP_2': 'www.example.com.external:80'
         },
         'protocol': 'tcp',
         'containerPort': 5000,
         'hostPort': 0
     }]
     service_data = {
         'ports': ["5000"],
         'labels': {
             'com.MICROSOFT.acs.dcos.marathon.vhost': 'www.example.com:5000'
         }
     }
     self.assertEquals(
         p.get_port_mappings('1.1.1.1', service_data, 'myvipname'),
         expected)
Beispiel #10
0
 def test_get_port_mappings_single_published_and_exposed_port(self):
     p = portmappings.PortMappings()
     expected = [{
         'labels': {
             'VIP_1': 'myvipname.internal:5000',
             'VIP_0': '1.1.1.1:5000'
         },
         'protocol': 'tcp',
         'containerPort': 5000,
         'hostPort': 0
     }, {
         'labels': {
             'VIP_0': '1.1.1.1:3000'
         },
         'protocol': 'tcp',
         'containerPort': 3000,
         'hostPort': 0
     }]
     service_data = {'ports': ["5000"], 'expose': ["3000"]}
     self.assertEquals(
         sorted(p.get_port_mappings('1.1.1.1', service_data, 'myvipname')),
         sorted(expected))
Beispiel #11
0
 def test_are_port_ranges_same_length_invalid(self):
     p = portmappings.PortMappings()
     self.assertRaises(ValueError, p._are_port_ranges_same_length, '3000',
                       '4000-4015')
Beispiel #12
0
 def test_is_port_range_not_a_number(self):
     p = portmappings.PortMappings()
     self.assertFalse(p._is_port_range('blah'))
Beispiel #13
0
 def test_are_port_ranges_same_length_different_range(self):
     p = portmappings.PortMappings()
     self.assertFalse(
         p._are_port_ranges_same_length('3000-3005', '4000-4015'))
Beispiel #14
0
 def test_split_port_range_valid(self):
     p = portmappings.PortMappings()
     self.assertEqual(p._split_port_range('3000-3005'), (3000, 3005))
Beispiel #15
0
 def test_parse_internal_ports_pair(self):
     p = portmappings.PortMappings()
     service_data = {'ports': ["8080:80"]}
     self.assertEquals(p._parse_internal_ports(service_data), [(8080, 80)])
Beispiel #16
0
 def test_parse_private_ports_pair(self):
     p = portmappings.PortMappings()
     self.assertRaises(ValueError, p._parse_private_ports,
                       {'expose': ['3000:3001']})
Beispiel #17
0
 def test_parse_vhosts_json(self):
     p = portmappings.PortMappings()
     label = '["example:123", "api.example:80"]'
     actual = p._parse_vhost_json(label)
     expected = {'example': 123, 'api.example': 80}
     self.assertEquals(actual, expected)
Beispiel #18
0
 def test_parse_vhost_label_no_port(self):
     p = portmappings.PortMappings()
     label = '1.1.1.1'
     expected = ('1.1.1.1', 80)
     actual = p._parse_vhost_label(label)
     self.assertEquals(actual, expected)
Beispiel #19
0
 def test_create_instance(self):
     p = portmappings.PortMappings()
     self.assertIsNotNone(p)
Beispiel #20
0
 def test_split_port_range_with_colon(self):
     p = portmappings.PortMappings()
     self.assertRaises(ValueError, p._split_port_range,
                       '3000-3005:4000-4005')
Beispiel #21
0
 def test_is_port_range_missing_second_part(self):
     p = portmappings.PortMappings()
     self.assertFalse(p._is_port_range('3000-'))
Beispiel #22
0
 def test_split_port_range_empty(self):
     p = portmappings.PortMappings()
     self.assertRaises(ValueError, p._split_port_range, '')
Beispiel #23
0
 def test_parse_private_ports_valid(self):
     p = portmappings.PortMappings()
     self.assertEquals(p._parse_private_ports({'expose': ['3000']}),
                       [(3000, 3000)])
Beispiel #24
0
 def test_parse_vhosts_json_invalid(self):
     p = portmappings.PortMappings()
     label = '//ewr"example:123", "api.example:80"]'
     self.assertRaises(ValueError, p._parse_vhost_json, label)
Beispiel #25
0
 def test_parse_private_ports_empty_service_data(self):
     p = portmappings.PortMappings()
     self.assertRaises(ValueError, p._parse_private_ports, {})
Beispiel #26
0
 def test_get_all_vhosts_no_labels(self):
     p = portmappings.PortMappings()
     service_data = {}
     expected = {}
     actual = p._get_all_vhosts(service_data)
     self.assertEquals(actual, expected)
Beispiel #27
0
 def test_parse_private_ports_not_a_number(self):
     p = portmappings.PortMappings()
     self.assertRaises(ValueError, p._parse_private_ports,
                       {'expose': ['blah']})
Beispiel #28
0
 def test_are_port_ranges_same_length_valid(self):
     p = portmappings.PortMappings()
     self.assertTrue(
         p._are_port_ranges_same_length('3000-3005', '4000-4005'))
Beispiel #29
0
 def test_parse_vhosts_json_none(self):
     p = portmappings.PortMappings()
     actual = p._parse_vhost_json(None)
     self.assertIsNone(actual)
Beispiel #30
0
 def test_split_port_range_single_port(self):
     p = portmappings.PortMappings()
     self.assertRaises(ValueError, p._split_port_range, '3000')