Skip to content

Commit

Permalink
test: refactor csc tests to handle empty csc ConfigMaps
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ebaneck committed May 5, 2020
1 parent 11b59f6 commit 05721b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/post/features/service_configuration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
32 changes: 18 additions & 14 deletions tests/post/steps/test_service_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {{{


Expand Down Expand Up @@ -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)

Expand All @@ -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)


Expand All @@ -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
)
}
}
Expand Down

0 comments on commit 05721b0

Please sign in to comment.