1 # Copyright 2019 AT&T Intellectual Property. All rights reserved.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 from robot import utils
16 from robot.api.deco import keyword
17 from robot.libraries.BuiltIn import BuiltIn
22 class PreloadDataKeywords(object):
23 """PreloadData is used for loading data for services into the robot framework in a structured decentralized way
24 that lets vnfs be added without code change to testuite"""
27 super(PreloadDataKeywords, self).__init__()
28 self._cache = utils.ConnectionCache('No Preload Data directories loaded')
29 self.builtin = BuiltIn()
32 def set_directory(self, alias, preload_data_directory):
33 self._cache.register(preload_data_directory, alias=alias)
36 def get_preload_data(self, alias, service, template):
37 """returns a dictionary with all of the preload data for the passed in service and template"""
38 return self._preload_data(alias, service)[template]
41 def get_default_preload_data(self, alias):
42 """returns a dictionary with all of the default values"""
43 return self._preload_data(alias, "defaults")
45 def _preload_data(self, alias, service):
46 filepath = os.path.join(self._cache.switch(alias), service, 'preload_data.json')
47 with open(filepath, 'r') as f: