From 05721b00080de17b53b0ce68fd3044ad2a4bf0cd Mon Sep 17 00:00:00 2001 From: Claude Ebaneck Date: Tue, 5 May 2020 00:10:41 +0200 Subject: [PATCH] test: refactor csc tests to handle empty csc ConfigMaps Initially, we expect default CSC ConfigMaps to contain default values and so we read these default values e.g `replicas` to perform csc persistence tests But with our new approach, default CSC ConfigMaps are deployed without default service values, so we need to adapt the test accordingly --- .../features/service_configuration.feature | 2 +- .../post/steps/test_service_configuration.py | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/post/features/service_configuration.feature b/tests/post/features/service_configuration.feature index c5928daf5e..fdb24decac 100644 --- a/tests/post/features/service_configuration.feature +++ b/tests/post/features/service_configuration.feature @@ -4,7 +4,7 @@ Feature: Cluster and Services Configurations Given the Kubernetes API is available And pods with label 'app.kubernetes.io/name=dex' are 'Ready' And we have 2 running pod labeled 'app.kubernetes.io/name=dex' in namespace 'metalk8s-auth' - And we have a 'metalk8s-dex-config' CSC in namespace 'metalk8s-auth' with 'spec.deployment.replicas' equal to '2' + And we have a 'metalk8s-dex-config' CSC in namespace 'metalk8s-auth' When we update 'metalk8s-dex-config' CSC in namespace 'metalk8s-auth' 'spec.deployment.replicas' to '3' And we apply the 'metalk8s.addons.dex.deployed' salt state Then we have '3' at 'status.available_replicas' for 'dex' Deployment in namespace 'metalk8s-auth' diff --git a/tests/post/steps/test_service_configuration.py b/tests/post/steps/test_service_configuration.py index aaf6080d67..72c9f2b21c 100644 --- a/tests/post/steps/test_service_configuration.py +++ b/tests/post/steps/test_service_configuration.py @@ -11,6 +11,20 @@ from tests import utils +# Constants {{{ + + +DEFAULT_CSC_CONFIG_YAML = """ +apiVersion: addons.metalk8s.scality.com +kind: DexConfig +spec: + deployment: + replicas: {replicas} +""" + + +# }}} + # Fixtures {{{ @@ -42,15 +56,12 @@ def test_service_config_propagation(host): @given(parsers.parse( - "we have a '{name}' CSC in namespace '{namespace}' with " - "'{path}' equal to '{value}'")) + "we have a '{name}' CSC in namespace '{namespace}'")) def check_csc_configuration( k8s_client, csc, name, namespace, - path, - value ): csc_response = csc.get(name, namespace) @@ -61,12 +72,6 @@ def check_csc_configuration( ) csc_obj = csc.load(csc_response, name, namespace) - response_value = utils.get_dict_element(csc_obj, path) - - assert literal_eval(value) == response_value, ( - "Expected value {} for key {} in ConfigMap {} found in namespace {}, " - "got {}".format(value, path, name, namespace, response_value) - ) return dict(csc_obj=csc_obj) @@ -88,14 +93,13 @@ def update_service_configuration( value ): - full_csc = csc.get(name, namespace) - csc_obj = utils.set_dict_element( - csc.load(full_csc, name, namespace), path, literal_eval(value) + csc_from_yaml = yaml.safe_load( + DEFAULT_CSC_CONFIG_YAML.format(replicas=value) ) patch = { 'data': { 'config.yaml': yaml.safe_dump( - csc_obj, default_flow_style=False + csc_from_yaml, default_flow_style=False ) } }