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
This commit is contained in:
parent
5afa8e9ef2
commit
797fb484fe
|
@ -164,18 +164,17 @@ def _create_service(service):
|
||||||
return
|
return
|
||||||
ports = []
|
ports = []
|
||||||
for port in service["ports"]:
|
for port in service["ports"]:
|
||||||
source_port, _, node_port = str(port).partition(":")
|
source_port = int(port.get('cont'))
|
||||||
source_port = int(source_port)
|
node_port = port.get('node')
|
||||||
name_port = str(source_port)
|
port_name = str(source_port)
|
||||||
if node_port:
|
if node_port:
|
||||||
node_port = int(node_port)
|
ports.append({"port": source_port, "name": port_name,
|
||||||
if node_port:
|
"node-port": int(node_port)})
|
||||||
ports.append({"port": source_port, "name": name_port,
|
|
||||||
"node-port": node_port})
|
|
||||||
else:
|
else:
|
||||||
ports.append({"port": source_port, "name": name_port})
|
ports.append({"port": source_port, "name": port_name})
|
||||||
template = templates.serialize_service(service["name"], ports)
|
|
||||||
kubernetes.process_object(template)
|
service_template = templates.serialize_service(service["name"], ports)
|
||||||
|
kubernetes.process_object(service_template)
|
||||||
|
|
||||||
|
|
||||||
def _create_pre_commands(workflow, container):
|
def _create_pre_commands(workflow, container):
|
||||||
|
|
|
@ -167,16 +167,16 @@ class TestDeployCreateService(base.TestCase):
|
||||||
self.assertFalse(self.create_obj.called)
|
self.assertFalse(self.create_obj.called)
|
||||||
|
|
||||||
def test_create_service(self):
|
def test_create_service(self):
|
||||||
|
self.conf.configs._merge({'ingress': {'enabled': False}})
|
||||||
service = {
|
service = {
|
||||||
"name": "foo",
|
"name": "foo",
|
||||||
"ports": [
|
"ports": [
|
||||||
1234,
|
{"cont": 1111},
|
||||||
"1122:3344",
|
{"cont": "2222"},
|
||||||
"5566",
|
{"cont": 3333,
|
||||||
"9999",
|
"node": 30000},
|
||||||
"8888:6666",
|
{"cont": "4444",
|
||||||
"7788:6666",
|
"node": "33333"}
|
||||||
"7777:9900"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
service_k8s_obj = """
|
service_k8s_obj = """
|
||||||
|
@ -188,38 +188,24 @@ metadata:
|
||||||
name: foo
|
name: foo
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
- name: "1234"
|
- name: "1111"
|
||||||
port: 1234
|
port: 1111
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
targetPort: 1234
|
targetPort: 1111
|
||||||
- name: "1122"
|
- name: "2222"
|
||||||
nodePort: 3344
|
port: 2222
|
||||||
port: 1122
|
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
targetPort: 1122
|
targetPort: 2222
|
||||||
- name: "5566"
|
- name: "3333"
|
||||||
port: 5566
|
nodePort: 30000
|
||||||
|
port: 3333
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
targetPort: 5566
|
targetPort: 3333
|
||||||
- name: "9999"
|
- name: "4444"
|
||||||
port: 9999
|
nodePort: 33333
|
||||||
|
port: 4444
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
targetPort: 9999
|
targetPort: 4444
|
||||||
- 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
|
|
||||||
selector:
|
selector:
|
||||||
app: foo
|
app: foo
|
||||||
type: NodePort"""
|
type: NodePort"""
|
||||||
|
|
|
@ -3,7 +3,6 @@ import mock
|
||||||
from fuel_ccp.tests import base
|
from fuel_ccp.tests import base
|
||||||
from fuel_ccp.validation import base as base_validation
|
from fuel_ccp.validation import base as base_validation
|
||||||
from fuel_ccp.validation import deploy as deploy_validation
|
from fuel_ccp.validation import deploy as deploy_validation
|
||||||
from fuel_ccp.validation import service as service_validation
|
|
||||||
|
|
||||||
|
|
||||||
COMPONENTS_MAP = {
|
COMPONENTS_MAP = {
|
||||||
|
@ -81,26 +80,3 @@ class TestDeployValidation(base.TestCase):
|
||||||
'deployment: service2',
|
'deployment: service2',
|
||||||
deploy_validation.validate_requested_components,
|
deploy_validation.validate_requested_components,
|
||||||
{'service1'}, COMPONENTS_MAP)
|
{'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)
|
|
||||||
|
|
|
@ -7,17 +7,6 @@ import jsonschema
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
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.-]+)+/?))$'
|
PATH_RE = r'^(/|((/[\w.-]+)+/?))$'
|
||||||
FILE_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 = {
|
PROBE_SCHEMA_HTTP = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
|
@ -135,9 +136,7 @@ PROBE_SCHEMA_HTTP = {
|
||||||
"type": {
|
"type": {
|
||||||
"enum": ["httpGet"]
|
"enum": ["httpGet"]
|
||||||
},
|
},
|
||||||
"port": {
|
"port": PORT_SCHEMA,
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"path": NOT_EMPTY_STRING_SCHEMA,
|
"path": NOT_EMPTY_STRING_SCHEMA,
|
||||||
"initialDelay": TIMEOUT_SCHEMA,
|
"initialDelay": TIMEOUT_SCHEMA,
|
||||||
"timeout": TIMEOUT_SCHEMA
|
"timeout": TIMEOUT_SCHEMA
|
||||||
|
@ -171,19 +170,13 @@ SERVICE_SCHEMA = {
|
||||||
"minItems": 1,
|
"minItems": 1,
|
||||||
|
|
||||||
"items": {
|
"items": {
|
||||||
"oneOf": [
|
"type": "object",
|
||||||
{
|
"additionalProperties": False,
|
||||||
"type": "integer",
|
"required": ["cont"],
|
||||||
"minimum": 1,
|
"properties": {
|
||||||
"maximum": 65535
|
"cont": PORT_SCHEMA,
|
||||||
},
|
'node': NODE_PORT_SCHEMA
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"pattern": r"^{}(:{})?$".format(
|
|
||||||
ALL_PORT_RE, HOST_PORT_RE
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"kind": {
|
"kind": {
|
||||||
|
|
Loading…
Reference in New Issue