| Frank Bryden | e570b10 | 2020-09-07 08:45:54 +0000 | [diff] [blame] | 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, |
| 39 | suite_name, arg_file)], cwd=suite_dir, shell=True) |
| 40 | |
| 41 | |
| 42 | def 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 |
| 47 | nsd_id, vnfd_id = "", "" |
| 48 | |
| 49 | osm = OSM(osm_hostname) |
| 50 | |
| 51 | os.environ["AUTH_TOKEN"] = osm.get_auth_token() |
| 52 | |
| 53 | try: |
| 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")) |
| 56 | except ResourceException as e: |
| 57 | print(e.message) |
| 58 | |
| 59 | print("VNFD: {}\nNSD: {}".format(vnfd_id, nsd_id)) |
| 60 | # Apply relevant env variables (required for test vars) |
| 61 | os.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)) |
| 67 | for 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)) |
| 79 | for d in directories: |
| 80 | run_test_suite("{}/{}".format(sol005_folder, d), d, d + ".txt") |
| 81 | |
| 82 | # We then need to clear the created resources |
| 83 | try: |
| 84 | osm.delete_nsd(nsd_id) |
| 85 | osm.delete_vnfd(vnfd_id) |
| 86 | except ResourceException as e: |
| 87 | print("Deletion failed: {}".format(e.message)) |
| 88 | |
| 89 | print("Cleared resources") |