blob: 02a8221dcb50fac3566b0dc339980bd255930a0a [file] [log] [blame]
Frank Brydene570b102020-09-07 08:45:54 +00001# 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
16import os
17from shutil import copy
18from subprocess import run
19from osm_client import *
20
21packages_folder = os.environ["PACKAGES_FOLDER"]
22conformance_folder = "{}/{}".format(os.environ["ROBOT_DEVOPS_FOLDER"], "conformance-tests")
23test_lists_folder = "{}/{}".format(conformance_folder, "test-lists")
24sol005_folder = "{}/repo/SOL005".format(conformance_folder)
25osm_hostname = os.environ["OSM_HOSTNAME"]
26
27
28def get_package_path(package_name):
29 return "{}/{}".format(packages_folder, package_name)
30
31
32def get_suite_path(suite_name):
33 return "{}/repo/SOL005/{}".format(conformance_folder, suite_name)
34
35
36def 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,
39 suite_name, arg_file)], cwd=suite_dir, shell=True)
40
41
42def sub_env_vars(file_dir, file_name):
43 run(["envsubst < {0} > {0}".format(file_name)], cwd=file_dir, shell=True)
44
45
46# RESOURCE CREATION HAPPENS BELOW
47nsd_id, vnfd_id = "", ""
48
49osm = OSM(osm_hostname)
50
51os.environ["AUTH_TOKEN"] = osm.get_auth_token()
52
53try:
54 vnfd_id = osm.create_vnfd(get_package_path("hackfest_basic_vnf/hackfest_basic_vnfd.yaml"))
55 nsd_id = osm.create_nsd(get_package_path("hackfest_basic_ns/hackfest_basic_nsd.yaml"))
56except ResourceException as e:
57 print(e.message)
58
59print("VNFD: {}\nNSD: {}".format(vnfd_id, nsd_id))
60# Apply relevant env variables (required for test vars)
61os.environ["NSD_INFO_ID"] = nsd_id
62
63# RESOURCE CREATION HAPPENS ABOVE
64
65# Copy test selection files over to relevant directories
66(_, _, filenames) = next(os.walk(test_lists_folder))
67for f in filenames:
68 if f.endswith(".txt"):
69 # Apply ENV Variables
70 sub_env_vars(test_lists_folder, f)
71
72 # Then copy to appropriate directory
73 print("Copying {} to {}".format(f, get_suite_path(f.split(".")[0])))
74 copy("{}/{}".format(test_lists_folder, f), get_suite_path(f.split(".")[0]))
75
76
77# Run the robot tests
78(_, directories, _) = next(os.walk(sol005_folder))
79for d in directories:
80 run_test_suite("{}/{}".format(sol005_folder, d), d, d + ".txt")
81
82# We then need to clear the created resources
83try:
84 osm.delete_nsd(nsd_id)
85 osm.delete_vnfd(vnfd_id)
86except ResourceException as e:
87 print("Deletion failed: {}".format(e.message))
88
89print("Cleared resources")