Updated run_conformance_tests.py
[osm/tests.git] / conformance-tests / run_conformance_tests.py
1 ## Copyright 2020 ETSI OSM
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
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import os
17 from shutil import copy
18 from subprocess import run
19 from osm_client import *
20
21 packages_folder = os.environ["PACKAGES_FOLDER"]
22 conformance_folder = "{}/{}".format(os.environ["ROBOT_DEVOPS_FOLDER"], "conformance-tests")
23 test_lists_folder = "{}/{}".format(conformance_folder, "test-lists")
24 sol005_folder = "{}/repo/SOL005".format(conformance_folder)
25 osm_hostname = os.environ["OSM_HOSTNAME"]
26
27
28 def get_package_path(package_name):
29 return "{}/{}".format(packages_folder, package_name)
30
31
32 def get_suite_path(suite_name):
33 return "{}/repo/SOL005/{}".format(conformance_folder, suite_name)
34
35
36 def run_test_suite(suite_dir, suite_name, arg_file):
37 print("robot -d {}/repo/{}/reports --argumentfile {} .".format(conformance_folder, suite_name, arg_file))
38 run(["robot --loglevel=TRACE -d {}/reports/{} --argumentfile {} .".format(conformance_folder, suite_name, arg_file)], cwd=suite_dir, shell=True)
39
40
41 def sub_env_vars(file_dir, file_name):
42 run(["cat {} | envsubst | cat > {}".format(file_name, get_suite_path(file_name.split(".")[0]) + "/" + file_name)], cwd=file_dir, shell=True)
43
44
45 # RESOURCE CREATION HAPPENS BELOW
46
47 nsd_id, vnfd_id, ns_id = "", "", ""
48
49 if ':' in osm_hostname:
50 port = osm_hostname.split(':')[-1]
51 else:
52 port = "9999"
53 osm_hostname = osm_hostname.split(':')[0]
54
55 osm = OSM(osm_hostname, port)
56
57 os.environ["AUTH_TOKEN"] = osm.get_auth_token()
58
59 try:
60 vnfd_id = osm.create_vnfd(get_package_path("hackfest_basic_vnf/hackfest_basic_vnfd.yaml"))
61 nsd_id = osm.create_nsd(get_package_path("hackfest_basic_ns/hackfest_basic_nsd.yaml"))
62 ns_id = osm.create_ns("Test_NS", nsd_id, "osm")
63 except ResourceException as e:
64 print(e.message)
65
66 print("VNFD: {}\nNSD: {}\nNS: {}".format(vnfd_id, nsd_id, ns_id))
67
68 # Apply relevant env variables (required for test vars)
69 os.environ["NSD_INFO_ID"] = nsd_id
70 os.environ["VNFD_INFO_ID"] = vnfd_id
71 os.environ["NS_INFO_ID"] = ns_id
72 os.environ["NFVO_HOST"] = osm_hostname
73 os.environ["NFVO_PORT"] = port
74
75 # RESOURCE CREATION HAPPENS ABOVE
76
77
78 # Copy test selection files over to relevant directories
79 (_, _, filenames) = next(os.walk(test_lists_folder))
80 for f in filenames:
81 if f.endswith(".txt"):
82 # Apply ENV Variables
83 sub_env_vars(test_lists_folder, f)
84
85
86 # Run the robot tests
87 (_, directories, _) = next(os.walk(sol005_folder))
88 for d in directories:
89 run_test_suite("{}/{}".format(sol005_folder, d), d, d + ".txt")
90
91
92 # We then need to clear the created resources
93 try:
94 osm.delete_ns(ns_id)
95 osm.delete_nsd(nsd_id)
96 osm.delete_vnfd(vnfd_id)
97 except ResourceException as e:
98 print("Deletion failed: {}".format(e.message))
99
100 print("Cleared resources")