Skip to content

Commit

Permalink
bugfix: use kubeconfig fixture to get config for clusterinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniszewski committed Dec 17, 2019
1 parent 4f6bf26 commit f3a6666
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kubetest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def __init__(self, current, config):


@pytest.fixture
def clusterinfo(request):
def clusterinfo(kubeconfig):
"""Get a ``ClusterInfo`` instance which provides basic information
about the cluster the tests are being run on.
"""
Expand All @@ -398,7 +398,7 @@ def clusterinfo(request):
# Get the current context.
_, current = kubernetes.config.list_kube_config_contexts(
os.path.expandvars(os.path.expanduser(
request.session.config.getoption('kube_config')
kubeconfig,
))
)

Expand Down
13 changes: 13 additions & 0 deletions regression/156-bl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

https://github.com/vapor-ware/kubetest/issues/156

### Summary

This is a baseline (bl) test case for issue #156. It verifies that the `clusterinfo` fixture
will use the value specified by the `--kube-config` command line arg when specified. See
[regression/156](../156) for more details.

#### Expectations

When run with a command-line defined kubeconfig, a test using the `clusterinfo` fixture should
resolve the cluster info using the kubeconfig specified by the command line flag.
5 changes: 5 additions & 0 deletions regression/156-bl/test_156.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


def test_156_baseline(kube, clusterinfo):
kube.wait_for_ready_nodes(1, timeout=3 * 60)
print(f'cluster info: {vars(clusterinfo)}')
13 changes: 13 additions & 0 deletions regression/156/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

https://github.com/vapor-ware/kubetest/issues/156

### Summary

When the kubeconfig is provided by a pytest fixture and not via the `--kube-config` command line
flag, the `clusterinfo` fixture will fail, since it uses the kubeconfig value specified by the
command line flag and does not account for custom fixture.

#### Expectations

When run with a fixture-defined kubeconfig, a test using the `clusterinfo` fixture should
resolve the cluster info using the kubeconfig provided by the custom fixture.
12 changes: 12 additions & 0 deletions regression/156/test_156.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import pytest


@pytest.fixture
def kubeconfig(request):
return '~/.kube/config'


def test_156(kube, clusterinfo):
kube.wait_for_ready_nodes(1, timeout=3 * 60)
print(f'cluster info: {vars(clusterinfo)}')

0 comments on commit f3a6666

Please sign in to comment.