adding in new onap lib and servicemapping
[testsuite/python-testing-utils.git] / robotframework-onap / ONAPLibrary / ServiceMappingKeywords.py
1 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from robot import utils
16 from robot.api.deco import keyword
17 import os.path
18 import json
19
20
21 class ServiceMappingKeywords(object):
22     """ServiceMapping is used for loading data for services into the robot framework in a structured decentralized way
23     that lets vnfs be added without code change to testuite"""
24
25     def __init__(self):
26         super(ServiceMappingKeywords, self).__init__()
27         self._cache = utils.ConnectionCache('No Service Mappings directories loaded')
28
29     @keyword
30     def set_directory(self, alias, service_mappings_directory):
31         self._cache.register(service_mappings_directory, alias=alias)
32
33     @keyword
34     def get_service_folder_mapping(self, alias, service):
35         """returns an array of strings with the folder where the vnf's heat files are stored """
36         return self._service_mapping(alias, service)['GLOBAL_SERVICE_FOLDER_MAPPING'][service]
37
38     @keyword
39     def get_service_vnf_mapping(self, alias, service):
40         """returns an array of strings that is the vnfs in this service """
41         return self._service_mapping(alias, service)['GLOBAL_SERVICE_VNF_MAPPING'][service]
42
43     @keyword
44     def get_service_neutron_mapping(self, alias, service):
45         """returns an array of strings that lists the neutron networks needed in this service """
46         return self._service_mapping(alias, service)['GLOBAL_SERVICE_GEN_NEUTRON_NETWORK_MAPPING'][service]
47
48     @keyword
49     def get_service_deployment_artifact_mapping(self, alias, service):
50         """returns an array of strings that is the extra deployment artifacts needed with this service """
51         return self._service_mapping(alias, service)['GLOBAL_SERVICE_DEPLOYMENT_ARTIFACT_MAPPING'][service]
52
53     @keyword
54     def get_service_template_mapping(self, alias, service, vnf):
55         """returns an array of strings that are the heat templates for this vnf """
56         return self._service_mapping(alias, service)['GLOBAL_SERVICE_TEMPLATE_MAPPING'][vnf]
57
58     """@PendingDeprecationWarning"""
59     @keyword
60     def get_validate_name_mapping(self, alias, service, vnf):
61         """returns an array of strings that are the names to validate in heatbridge for the vnf """
62         return self._service_mapping(alias, service)['GLOBAL_VALIDATE_NAME_MAPPING'][vnf]
63
64     def _service_mapping(self, alias, service):
65         filepath = os.path.join(self._cache.switch(alias), service, 'service_mapping.json')
66         with open(filepath, 'r') as f:
67             return json.load(f)