From 41fbc58073f3fabf4ea7a0d602244489d8621ccf Mon Sep 17 00:00:00 2001 From: Peter Jausovec Date: Thu, 10 Nov 2016 17:00:16 -0800 Subject: [PATCH] External VHOST port should always be 80. The port specified in the label is the container port under which the VIP ends up. --- .../dockerDeploy/acs-dcos/portmappings.py | 2 +- .../acs-dcos/test_portmappings.py | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/tasks/dockerDeploy/acs-dcos/portmappings.py b/src/tasks/dockerDeploy/acs-dcos/portmappings.py index d40c021..4686ae9 100644 --- a/src/tasks/dockerDeploy/acs-dcos/portmappings.py +++ b/src/tasks/dockerDeploy/acs-dcos/portmappings.py @@ -208,7 +208,7 @@ class PortMappings(object): vhost_added = False port = all_vhosts[vhost] port = str(port).strip() - external_vip = vhost + '.external' + ':' + port + external_vip = vhost + '.external' + ':80' for port_mapping in existing_port_mappings: if str(port_mapping['containerPort']).strip() == str(port): port_mapping['labels']['VIP_2'] = external_vip diff --git a/src/tasks/dockerDeploy/acs-dcos/test_portmappings.py b/src/tasks/dockerDeploy/acs-dcos/test_portmappings.py index dca3038..2308cfd 100644 --- a/src/tasks/dockerDeploy/acs-dcos/test_portmappings.py +++ b/src/tasks/dockerDeploy/acs-dcos/test_portmappings.py @@ -186,64 +186,64 @@ class PortMappingsTest(unittest.TestCase): def test_get_port_mappings_external_port(self): p = portmappings.PortMappings() - expected = [{'labels': {'VIP_1': 'myvipname.internal:5000', 'VIP_0': '1.1.1.1:5000', 'VIP_2': 'www.example.com.external:5000'}, 'protocol': 'tcp', 'containerPort': 5000, 'hostPort': 0}] + 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) 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:5000'}, 'protocol': 'tcp', 'containerPort': 5000, 'hostPort': 0}] + 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) def test_get_port_mappings_external_no_internal_port(self): p = portmappings.PortMappings() - expected = [{'labels': {'VIP_0': '1.1.1.1:5000', 'VIP_2': 'www.example.com.external:5000'}, 'protocol': 'tcp', 'containerPort': 5000, 'hostPort': 0}] + 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 test_get_port_mappings_external_no_internal_port_case(self): p = portmappings.PortMappings() - expected = [{'labels': {'VIP_0': '1.1.1.1:5000', 'VIP_2': 'www.example.com.external:5000'}, 'protocol': 'tcp', 'containerPort': 5000, 'hostPort': 0}] + 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 test_get_port_mappings_multiple_externals(self): p = portmappings.PortMappings() - expected = [{'labels': {'VIP_0': '1.1.1.1:8080', 'VIP_2': u'www.contoso.com.external:8080'}, 'protocol': 'tcp', 'containerPort': 8080, 'hostPort': 0}, {'labels': {'VIP_0': '1.1.1.1:8081', 'VIP_2': u'api.contoso.com.external:8081'}, 'protocol': 'tcp', 'containerPort': 8081, 'hostPort': 0}] + 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) 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:8080'}, 'protocol': 'tcp', 'containerPort': 8080, 'hostPort': 0}, {'labels': {'VIP_0': '1.1.1.1:8081', 'VIP_2': u'api.contoso.com.external:8081'}, 'protocol': 'tcp', 'containerPort': 8081, 'hostPort': 0}] + 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) def test_get_port_mappings_string(self): p = portmappings.PortMappings() - expected = [{'labels': {'VIP_0': '1.1.1.1:5000', 'VIP_2': 'www.example.com.external:5000'}, 'protocol': 'tcp', 'containerPort': 5000, 'hostPort': 0}] + 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 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:5000'}, 'protocol': 'tcp', 'containerPort': 5000, 'hostPort': 0}] + 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 test_get_port_mappings_string_list(self): p = portmappings.PortMappings() - expected = [{'labels': {'VIP_0': '1.1.1.1:8080', 'VIP_2': u'www.contoso.com.external:8080'}, 'protocol': 'tcp', 'containerPort': 8080, 'hostPort': 0}, {'labels': {'VIP_0': '1.1.1.1:8081', 'VIP_2': u'api.contoso.com.external:8081'}, 'protocol': 'tcp', 'containerPort': 8081, 'hostPort': 0}] + 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) 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:8080'}, 'protocol': 'tcp', 'containerPort': 8080, 'hostPort': 0}, {'labels': {'VIP_0': '1.1.1.1:8081', 'VIP_2': u'api.contoso.com.external:8081'}, 'protocol': 'tcp', 'containerPort': 8081, 'hostPort': 0}] + 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)