Skip to content

Commit

Permalink
Test the cluster version matches configuration
Browse files Browse the repository at this point in the history
We introduce a test to verify the running Kubernetes version against our
list of versions from the buildchain.

Note: we create a symlink, under `tests/versions.py`, pointing to
`buildchain/buildchain/versions.py`, for ease of importation within
tests.

Issue: #640
  • Loading branch information
gdemonet committed Jul 29, 2019
1 parent 783254d commit f12d780
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def k8s_client(request, k8s_apiclient):
def test_something(k8s_client):
assert k8s_client.list_namespaced_deployment(namespace="default")
```
FIXME: this is not working as of right now, since `pytest-bdd` manipulates
fixtures in its own way through the various scenario/when/then/given
decorators.
"""
api_name = getattr(request, "param", "CoreV1Api")
api_cls = getattr(kubernetes.client, api_name, None)
Expand Down
5 changes: 5 additions & 0 deletions tests/post/features/versions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@post @ci @local
Feature: Check versions in the running cluster
Scenario: Check the cluster's Kubernetes version
Given the Kubernetes API is available
Then the Kubernetes version deployed is the same as the configured one
26 changes: 26 additions & 0 deletions tests/post/steps/test_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from kubernetes.client import VersionApi
from pytest_bdd import scenario, then

from tests import versions


# Scenarios
@scenario('../features/versions.feature',
"Check the cluster's Kubernetes version")
def test_cluster_version(host):
pass


# Then
@then('the Kubernetes version deployed is the same as the configured one')
def check_kubernetes_version(k8s_apiclient):
# NOTE: the `vX.Y.Z` format is used by Kubernetes, not our buildchain
configured_version = 'v{}'.format(versions.K8S_VERSION)

k8s_client = VersionApi(api_client=k8s_apiclient)
observed_version = k8s_client.get_code().git_version

assert configured_version == observed_version, (
"The running version of Kubernetes is '{}', while the expected version"
"is '{}'.".format(observed_version, configured_version)
)
1 change: 1 addition & 0 deletions tests/versions.py

0 comments on commit f12d780

Please sign in to comment.