From 797fb484fe6e4b9ced4e88dbd36f92b5caf32d53 Mon Sep 17 00:00:00 2001 From: Andrey Pavlov Date: Wed, 26 Oct 2016 15:52:26 +0300 Subject: [PATCH] Ports configuration refactoring * regex ports validation was removed * ports configuration has been changed: before: port: 123:3333 after: port: cont: 123 node: 3333 Change-Id: I54ab8dd02fc88b821a1f0d05c08f98b618730150 --- fuel_ccp/deploy.py | 19 +++++------ fuel_ccp/tests/test_deploy.py | 56 ++++++++++++------------------- fuel_ccp/tests/test_validation.py | 24 ------------- fuel_ccp/validation/service.py | 47 +++++++++++--------------- 4 files changed, 50 insertions(+), 96 deletions(-) diff --git a/fuel_ccp/deploy.py b/fuel_ccp/deploy.py index 8fb849bf..6d21a811 100644 --- a/fuel_ccp/deploy.py +++ b/fuel_ccp/deploy.py @@ -164,18 +164,17 @@ def _create_service(service): return ports = [] for port in service["ports"]: - source_port, _, node_port = str(port).partition(":") - source_port = int(source_port) - name_port = str(source_port) + source_port = int(port.get('cont')) + node_port = port.get('node') + port_name = str(source_port) if node_port: - node_port = int(node_port) - if node_port: - ports.append({"port": source_port, "name": name_port, - "node-port": node_port}) + ports.append({"port": source_port, "name": port_name, + "node-port": int(node_port)}) else: - ports.append({"port": source_port, "name": name_port}) - template = templates.serialize_service(service["name"], ports) - kubernetes.process_object(template) + ports.append({"port": source_port, "name": port_name}) + + service_template = templates.serialize_service(service["name"], ports) + kubernetes.process_object(service_template) def _create_pre_commands(workflow, container): diff --git a/fuel_ccp/tests/test_deploy.py b/fuel_ccp/tests/test_deploy.py index fc3529dd..ce09383b 100644 --- a/fuel_ccp/tests/test_deploy.py +++ b/fuel_ccp/tests/test_deploy.py @@ -167,16 +167,16 @@ class TestDeployCreateService(base.TestCase): self.assertFalse(self.create_obj.called) def test_create_service(self): + self.conf.configs._merge({'ingress': {'enabled': False}}) service = { "name": "foo", "ports": [ - 1234, - "1122:3344", - "5566", - "9999", - "8888:6666", - "7788:6666", - "7777:9900" + {"cont": 1111}, + {"cont": "2222"}, + {"cont": 3333, + "node": 30000}, + {"cont": "4444", + "node": "33333"} ] } service_k8s_obj = """ @@ -188,38 +188,24 @@ metadata: name: foo spec: ports: - - name: "1234" - port: 1234 + - name: "1111" + port: 1111 protocol: TCP - targetPort: 1234 - - name: "1122" - nodePort: 3344 - port: 1122 + targetPort: 1111 + - name: "2222" + port: 2222 protocol: TCP - targetPort: 1122 - - name: "5566" - port: 5566 + targetPort: 2222 + - name: "3333" + nodePort: 30000 + port: 3333 protocol: TCP - targetPort: 5566 - - name: "9999" - port: 9999 + targetPort: 3333 + - name: "4444" + nodePort: 33333 + port: 4444 protocol: TCP - targetPort: 9999 - - name: "8888" - nodePort: 6666 - port: 8888 - protocol: TCP - targetPort: 8888 - - name: "7788" - nodePort: 6666 - port: 7788 - protocol: TCP - targetPort: 7788 - - name: "7777" - nodePort: 9900 - port: 7777 - protocol: TCP - targetPort: 7777 + targetPort: 4444 selector: app: foo type: NodePort""" diff --git a/fuel_ccp/tests/test_validation.py b/fuel_ccp/tests/test_validation.py index a07f7673..1a628923 100644 --- a/fuel_ccp/tests/test_validation.py +++ b/fuel_ccp/tests/test_validation.py @@ -3,7 +3,6 @@ import mock from fuel_ccp.tests import base from fuel_ccp.validation import base as base_validation from fuel_ccp.validation import deploy as deploy_validation -from fuel_ccp.validation import service as service_validation COMPONENTS_MAP = { @@ -81,26 +80,3 @@ class TestDeployValidation(base.TestCase): 'deployment: service2', deploy_validation.validate_requested_components, {'service1'}, COMPONENTS_MAP) - - -class TestValidationRegex(base.TestCase): - def test_ports_re(self): - regex = r"^{}(:{})?$".format( - service_validation.ALL_PORT_RE, service_validation.HOST_PORT_RE) - self.assertRegexpMatches('0', regex) - self.assertRegexpMatches('12', regex) - self.assertRegexpMatches('123', regex) - self.assertRegexpMatches('1234', regex) - self.assertRegexpMatches('12345', regex) - self.assertRegexpMatches('65535', regex) - - self.assertNotRegexpMatches('65536', regex) - self.assertNotRegexpMatches('123456', regex) - - self.assertRegexpMatches('1234:30000', regex) - self.assertRegexpMatches('1234:32767', regex) - - self.assertNotRegexpMatches('1234:1000', regex) - self.assertNotRegexpMatches('1234:29999', regex) - self.assertNotRegexpMatches('1234:32768', regex) - self.assertNotRegexpMatches('1234:40000', regex) diff --git a/fuel_ccp/validation/service.py b/fuel_ccp/validation/service.py index 401d5e86..c8e09ed3 100644 --- a/fuel_ccp/validation/service.py +++ b/fuel_ccp/validation/service.py @@ -7,17 +7,6 @@ import jsonschema LOG = logging.getLogger(__name__) - -# RegExp for range 0-65535 -ALL_PORT_RE = ( - r'0*(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]' - r'{4}|[1-9][0-9]{1,3}|[0-9])' -) -# RegExp for range 30000-32767 -HOST_PORT_RE = ( - r'(3[0-1][0-9]{3}|32[0-6][0-9]{2}|327[0-5][0-9]|3276[0-7])' -) - PATH_RE = r'^(/|((/[\w.-]+)+/?))$' FILE_PATH_RE = r'^(/|((/[\w.-]+)+))$' @@ -126,6 +115,18 @@ PROBE_SCHEMA_EXEC = { } } +PORT_SCHEMA = { + "type": "integer", + "minimum": 1, + "maximum": 65535 +} + +NODE_PORT_SCHEMA = { + "type": "integer", + "minimum": 30000, + "maximum": 32767 +} + PROBE_SCHEMA_HTTP = { "type": "object", "additionalProperties": False, @@ -135,9 +136,7 @@ PROBE_SCHEMA_HTTP = { "type": { "enum": ["httpGet"] }, - "port": { - "type": "integer" - }, + "port": PORT_SCHEMA, "path": NOT_EMPTY_STRING_SCHEMA, "initialDelay": TIMEOUT_SCHEMA, "timeout": TIMEOUT_SCHEMA @@ -171,19 +170,13 @@ SERVICE_SCHEMA = { "minItems": 1, "items": { - "oneOf": [ - { - "type": "integer", - "minimum": 1, - "maximum": 65535 - }, - { - "type": "string", - "pattern": r"^{}(:{})?$".format( - ALL_PORT_RE, HOST_PORT_RE - ) - } - ] + "type": "object", + "additionalProperties": False, + "required": ["cont"], + "properties": { + "cont": PORT_SCHEMA, + 'node': NODE_PORT_SCHEMA + } } }, "kind": {