1 ## Copyright 2020 ETSI OSM
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
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 from shutil
import copy
18 from subprocess
import run
19 from osm_client
import *
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"]
28 def get_package_path(package_name
):
29 return "{}/{}".format(packages_folder
, package_name
)
32 def get_suite_path(suite_name
):
33 return "{}/repo/SOL005/{}".format(conformance_folder
, suite_name
)
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)
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)
45 # RESOURCE CREATION HAPPENS BELOW
47 nsd_id
, vnfd_id
, ns_id
= "", "", ""
49 if ':' in osm_hostname
:
50 port
= osm_hostname
.split(':')[-1]
53 osm_hostname
= osm_hostname
.split(':')[0]
55 osm
= OSM(osm_hostname
, port
)
57 os
.environ
["AUTH_TOKEN"] = osm
.get_auth_token()
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
:
66 print("VNFD: {}\nNSD: {}\nNS: {}".format(vnfd_id
, nsd_id
, ns_id
))
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
75 # RESOURCE CREATION HAPPENS ABOVE
78 # Copy test selection files over to relevant directories
79 (_
, _
, filenames
) = next(os
.walk(test_lists_folder
))
81 if f
.endswith(".txt"):
83 sub_env_vars(test_lists_folder
, f
)
87 (_
, directories
, _
) = next(os
.walk(sol005_folder
))
89 run_test_suite("{}/{}".format(sol005_folder
, d
), d
, d
+ ".txt")
92 # We then need to clear the created resources
95 osm
.delete_nsd(nsd_id
)
96 osm
.delete_vnfd(vnfd_id
)
97 except ResourceException
as e
:
98 print("Deletion failed: {}".format(e
.message
))
100 print("Cleared resources")