aboutsummaryrefslogtreecommitdiffstats
path: root/ice_validator/app_tests/preload_tests/test_environment.py
diff options
context:
space:
mode:
authorLovett, Trevor <trevor.lovett@att.com>2019-08-27 12:40:36 -0500
committerLovett, Trevor (tl2972) <tl2972@att.com>2019-08-27 16:02:47 -0500
commit84db7f8f65cd0ec77f09cfde365599df9890ce6c (patch)
treeeadedec4cb5f0db131442a6e594a5b8c61ee50cf /ice_validator/app_tests/preload_tests/test_environment.py
parentb1df832ae5ddaac6344b7ccf3f1f32a0bcfbdd67 (diff)
[VVP] Generated completed preload from env files
User can supply an optional directory containing .env files and/or CSAR VSP which can be used to generate populated preloads in the requested format. The nested directories can be used to create sub-environments that inherit their settings from the parent directories. Optionally, values can be specified in a defaults.yaml and they will be used if that value is not defined in the .env file. This is useful if the parameter name and value will be the same in all modules. Issue-ID: VVP-278 Change-Id: Icd9846c63463537793db908be8ce5dba13c4bda3 Signed-off-by: Lovett, Trevor <trevor.lovett@att.com>
Diffstat (limited to 'ice_validator/app_tests/preload_tests/test_environment.py')
-rw-r--r--ice_validator/app_tests/preload_tests/test_environment.py180
1 files changed, 180 insertions, 0 deletions
diff --git a/ice_validator/app_tests/preload_tests/test_environment.py b/ice_validator/app_tests/preload_tests/test_environment.py
new file mode 100644
index 0000000..b627b4b
--- /dev/null
+++ b/ice_validator/app_tests/preload_tests/test_environment.py
@@ -0,0 +1,180 @@
+# -*- coding: utf8 -*-
+# ============LICENSE_START====================================================
+# org.onap.vvp/validation-scripts
+# ===================================================================
+# Copyright © 2019 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the "License");
+# you may not use this software except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ============LICENSE_END============================================
+from pathlib import Path
+
+import pytest
+
+from preload.environment import CloudServiceArchive, PreloadEnvironment
+
+THIS_DIR = Path(__file__).parent
+PRELOAD_ENV_DIR = THIS_DIR / "preload_envs"
+
+
+@pytest.fixture(scope="session")
+def csar():
+ return CloudServiceArchive(PRELOAD_ENV_DIR / "test.csar")
+
+
+@pytest.fixture(scope="session")
+def env():
+ return PreloadEnvironment(PRELOAD_ENV_DIR)
+
+
+def test_csar_service_name(csar):
+ assert csar.service_name == "stark_vccf_svc"
+
+
+def test_csar_str_and_repr(csar):
+ assert str(csar) == "CSAR (path=test.csar, name=stark_vccf_svc)"
+ assert repr(csar) == "CSAR (path=test.csar, name=stark_vccf_svc)"
+
+
+def test_csar_vf_module_model_name(csar):
+ assert (
+ csar.get_vf_module_model_name("base_vIECCF")
+ == "StarkVccfVf..base_vIECCF..module-0"
+ )
+
+
+def test_csar_get_vf_module_resource_name(csar):
+ assert csar.get_vf_module_resource_name("base_vIECCF") == "stark_vccf_vf"
+
+
+def test_csar_get_vf_module_resource_name_not_found(csar):
+ assert csar.get_vf_module_resource_name("unknown") is None
+
+
+def test_preload_environment_global_csar(env):
+ assert env.csar.service_name == "stark_vccf_svc"
+
+
+def test_preload_environment_nest_env_csar_inherit(env):
+ env_two = env.get_environment("env_two")
+ assert env_two.csar.service_name == "stark_vccf_svc"
+
+
+def test_preload_environment_nest_env_csar_override(env):
+ sub_env = env.get_environment("env_three")
+ assert sub_env.csar.service_name == "StarkMultiModule2_43550"
+
+
+def test_preload_environment_environments(env):
+ names = {e.name for e in env.environments}
+ assert names == {"env_two", "env_three", "env_one_a"}
+
+
+def test_preload_environment_environments_nested(env):
+ env_one = env.get_environment("env_one")
+ names = {e.name for e in env_one.environments}
+ assert names == {"env_one_a"}
+
+
+def test_preload_environment_get_module_global_base(env):
+ module = env.get_module("base")
+ assert module["my_ip"] == "default"
+
+
+def test_preload_environment_get_module_global_not_found(env):
+ module = env.get_module("unknown")
+ assert module == {}
+
+
+def test_preload_environment_get_module_sub_env(env):
+ env_two = env.get_environment("env_two")
+ module = env_two.get_module("base")
+ assert module["my_ip"] == "192.168.0.2"
+ assert module["common"] == "ABC"
+
+
+def test_preload_environment_module_names(env):
+ expected = {"base.env", "incremental.env"}
+ assert env.module_names == expected
+ # check a nested env with inherits all modules
+ assert env.get_environment("env_three").module_names == expected
+
+
+def test_preload_environment_modules(env):
+ modules = env.modules
+ assert isinstance(modules, dict)
+ assert modules.keys() == {"base.env", "incremental.env"}
+ assert all(isinstance(val, dict) for val in modules.values())
+
+
+def test_preload_environment_is_base(env):
+ assert env.is_base
+ assert not env.get_environment("env_one").is_base
+
+
+def test_preload_environment_is_leaf(env):
+ assert not env.is_leaf
+ assert env.get_environment("env_two").is_leaf
+ assert not env.get_environment("env_one").is_leaf
+ assert env.get_environment("env_one_a").is_leaf
+
+
+def test_preload_environment_str_repr(env):
+ assert str(env) == "PreloadEnvironment(name=preload_envs)"
+ assert repr(env) == "PreloadEnvironment(name=preload_envs)"
+
+
+def test_preload_environment_defaults(env):
+ expected = {"availability_zone_0": "az0"}
+ assert env.defaults == expected
+ assert env.get_environment("env_one_a").defaults == expected
+
+
+def test_preload_environment_defaults_merging_and_override(env):
+ assert env.get_environment("env_three").defaults == {
+ "availability_zone_0": "az0-b",
+ "custom_env_3": "default",
+ }
+
+
+def test_preload_environment_defaults_in_module_env(env):
+ mod = env.get_environment("env_three").get_module("base")
+ assert mod == {
+ "availability_zone_0": "az0-b",
+ "common": "ABC",
+ "custom_env_3": "default",
+ "my_ip": "default",
+ }
+ mod = env.get_environment("env_one").get_module("base")
+ assert mod == {
+ "availability_zone_0": "az0",
+ "common": "ABC",
+ "my_ip": "192.168.0.1",
+ }