3 # ============LICENSE_START=======================================================
4 # ORAN SMO PACKAGE - PYTHONSDK TESTS
5 # ================================================================================
6 # Copyright (C) 2021-2022 AT&T Intellectual Property. All rights
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END============================================
21 # ===================================================================
24 """Onap Policy module."""
26 from dataclasses import dataclass
27 from typing import Dict
28 from onapsdk.onap_service import OnapService
29 from oransdk.configuration import settings
33 """PolicyType dataclass."""
39 class OranPolicy(OnapService):
40 """Onap Policy library."""
42 pap_url = settings.POLICY_PAP_URL
43 api_url = settings.POLICY_API_URL
44 header = {"Accept": "application/json", "Content-Type": "application/json"}
47 def get_components_status(cls,
48 basic_auth: Dict[str, str]) -> Dict:
50 Get status of Policy component.
53 basic_auth: (Dict[str, str]) for example:{ 'username': 'bob', 'password': 'secret' }
56 the status of the Policy component
59 url = f"{cls.pap_url}/policy/pap/v1/components/healthcheck"
60 status = cls.send_message_json('GET',
61 'Get status of Policy component',
63 basic_auth=basic_auth)
67 def get_policy_status(cls, basic_auth: Dict[str, str]) -> Dict:
69 Get status of all the policies.
72 the status of all the policies
75 url = f"{cls.pap_url}/policy/pap/v1/policies/status"
76 status = cls.send_message_json('GET',
77 'Get status of all the policies',
79 basic_auth=basic_auth)
83 def get_policy(cls, policy_type: PolicyType, policy_name, policy_version, basic_auth: Dict[str, str]) -> Dict:
88 policy_type: the policy type
89 policy_name: the policy name
90 policy_version: the version of the policy
91 basic_auth: (Dict[str, str]) for example:{ 'username': 'bob', 'password': 'secret' }
97 url = f"{cls.api_url}/policy/api/v1/policytypes/{policy_type.type}/versions/{policy_type.version}/policies/{policy_name}/versions/{policy_version}"
98 policy_response = cls.send_message('GET', 'Get the policy', url, basic_auth=basic_auth)
99 return policy_response
102 def create_policy(cls, policy_type: PolicyType, policy_data, basic_auth: Dict[str, str]) -> None:
107 policy_type: the policy type
108 type_version: the version of the policy type
109 policy_data: the policy to be created, in binary format
112 url = f"{cls.api_url}/policy/api/v1/policytypes/{policy_type.type}/versions/{policy_type.version}/policies"
113 cls.send_message('POST', 'Create Policy', url, data=policy_data, headers=cls.header,
114 basic_auth=basic_auth)
117 def deploy_policy(cls, policy_data, basic_auth: Dict[str, str]) -> None:
122 policy_data: the policy to be deployed, in binary format
125 url = f"{cls.pap_url}/policy/pap/v1/pdps/policies"
126 cls.send_message('POST', 'Deploy Policy', url, data=policy_data, headers=cls.header, basic_auth=basic_auth)
129 def undeploy_policy(cls, policy_id, policy_version, basic_auth: Dict[str, str]) -> None:
134 policy_id: The policy id as provided during the create
135 policy_version: The policy version as provided during the create
138 url = f"{cls.pap_url}/policy/pap/v1/pdps/policies/{policy_id}/versions/{policy_version}"
139 cls.send_message('DELETE', 'Undeploy Policy', url, headers=cls.header, basic_auth=basic_auth)
142 def delete_policy(cls, policy_type: PolicyType, policy_id, policy_version, basic_auth: Dict[str, str]) -> None:
147 policy_type: the policy type
148 policy_id: The policy id as provided during the create
149 policy_version: The policy version as provided during the create
152 url = f"{cls.api_url}/policy/api/v1/policytypes/{policy_type.type}/versions/{policy_type.version}/policies/{policy_id}/versions/{policy_version}"
153 cls.send_message('DELETE', 'Delete Policy', url, headers=cls.header, basic_auth=basic_auth)