-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
import pytest | ||
import testinfra.utils.ansible_runner | ||
|
||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | ||
os.environ["MOLECULE_INVENTORY_FILE"] | ||
).get_hosts("all") | ||
|
||
def test_cloudinit_feature_flags(host): | ||
""" | ||
ubuntu 18.04: does not need the feature flag | ||
all other except flatcar: expect feature overrides | ||
""" | ||
distro = host.system_info.distribution | ||
release = host.system_info.release | ||
|
||
# for flatcar we can skip | ||
if distro == "flatcar": | ||
pytest.skip("no changes on flatcar") | ||
|
||
# if cloud-init is lower than 20.0 we can skip | ||
cloud_init_version = host.run("cloud-init --version") | ||
assert cloud_init_version.succeeded | ||
|
||
cloud_init_version_str = cloud_init_version.stdout.strip('\n') | ||
if not cloud_init_version_str: | ||
cloud_init_version_str = cloud_init_version.stderr.strip('\n') | ||
|
||
assert cloud_init_version_str | ||
|
||
cloud_init_version_str_version_part = cloud_init_version_str.split(" ")[-1] | ||
major_version = cloud_init_version_str_version_part.split(".")[0] | ||
|
||
if int(major_version) < 20: | ||
pytest.skip("cloud-init major version ({}) below 20".format(major_version)) | ||
|
||
if distro != "ubuntu": | ||
cmd = host.run("python3 -c \"import sysconfig; print(sysconfig.get_path('purelib'))\"") | ||
assert cmd.succeeded | ||
|
||
featurefile = host.file("{}/cloudinit/feature_overrides.py".format(cmd.stdout.strip('\n'))) | ||
assert featurefile.exists | ||
assert b'ERROR_ON_USER_DATA_FAILURE = False' in featurefile.content | ||
# ubuntu 18.04 still supported and no need for this feature flag | ||
elif distro == "ubuntu" and not release == "18.04": | ||
featurefile = host.file("/usr/lib/python3/dist-packages/cloudinit/feature_overrides.py") | ||
assert featurefile.exists | ||
assert b'ERROR_ON_USER_DATA_FAILURE = False' in featurefile.content | ||
else: | ||
assert True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
import pytest | ||
import testinfra.utils.ansible_runner | ||
|
||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | ||
os.environ["MOLECULE_INVENTORY_FILE"] | ||
).get_hosts("all") | ||
|
||
def test_kubelet_kubectl_installed(host): | ||
""" | ||
we expect kubectl and kubelet package to be installed | ||
flatcar: skip no packages | ||
""" | ||
distro = host.system_info.distribution | ||
if distro == "flatcar": | ||
pytest.skip("no packages on flatcar") | ||
|
||
assert host.package("kubectl").is_installed | ||
assert host.package("kubelet").is_installed | ||
|
||
def test_kubeadm_installed(host): | ||
""" | ||
we expect kubeadm package to be installed | ||
flatcar: skip no packages | ||
""" | ||
distro = host.system_info.distribution | ||
if distro == "flatcar": | ||
pytest.skip("no packages on flatcar") | ||
|
||
assert host.package("kubeadm").is_installed | ||
|
||
def test_kube_cmd_path(host): | ||
""" | ||
kubelet, kubeadm and kubectl must be in path | ||
""" | ||
distro = host.system_info.distribution | ||
if distro == "flatcar": | ||
pytest.skip("flatcar uses different PATH for non-interactive") | ||
|
||
assert host.exists("kubelet") | ||
assert host.exists("kubeadm") | ||
assert host.exists("kubectl") | ||
|
||
def test_kube_cmd_path_flatcar(host): | ||
distro = host.system_info.distribution | ||
if distro != "flatcar": | ||
pytest.skip("flatcar uses different PATH for non-interactive") | ||
# the path is only set on interactive shell. SO lets append it here | ||
cmd = host.run("bash -c 'PATH=$PATH:/opt/bin type kubectl'") | ||
assert cmd.succeeded is True | ||
cmd = host.run("bash -c 'PATH=$PATH:/opt/bin type kubelet'") | ||
assert cmd.succeeded is True | ||
cmd = host.run("bash -c 'PATH=$PATH:/opt/bin type kubeadm'") | ||
assert cmd.succeeded is True |