salt/tests/kitchen/test_kitchen.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.6 KiB
Python
Raw Normal View History

2020-04-02 20:10:20 -05:00
"""
2017-10-12 12:17:41 -06:00
Test wrapper for running all KitchenSalt tests
2017-10-30 13:16:42 -06:00
All directories in 'tests/kitchen/' will be treated as a separate test under
the KitchenTestCase.
2020-04-02 20:10:20 -05:00
"""
2017-10-11 20:40:44 -06:00
import os
import setup
from salt.modules import cmdmod as cmd
from tests.support.unit import TestCase
import pytest
2017-10-11 20:40:44 -06:00
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
@pytest.mark.skip_if_binaries_missing("bundle")
2017-10-11 20:40:44 -06:00
class KitchenTestCase(TestCase):
2020-04-02 20:10:20 -05:00
"""
2017-10-11 20:40:44 -06:00
Test kitchen environments
2020-04-02 20:10:20 -05:00
"""
2017-10-11 20:40:44 -06:00
@classmethod
def setUpClass(cls):
2020-04-02 20:10:20 -05:00
"""
2017-10-11 20:40:44 -06:00
setup kitchen tests
2020-04-02 20:10:20 -05:00
"""
2017-10-11 20:40:44 -06:00
cls.topdir = "/" + os.path.join(*CURRENT_DIR.split("/")[:-2])
2017-10-11 21:46:03 -06:00
cls.use_vt = int(os.environ.get("TESTS_LOG_LEVEL")) >= 5
2017-10-11 20:40:44 -06:00
cmd.run("python setup.py sdist", cwd=cls.topdir)
# TBD cmd.run("python -m pip install --upgrade build") # add build when implement pyproject.toml
# TBD cmd.run("python -m build --sdist {}".format(cls.topdir)) # replace with build when implement pyproject.toml
2017-10-11 20:40:44 -06:00
cmd.run("bundle install", cwd=CURRENT_DIR)
2017-10-11 21:45:09 -06:00
cls.env = {
"KITCHEN_YAML": os.path.join(CURRENT_DIR, ".kitchen.yml"),
"SALT_SDIST_PATH": os.path.join(
2021-04-01 16:29:01 -07:00
cls.topdir, "dist", "salt-{}.tar.gz".format(setup.__version__)
2017-10-11 21:45:09 -06:00
),
}
2017-10-11 20:40:44 -06:00
@classmethod
def tearDownClass(cls):
del cls.topdir
2017-10-11 21:45:09 -06:00
del cls.env
def tearDown(self):
cmd.run(
"bundle exec kitchen destroy all",
cwd=os.path.join(CURRENT_DIR, "tests", self.testdir),
env=self.env,
use_vt=self.use_vt,
)
del self.testdir
2017-10-11 20:40:44 -06:00
def func_builder(testdir):
def func(self):
2017-10-11 21:45:09 -06:00
self.testdir = testdir
2017-10-11 20:40:44 -06:00
if "TESTS_XML_OUTPUT_DIR" in os.environ:
2017-10-12 10:23:40 -06:00
self.env[
"TESTS_JUNIT_XML_PATH"
2021-04-01 16:29:01 -07:00
] = "{}/kitchen.tests.{}.$KITCHEN_SUITE.$KITCHEN_PLATFORM.xml".format(
2017-10-11 20:40:44 -06:00
os.environ.get("TESTS_XML_OUTPUT_DIR"), self.testdir,
)
self.assertEqual(
cmd.retcode(
2017-10-11 21:45:09 -06:00
"bundle exec kitchen converge -c 999 all",
cwd=os.path.join(CURRENT_DIR, "tests", self.testdir),
2017-10-11 22:22:01 -06:00
env=self.env,
2017-10-11 20:40:44 -06:00
use_vt=self.use_vt,
),
0,
)
self.assertEqual(
cmd.retcode(
"bundle exec kitchen verify all",
2017-10-11 21:45:09 -06:00
cwd=os.path.join(CURRENT_DIR, "tests", self.testdir),
2017-10-11 22:22:01 -06:00
env=self.env,
2017-10-11 20:40:44 -06:00
use_vt=self.use_vt,
),
0,
)
2020-04-02 20:10:20 -05:00
2017-10-11 20:40:44 -06:00
return func
2018-12-20 16:19:01 -08:00
2017-10-11 20:40:44 -06:00
for testdir in os.listdir(os.path.join(CURRENT_DIR, "tests")):
2021-04-01 16:29:01 -07:00
setattr(KitchenTestCase, "test_kitchen_{}".format(testdir), func_builder(testdir))