salt/tests/kitchen/test_kitchen.py

85 lines
2.5 KiB
Python
Raw Normal View History

2017-10-12 18:17:41 +00:00
# -*- coding: utf-8 -*-
'''
Test wrapper for running all KitchenSalt tests
2017-10-30 19:16:42 +00:00
All directories in 'tests/kitchen/' will be treated as a separate test under
the KitchenTestCase.
2017-10-12 18:17:41 +00:00
'''
from __future__ import absolute_import
2017-10-12 02:40:44 +00:00
import os
from tests.support.unit import TestCase, skipIf
import setup
import salt.utils.path
from salt.modules import cmdmod as cmd
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
@skipIf(not salt.utils.path.which('bundle'), 'Bundler is not installed')
class KitchenTestCase(TestCase):
'''
Test kitchen environments
'''
@classmethod
def setUpClass(cls):
'''
setup kitchen tests
'''
cls.topdir = '/' + os.path.join(*CURRENT_DIR.split('/')[:-2])
2017-10-12 03:46:03 +00:00
cls.use_vt = int(os.environ.get('TESTS_LOG_LEVEL')) >= 5
2017-10-12 02:40:44 +00:00
cmd.run('python setup.py sdist', cwd=cls.topdir)
cmd.run('bundle install', cwd=CURRENT_DIR)
2017-10-12 03:45:09 +00:00
cls.env = {
'KITCHEN_YAML': os.path.join(CURRENT_DIR, '.kitchen.yml'),
'SALT_SDIST_PATH': os.path.join(cls.topdir, 'dist', 'salt-{0}.tar.gz'.format(setup.__version__)),
}
2017-10-12 02:40:44 +00:00
@classmethod
def tearDownClass(cls):
del cls.topdir
2017-10-12 03:45:09 +00: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-12 02:40:44 +00:00
def func_builder(testdir):
def func(self):
2017-10-12 03:45:09 +00:00
self.testdir = testdir
2017-10-12 02:40:44 +00:00
if 'TESTS_XML_OUTPUT_DIR' in os.environ:
2017-10-12 16:23:40 +00:00
self.env['TESTS_JUNIT_XML_PATH'] = '{0}/kitchen.tests.{1}.$KITCHEN_SUITE.$KITCHEN_PLATFORM.xml'.format(
2017-10-12 02:40:44 +00:00
os.environ.get('TESTS_XML_OUTPUT_DIR'),
2017-10-12 03:45:09 +00:00
self.testdir,
2017-10-12 02:40:44 +00:00
)
self.assertEqual(
cmd.retcode(
2017-10-12 03:45:09 +00:00
'bundle exec kitchen converge -c 999 all',
cwd=os.path.join(CURRENT_DIR, 'tests', self.testdir),
2017-10-12 04:22:01 +00:00
env=self.env,
2017-10-12 02:40:44 +00:00
use_vt=self.use_vt,
),
0
)
self.assertEqual(
cmd.retcode(
'bundle exec kitchen verify all',
2017-10-12 03:45:09 +00:00
cwd=os.path.join(CURRENT_DIR, 'tests', self.testdir),
2017-10-12 04:22:01 +00:00
env=self.env,
2017-10-12 02:40:44 +00:00
use_vt=self.use_vt,
),
0
)
return func
2018-12-21 00:19:01 +00:00
2017-10-12 02:40:44 +00:00
for testdir in os.listdir(os.path.join(CURRENT_DIR, 'tests')):
setattr(KitchenTestCase, 'test_kitchen_{0}'.format(testdir), func_builder(testdir))