From: Zhang Rong(Jon) Date: Thu, 3 Nov 2022 01:45:14 +0000 (+0800) Subject: Update DMS profile support list; bugfix of resource type duplicate X-Git-Tag: 2.0.0-rc1~8 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=d9000f0859a254f2c3c32f30ed71a143e731e2ff;p=pti%2Fo2.git Update DMS profile support list; bugfix of resource type duplicate Issue-ID: INF-308 Issue-ID: INF-334 Signed-off-by: Zhang Rong(Jon) Change-Id: I5ce206ec9003ce1040e953f3b9495982ee3e8b49 --- diff --git a/configs/o2app.conf b/configs/o2app.conf index b59cab9..cf6bdfe 100644 --- a/configs/o2app.conf +++ b/configs/o2app.conf @@ -12,6 +12,9 @@ OS_PASSWORD = API_HOST_EXTERNAL_FLOATING = [API] +# support native_k8sapi,sol018,sol018_helmcli +# if the value is black, then native_k8sapi will set by default +DMS_SUPPORT_PROFILES = [WATCHER] diff --git a/o2common/config/config.py b/o2common/config/config.py index 2769529..ef67e74 100644 --- a/o2common/config/config.py +++ b/o2common/config/config.py @@ -303,25 +303,22 @@ def get_events_yaml_filename(): return events_yaml_name return "/configs/events.yaml" -# get k8s host from env: - +# get k8s host from env: def get_k8s_host(): k8s_host = os.environ.get("KUBERNETES_SERVICE_HOST") if k8s_host is None: raise Exception('Get k8s host failed.') return k8s_host -# get k8s host port from env: - +# get k8s host port from env: def get_k8s_port(): k8s_port = os.environ.get("KUBERNETES_SERVICE_PORT_HTTPS", '443') return k8s_port -# token review url - +# token review url def get_review_url(): try: api = '/apis/authentication.k8s.io/v1/tokenreviews' @@ -330,9 +327,8 @@ def get_review_url(): except Exception: raise Exception('Get k8s review url failed') -# get reviewer token - +# get reviewer token def get_reviewer_token(): # token path default is below. token_path = '/var/run/secrets/kubernetes.io/serviceaccount/token' @@ -343,3 +339,13 @@ def get_reviewer_token(): def get_auth_provider(): return 'k8s' + + +def get_dms_support_profiles(): + profiles = config.conf.API.DMS_SUPPORT_PROFILES + profiles = profiles.replace("'", "").replace( + '"', "").replace('[', "").replace(']', "") + profiles = profiles.split(',') + if 'native_k8sapi' not in profiles: + profiles.append('native_k8sapi') + return profiles diff --git a/o2ims/domain/ocloud.py b/o2ims/domain/ocloud.py index a2047af..c6f5fd8 100644 --- a/o2ims/domain/ocloud.py +++ b/o2ims/domain/ocloud.py @@ -16,15 +16,14 @@ from __future__ import annotations import json from o2common.domain.base import AgRoot, Serializer -from o2common.config import conf as CONF +from o2common.config import config, conf as CONF # from dataclasses import dataclass # from datetime import date # from typing import Optional, List, Set from .resource_type import ResourceKindEnum, ResourceTypeEnum -# from uuid import UUID -DeploymentManagerProfileDefault = 'default' +DeploymentManagerProfileDefault = 'native_k8sapi' DeploymentManagerProfileSOL018 = 'sol018' DeploymentManagerProfileSOL018HelmCLI = 'sol018_helmcli' @@ -55,9 +54,13 @@ class DeploymentManager(AgRoot, Serializer): d['profile'] = json.loads(d['profile']) d['profileSupportList'] = [ DeploymentManagerProfileDefault, - DeploymentManagerProfileSOL018, - DeploymentManagerProfileSOL018HelmCLI, ] + profiles = config.get_dms_support_profiles() + for profile in profiles: + if profile == DeploymentManagerProfileSOL018: + d['profileSupportList'].append(profile) + elif profile == DeploymentManagerProfileSOL018HelmCLI: + d['profileSupportList'].append(profile) return d diff --git a/o2ims/service/auditor/pserver_mem_handler.py b/o2ims/service/auditor/pserver_mem_handler.py index 2a0ba73..4072daf 100644 --- a/o2ims/service/auditor/pserver_mem_handler.py +++ b/o2ims/service/auditor/pserver_mem_handler.py @@ -51,11 +51,6 @@ def update_pserver_mem( ) first = res.first() if first is None: - resourcetype_id = str(uuid.uuid4()) - uow.resource_types.add(ResourceType( - resourcetype_id, - 'pserver_mem', stxobj.type, - resourcepool.oCloudId)) res_type_name = 'pserver_mem' resourcetype_id = str(uuid.uuid3( uuid.NAMESPACE_URL, res_type_name)) diff --git a/o2ims/views/ocloud_route.py b/o2ims/views/ocloud_route.py index 570292d..7616b25 100644 --- a/o2ims/views/ocloud_route.py +++ b/o2ims/views/ocloud_route.py @@ -18,6 +18,7 @@ from flask_restx import Resource, reqparse from o2common.service.messagebus import MessageBus from o2common.views.pagination_route import link_header, PAGE_PARAM from o2common.views.route_exception import NotFoundException +from o2ims.domain import ocloud from o2ims.views import ocloud_view from o2ims.views.api_ns import api_ims_inventory as api_ims_inventory_v1 from o2ims.views.ocloud_dto import OcloudDTO, ResourceTypeDTO,\ @@ -408,8 +409,9 @@ class DeploymentManagersListRouter(Resource): @api_ims_inventory_v1.route("/v1/deploymentManagers/") @api_ims_inventory_v1.param('deploymentManagerID', 'ID of the deployment manager') -@api_ims_inventory_v1.param('profile', 'DMS profile: value supports "sol018"', - _in='query') +@api_ims_inventory_v1.param( + 'profile', 'DMS profile: value supports "native_k8sapi"', + _in='query') @api_ims_inventory_v1.response(404, 'Deployment manager not found') @api_ims_inventory_v1.param( 'all_fields', @@ -443,11 +445,16 @@ class DeploymentManagerGetRouter(Resource): args = parser.parse_args() profile = ( args.profile if args.profile is not None and args.profile != '' - else 'default') + else ocloud.DeploymentManagerProfileDefault) result = ocloud_view.deployment_manager_one( deploymentManagerID, bus.uow, profile) - if result is not None: + if result is not None and result != "": return result + elif result == "": + raise NotFoundException( + "Profile {} doesn't support".format( + args.profile)) + raise NotFoundException("Deployment manager {} doesn't exist".format( deploymentManagerID)) diff --git a/o2ims/views/ocloud_view.py b/o2ims/views/ocloud_view.py index a70ebf4..441c938 100644 --- a/o2ims/views/ocloud_view.py +++ b/o2ims/views/ocloud_view.py @@ -128,7 +128,8 @@ def deployment_managers(uow: unit_of_work.AbstractUnitOfWork, **kwargs): def deployment_manager_one(deploymentManagerId: str, uow: unit_of_work.AbstractUnitOfWork, - profile: str = 'default'): + profile: str = + ocloud.DeploymentManagerProfileDefault): profile = profile.lower() with uow: first = uow.deployment_managers.get(deploymentManagerId) @@ -140,10 +141,12 @@ def deployment_manager_one(deploymentManagerId: str, profile_data = result.pop("profile", None) result['profileName'] = profile + profiles = config.get_dms_support_profiles() + if profile not in profiles: + return "" - if ocloud.DeploymentManagerProfileDefault == profile: - pass - elif ocloud.DeploymentManagerProfileSOL018 == profile: + if ocloud.DeploymentManagerProfileDefault == profile \ + or ocloud.DeploymentManagerProfileSOL018 == profile: result['serviceUri'] = \ profile_data['cluster_api_endpoint'] result['profileData'] = profile_data @@ -159,7 +162,7 @@ def deployment_manager_one(deploymentManagerId: str, deploymentManagerId, profile_data) result['profileData'] = helmcli_profile else: - return None + return "" return result diff --git a/tests/unit/test_ocloud.py b/tests/unit/test_ocloud.py index 01395ee..3c0fde7 100644 --- a/tests/unit/test_ocloud.py +++ b/tests/unit/test_ocloud.py @@ -18,7 +18,7 @@ from unittest.mock import MagicMock from o2ims.domain import ocloud, subscription_obj from o2ims.domain import resource_type as rt from o2ims.views import ocloud_view -from o2common.config import config +from o2common.config import config, conf as CONF def setup_ocloud(): @@ -298,18 +298,24 @@ def test_view_deployment_manager_one(mock_uow): "profile": {} } + CONF.API.DMS_SUPPORT_PROFILES = 'native_k8sapi,sol018,sol018_helmcli' + cluster_endpoint = "https://test_k8s:6443" + session.return_value.query.return_value.filter_by.return_value.first.\ + return_value.serialize.return_value['profile'] = { + "cluster_api_endpoint": cluster_endpoint + } + # profile default deployment_manager_res = ocloud_view.deployment_manager_one( deployment_manager_id1, uow) assert str(deployment_manager_res.get( "deploymentManagerId")) == deployment_manager_id1 assert str(deployment_manager_res.get( - 'serviceUri')) == dms_endpoint + 'serviceUri')) == cluster_endpoint assert deployment_manager_res.get('profile') is None # profile sol018 profileName = ocloud.DeploymentManagerProfileSOL018 - cluster_endpoint = "https://test_k8s:6443" session.return_value.query.return_value.filter_by.return_value.first.\ return_value.serialize.return_value['profile'] = { "cluster_api_endpoint": cluster_endpoint @@ -323,13 +329,9 @@ def test_view_deployment_manager_one(mock_uow): # profile wrong name profileName = 'wrong_profile' - session.return_value.query.return_value.filter_by.return_value.first.\ - return_value.serialize.return_value['profile'] = { - "cluster_api_endpoint": cluster_endpoint - } deployment_manager_res = ocloud_view.deployment_manager_one( deployment_manager_id1, uow, profile=profileName) - assert deployment_manager_res is None + assert deployment_manager_res == "" def test_view_subscriptions(mock_uow):