Browse Source

Refactor fixtures that check required files and settings

Refactor those fixtures in a more general way, so they can be used in
any test, not only netchecker one.
Just set class variables required_files and required_settings to use them
In that way all required files and settings will be in the test class, and not
in the fixture itself.

Change-Id: I27eb98e46978205f4a4e9769e368d4720e2f8b55
Volodymyr Shypyguzov 2 years ago
parent
commit
493dc8b27a

+ 10
- 17
fuel_ccp_tests/fixtures/k8s_fixtures.py View File

@@ -85,28 +85,21 @@ def k8scluster(revert_snapshot, request, config,
85 85
 
86 86
 
87 87
 @pytest.fixture(scope='class')
88
-def check_netchecker_files(request):
89
-    files_missing = []
90
-    for arg in request.cls.netchecker_files:
91
-        if not os.path.isfile(arg):
92
-            files_missing.append(arg)
88
+def check_files_missing(request):
89
+    LOG.info("Required files: {}".format(request.cls.required_files))
90
+    files_missing = [f for f in request.cls.required_files
91
+                     if not os.path.isfile(f)]
93 92
     assert len(files_missing) == 0, \
94
-        ("The following netchecker files not found: "
95
-         "{0}!".format(', '.join(files_missing)))
93
+        "Following files are not found {0}".format(files_missing)
96 94
 
97 95
 
98 96
 @pytest.fixture(scope='class')
99
-def check_netchecker_images_settings():
100
-    settings_missing = []
101
-    for setting in ('MCP_NETCHECKER_AGENT_IMAGE_REPO',
102
-                    'MCP_NETCHECKER_AGENT_VERSION',
103
-                    'MCP_NETCHECKER_SERVER_IMAGE_REPO',
104
-                    'MCP_NETCHECKER_SERVER_VERSION'):
105
-        if not getattr(settings, setting, None):
106
-            settings_missing.append(setting)
97
+def check_settings_missing(request):
98
+    LOG.info("Required settings: {}".format(request.cls.required_settings))
99
+    settings_missing = [s for s in request.cls.required_settings
100
+                        if not getattr(settings, s, None)]
107 101
     assert len(settings_missing) == 0, \
108
-        ("The following environment variables are not set: "
109
-         "{0}!".format(', '.join(settings_missing)))
102
+        "Following env variables are not set {}". format(settings_missing)
110 103
 
111 104
 
112 105
 @pytest.fixture(scope='class')

+ 7
- 3
fuel_ccp_tests/tests/system/test_netchecker.py View File

@@ -27,6 +27,11 @@ LOG = logger.logger
27 27
 
28 28
 class TestFuelCCPNetCheckerMixin:
29 29
 
30
+    required_settings = ('MCP_NETCHECKER_AGENT_IMAGE_REPO',
31
+                         'MCP_NETCHECKER_AGENT_VERSION',
32
+                         'MCP_NETCHECKER_SERVER_IMAGE_REPO',
33
+                         'MCP_NETCHECKER_SERVER_VERSION')
34
+
30 35
     kube_settings = settings.DEFAULT_CUSTOM_YAML
31 36
     kube_settings['deploy_netchecker'] = False
32 37
 
@@ -38,7 +43,7 @@ class TestFuelCCPNetCheckerMixin:
38 43
         'k8s_resources/netchecker-server_svc.yaml')
39 44
     ds_yaml_file = os.path.join(
40 45
         settings.NETCHECKER_AGENT_DIR, 'netchecker-agent.yaml')
41
-    netchecker_files = (pod_yaml_file, svc_yaml_file, ds_yaml_file)
46
+    required_files = (pod_yaml_file, svc_yaml_file, ds_yaml_file)
42 47
 
43 48
     @property
44 49
     def pod_spec(self):
@@ -62,8 +67,7 @@ class TestFuelCCPNetCheckerMixin:
62 67
             return [i for i in yaml.load_all(ds_conf)]
63 68
 
64 69
 
65
-@pytest.mark.usefixtures("check_netchecker_files")
66
-@pytest.mark.usefixtures("check_netchecker_images_settings")
70
+@pytest.mark.usefixtures("check_files_missing", "check_settings_missing")
67 71
 class TestFuelCCPNetChecker(base_test.SystemBaseTest,
68 72
                             TestFuelCCPNetCheckerMixin):
69 73
     """Test class for network connectivity verification in k8s"""

Loading…
Cancel
Save