3 # jose.lausuch@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
10 import tier_handler as th
14 class TierBuilder(object):
16 def __init__(self, ci_installer, ci_scenario, testcases_file):
17 self.ci_installer = ci_installer
18 self.ci_scenario = ci_scenario
19 self.testcases_file = testcases_file
20 self.dic_tier_array = None
21 self.tier_objects = []
22 self.testcases_yaml = None
25 def read_test_yaml(self):
26 with open(self.testcases_file) as f:
27 self.testcases_yaml = yaml.safe_load(f)
29 self.dic_tier_array = []
30 for tier in self.testcases_yaml.get("tiers"):
31 self.dic_tier_array.append(tier)
33 def generate_tiers(self):
34 if self.dic_tier_array is None:
37 del self.tier_objects[:]
38 for dic_tier in self.dic_tier_array:
39 tier = th.Tier(name=dic_tier['name'],
40 order=dic_tier['order'],
41 ci_loop=dic_tier['ci_loop'],
42 description=dic_tier['description'])
44 for dic_testcase in dic_tier['testcases']:
45 installer = dic_testcase['dependencies']['installer']
46 scenario = dic_testcase['dependencies']['scenario']
47 dep = th.Dependency(installer, scenario)
49 testcase = th.TestCase(name=dic_testcase['name'],
51 criteria=dic_testcase['criteria'],
52 blocking=dic_testcase['blocking'],
53 clean_flag=dic_testcase['clean_flag'],
54 description=dic_testcase['description'])
55 if testcase.is_compatible(self.ci_installer, self.ci_scenario):
56 tier.add_test(testcase)
58 self.tier_objects.append(tier)
61 return self.tier_objects
63 def get_tier_names(self):
65 for tier in self.tier_objects:
66 tier_names.append(tier.get_name())
69 def get_tier(self, tier_name):
70 for i in range(0, len(self.tier_objects)):
71 if self.tier_objects[i].get_name() == tier_name:
72 return self.tier_objects[i]
75 def get_test(self, test_name):
76 for i in range(0, len(self.tier_objects)):
77 if self.tier_objects[i].is_test(test_name):
78 return self.tier_objects[i].get_test(test_name)
81 def get_tests(self, tier_name):
82 for i in range(0, len(self.tier_objects)):
83 if self.tier_objects[i].get_name() == tier_name:
84 return self.tier_objects[i].get_tests()
89 for i in range(0, len(self.tier_objects)):
90 output += str(self.tier_objects[i]) + "\n"