Skip to content
Snippets Groups Projects
Commit 711dbff3 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch...

Merge branch 'feat/100-cttc-improve-nbi-unitary-tests-framework-and-integration-with-gitlab-ci-cd-pipeline' into 'develop'

Resolve "(CTTC) Improve NBI unitary tests framework and integration with GitLab CI/CD pipeline"

Closes #100

See merge request !186
parents b27dd5d2 c622f31f
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!186Resolve "(CTTC) Improve NBI unitary tests framework and integration with GitLab CI/CD pipeline"
#!/bin/bash
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PROJECTDIR=`pwd`
cd $PROJECTDIR/src
RCFILE=$PROJECTDIR/coverage/.coveragerc
# Run unitary tests and analyze coverage of code at same time
# helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0
coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
nbi/tests/test_ietf_l2vpn.py
coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
nbi/tests/test_ietf_network.py
......@@ -20,5 +20,6 @@ cd $PROJECTDIR/src
RCFILE=$PROJECTDIR/coverage/.coveragerc
# Run unitary tests and analyze coverage of code at same time
# helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0
coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
nbi/tests/test_unitary.py
nbi/tests/test_ietf_l2vpn.py
......@@ -430,7 +430,7 @@ class MockServicerImpl_Context(ContextServiceServicer):
def RemoveSlice(self, request: SliceId, context : grpc.ServicerContext) -> Empty:
LOGGER.debug('[RemoveSlice] request={:s}'.format(grpc_message_to_json_string(request)))
context_uuid = str(request.slice_id.context_id.context_uuid.uuid)
context_uuid = str(request.context_id.context_uuid.uuid)
container_name = 'slice[{:s}]'.format(context_uuid)
slice_uuid = request.slice_uuid.uuid
reply = self._del(request, container_name, slice_uuid, 'slice_id', TOPIC_SLICE, context)
......@@ -522,7 +522,7 @@ class MockServicerImpl_Context(ContextServiceServicer):
def RemoveService(self, request: ServiceId, context : grpc.ServicerContext) -> Empty:
LOGGER.debug('[RemoveService] request={:s}'.format(grpc_message_to_json_string(request)))
context_uuid = str(request.service_id.context_id.context_uuid.uuid)
context_uuid = str(request.context_id.context_uuid.uuid)
container_name = 'service[{:s}]'.format(context_uuid)
service_uuid = request.service_uuid.uuid
reply = self._del(request, container_name, service_uuid, 'service_id', TOPIC_SERVICE, context)
......
......@@ -48,15 +48,26 @@ unit_test nbi:
- build nbi
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi
- if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi
- >
if docker network list | grep teraflowbridge; then
echo "teraflowbridge is already created";
else
docker network create -d bridge teraflowbridge;
fi
- >
if docker container ls | grep $IMAGE_NAME; then
docker rm -f $IMAGE_NAME;
else
echo "$IMAGE_NAME image is not in the system";
fi
script:
- docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
- docker run --name $IMAGE_NAME -d -p 9090:9090 -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG
- sleep 5
- docker ps -a
- docker logs $IMAGE_NAME
- docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_unitary.py $IMAGE_NAME/tests/test_ietf_network.py --junitxml=/opt/results/${IMAGE_NAME}_report.xml"
- docker exec -i $IMAGE_NAME bash -c "coverage run --append -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_ietf_l2vpn.py --junitxml=/opt/results/${IMAGE_NAME}_report_ietf_l2vpn.xml"
- docker exec -i $IMAGE_NAME bash -c "coverage run --append -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_ietf_network.py --junitxml=/opt/results/${IMAGE_NAME}_report_ietf_network.xml"
- docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing"
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
after_script:
......@@ -77,7 +88,7 @@ unit_test nbi:
artifacts:
when: always
reports:
junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml
junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report_*.xml
## Deployment of the service in Kubernetes Cluster
#deploy nbi:
......
......@@ -17,7 +17,7 @@ Flask==2.1.3
Flask-HTTPAuth==4.5.0
Flask-RESTful==0.3.9
jsonschema==4.4.0
pyang
pyang==2.6.0
git+https://github.com/robshakir/pyangbind.git
requests==2.27.1
werkzeug==2.3.7
......@@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging, os, pytest, requests, time
from typing import Dict, List, Optional, Set, Union
import enum, logging, os, pytest, requests, time
from typing import Any, Dict, List, Optional, Set, Union
from common.Constants import ServiceNameEnum
from common.Settings import (
ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_HTTP,
......@@ -79,17 +79,73 @@ def slice_client(mock_service : MockService_Dependencies): # pylint: disable=red
yield _client
_client.close()
class RestRequestMethod(enum.Enum):
GET = 'get'
POST = 'post'
PUT = 'put'
DELETE = 'delete'
EXPECTED_STATUS_CODES : Set[int] = {
requests.codes['OK' ],
requests.codes['CREATED' ],
requests.codes['ACCEPTED' ],
requests.codes['NO_CONTENT'],
}
def do_rest_request(
url : str, logger : Optional[logging.Logger] = None, timeout=10, expected_status_codes : Set[int] = {200}
) -> Union[Dict, List]:
method : RestRequestMethod, url : str, body : Optional[Any] = None, timeout : int = 10,
allow_redirects : bool = True, expected_status_codes : Set[int] = EXPECTED_STATUS_CODES,
logger : Optional[logging.Logger] = None
) -> Optional[Union[Dict, List]]:
base_url = get_service_baseurl_http(ServiceNameEnum.NBI) or ''
request_url = 'http://{:s}:{:s}@{:s}:{:d}{:s}{:s}'.format(
USERNAME, PASSWORD, LOCAL_HOST, NBI_SERVICE_PORT, str(base_url), url
)
if logger is not None:
logger.warning('Request: GET {:s}'.format(str(request_url)))
reply = requests.get(request_url, timeout=timeout)
msg = 'Request: {:s} {:s}'.format(str(method.value).upper(), str(request_url))
if body is not None: msg += ' body={:s}'.format(str(body))
logger.warning(msg)
reply = requests.request(method.value, request_url, timeout=timeout, json=body, allow_redirects=allow_redirects)
if logger is not None:
logger.warning('Reply: {:s}'.format(str(reply.text)))
assert reply.status_code in expected_status_codes, 'Reply failed with status code {:d}'.format(reply.status_code)
return reply.json()
if reply.content and len(reply.content) > 0: return reply.json()
return None
def do_rest_get_request(
url : str, body : Optional[Any] = None, timeout : int = 10,
allow_redirects : bool = True, expected_status_codes : Set[int] = EXPECTED_STATUS_CODES,
logger : Optional[logging.Logger] = None
) -> Union[Dict, List]:
return do_rest_request(
RestRequestMethod.GET, url, body=body, timeout=timeout, allow_redirects=allow_redirects,
expected_status_codes=expected_status_codes, logger=logger
)
def do_rest_post_request(url : str, body : Optional[Any] = None, timeout : int = 10,
allow_redirects : bool = True, expected_status_codes : Set[int] = EXPECTED_STATUS_CODES,
logger : Optional[logging.Logger] = None
) -> Union[Dict, List]:
return do_rest_request(
RestRequestMethod.POST, url, body=body, timeout=timeout, allow_redirects=allow_redirects,
expected_status_codes=expected_status_codes, logger=logger
)
def do_rest_put_request(url : str, body : Optional[Any] = None, timeout : int = 10,
allow_redirects : bool = True, expected_status_codes : Set[int] = EXPECTED_STATUS_CODES,
logger : Optional[logging.Logger] = None
) -> Union[Dict, List]:
return do_rest_request(
RestRequestMethod.PUT, url, body=body, timeout=timeout, allow_redirects=allow_redirects,
expected_status_codes=expected_status_codes, logger=logger
)
def do_rest_delete_request(url : str, body : Optional[Any] = None, timeout : int = 10,
allow_redirects : bool = True, expected_status_codes : Set[int] = EXPECTED_STATUS_CODES,
logger : Optional[logging.Logger] = None
) -> Union[Dict, List]:
return do_rest_request(
RestRequestMethod.DELETE, url, body=body, timeout=timeout, allow_redirects=allow_redirects,
expected_status_codes=expected_status_codes, logger=logger
)
{
"dummy_mode": true,
"contexts": [
{"context_id": {"context_uuid": {"uuid": "admin"}}}
],
"topologies": [
{"topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}}}
],
"devices": [
{"device_id": {"device_uuid": {"uuid": "R1"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R2"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R3"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R4"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R5"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R6"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R7"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"},
{"uuid": "1/3", "type": "copper"}, {"uuid": "2/1", "type": "copper"},
{"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"},
{"uuid": "2/4", "type": "copper"}, {"uuid": "2/5", "type": "copper"},
{"uuid": "2/6", "type": "copper"}
]}}}
]}}
],
"links": [
{"link_id": {"link_uuid": {"uuid": "R1==R2"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R1==R6"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R6"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R1==R7"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/3"}},
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R2==R1"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R2==R3"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R3==R2"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R3==R4"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R4"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R3==R7"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/3"}},
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/3"}}
]},
{"link_id": {"link_uuid": {"uuid": "R4==R3"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R4"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R4==R5"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R4"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R5==R4"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R4"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R5==R6"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R6"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R5==R7"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/3"}},
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/5"}}
]},
{"link_id": {"link_uuid": {"uuid": "R6==R1"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R6"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R6==R5"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R6"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R7==R1"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/3"}}
]},
{"link_id": {"link_uuid": {"uuid": "R7==R3"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/3"}},
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/3"}}
]},
{"link_id": {"link_uuid": {"uuid": "R7==R5"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/5"}},
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/3"}}
]}
]
}
{
"contexts": [
{"context_id": {"context_uuid": {"uuid": "admin"}}}
],
"topologies": [
{"topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, "topology_uuid": {"uuid": "admin"}}}
],
"devices": [
{"device_id": {"device_uuid": {"uuid": "R1"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R2"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R3"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R4"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R5"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R6"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"}, {"uuid": "1/3", "type": "copper"},
{"uuid": "1/4", "type": "copper"}, {"uuid": "1/5", "type": "copper"}, {"uuid": "1/6", "type": "copper"},
{"uuid": "2/1", "type": "copper"}, {"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"}
]}}}
]}},
{"device_id": {"device_uuid": {"uuid": "R7"}}, "device_type": "emu-packet-router", "device_drivers": [0],
"device_endpoints": [], "device_operational_status": 1, "device_config": {"config_rules": [
{"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}},
{"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}},
{"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": {"endpoints": [
{"uuid": "1/1", "type": "copper"}, {"uuid": "1/2", "type": "copper"},
{"uuid": "1/3", "type": "copper"}, {"uuid": "2/1", "type": "copper"},
{"uuid": "2/2", "type": "copper"}, {"uuid": "2/3", "type": "copper"},
{"uuid": "2/4", "type": "copper"}, {"uuid": "2/5", "type": "copper"},
{"uuid": "2/6", "type": "copper"}
]}}}
]}}
],
"links": [
{"link_id": {"link_uuid": {"uuid": "R1==R2"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R1==R6"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R6"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R1==R7"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/3"}},
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R2==R1"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R2==R3"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R3==R2"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R2"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R3==R4"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R4"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R3==R7"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/3"}},
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/3"}}
]},
{"link_id": {"link_uuid": {"uuid": "R4==R3"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R4"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R4==R5"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R4"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R5==R4"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R4"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R5==R6"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R6"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R5==R7"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/3"}},
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/5"}}
]},
{"link_id": {"link_uuid": {"uuid": "R6==R1"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R6"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/2"}}
]},
{"link_id": {"link_uuid": {"uuid": "R6==R5"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R6"}}, "endpoint_uuid": {"uuid": "2/2"}},
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/1"}}
]},
{"link_id": {"link_uuid": {"uuid": "R7==R1"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/1"}},
{"device_id": {"device_uuid": {"uuid": "R1"}}, "endpoint_uuid": {"uuid": "2/3"}}
]},
{"link_id": {"link_uuid": {"uuid": "R7==R3"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/3"}},
{"device_id": {"device_uuid": {"uuid": "R3"}}, "endpoint_uuid": {"uuid": "2/3"}}
]},
{"link_id": {"link_uuid": {"uuid": "R7==R5"}}, "link_endpoint_ids": [
{"device_id": {"device_uuid": {"uuid": "R7"}}, "endpoint_uuid": {"uuid": "2/5"}},
{"device_id": {"device_uuid": {"uuid": "R5"}}, "endpoint_uuid": {"uuid": "2/3"}}
]}
]
}
......@@ -12,27 +12,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging, os, pytest, requests, time, urllib
from typing import Tuple
import logging, os, pytest, time, urllib
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME, ServiceNameEnum
from common.proto.context_pb2 import Connection, Context, Device, Link, Service, Slice, Topology
from common.proto.policy_pb2 import PolicyRuleIdList, PolicyRuleId, PolicyRuleList, PolicyRule
from common.Settings import (
ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, ENVVAR_SUFIX_SERVICE_PORT_HTTP, get_env_var_name,
get_service_baseurl_http, get_service_port_grpc, get_service_port_http)
get_service_port_grpc, get_service_port_http
)
from common.type_checkers.Assertions import (
validate_connection, validate_connection_ids, validate_connections, validate_context, validate_context_ids,
validate_contexts, validate_device, validate_device_ids, validate_devices, validate_link, validate_link_ids,
validate_links, validate_service, validate_service_ids, validate_services, validate_topologies, validate_topology,
validate_topology_ids)
from context.client.ContextClient import ContextClient
from nbi.tests.PrepareTestScenario import do_rest_get_request
from .MockService_Dependencies import MockService_Dependencies
from .Objects import (
CONNECTION_R1_R3, CONNECTION_R1_R3_ID, CONNECTION_R1_R3_UUID, CONTEXT, CONTEXT_ID, DEVICE_R1, DEVICE_R1_ID,
DEVICE_R1_UUID, DEVICE_R2, DEVICE_R2_ID, DEVICE_R2_UUID, DEVICE_R3, DEVICE_R3_ID, DEVICE_R3_UUID, LINK_R1_R2,
LINK_R1_R2_ID, LINK_R1_R2_UUID, SERVICE_R1_R2, SERVICE_R1_R2_ID, SERVICE_R1_R2_UUID, SERVICE_R1_R3,
SERVICE_R1_R3_ID, SERVICE_R1_R3_UUID, SERVICE_R2_R3, SERVICE_R2_R3_ID, SERVICE_R2_R3_UUID, SLICE_R1_R3, TOPOLOGY,
TOPOLOGY_ID, POLICY_RULE, POLICY_RULE_ID, POLICY_RULE_UUID)
TOPOLOGY_ID, POLICY_RULE, POLICY_RULE_ID, POLICY_RULE_UUID
)
@pytest.fixture(scope='session')
......@@ -100,129 +102,119 @@ def test_populate_database():
client.SetSlice(Slice(**SLICE_R1_R3))
client.SetConnection(Connection(**CONNECTION_R1_R3))
def do_rest_request(url : str):
base_url = get_service_baseurl_http(ServiceNameEnum.CONTEXT)
request_url = 'http://{:s}:{:s}{:s}{:s}'.format(str(LOCAL_HOST), str(HTTP_PORT), str(base_url), url)
LOGGER.warning('Request: GET {:s}'.format(str(request_url)))
reply = requests.get(request_url)
LOGGER.warning('Reply: {:s}'.format(str(reply.text)))
assert reply.status_code == 200, 'Reply failed with code {}'.format(reply.status_code)
return reply.json()
def test_rest_get_context_ids(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
reply = do_rest_request('/context_ids')
reply = do_rest_get_request('/context_ids')
validate_context_ids(reply)
def test_rest_get_contexts(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
reply = do_rest_request('/contexts')
reply = do_rest_get_request('/contexts')
validate_contexts(reply)
def test_rest_get_context(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
reply = do_rest_request('/context/{:s}'.format(context_uuid))
reply = do_rest_get_request('/context/{:s}'.format(context_uuid))
validate_context(reply)
def test_rest_get_topology_ids(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
reply = do_rest_request('/context/{:s}/topology_ids'.format(context_uuid))
reply = do_rest_get_request('/context/{:s}/topology_ids'.format(context_uuid))
validate_topology_ids(reply)
def test_rest_get_topologies(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
reply = do_rest_request('/context/{:s}/topologies'.format(context_uuid))
reply = do_rest_get_request('/context/{:s}/topologies'.format(context_uuid))
validate_topologies(reply)
def test_rest_get_topology(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
topology_uuid = urllib.parse.quote(DEFAULT_TOPOLOGY_NAME)
reply = do_rest_request('/context/{:s}/topology/{:s}'.format(context_uuid, topology_uuid))
reply = do_rest_get_request('/context/{:s}/topology/{:s}'.format(context_uuid, topology_uuid))
validate_topology(reply, num_devices=3, num_links=3)
def test_rest_get_service_ids(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
reply = do_rest_request('/context/{:s}/service_ids'.format(context_uuid))
reply = do_rest_get_request('/context/{:s}/service_ids'.format(context_uuid))
validate_service_ids(reply)
def test_rest_get_services(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
reply = do_rest_request('/context/{:s}/services'.format(context_uuid))
reply = do_rest_get_request('/context/{:s}/services'.format(context_uuid))
validate_services(reply)
def test_rest_get_service(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
service_uuid = urllib.parse.quote(SERVICE_R1_R2_UUID, safe='')
reply = do_rest_request('/context/{:s}/service/{:s}'.format(context_uuid, service_uuid))
reply = do_rest_get_request('/context/{:s}/service/{:s}'.format(context_uuid, service_uuid))
validate_service(reply)
def test_rest_get_slice_ids(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
reply = do_rest_request('/context/{:s}/slice_ids'.format(context_uuid))
reply = do_rest_get_request('/context/{:s}/slice_ids'.format(context_uuid))
#validate_slice_ids(reply)
def test_rest_get_slices(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
reply = do_rest_request('/context/{:s}/slices'.format(context_uuid))
reply = do_rest_get_request('/context/{:s}/slices'.format(context_uuid))
#validate_slices(reply)
def test_rest_get_slice(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
slice_uuid = urllib.parse.quote(SLICE_R1_R3_UUID, safe='')
reply = do_rest_request('/context/{:s}/slice/{:s}'.format(context_uuid, slice_uuid))
reply = do_rest_get_request('/context/{:s}/slice/{:s}'.format(context_uuid, slice_uuid))
#validate_slice(reply)
def test_rest_get_device_ids(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
reply = do_rest_request('/device_ids')
reply = do_rest_get_request('/device_ids')
validate_device_ids(reply)
def test_rest_get_devices(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
reply = do_rest_request('/devices')
reply = do_rest_get_request('/devices')
validate_devices(reply)
def test_rest_get_device(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
device_uuid = urllib.parse.quote(DEVICE_R1_UUID, safe='')
reply = do_rest_request('/device/{:s}'.format(device_uuid))
reply = do_rest_get_request('/device/{:s}'.format(device_uuid))
validate_device(reply)
def test_rest_get_link_ids(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
reply = do_rest_request('/link_ids')
reply = do_rest_get_request('/link_ids')
validate_link_ids(reply)
def test_rest_get_links(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
reply = do_rest_request('/links')
reply = do_rest_get_request('/links')
validate_links(reply)
def test_rest_get_link(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
link_uuid = urllib.parse.quote(LINK_R1_R2_UUID, safe='')
reply = do_rest_request('/link/{:s}'.format(link_uuid))
reply = do_rest_get_request('/link/{:s}'.format(link_uuid))
validate_link(reply)
def test_rest_get_connection_ids(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
service_uuid = urllib.parse.quote(SERVICE_R1_R3_UUID, safe='')
reply = do_rest_request('/context/{:s}/service/{:s}/connection_ids'.format(context_uuid, service_uuid))
reply = do_rest_get_request('/context/{:s}/service/{:s}/connection_ids'.format(context_uuid, service_uuid))
validate_connection_ids(reply)
def test_rest_get_connections(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
context_uuid = urllib.parse.quote(DEFAULT_CONTEXT_NAME)
service_uuid = urllib.parse.quote(SERVICE_R1_R3_UUID, safe='')
reply = do_rest_request('/context/{:s}/service/{:s}/connections'.format(context_uuid, service_uuid))
reply = do_rest_get_request('/context/{:s}/service/{:s}/connections'.format(context_uuid, service_uuid))
validate_connections(reply)
def test_rest_get_connection(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
connection_uuid = urllib.parse.quote(CONNECTION_R1_R3_UUID, safe='')
reply = do_rest_request('/connection/{:s}'.format(connection_uuid))
reply = do_rest_get_request('/connection/{:s}'.format(connection_uuid))
validate_connection(reply)
def test_rest_get_policyrule_ids(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
reply = do_rest_request('/policyrule_ids')
reply = do_rest_get_request('/policyrule_ids')
#validate_policyrule_ids(reply)
def test_rest_get_policyrules(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
reply = do_rest_request('/policyrules')
reply = do_rest_get_request('/policyrules')
#validate_policyrules(reply)
def test_rest_get_policyrule(context_service_rest : RestServer): # pylint: disable=redefined-outer-name
policyrule_uuid = urllib.parse.quote(POLICYRULE_UUID, safe='')
reply = do_rest_request('/policyrule/{:s}'.format(policyrule_uuid))
reply = do_rest_get_request('/policyrule/{:s}'.format(policyrule_uuid))
#validate_policyrule(reply)
......@@ -13,27 +13,63 @@
# limitations under the License.
import logging
from common.Constants import DEFAULT_CONTEXT_NAME
from common.proto.context_pb2 import ContextId
from common.tools.descriptor.Loader import DescriptorLoader, check_descriptor_load_results, validate_empty_scenario
from common.tools.object_factory.Context import json_context_id
from context.client.ContextClient import ContextClient
from tests.tools.mock_osm.MockOSM import MockOSM
from .Constants import SERVICE_CONNECTION_POINTS_1, SERVICE_CONNECTION_POINTS_2, SERVICE_TYPE
from .PrepareTestScenario import ( # pylint: disable=unused-import
# be careful, order of symbols is important here!
mock_service, nbi_service_rest, osm_wim)
mock_service, nbi_service_rest, osm_wim, context_client
)
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
DESCRIPTOR_FILE = 'nbi/tests/data/topology-7router-emu-dummy.json'
def test_nbi_create_connectivity_service_rest_api(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
JSON_ADMIN_CONTEXT_ID = json_context_id(DEFAULT_CONTEXT_NAME)
ADMIN_CONTEXT_ID = ContextId(**JSON_ADMIN_CONTEXT_ID)
def test_prepare_environment(context_client : ContextClient) -> None: # pylint: disable=redefined-outer-name
validate_empty_scenario(context_client)
descriptor_loader = DescriptorLoader(descriptors_file=DESCRIPTOR_FILE, context_client=context_client)
results = descriptor_loader.process()
check_descriptor_load_results(results, descriptor_loader)
descriptor_loader.validate()
# Verify the scenario has no services/slices
response = context_client.GetContext(ADMIN_CONTEXT_ID)
assert len(response.topology_ids) == 1
assert len(response.service_ids ) == 0
assert len(response.slice_ids ) == 0
def test_create_service(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
osm_wim.create_connectivity_service(SERVICE_TYPE, SERVICE_CONNECTION_POINTS_1)
def test_nbi_get_connectivity_service_status_rest_api(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
def test_get_service_status(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
service_uuid = list(osm_wim.conn_info.keys())[0] # this test adds a single service
osm_wim.get_connectivity_service_status(service_uuid)
def test_nbi_edit_connectivity_service_rest_api(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
def test_edit_service(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
service_uuid = list(osm_wim.conn_info.keys())[0] # this test adds a single service
osm_wim.edit_connectivity_service(service_uuid, SERVICE_CONNECTION_POINTS_2)
def test_nbi_delete_connectivity_service_rest_api(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
def test_delete_service(osm_wim : MockOSM): # pylint: disable=redefined-outer-name
service_uuid = list(osm_wim.conn_info.keys())[0] # this test adds a single service
osm_wim.delete_connectivity_service(service_uuid)
def test_cleanup_environment(context_client : ContextClient) -> None: # pylint: disable=redefined-outer-name
# Verify the scenario has no services/slices
response = context_client.GetContext(ADMIN_CONTEXT_ID)
assert len(response.topology_ids) == 1
assert len(response.service_ids ) == 0
assert len(response.slice_ids ) == 0
# Load descriptors and validate the base scenario
descriptor_loader = DescriptorLoader(descriptors_file=DESCRIPTOR_FILE, context_client=context_client)
descriptor_loader.validate()
descriptor_loader.unload()
validate_empty_scenario(context_client)
......@@ -14,16 +14,16 @@
from typing import Dict
import deepdiff, json, logging, operator
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from common.proto.context_pb2 import ContextId, TopologyId
from common.Constants import DEFAULT_CONTEXT_NAME
from common.proto.context_pb2 import ContextId
from common.tools.descriptor.Loader import DescriptorLoader, check_descriptor_load_results, validate_empty_scenario
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Topology import json_topology_id
from context.client.ContextClient import ContextClient
from nbi.service.rest_server import RestServer
from .PrepareTestScenario import ( # pylint: disable=unused-import
# be careful, order of symbols is important here!
do_rest_request, mock_service, nbi_service_rest, osm_wim, context_client)
do_rest_get_request, mock_service, nbi_service_rest, osm_wim, context_client
)
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)
......@@ -33,7 +33,6 @@ TARGET_DATA_FILE = 'nbi/tests/data/test-ietf-network.json'
JSON_ADMIN_CONTEXT_ID = json_context_id(DEFAULT_CONTEXT_NAME)
ADMIN_CONTEXT_ID = ContextId(**JSON_ADMIN_CONTEXT_ID)
ADMIN_TOPOLOGY_ID = TopologyId(**json_topology_id(DEFAULT_TOPOLOGY_NAME, context_id=JSON_ADMIN_CONTEXT_ID))
def test_prepare_environment(context_client : ContextClient) -> None: # pylint: disable=redefined-outer-name
validate_empty_scenario(context_client)
......@@ -79,7 +78,7 @@ def test_rest_get_networks(nbi_service_rest : RestServer): # pylint: disable=red
with open(TARGET_DATA_FILE, 'r', encoding='UTF-8') as f:
target_data = json.load(f)
URL = '/restconf/data/ietf-network:networks'
retrieved_data = do_rest_request(URL, logger=LOGGER, expected_status_codes={200})
retrieved_data = do_rest_get_request(URL, logger=LOGGER, expected_status_codes={200})
sort_data(retrieved_data)
sort_data(target_data)
diff_data = deepdiff.DeepDiff(target_data, retrieved_data)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment