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.
18 from copy import deepcopy
19 from robot.libraries.BuiltIn import BuiltIn
20 from zipfile import ZipFile
32 "name": "onap-vvp.validate.heat",
33 "result": "NOT_STARTED",
34 "objective": "onap heat template validation",
36 "portal_key_file": "report.json",
40 "name": "onap-vvp.lifecycle_validate.heat",
41 "result": "NOT_STARTED",
42 "objective": "onap vnf lifecycle validation",
44 {"name": "model-and-distribute", "result": "NOT_STARTED"},
45 {"name": "instantiation", "result": "NOT_STARTED"},
47 "portal_key_file": "log.html",
51 "name": "stack_validation",
52 "result": "NOT_STARTED",
53 "objective": "onap vnf openstack validation",
55 "portal_key_file": "stack_report.json",
62 ROBOT_LISTENER_API_VERSION = 2
65 self.report = deepcopy(OUTPUT_DATA)
67 self.build_number = ""
68 self.build_directory = ""
69 self.output_directory = ""
70 self.template_directory = ""
73 self.build_number = BuiltIn().get_variable_value("${GLOBAL_BUILD_NUMBER}")
74 self.build_directory = BuiltIn().get_variable_value("${BUILD_DIR}")
75 self.output_directory = BuiltIn().get_variable_value("${OUTPUTDIR}")
77 self.template_directory = "{}/templates".format(self.build_directory)
78 self.report["build_tag"] = "vnf-validation-{}".format(self.build_number)
79 self.report["vnf_checksum"] = sha256(self.template_directory)
81 def start_test(self, name, attrs):
83 date = datetime.datetime.strptime(attrs["starttime"], '%Y%m%d %H:%M:%S.%f').strftime('%Y-%m-%d %H:%M:%S')
84 self.report["test_date"] = date
86 def end_keyword(self, name, attrs):
87 kwname = attrs["kwname"]
88 status = attrs["status"]
90 if kwname == "Run VVP Validation Scripts":
91 self.report["testcases_list"][0]["result"] = status
92 elif kwname == "Model Distribution For Directory":
93 self.report["testcases_list"][1]["sub_testcase"][0]["result"] = status
94 elif kwname == "Instantiate VNF":
95 self.report["testcases_list"][1]["sub_testcase"][1]["result"] = status
96 self.report["testcases_list"][1]["result"] = status
97 elif kwname == "Run VNF Instantiation Report":
98 self.report["testcases_list"][2]["result"] = status
100 def end_test(self, name, attrs):
101 self.report["duration"] = attrs["elapsedtime"] / 1000
104 with open("{}/summary/results.json".format(self.output_directory), "w") as f:
105 json.dump(self.report, f, indent=4)
108 def sha256(template_directory):
110 zip_file = "{}/tmp.zip".format(template_directory)
111 onlyfiles = [f for f in os.listdir(template_directory) if os.path.isfile(os.path.join(template_directory, f))]
113 with ZipFile(zip_file, 'w') as zipObj:
114 for filename in onlyfiles:
115 zipObj.write(os.path.join(template_directory, filename), arcname=filename)
117 with open(zip_file, "rb") as f:
119 heat_sha = hashlib.sha256(bytes).hexdigest()
121 if os.path.exists(zip_file):