From 755ec559558ce3f4aa7e993670a2eb17e1bbe648 Mon Sep 17 00:00:00 2001 From: jimenezquesa <manuel.jimenez@eviden.com> Date: Tue, 18 Mar 2025 12:27:26 +0000 Subject: [PATCH] Solve some minor Typo Delete unused files --- manifests/ztp_server.yaml | 3 +- proto/ztp_server.proto | 2 +- src/common/Constants.py | 2 +- src/ztp_server/.gitlab-ci.yml | 120 ------------------ .../data/provisioning_script_sonic.sh | 15 +++ src/ztp_server/data/ztp.json | 1 - src/ztp_server/requirements.in | 25 ---- .../service/ZtpServerServiceServicerImpl.py | 13 -- src/ztp_server/service/__main__.py | 6 +- .../tools/HttpStatusCodes.py | 2 +- .../Resources.py | 4 +- .../Tools.py | 4 +- .../__init__.py | 6 +- 13 files changed, 28 insertions(+), 175 deletions(-) delete mode 100755 src/ztp_server/.gitlab-ci.yml delete mode 100755 src/ztp_server/requirements.in rename src/ztp_server/service/rest_server/ztpServer_plugins/{tfs_api => ztp_provisioning_api}/Resources.py (94%) rename src/ztp_server/service/rest_server/ztpServer_plugins/{tfs_api => ztp_provisioning_api}/Tools.py (94%) rename src/ztp_server/service/rest_server/ztpServer_plugins/{tfs_api => ztp_provisioning_api}/__init__.py (89%) diff --git a/manifests/ztp_server.yaml b/manifests/ztp_server.yaml index 6ed469174..398aaa71e 100644 --- a/manifests/ztp_server.yaml +++ b/manifests/ztp_server.yaml @@ -74,5 +74,4 @@ spec: - name: metrics protocol: TCP port: 9192 - targetPort: ---- + targetPort: 9192 diff --git a/proto/ztp_server.proto b/proto/ztp_server.proto index 807751084..31e568d3a 100755 --- a/proto/ztp_server.proto +++ b/proto/ztp_server.proto @@ -19,7 +19,7 @@ package ztpServer; service ZtpServerService { rpc GetProvisioningScript (ProvisioningScriptName ) returns (ProvisioningScript ) {} - rpc GetZtpProvisioning (ZtpFileName ) returns (ZtpFile ) {} + rpc GetZtpProvisioning (ZtpFileName ) returns (ZtpFile ) {} } diff --git a/src/common/Constants.py b/src/common/Constants.py index 50b792c65..b95b6d01b 100644 --- a/src/common/Constants.py +++ b/src/common/Constants.py @@ -42,7 +42,7 @@ class ServiceNameEnum(Enum): SERVICE = 'service' SLICE = 'slice' ZTP = 'ztp' - ZTP_SERVER = 'ztp_server' + ZTP_SERVER = 'ztp-server' POLICY = 'policy' MONITORING = 'monitoring' DLT = 'dlt' diff --git a/src/ztp_server/.gitlab-ci.yml b/src/ztp_server/.gitlab-ci.yml deleted file mode 100755 index 71bf223ba..000000000 --- a/src/ztp_server/.gitlab-ci.yml +++ /dev/null @@ -1,120 +0,0 @@ -# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (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. - -# Build, tag, and push the Docker image to the GitLab Docker registry -build nbi: - variables: - IMAGE_NAME: 'nbi' # name of the microservice - IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) - stage: build - before_script: - - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - script: - - docker buildx build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile . - - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - after_script: - - docker images --filter="dangling=true" --quiet | xargs -r docker rmi - rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' - - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' - - changes: - - src/common/**/*.py - - proto/*.proto - - src/$IMAGE_NAME/**/*.{py,in,yml} - - src/$IMAGE_NAME/Dockerfile - - src/$IMAGE_NAME/tests/*.py - - manifests/${IMAGE_NAME}service.yaml - - .gitlab-ci.yml - -# Apply unit test to the component -unit_test nbi: - variables: - IMAGE_NAME: 'nbi' # name of the microservice - IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) - stage: unit_test - needs: - - 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 - 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 --append -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_tfs_api.py --junitxml=/opt/results/${IMAGE_NAME}_report_tfs_api.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 run --append -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_ietf_l3vpn.py --junitxml=/opt/results/${IMAGE_NAME}_report_ietf_l3vpn.xml" - - docker exec -i $IMAGE_NAME bash -c "coverage run --append -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_etsi_bwm.py --junitxml=/opt/results/${IMAGE_NAME}_report_etsi_bwm.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: - - docker rm -f $IMAGE_NAME - - docker network rm teraflowbridge - rules: - - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' - - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' - - changes: - - src/common/**/*.py - - proto/*.proto - - src/$IMAGE_NAME/**/*.{py,in,yml} - - src/$IMAGE_NAME/Dockerfile - - src/$IMAGE_NAME/tests/*.py - - src/$IMAGE_NAME/tests/Dockerfile - - manifests/${IMAGE_NAME}service.yaml - - .gitlab-ci.yml - artifacts: - when: always - reports: - junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report_*.xml - -## Deployment of the service in Kubernetes Cluster -#deploy nbi: -# variables: -# IMAGE_NAME: 'nbi' # name of the microservice -# IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) -# stage: deploy -# needs: -# - unit test nbi -# # - integ_test execute -# script: -# - 'sed -i "s/$IMAGE_NAME:.*/$IMAGE_NAME:$IMAGE_TAG/" manifests/${IMAGE_NAME}service.yaml' -# - kubectl version -# - kubectl get all -# - kubectl apply -f "manifests/${IMAGE_NAME}service.yaml" -# - kubectl get all -# # environment: -# # name: test -# # url: https://example.com -# # kubernetes: -# # namespace: test -# rules: -# - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' -# when: manual -# - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' -# when: manual diff --git a/src/ztp_server/data/provisioning_script_sonic.sh b/src/ztp_server/data/provisioning_script_sonic.sh index c4dd20438..24b1eb8a6 100644 --- a/src/ztp_server/data/provisioning_script_sonic.sh +++ b/src/ztp_server/data/provisioning_script_sonic.sh @@ -1,5 +1,20 @@ #!/bin/bash +# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (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 + + PRODUCT_NAME=$(show version | grep 'Platform' | awk '{print $2}') SERIAL_NUMBER=$(show version | grep 'Serial Number' | awk '{print $3}') BASE_MAC_ADDRESS=$(show platform syseeprom | grep 'Base MAC Address' | awk '{print $6}') diff --git a/src/ztp_server/data/ztp.json b/src/ztp_server/data/ztp.json index 6e606a5e8..4a4cdc3cf 100644 --- a/src/ztp_server/data/ztp.json +++ b/src/ztp_server/data/ztp.json @@ -8,4 +8,3 @@ } } } - \ No newline at end of file diff --git a/src/ztp_server/requirements.in b/src/ztp_server/requirements.in deleted file mode 100755 index ba715494d..000000000 --- a/src/ztp_server/requirements.in +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (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. - -deepdiff==6.7.* -deepmerge==1.1.* -Flask==2.1.3 -Flask-HTTPAuth==4.5.0 -Flask-RESTful==0.3.9 -jsonschema==4.4.0 -netaddr==0.9.0 -pydantic==2.6.3 -requests==2.27.1 -werkzeug==2.3.7 -websockets==12.0 diff --git a/src/ztp_server/service/ZtpServerServiceServicerImpl.py b/src/ztp_server/service/ZtpServerServiceServicerImpl.py index 410db6cb3..62ddb856f 100755 --- a/src/ztp_server/service/ZtpServerServiceServicerImpl.py +++ b/src/ztp_server/service/ZtpServerServiceServicerImpl.py @@ -38,16 +38,3 @@ class ZtpServerServiceServicerImpl(ZtpServerServiceServicer): context.set_code(grpc.StatusCode.NOT_FOUND) context.set_details('File not found') return ProvisioningScript() - - - @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) - def GetZtpProvisioning(self, request : ZtpFileName, context : grpc.ServicerContext) -> ZtpFile: - try: - ztpPath = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', 'data', request.filename) - with open(ztpPath, 'r') as json_file: - json_content = json_file.read() - return ZtpFile(json=json_content) - except FileNotFoundError: - context.set_code(grpc.StatusCode.NOT_FOUND) - context.set_details('File not found') - return ZtpFile() \ No newline at end of file diff --git a/src/ztp_server/service/__main__.py b/src/ztp_server/service/__main__.py index 55bd5f187..ae8a95d21 100755 --- a/src/ztp_server/service/__main__.py +++ b/src/ztp_server/service/__main__.py @@ -21,9 +21,7 @@ from common.Settings import ( ) from .ZtpServerService import ZtpServerService from .rest_server.RestServer import RestServer -from .rest_server.ztpServer_plugins.tfs_api import register_tfs_api - -from .context_subscription import register_context_subscription +from .rest_server.ztpServer_plugins.ztp_provisioning_api import register_ztp_provisioning terminate = threading.Event() LOGGER = None @@ -53,7 +51,7 @@ def main(): grpc_service.start() rest_server = RestServer() - register_tfs_api(rest_server) + register_ztp_provisioning(rest_server) rest_server.start() LOGGER.debug('Configured Resources:') diff --git a/src/ztp_server/service/rest_server/ztpServer_plugins/tools/HttpStatusCodes.py b/src/ztp_server/service/rest_server/ztpServer_plugins/tools/HttpStatusCodes.py index 56ea475c7..f9d749613 100755 --- a/src/ztp_server/service/rest_server/ztpServer_plugins/tools/HttpStatusCodes.py +++ b/src/ztp_server/service/rest_server/ztpServer_plugins/tools/HttpStatusCodes.py @@ -17,4 +17,4 @@ HTTP_CREATED = 201 HTTP_NOCONTENT = 204 HTTP_BADREQUEST = 400 HTTP_SERVERERROR = 500 -HTTP_GATEWAYTIMEOUT = 504 \ No newline at end of file +HTTP_GATEWAYTIMEOUT = 504 diff --git a/src/ztp_server/service/rest_server/ztpServer_plugins/tfs_api/Resources.py b/src/ztp_server/service/rest_server/ztpServer_plugins/ztp_provisioning_api/Resources.py similarity index 94% rename from src/ztp_server/service/rest_server/ztpServer_plugins/tfs_api/Resources.py rename to src/ztp_server/service/rest_server/ztpServer_plugins/ztp_provisioning_api/Resources.py index 43b7b79b6..f4169742a 100755 --- a/src/ztp_server/service/rest_server/ztpServer_plugins/tfs_api/Resources.py +++ b/src/ztp_server/service/rest_server/ztpServer_plugins/ztp_provisioning_api/Resources.py @@ -32,6 +32,6 @@ class _Resource(Resource): class config(_Resource): @HTTP_AUTH.login_required def get(self, config_db : str): - #if returnConfigFile(config_db) + content = returnConfigFile(config_db) - return + return content diff --git a/src/ztp_server/service/rest_server/ztpServer_plugins/tfs_api/Tools.py b/src/ztp_server/service/rest_server/ztpServer_plugins/ztp_provisioning_api/Tools.py similarity index 94% rename from src/ztp_server/service/rest_server/ztpServer_plugins/tfs_api/Tools.py rename to src/ztp_server/service/rest_server/ztpServer_plugins/ztp_provisioning_api/Tools.py index 7d05816ee..92573fd2e 100755 --- a/src/ztp_server/service/rest_server/ztpServer_plugins/tfs_api/Tools.py +++ b/src/ztp_server/service/rest_server/ztpServer_plugins/ztp_provisioning_api/Tools.py @@ -20,6 +20,6 @@ def returnConfigFile(config_db): with open(configFilePath, 'r', encoding='utf-8') as configFile: content = configFile.read() except FileNotFoundError: - return "File not Found" + return None - return content \ No newline at end of file + return content diff --git a/src/ztp_server/service/rest_server/ztpServer_plugins/tfs_api/__init__.py b/src/ztp_server/service/rest_server/ztpServer_plugins/ztp_provisioning_api/__init__.py similarity index 89% rename from src/ztp_server/service/rest_server/ztpServer_plugins/tfs_api/__init__.py rename to src/ztp_server/service/rest_server/ztpServer_plugins/ztp_provisioning_api/__init__.py index 7062772b4..ab06fd7bd 100755 --- a/src/ztp_server/service/rest_server/ztpServer_plugins/tfs_api/__init__.py +++ b/src/ztp_server/service/rest_server/ztpServer_plugins/ztp_provisioning_api/__init__.py @@ -14,7 +14,7 @@ from ztp_server.service.rest_server.RestServer import RestServer from .Resources import ( - config + Config ) URL_PREFIX = '/provisioning' @@ -22,9 +22,9 @@ URL_PREFIX = '/provisioning' # Use 'path' type since some identifiers might contain char '/' and Flask is unable to recognize them in 'string' type. RESOURCES = [ # (endpoint_name, resource_class, resource_url) - ('api.config', config, '/config/<path:config_db>'), + ('api.config', Config, '/config/<path:config_db>'), ] -def register_tfs_api(rest_server : RestServer): +def register_ztp_provisioning(rest_server : RestServer): for endpoint_name, resource_class, resource_url in RESOURCES: rest_server.add_resource(resource_class, URL_PREFIX + resource_url, endpoint=endpoint_name) -- GitLab