blob: 87d327ba55ff310d9589447d03a0bad67e529906 [file] [log] [blame]
DR695H217b2cc2019-07-11 18:00:10 -04001# 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
15from robot import utils
16from robot.api.deco import keyword
DR695H0605e352019-07-26 15:56:10 -040017from robot.libraries.BuiltIn import BuiltIn
DR695H217b2cc2019-07-11 18:00:10 -040018import os.path
19import json
20
21
22class 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"""
25
26 def __init__(self):
27 super(PreloadDataKeywords, self).__init__()
28 self._cache = utils.ConnectionCache('No Preload Data directories loaded')
DR695H0605e352019-07-26 15:56:10 -040029 self.builtin = BuiltIn()
DR695H217b2cc2019-07-11 18:00:10 -040030
31 @keyword
32 def set_directory(self, alias, preload_data_directory):
33 self._cache.register(preload_data_directory, alias=alias)
34
35 @keyword
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]
39
40 @keyword
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")
44
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:
48 return json.load(f)