diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2024-01-31 16:48:30 +0100 |
---|---|---|
committer | Micha? Jagie??o <michal.jagiello@t-mobile.pl> | 2024-02-01 08:30:19 +0000 |
commit | a39a9545a95111249c0e8e23a9be3a6a2dc059db (patch) | |
tree | d2880529888f8ac0e13b67eee6735cffe5d74982 | |
parent | 2cd534174ca9e43b1d6302b0d95e51f739a3093c (diff) |
Create 13.0.0 (Montreal) version
Remove code of deprecated modules and functions
Issue-ID: TEST-404
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I8fbab8688e35820272522705638d65d871fb3421
-rw-r--r-- | src/onapsdk/msb/k8s/__init__.py | 18 | ||||
-rw-r--r-- | src/onapsdk/msb/k8s/connectivity_info.py | 19 | ||||
-rw-r--r-- | src/onapsdk/msb/k8s/definition.py | 19 | ||||
-rw-r--r-- | src/onapsdk/msb/k8s/instance.py | 25 | ||||
-rw-r--r-- | src/onapsdk/msb/k8s/k8splugin_msb_service.py | 20 | ||||
-rw-r--r-- | src/onapsdk/so/so_db_adapter.py | 18 | ||||
-rw-r--r-- | src/onapsdk/utils/jinja.py | 3 | ||||
-rw-r--r-- | src/onapsdk/version.py | 2 | ||||
-rw-r--r-- | src/onapsdk/vid/__init__.py | 16 | ||||
-rw-r--r-- | src/onapsdk/vid/templates/vid_declare_resource.json.j2 | 3 | ||||
-rw-r--r-- | src/onapsdk/vid/vid.py | 132 | ||||
-rw-r--r-- | tests/test_msb_k8s.py | 900 | ||||
-rw-r--r-- | tests/test_so_db_adapter.py | 11 | ||||
-rw-r--r-- | tests/test_so_instantiation.py | 7 | ||||
-rw-r--r-- | tests/test_version.py | 2 | ||||
-rw-r--r-- | tests/test_vid.py | 54 |
16 files changed, 6 insertions, 1243 deletions
diff --git a/src/onapsdk/msb/k8s/__init__.py b/src/onapsdk/msb/k8s/__init__.py deleted file mode 100644 index 91f4206..0000000 --- a/src/onapsdk/msb/k8s/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -"""K8s MSB package.""" -# Copyright 2022 Orange, Deutsche Telekom AG -# -# 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. -from .definition import Definition, Profile, ConfigurationTemplate -from .connectivity_info import ConnectivityInfo -from .instance import InstantiationParameter, InstantiationRequest, Instance, Configuration -from .k8splugin_msb_service import K8sPlugin diff --git a/src/onapsdk/msb/k8s/connectivity_info.py b/src/onapsdk/msb/k8s/connectivity_info.py deleted file mode 100644 index 5faf8db..0000000 --- a/src/onapsdk/msb/k8s/connectivity_info.py +++ /dev/null @@ -1,19 +0,0 @@ -"""Connectivity-Info module.""" -# Copyright 2022 Orange, Deutsche Telekom AG -# -# 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. -import warnings -from onapsdk.k8s.connectivity_info import ConnectivityInfo # pylint: disable=unused-import - -warnings.warn("onapsdk.msb.k8s.connectivity_info module is deprecated and will be removed with " - "the next version of ONAP SDK. Use onapsdk.k8s.connectivity_info") diff --git a/src/onapsdk/msb/k8s/definition.py b/src/onapsdk/msb/k8s/definition.py deleted file mode 100644 index a8c5d6d..0000000 --- a/src/onapsdk/msb/k8s/definition.py +++ /dev/null @@ -1,19 +0,0 @@ -"""Definition module.""" -# Copyright 2022 Orange, Deutsche Telekom AG -# -# 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. -import warnings -from onapsdk.k8s.definition import Definition, Profile, ConfigurationTemplate # pylint: disable=unused-import - -warnings.warn("onapsdk.msb.k8s.definition module is deprecated and will be removed with " - "the next version of ONAP SDK. Use onapsdk.k8s.definition") diff --git a/src/onapsdk/msb/k8s/instance.py b/src/onapsdk/msb/k8s/instance.py deleted file mode 100644 index d85e8c6..0000000 --- a/src/onapsdk/msb/k8s/instance.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Instantiation module.""" -# Copyright 2022 Orange, Deutsche Telekom AG -# -# 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. - -import warnings -from onapsdk.k8s.instance import ( # pylint: disable=unused-import - InstantiationParameter, - InstantiationRequest, - Instance, - Configuration -) - -warnings.warn("onapsdk.msb.k8s.instance module is deprecated and will be removed with " - "the next version of ONAP SDK. Use onapsdk.k8s.instance") diff --git a/src/onapsdk/msb/k8s/k8splugin_msb_service.py b/src/onapsdk/msb/k8s/k8splugin_msb_service.py deleted file mode 100644 index d1e38df..0000000 --- a/src/onapsdk/msb/k8s/k8splugin_msb_service.py +++ /dev/null @@ -1,20 +0,0 @@ -"""K8s package.""" -# Copyright 2023 Deutsche Telekom AG -# -# 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. - -import warnings -from onapsdk.k8s.k8splugin_service import K8sPlugin # pylint: disable=unused-import - -warnings.warn("onapsdk.msb.k8s.k8splugin_service module is deprecated and will be removed with " - "the next version of ONAP SDK. Use onapsdk.k8s.k8splugin_service") diff --git a/src/onapsdk/so/so_db_adapter.py b/src/onapsdk/so/so_db_adapter.py index 57c5f33..ead750e 100644 --- a/src/onapsdk/so/so_db_adapter.py +++ b/src/onapsdk/so/so_db_adapter.py @@ -14,12 +14,10 @@ # limitations under the License. from abc import ABC from dataclasses import dataclass -from typing import Dict, Any -import warnings from onapsdk.so.so_element import SoElement from onapsdk.onap_service import OnapService -from onapsdk.utils.headers_creator import headers_so_creator, headers_so_catelog_db_creator +from onapsdk.utils.headers_creator import headers_so_creator from onapsdk.utils.jinja import jinja_env @@ -82,17 +80,3 @@ class SoDbAdapter(SoElement, ABC): headers=headers_so_creator(OnapService.headers) ) return response - - @classmethod - def get_service_vnf_info(cls, identifier: str) -> Dict[Any, Any]: - """Get Service VNF and VF details. - - Returns: - The response in a dict format - - """ - warnings.warn("That method is deprecated and it's going to be removed. Please use " - "onapsdk.so.ecomp.Ecomp.get_service_vnf_info instead.") - url = f"{cls.base_url}/ecomp/mso/catalog/v2/serviceVnfs?serviceModelUuid={identifier}" - headers = headers_so_catelog_db_creator(OnapService.headers) - return cls.send_message_json("GET", "Get Service Details", url, headers=headers) diff --git a/src/onapsdk/utils/jinja.py b/src/onapsdk/utils/jinja.py index 10160b2..ca87ef4 100644 --- a/src/onapsdk/utils/jinja.py +++ b/src/onapsdk/utils/jinja.py @@ -45,6 +45,5 @@ def jinja_env() -> Environment: PackageLoader("onapsdk.sdc2"), PackageLoader("onapsdk.sdnc"), PackageLoader("onapsdk.so"), - PackageLoader("onapsdk.ves"), - PackageLoader("onapsdk.vid") + PackageLoader("onapsdk.ves") ])) diff --git a/src/onapsdk/version.py b/src/onapsdk/version.py index 5ff20c2..e338553 100644 --- a/src/onapsdk/version.py +++ b/src/onapsdk/version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "12.11.0" +__version__ = "13.0.0" diff --git a/src/onapsdk/vid/__init__.py b/src/onapsdk/vid/__init__.py deleted file mode 100644 index fd58581..0000000 --- a/src/onapsdk/vid/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -"""VID package.""" -# Copyright 2022 Orange, Deutsche Telekom AG -# -# 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. - -from .vid import LineOfBusiness, OwningEntity, Platform, Project, Vid diff --git a/src/onapsdk/vid/templates/vid_declare_resource.json.j2 b/src/onapsdk/vid/templates/vid_declare_resource.json.j2 deleted file mode 100644 index b14e6f4..0000000 --- a/src/onapsdk/vid/templates/vid_declare_resource.json.j2 +++ /dev/null @@ -1,3 +0,0 @@ -{ - "options": ["{{ name }}"] -}
\ No newline at end of file diff --git a/src/onapsdk/vid/vid.py b/src/onapsdk/vid/vid.py deleted file mode 100644 index 8abef6b..0000000 --- a/src/onapsdk/vid/vid.py +++ /dev/null @@ -1,132 +0,0 @@ -"""VID module.""" -# Copyright 2022 Orange, Deutsche Telekom AG -# -# 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. -from abc import ABC -from warnings import warn - -from onapsdk.configuration import settings -from onapsdk.onap_service import OnapService -from onapsdk.utils.jinja import jinja_env - - -WARN_MSG = ("VID is deprecated and shouldn't be used! " - "It's not a part of the ONAP release since Istanbul.") - - -class Vid(OnapService, ABC): - """VID base class.""" - - base_url = settings.VID_URL - api_version = settings.VID_API_VERSION - - def __init__(self, name: str) -> None: - """VID resource object initialization. - - Args: - name (str): Resource name - """ - warn(WARN_MSG) - super().__init__() - self.name: str = name - - @classmethod - def get_create_url(cls) -> str: - """Resource url. - - Used to create resources - - Returns: - str: Url used for resource creation - - """ - raise NotImplementedError - - @classmethod - def create(cls, name: str) -> "Vid": - """Create VID resource. - - Returns: - Vid: Created VID resource - - """ - warn(WARN_MSG) - cls.send_message( - "POST", - f"Declare VID resource with {name} name", - cls.get_create_url(), - data=jinja_env().get_template("vid_declare_resource.json.j2").render( - name=name - ) - ) - return cls(name) - - -class OwningEntity(Vid): - """VID owning entity class.""" - - @classmethod - def get_create_url(cls) -> str: - """Owning entity creation url. - - Returns: - str: Url used for ownint entity creation - - """ - warn(WARN_MSG) - return f"{cls.base_url}{cls.api_version}/maintenance/category_parameter/owningEntity" - - -class Project(Vid): - """VID project class.""" - - @classmethod - def get_create_url(cls) -> str: - """Project creation url. - - Returns: - str: Url used for project creation - - """ - warn(WARN_MSG) - return f"{cls.base_url}{cls.api_version}/maintenance/category_parameter/project" - - -class LineOfBusiness(Vid): - """VID line of business class.""" - - @classmethod - def get_create_url(cls) -> str: - """Line of business creation url. - - Returns: - str: Url used for line of business creation - - """ - warn(WARN_MSG) - return f"{cls.base_url}{cls.api_version}/maintenance/category_parameter/lineOfBusiness" - - -class Platform(Vid): - """VID platform class.""" - - @classmethod - def get_create_url(cls) -> str: - """Platform creation url. - - Returns: - str: Url used for platform creation - - """ - warn(WARN_MSG) - return f"{cls.base_url}{cls.api_version}/maintenance/category_parameter/platform" diff --git a/tests/test_msb_k8s.py b/tests/test_msb_k8s.py deleted file mode 100644 index 5b6a01f..0000000 --- a/tests/test_msb_k8s.py +++ /dev/null @@ -1,900 +0,0 @@ -# Copyright 2022 Orange, Deutsche Telekom AG -# -# 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. -from unittest import mock - -from onapsdk.msb.k8s import Definition, ConnectivityInfo, Instance, InstantiationRequest -from onapsdk.msb.k8s import K8sPlugin, Profile, ConfigurationTemplate, Configuration - - -CONNECTIVITY_INFO = { - "cloud-region": "test_cloud_region", - "cloud-owner": "test_cloud_owner", - "other-connectivity-list": {}, - "kubeconfig": "test_kubeconfig" -} - - -DEFINITION = { - "rb-name": "test_rb_name_0", - "rb-version": "test_rb_version_0" -} - - -DEFINITIONS = [ - DEFINITION, - { - "rb-name": "test_rb_name_1", - "rb-version": "test_rb_version_1", - "chart-name": "test_chart_name_1", - "description": "test_description_1", - "labels": {} - } -] - - -PROFILE = { - "rb-name": "test_rb_name", - "rb-version": "test_rb_version", - "profile-name": "test_profile_name", - "namespace": "test_namespace", - "kubernetes-version": "1.19.0", - "labels": { - "region": "test" - }, - "extra-resource-types": [ - { - "Group": "", - "Kind": "Pod", - "Version": "v1" - } - ] -} - - -PROFILES = [ - PROFILE, - { - "rb-name": "test_rb_name_1", - "rb-version": "test_rb_version_1", - "profile-name": "test_profile_name_1", - "namespace": "test_namespace_1", - "kubernetes-version": "1.19.0", - "labels": { - "region": "test-new" - }, - "extra-resource-types": [ - { - "Group": "", - "Kind": "Pod", - "Version": "v1" - } - ] - } -] - - -CONFIGURATION_TEMPLATE = { - "template-name": "test_configuration_template_name", - "description": "test_configuration_template_description" -} - - -CONFIGURATION_TEMPLATES = [ - CONFIGURATION_TEMPLATE, - { - "template-name": "test_configuration_template_name_0" - } -] - - -INSTANCE = { - "id": "ID_GENERATED_BY_K8SPLUGIN", - "namespace": "NAMESPACE_WHERE_INSTANCE_HAS_BEEN_DEPLOYED_AS_DERIVED_FROM_PROFILE", - "release-name": "RELEASE_NAME_AS_COMPUTED_BASED_ON_INSTANTIATION_REQUEST_AND_PROFILE_DEFAULT", - "request": { - "rb-name": "test-rbdef", - "rb-version": "v1", - "profile-name": "p1", - "release-name": "release-x", - "cloud-region": "krd", - "override-values": { - "optionalDictOfParameters": "andTheirValues, like", - "global.name": "dummy-name" - }, - "labels": { - "optionalLabelForInternalK8spluginInstancesMetadata": "dummy-value" - }, - }, - "resources": [ - { - "GVK": { - "Group": "", - "Kind": "ConfigMap", - "Version": "v1" - }, - "Name": "test-cm" - }, - { - "GVK": { - "Group": "", - "Kind": "Service", - "Version": "v1" - }, - "Name": "test-svc" - }, - { - "GVK": { - "Group": "apps", - "Kind": "Deployment", - "Version": "v1" - }, - "Name": "test-dep" - } - ] -} - - -INSTANCES = [ - INSTANCE -] - -STATUS = { - "request": { - "rb-name": "apache-7.6.0", - "rb-version": "test", - "profile-name": "test-k8s", - "release-name": "", - "cloud-region": "test", - "labels": {}, - "override-values": { - "global.normal": "value", - "global.second.last": "value", - "service.type": "LoadBalancer", - "vnf_name": "test-vnf-first" - } - }, - "ready": False, - "resourceCount": 1, - "resourcesStatus": [ - { - "name": "test-k8s-apache", - "GVK": { - "Group": "", - "Version": "v1", - "Kind": "Service" - }, - "status": { - "apiVersion": "v1", - "kind": "Service", - "metadata": { - "annotations": { - "loadbalancer.openstack.org/load-balancer-id": "4eb4e8e4-d4b7-4dd8-a0df-d2a949513dd4" - }, - "creationTimestamp": "2023-02-27T14:16:59Z", - "finalizers": [ - "service.kubernetes.io/load-balancer-cleanup" - ], - "labels": { - "app.kubernetes.io/instance": "test-k8s", - "app.kubernetes.io/managed-by": "Helm", - "app.kubernetes.io/name": "apache", - "helm.sh/chart": "apache-7.6.0", - "k8splugin.io/rb-instance-id": "serene_mcnulty" - }, - "name": "test-k8s-apache", - "namespace": "test-k8s", - "resourceVersion": "3983718", - "uid": "7904a5c5-9732-4581-8ef7-60d5bf5d399b" - }, - "spec": { - "allocateLoadBalancerNodePorts": True, - "clusterIP": "10.1.44.85", - "clusterIPs": [ - "10.1.44.85" - ], - "externalTrafficPolicy": "Cluster", - "internalTrafficPolicy": "Cluster", - "ipFamilies": [ - "IPv4" - ], - "ipFamilyPolicy": "SingleStack", - "ports": [ - { - "name": "http", - "nodePort": 32350, - "port": 80, - "protocol": "TCP", - "targetPort": "http" - }, - { - "name": "https", - "nodePort": 32514, - "port": 443, - "protocol": "TCP", - "targetPort": "https" - } - ], - "selector": { - "app.kubernetes.io/instance": "test-k8s", - "app.kubernetes.io/name": "apache" - }, - "sessionAffinity": "None", - "type": "LoadBalancer" - }, - "status": { - "loadBalancer": { - "ingress": [ - { - "ip": "10.0.0.0" - } - ] - } - } - } - } - ] -} - -CONFIG = { - "config-name": "conf", - "template-name": "conf", - "description": "", - "values": { - "replicaCount": 2 - }, - "config-version": 1, - "config-tag": "two-replicas" -} - -CONFIG_THREE = { - "config-name": "conf", - "template-name": "conf", - "description": "", - "values": { - "replicaCount": 3 - }, - "config-version": 2, - "config-tag": "" -} - -CONFIGS = [ - CONFIG -] - -CONFIG_TAGS = [ - { - "config-version": 1, - "config-tag": "two-replicas" - } -] - -@mock.patch.object(ConnectivityInfo, "send_message_json") -def test_get_connectivity_info_by_region_id(mock_send_message_json): - mock_send_message_json.return_value = CONNECTIVITY_INFO - conn_info: ConnectivityInfo = ConnectivityInfo.get_connectivity_info_by_region_id("test_cloud_region") - assert conn_info.cloud_region_id == "test_cloud_region" - assert conn_info.cloud_owner == "test_cloud_owner" - assert conn_info.other_connectivity_list == {} - assert conn_info.kubeconfig == "test_kubeconfig" - - -@mock.patch.object(ConnectivityInfo, "send_message") -@mock.patch.object(ConnectivityInfo, "send_message_json") -def test_connectivity_info_create_delete(mock_send_message_json, mock_send_message): - mock_send_message_json.return_value = CONNECTIVITY_INFO - conn_info: ConnectivityInfo = ConnectivityInfo.create("test_cloud_region", "test_cloud_owner", b"kubeconfig") - assert conn_info.cloud_region_id == "test_cloud_region" - assert conn_info.cloud_owner == "test_cloud_owner" - assert conn_info.other_connectivity_list == {} - assert conn_info.kubeconfig == "test_kubeconfig" - assert conn_info.url == f"{K8sPlugin.base_url_and_version()}/connectivity-info/test_cloud_region" - conn_info.delete() - - -@mock.patch.object(Definition, "send_message_json") -def test_definition_get_all(mock_send_message_json): - mock_send_message_json.return_value = [] - assert len(list(Definition.get_all())) == 0 - - mock_send_message_json.return_value = DEFINITIONS - definitions = list(Definition.get_all()) - assert len(definitions) == 2 - - def_0, def_1 = definitions - assert def_0.rb_name == "test_rb_name_0" - assert def_0.rb_version == "test_rb_version_0" - assert def_0.chart_name is None - assert def_0.description is None - assert def_0.labels is None - - assert def_1.rb_name == "test_rb_name_1" - assert def_1.rb_version == "test_rb_version_1" - assert def_1.chart_name == "test_chart_name_1" - assert def_1.description == "test_description_1" - assert def_1.labels == {} - - -@mock.patch.object(Definition, "send_message_json") -def test_get_definition_by_name_version(mock_send_message_json): - mock_send_message_json.return_value = DEFINITION - def_0 = Definition.get_definition_by_name_version("rb_name", "rb_version") - assert def_0.rb_name == "test_rb_name_0" - assert def_0.rb_version == "test_rb_version_0" - assert def_0.chart_name is None - assert def_0.description is None - assert def_0.labels is None - - -@mock.patch.object(Definition, "send_message_json") -@mock.patch.object(Definition, "send_message") -def test_create_delete_definition(mock_send_message, mock_send_message_json): - mock_send_message_json.return_value = DEFINITION - def_0 = Definition.create( - rb_name="test_rb_name_0", - rb_version="test_rb_version_0" - ) - assert def_0.rb_name == "test_rb_name_0" - assert def_0.rb_version == "test_rb_version_0" - assert def_0.chart_name is None - assert def_0.description is None - assert def_0.labels is None - assert def_0.url == f"{K8sPlugin.base_url_and_version()}/rb/definition/test_rb_name_0/test_rb_version_0" - def_0.delete() - - -@mock.patch.object(Definition, "send_message_json") -@mock.patch.object(Definition, "send_message") -def test_update_definition(mock_send_message, mock_send_message_json): - mock_send_message_json.return_value = DEFINITION - def_0 = Definition( - rb_name="test_rb_name_0", - rb_version="test_rb_version_0", - chart_name=None, - description=None, - labels=None - ) - def_0 = def_0.update() - assert def_0.rb_name == "test_rb_name_0" - assert def_0.rb_version == "test_rb_version_0" - assert def_0.chart_name is None - assert def_0.description is None - assert def_0.labels is None - assert def_0.url == f"{K8sPlugin.base_url_and_version()}/rb/definition/test_rb_name_0/test_rb_version_0" - - - -@mock.patch.object(Definition, "send_message_json") -@mock.patch.object(Definition, "send_message") -@mock.patch.object(Profile, "send_message") -def test_definition_create_delete_profile(mock_send_message_profile, mock_send_message, mock_send_message_json): - mock_send_message_json.return_value = PROFILE - deff = Definition( - rb_name="test_rb_name", - rb_version="test_rb_version", - chart_name="test_chart_name", - description="test_description", - labels={} - ) - profile = deff.create_profile( - profile_name="test_profile_name", - namespace="test_namespace", - kubernetes_version="1.19.0", - labels={ - "region": "test" - }, - extra_resource_types=[{ - "Group": "", - "Version": "v1", - "Kind": "Pod" - }] - ) - assert profile.rb_name == "test_rb_name" - assert profile.rb_version == "test_rb_version" - assert profile.profile_name == "test_profile_name" - assert profile.namespace == "test_namespace" - assert profile.kubernetes_version == "1.19.0" - assert profile.labels == { - "region": "test" - } - assert profile.extra_resource_types[0].kind == "Pod" - assert profile.extra_resource_types[0].version == "v1" - assert profile.release_name == "test_profile_name" - assert profile.url == f"{deff.url}/profile/test_profile_name" - profile.delete() - - -@mock.patch.object(Profile, "send_message_json") -def test_definition_update_profile(mock_send_message_json): - mock_send_message_json.return_value = PROFILE - old_profile = Profile( - rb_name="test_rb_name", - rb_version="test_rb_version", - profile_name="test_profile_name", - namespace="test_namespace", - labels={ - "region": "test" - }, - kubernetes_version="1.19.0" - ) - profile = old_profile.update() - assert profile.rb_name == "test_rb_name" - assert profile.rb_version == "test_rb_version" - assert profile.profile_name == "test_profile_name" - assert profile.namespace == "test_namespace" - assert profile.kubernetes_version == "1.19.0" - assert profile.labels == { - "region": "test" - } - assert profile.release_name == "test_profile_name" - assert profile.url == old_profile.url - - -@mock.patch.object(Definition, "send_message_json") -def test_definition_get_profile_by_name(mock_send_message_json): - mock_send_message_json.return_value = PROFILE - deff = Definition( - rb_name="test_rb_name", - rb_version="test_rb_version", - chart_name="test_chart_name", - description="test_description", - labels={} - ) - profile = deff.get_profile_by_name("test_profile_name") - assert profile.rb_name == "test_rb_name" - assert profile.rb_version == "test_rb_version" - assert profile.profile_name == "test_profile_name" - assert profile.namespace == "test_namespace" - assert profile.kubernetes_version == "1.19.0" - assert profile.labels == { - "region": "test" - } - assert profile.release_name == "test_profile_name" - - -@mock.patch.object(Definition, "send_message_json") -def test_definition_get_all_profiles(mock_send_message_json): - mock_send_message_json.return_value = [] - deff = Definition( - rb_name="test_rb_name", - rb_version="test_rb_version", - chart_name="test_chart_name", - description="test_description", - labels={} - ) - assert len(list(deff.get_all_profiles())) == 0 - - mock_send_message_json.return_value = PROFILES - profiles = list(deff.get_all_profiles()) - assert len(profiles) == 2 - prof_0, prof_1 = profiles - - assert prof_0.rb_name == "test_rb_name" - assert prof_0.rb_version == "test_rb_version" - assert prof_0.profile_name == "test_profile_name" - assert prof_0.namespace == "test_namespace" - assert prof_0.kubernetes_version == "1.19.0" - assert prof_0.labels == { - "region": "test" - } - assert prof_0.release_name == "test_profile_name" - - assert prof_1.rb_name == "test_rb_name_1" - assert prof_1.rb_version == "test_rb_version_1" - assert prof_1.profile_name == "test_profile_name_1" - assert prof_1.namespace == "test_namespace_1" - assert prof_1.kubernetes_version == "1.19.0" - assert prof_1.labels == { - "region": "test-new" - } - assert prof_1.release_name == "test_profile_name_1" - - -@mock.patch.object(Definition, "send_message_json") -def test_definition_get_configuration_template_by_name(mock_send_message_json): - mock_send_message_json.return_value = CONFIGURATION_TEMPLATE - deff = Definition( - rb_name="test_rb_name", - rb_version="test_rb_version", - chart_name="test_chart_name", - description="test_description", - labels={} - ) - configuration_tmpl = deff.get_configuration_template_by_name( - template_name="test_configuration_template_name" - ) - assert configuration_tmpl.rb_name == deff.rb_name - assert configuration_tmpl.rb_version == deff.rb_version - assert configuration_tmpl.template_name == "test_configuration_template_name" - assert configuration_tmpl.description == "test_configuration_template_description" - - -@mock.patch.object(Definition, "send_message_json") -@mock.patch.object(Definition, "send_message") -@mock.patch.object(ConfigurationTemplate, "send_message") -def test_definition_create_delete_configuration_template(mock_send_message_config, mock_send_message, mock_send_message_json): - mock_send_message_json.return_value = CONFIGURATION_TEMPLATE - deff = Definition( - rb_name="test_rb_name", - rb_version="test_rb_version", - chart_name="test_chart_name", - description="test_description", - labels={} - ) - configuration_tmpl = deff.create_configuration_template( - template_name="test_configuration_template_name", - description="test_configuration_template_description" - ) - assert configuration_tmpl.rb_name == deff.rb_name - assert configuration_tmpl.rb_version == deff.rb_version - assert configuration_tmpl.template_name == "test_configuration_template_name" - assert configuration_tmpl.description == "test_configuration_template_description" - assert configuration_tmpl.url == f"{deff.url}/config-template/test_configuration_template_name" - configuration_tmpl.delete() - - -@mock.patch.object(ConfigurationTemplate, "send_message_json") -def test_definition_update_configuration_template(mock_send_message_json): - mock_send_message_json.return_value = CONFIGURATION_TEMPLATE - old_configuration_template = ConfigurationTemplate( - rb_name="test_rb_name", - rb_version="test_rb_version", - template_name="test_configuration_template_name", - description="test_configuration_template_description" - ) - configuration_tmpl = old_configuration_template.update() - assert configuration_tmpl.rb_name == old_configuration_template.rb_name - assert configuration_tmpl.rb_version == old_configuration_template.rb_version - assert configuration_tmpl.template_name == old_configuration_template.template_name - assert configuration_tmpl.description == old_configuration_template.description - assert configuration_tmpl.url == old_configuration_template.url - - -@mock.patch.object(Definition, "send_message_json") -def test_definition_get_all_configuration_templates(mock_send_message_json): - mock_send_message_json.return_value = [] - deff = Definition( - rb_name="test_rb_name", - rb_version="test_rb_version", - chart_name="test_chart_name", - description="test_description", - labels={} - ) - assert len(list(deff.get_all_configuration_templates())) == 0 - - mock_send_message_json.return_value = CONFIGURATION_TEMPLATES - configuration_tmplts = list(deff.get_all_configuration_templates()) - assert len(configuration_tmplts) == 2 - - tmpl_0, tmpl_1 = configuration_tmplts - assert tmpl_0.rb_name == deff.rb_name - assert tmpl_0.rb_version == deff.rb_version - assert tmpl_0.template_name == "test_configuration_template_name" - assert tmpl_0.description == "test_configuration_template_description" - - assert tmpl_1.rb_name == deff.rb_name - assert tmpl_1.rb_version == deff.rb_version - assert tmpl_1.template_name == "test_configuration_template_name_0" - assert tmpl_1.description is None - - -@mock.patch.object(Instance, "send_message_json") -def test_instance_get_all(mock_send_message_json): - mock_send_message_json.return_value = [] - assert len(list(Instance.get_all())) == 0 - - mock_send_message_json.return_value = INSTANCES - assert len(list(Instance.get_all())) == 1 - - -@mock.patch.object(Instance, "send_message_json") -@mock.patch.object(Instance, "send_message") -def test_instance_create_delete(mock_send_message, mock_send_message_json): - mock_send_message_json.return_value = INSTANCE - instance = Instance.create( - "test_cloud_region_id", - "test_profile_name", - "test_rb_name", - "test_rb_version" - ) - assert instance.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert instance.namespace == "NAMESPACE_WHERE_INSTANCE_HAS_BEEN_DEPLOYED_AS_DERIVED_FROM_PROFILE" - assert instance.url == f"{K8sPlugin.base_url_and_version()}/instance/ID_GENERATED_BY_K8SPLUGIN" - instance.delete() - - -@mock.patch.object(Instance, "send_message_json") -def test_instance_upgrade(mock_send_message_json): - mock_send_message_json.return_value = INSTANCE - old_instance = Instance( - "ID_GENERATED_BY_K8SPLUGIN", - "test-k8s", - STATUS["request"] - ) - instance = old_instance.upgrade( - "test_cloud_region_id", - "test_profile_name", - "test_rb_name", - "test_rb_version" - ) - assert instance.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert instance.namespace == "NAMESPACE_WHERE_INSTANCE_HAS_BEEN_DEPLOYED_AS_DERIVED_FROM_PROFILE" - assert instance.url == f"{K8sPlugin.base_url_and_version()}/instance/ID_GENERATED_BY_K8SPLUGIN" - - -@mock.patch.object(Instance, "send_message_json") -def test_instance_get_by_id(mock_send_message_json): - mock_send_message_json.return_value = INSTANCE - instance = Instance.get_by_id("ID_GENERATED_BY_K8SPLUGIN") - assert instance.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert instance.namespace == "NAMESPACE_WHERE_INSTANCE_HAS_BEEN_DEPLOYED_AS_DERIVED_FROM_PROFILE" - - -@mock.patch.object(Instance, "send_message_json") -def test_instance_get_status(mock_send_message_json): - mock_send_message_json.return_value = STATUS - instance = Instance( - "ID_GENERATED_BY_K8SPLUGIN", - "test-k8s", - STATUS["request"] - ) - status = instance.get_status() - assert status.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert status.resource_count == 1 - assert status.ready == False - assert status.request.rb_name == "apache-7.6.0" - assert status.request.rb_version == "test" - assert status.request.profile_name == "test-k8s" - assert status.resources_status[0].name == "test-k8s-apache" - assert status.resources_status[0].gvk.kind == "Service" - assert status.resources_status[0].gvk.version == "v1" - - -@mock.patch.object(Instance, "send_message_json") -def test_instance_query_status(mock_send_message_json): - mock_send_message_json.return_value = STATUS - instance = Instance( - "ID_GENERATED_BY_K8SPLUGIN", - "default", - InstantiationRequest(STATUS["request"]) - ) - status = instance.query_status("Service", "v1") - assert status.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert status.resource_count == 1 - assert status.ready == False - assert status.request.rb_name == "apache-7.6.0" - assert status.request.rb_version == "test" - assert status.request.profile_name == "test-k8s" - assert status.resources_status[0].name == "test-k8s-apache" - assert status.resources_status[0].gvk.kind == "Service" - assert status.resources_status[0].gvk.version == "v1" - - -@mock.patch.object(Instance, "send_message_json") -@mock.patch.object(Instance, "send_message") -@mock.patch.object(Configuration, "send_message") -def test_instance_create_delete_configuration(mock_send_message_delete, mock_send_message, mock_send_message_json): - mock_send_message_json.return_value = CONFIG - instance = Instance( - "ID_GENERATED_BY_K8SPLUGIN", - "default", - InstantiationRequest(STATUS["request"]) - ) - config = instance.create_configuration("conf", "conf", {"replicaCount": 2}) - assert config.name == "conf" - assert config.template_name == "conf" - assert config.config_version == "1" - config.delete() - - -@mock.patch.object(Instance, "send_message_json") -def test_instance_get_configuration_by_name(mock_send_message_json): - mock_send_message_json.return_value = CONFIG - instance = Instance( - "ID_GENERATED_BY_K8SPLUGIN", - "default", - InstantiationRequest(STATUS["request"]) - ) - config = instance.get_configuration_by_name("conf") - assert config.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert config.name == "conf" - assert config.template_name == "conf" - assert config.config_version == "1" - assert config.config_tag == "two-replicas" - - -@mock.patch.object(Instance, "send_message_json") -def test_instance_get_all_configurations(mock_send_message_json): - mock_send_message_json.return_value = CONFIGS - instance = Instance( - "ID_GENERATED_BY_K8SPLUGIN", - "default", - InstantiationRequest(STATUS["request"]) - ) - configs = instance.get_all_configurations() - for conf in configs: - assert conf.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert conf.name == "conf" - assert conf.template_name == "conf" - assert conf.config_version == "1" - assert conf.config_tag == "two-replicas" - - -@mock.patch.object(Configuration, "send_message_json") -def test_instance_config_get_all_versions(mock_send_message_json): - mock_send_message_json.return_value = CONFIGS - config = Configuration( - instance_id="ID_GENERATED_BY_K8SPLUGIN", - config_name="conf", - template_name="conf", - description="", - config_version="1", - config_tag="two-replicas", - values={ - "replicaCount": 2 - } - ) - configs = config.get_config_versions() - for conf in configs: - assert conf.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert conf.name == "conf" - assert conf.template_name == "conf" - assert conf.config_version == "1" - assert conf.config_tag == "two-replicas" - - -@mock.patch.object(Configuration, "send_message_json") -def test_instance_config_get_by_version(mock_send_message_json): - mock_send_message_json.return_value = CONFIG - config = Configuration( - instance_id="ID_GENERATED_BY_K8SPLUGIN", - config_name="conf", - template_name="conf", - description="", - config_version="1", - config_tag="two-replicas", - values={ - "replicaCount": 2 - } - ) - conf = config.get_config_by_version("1") - assert conf.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert conf.name == "conf" - assert conf.template_name == "conf" - assert conf.config_version == "1" - assert conf.config_tag == "two-replicas" - - -@mock.patch.object(Configuration, "send_message_json") -def test_instance_config_get_all_tags(mock_send_message_json): - mock_send_message_json.return_value = CONFIG_TAGS - config = Configuration( - instance_id="ID_GENERATED_BY_K8SPLUGIN", - config_name="conf", - template_name="conf", - description="", - config_version="1", - config_tag="two-replicas", - values={ - "replicaCount": 2 - } - ) - configs = config.get_config_tags() - for tag in configs: - assert tag.config_tag == "two-replicas" - assert tag.config_version == "1" - - -@mock.patch.object(Configuration, "send_message_json") -def test_instance_config_get_by_tag(mock_send_message_json): - mock_send_message_json.return_value = CONFIG - config = Configuration( - instance_id="ID_GENERATED_BY_K8SPLUGIN", - config_name="conf", - template_name="conf", - description="", - config_version="1", - config_tag="two-replicas", - values={ - "replicaCount": 2 - } - ) - conf = config.get_config_by_tag("two-replicas") - assert conf.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert conf.name == "conf" - assert conf.template_name == "conf" - assert conf.config_version == "1" - assert conf.config_tag == "two-replicas" - - -@mock.patch.object(Configuration, "send_message") -def test_instance_config_tag_version(mock_send_message): - config = Configuration( - instance_id="ID_GENERATED_BY_K8SPLUGIN", - config_name="conf", - template_name="conf", - description="", - config_version="1", - config_tag="", - values={ - "replicaCount": 2 - } - ) - conf = config.tag_config_version("two-replicas") - - -@mock.patch.object(Configuration, "send_message_json") -def test_instance_config_update(mock_send_message_json): - mock_send_message_json.return_value = CONFIG_THREE - config = Configuration( - instance_id="ID_GENERATED_BY_K8SPLUGIN", - config_name="conf", - template_name="conf", - description="", - config_version="1", - config_tag="two-replicas", - values={ - "replicaCount": 2 - } - ) - conf = config.update({ - "replicaCount": 3 - }) - assert conf.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert conf.name == "conf" - assert conf.template_name == "conf" - assert conf.config_version == "2" - assert conf.config_tag == "" - assert conf.values == { - "replicaCount": 3 - } - - -@mock.patch.object(Configuration, "send_message_json") -def test_instance_config_delete_version(mock_send_message_json): - mock_send_message_json.return_value = CONFIG_THREE - config = Configuration( - instance_id="ID_GENERATED_BY_K8SPLUGIN", - config_name="conf", - template_name="conf", - description="", - config_version="1", - config_tag="", - values={ - "replicaCount": 2 - } - ) - conf = config.create_delete_version() - assert conf.instance_id == "ID_GENERATED_BY_K8SPLUGIN" - assert conf.name == "conf" - assert conf.template_name == "conf" - assert conf.config_version == "2" - assert conf.config_tag == "" - - -@mock.patch.object(Configuration, "send_message_json") -def test_instance_config_rollback(mock_send_message_json): - mock_send_message_json.return_value = CONFIG - config = Configuration( - instance_id="ID_GENERATED_BY_K8SPLUGIN", - config_name="conf", - template_name="conf", - description="", - config_version="2", - config_tag="", - values={ - "replicaCount": 3 - } - ) - config.rollback_to(config_version="1", config_tag=None) - diff --git a/tests/test_so_db_adapter.py b/tests/test_so_db_adapter.py index 50f26d6..ee441b8 100644 --- a/tests/test_so_db_adapter.py +++ b/tests/test_so_db_adapter.py @@ -123,14 +123,3 @@ def test_add_cloud_site(mock_send_message_json): assert response['clli'] == "test_clli_0" assert response['orchestrator'] == "multicloud" assert response['identity_service_id'] == "test_identity_0" - -@mock.patch.object(SoDbAdapter, "send_message_json") -def test_get_service_vnf_info(mock_send_message_json): - mock_send_message_json.return_value = ADD_CLOUD_SITE_RESPONSE - - response = SoDbAdapter.get_service_vnf_info(identifier="test_id_0") - assert response['region_id'] == "test_region_0" - assert response['aic_version'] == "2.5" - assert response['clli'] == "test_clli_0" - assert response['orchestrator'] == "multicloud" - assert response['identity_service_id'] == "test_identity_0" diff --git a/tests/test_so_instantiation.py b/tests/test_so_instantiation.py index 0269110..ca221ea 100644 --- a/tests/test_so_instantiation.py +++ b/tests/test_so_instantiation.py @@ -37,7 +37,6 @@ from onapsdk.so.instantiation import ( VnfOperation, PnfInstantiation ) -from onapsdk.vid import Vid from onapsdk.aai.business.owning_entity import OwningEntity @@ -576,10 +575,9 @@ def test_network_instantiation_with_cr_and_tenant(mock_network_preload, mock_net assert network_instantiation.name == "test" -@mock.patch.object(Vid, "send_message") @mock.patch.object(VnfInstantiation, "send_message_json") @mock.patch("onapsdk.so.instantiation.SdcService") -def test_vnf_instantiation_get_by_vnf_instance_name(mock_sdc_service, mock_send_message_json, mock_send): +def test_vnf_instantiation_get_by_vnf_instance_name(mock_sdc_service, mock_send_message_json): mock_sdc_service.return_value.vnfs = [] mock_send_message_json.return_value = {} with pytest.raises(InvalidResponse): @@ -702,10 +700,9 @@ def test_vnf_instantiation_get_by_vnf_instance_name(mock_sdc_service, mock_send_ assert VnfInstantiation.get_by_vnf_instance_name("test_vnf_instance_name") is not None -@mock.patch.object(Vid, "send_message") @mock.patch.object(PnfInstantiation, "send_message_json") @mock.patch("onapsdk.so.instantiation.SdcService") -def test_pnf_instantiation_get_by_pnf_instance_name(mock_sdc_service, mock_send_message_json, mock_send): +def test_pnf_instantiation_get_by_pnf_instance_name(mock_sdc_service, mock_send_message_json): mock_sdc_service.return_value.pnfs = [] mock_send_message_json.return_value = {} with pytest.raises(InvalidResponse): diff --git a/tests/test_version.py b/tests/test_version.py index 9aef6ce..3b30793 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -17,4 +17,4 @@ import onapsdk.version as version def test_version(): """Check version is the right one.""" - assert version.__version__ == '12.11.0' + assert version.__version__ == '13.0.0' diff --git a/tests/test_vid.py b/tests/test_vid.py deleted file mode 100644 index 47281ba..0000000 --- a/tests/test_vid.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2022 Orange, Deutsche Telekom AG -# -# 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. - -from unittest.mock import patch - -from onapsdk.vid import ( - OwningEntity, - Project, - LineOfBusiness, - Platform -) - - -@patch.object(LineOfBusiness, "send_message") -def test_line_of_business(send_message_mock): - assert LineOfBusiness.get_create_url() == "https://vid.api.simpledemo.onap.org:30200/vid/maintenance/category_parameter/lineOfBusiness" - - line_of_businnes = LineOfBusiness.create("test") - assert line_of_businnes.name == "test" - - -@patch.object(OwningEntity, "send_message") -def test_owning_entity(send_message_mock): - assert OwningEntity.get_create_url() == "https://vid.api.simpledemo.onap.org:30200/vid/maintenance/category_parameter/owningEntity" - - owning_entity = OwningEntity.create("test") - assert owning_entity.name == "test" - - -@patch.object(Project, "send_message") -def test_project(send_message_mock): - assert Project.get_create_url() == "https://vid.api.simpledemo.onap.org:30200/vid/maintenance/category_parameter/project" - - project = Project.create("test") - assert project.name == "test" - - -@patch.object(Platform, "send_message") -def test_platform(send_message_mock): - assert Platform.get_create_url() == "https://vid.api.simpledemo.onap.org:30200/vid/maintenance/category_parameter/platform" - - platform = Platform.create("test") - assert platform.name == "test" |