2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
8 # Unless otherwise specified, all software contained herein is licensed
9 # under the Apache License, Version 2.0 (the "License");
10 # you may not use this software except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
23 # Unless otherwise specified, all documentation contained herein is licensed
24 # under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 # you may not use this documentation except in compliance with the License.
26 # You may obtain a copy of the License at
28 # https://creativecommons.org/licenses/by/4.0/
30 # Unless required by applicable law or agreed to in writing, documentation
31 # distributed under the License is distributed on an "AS IS" BASIS,
32 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 # See the License for the specific language governing permissions and
34 # limitations under the License.
36 # ============LICENSE_END============================================
38 from pathlib import Path
39 from shutil import rmtree
43 from app_tests.preload_tests.test_grapi import load_json
44 from preload.environment import PreloadEnvironment
45 from preload.model import Vnf, get_heat_templates
46 from preload_vnfapi import VnfApiPreloadGenerator
47 from tests.helpers import load_yaml, first
49 THIS_DIR = Path(__file__).parent
50 SAMPLE_HEAT_DIR = THIS_DIR / "sample_heat"
53 def load_module(base_dir, name):
54 path = Path(str(base_dir / "vnfapi" / name))
55 assert path.exists(), "{} does not exist".format(path)
56 return load_yaml(str(path))
59 @pytest.fixture(scope="session")
60 def session_dir(request):
61 # Temporary directory that gets deleted at the session
62 # pytest tmpdir doesn't support a non-function scoped temporary directory
63 session_dir = Path(tempfile.mkdtemp())
64 request.addfinalizer(lambda: rmtree(session_dir))
68 @pytest.fixture(scope="session")
69 def preload(pytestconfig, session_dir):
70 # Generate the preloads for testing
71 def fake_getoption(opt, default=None):
72 return [SAMPLE_HEAT_DIR.as_posix()] if opt == "template_dir" else None
74 pytestconfig.getoption = fake_getoption
75 templates = get_heat_templates(pytestconfig)
77 preload_env = PreloadEnvironment(THIS_DIR / "sample_env")
78 generator = VnfApiPreloadGenerator(vnf, session_dir, preload_env)
83 @pytest.fixture(scope="session")
85 return load_module(preload, "base_incomplete.json")
88 @pytest.fixture(scope="session")
89 def incremental(preload):
90 return load_module(preload, "incremental_incomplete.json")
93 def test_base_azs(base):
94 az = base["input"]["vnf-topology-information"]["vnf-assignments"][
98 {"availability-zone": "VALUE FOR: availability_zone_0"},
99 {"availability-zone": "VALUE FOR: availability_zone_1"},
103 def test_base_networks(base):
104 nets = base["input"]["vnf-topology-information"]["vnf-assignments"]["vnf-networks"]
107 "network-role": "oam",
108 "network-name": "VALUE FOR: network name for oam_net_id",
109 "subnet-id": "oam_subnet_id",
111 {"network-role": "ha", "network-name": "VALUE FOR: network name for ha_net_id"},
113 "network-role": "ctrl",
114 "network-name": "VALUE FOR: network name for ctrl_net_id",
115 "subnet-id": "ctrl_subnet_id",
120 def test_base_vm_types(base):
121 vms = base["input"]["vnf-topology-information"]["vnf-assignments"]["vnf-vms"]
122 vm_types = {vm["vm-type"] for vm in vms}
123 assert vm_types == {"db", "svc", "mgmt", "lb"}
124 db = first(vms, lambda v: v["vm-type"] == "db")
128 "vm-names": {"vm-name": ["VALUE FOR: db_name_0", "VALUE FOR: db_name_1"]},
131 "network-role": "oam",
132 "network-role-tag": "oam",
136 "floating-ip-v6": "",
138 {"ip-address": "VALUE FOR: db_oam_ip_0"},
139 {"ip-address": "VALUE FOR: db_oam_ip_1"},
141 "network-ips-v6": [],
143 "interface-route-prefixes": [],
147 "network-role": "ha",
148 "network-role-tag": "ha",
151 "floating-ip": "VALUE FOR: db_ha_floating_ip",
152 "floating-ip-v6": "VALUE FOR: db_ha_floating_v6_ip",
154 "network-ips-v6": [],
156 "interface-route-prefixes": [],
163 def test_base_parameters(base):
164 params = base["input"]["vnf-topology-information"]["vnf-parameters"]
167 "vnf-parameter-name": "db_vol0_id",
168 "vnf-parameter-value": "VALUE FOR: db_vol0_id",
171 "vnf-parameter-name": "db_vol1_id",
172 "vnf-parameter-value": "VALUE FOR: db_vol1_id",
177 def test_incremental(incremental):
178 az = incremental["input"]["vnf-topology-information"]["vnf-assignments"][
181 assert isinstance(az, list)
183 assert az[0] == {"availability-zone": "VALUE FOR: availability_zone_0"}
186 def test_incremental_networks(incremental):
187 nets = incremental["input"]["vnf-topology-information"]["vnf-assignments"][
190 assert isinstance(nets, list)
191 assert len(nets) == 1
192 assert nets[0]["network-role"] == "ha"
195 def test_preload_env_population(preload):
196 base_path = THIS_DIR / "sample_env/preloads/vnfapi/base_incomplete.json"
197 data = load_json(base_path)
198 azs = data["input"]["vnf-topology-information"]["vnf-assignments"][
201 assert azs == [{"availability-zone": "az0"}, {"availability-zone": "az1"}]