Merge pull request #44253 from Ch3LL/spm_install

Add multiple spm integration tests
This commit is contained in:
Mike Place 2017-10-25 15:36:02 +02:00 committed by GitHub
commit bd75be24ca
6 changed files with 242 additions and 4 deletions

View file

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
'''
Tests for the spm files utility
'''
# Import python libs
from __future__ import absolute_import
import os
import shutil
# Import Salt Testing libs
from tests.support.case import SPMCase
from tests.support.helpers import destructiveTest
@destructiveTest
class SPMFilesTest(SPMCase):
'''
Validate the spm files command
'''
def setUp(self):
self.config = self._spm_config()
self._spm_build_files(self.config)
def test_spm_files(self):
'''
test spm files
'''
self._spm_create_update_repo(self.config)
install = self.run_spm('install', self.config, 'apache')
get_files = self.run_spm('files', self.config, 'apache')
os.path.exists(os.path.join(self.config['formula_path'], 'apache',
'apache.sls'))
def tearDown(self):
shutil.rmtree(self._tmp_spm)

View file

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
'''
Tests for the spm info utility
'''
# Import python libs
from __future__ import absolute_import
import shutil
# Import Salt Testing libs
from tests.support.case import SPMCase
from tests.support.helpers import destructiveTest
@destructiveTest
class SPMInfoTest(SPMCase):
'''
Validate the spm info command
'''
def setUp(self):
self.config = self._spm_config()
self._spm_build_files(self.config)
def test_spm_info(self):
'''
test spm build
'''
self._spm_create_update_repo(self.config)
install = self.run_spm('install', self.config, 'apache')
get_info = self.run_spm('info', self.config, 'apache')
check_info = ['Supported OSes', 'Supported OS', 'installing Apache']
for info in check_info:
self.assertIn(info, ''.join(get_info))
def tearDown(self):
shutil.rmtree(self._tmp_spm)

View file

@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
'''
Tests for the spm install utility
'''
# Import python libs
from __future__ import absolute_import
import os
import shutil
# Import Salt Testing libs
from tests.support.case import SPMCase
from tests.support.helpers import destructiveTest
@destructiveTest
class SPMInstallTest(SPMCase):
'''
Validate the spm install command
'''
def setUp(self):
self.config = self._spm_config()
self._spm_build_files(self.config)
def test_spm_install_local_dir(self):
'''
test spm install from local directory
'''
build_spm = self.run_spm('build', self.config, self.formula_dir)
spm_file = os.path.join(self.config['spm_build_dir'],
'apache-201506-2.spm')
install = self.run_spm('install', self.config, spm_file)
sls = os.path.join(self.config['formula_path'], 'apache', 'apache.sls')
self.assertTrue(os.path.exists(sls))
def test_spm_install_from_repo(self):
'''
test spm install from repo
'''
self._spm_create_update_repo(self.config)
install = self.run_spm('install', self.config, 'apache')
sls = os.path.join(self.config['formula_path'], 'apache', 'apache.sls')
self.assertTrue(os.path.exists(sls))
def tearDown(self):
shutil.rmtree(self._tmp_spm)

View file

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
'''
Tests for the spm repo
'''
# Import python libs
from __future__ import absolute_import
import os
import shutil
# Import Salt Testing libs
from tests.support.case import SPMCase
from tests.support.helpers import destructiveTest
@destructiveTest
class SPMRepoTest(SPMCase):
'''
Validate commands related to spm repo
'''
def setUp(self):
self.config = self._spm_config()
self._spm_build_files(self.config)
def test_spm_create_update_repo(self):
'''
test spm create_repo
'''
self._spm_create_update_repo(self.config)
self.assertTrue(os.path.exists(self.config['spm_db']))
l_repo_file = os.path.join(self.config['spm_cache_dir'], 'local_repo.p')
self.assertTrue(os.path.exists(l_repo_file))
def tearDown(self):
shutil.rmtree(self._tmp_spm)

View file

@ -130,6 +130,9 @@ TEST_SUITES = {
'returners':
{'display_name': 'Returners',
'path': 'integration/returners'},
'spm':
{'display_name': 'SPM',
'path': 'integration/spm'},
'loader':
{'display_name': 'Loader',
'path': 'integration/loader'},
@ -338,6 +341,13 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
action='store_true',
help='Run salt/returners/*.py tests'
)
self.test_selection_group.add_option(
'--spm',
dest='spm',
default=False,
action='store_true',
help='Run spm integration tests'
)
self.test_selection_group.add_option(
'-l',
'--loader',

View file

@ -22,6 +22,7 @@ import time
import stat
import errno
import signal
import textwrap
import logging
import tempfile
import subprocess
@ -564,11 +565,60 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
timeout=timeout)
class SPMTestUserInterface(object):
'''
Test user interface to SPMClient
'''
def __init__(self):
self._status = []
self._confirm = []
self._error = []
def status(self, msg):
self._status.append(msg)
def confirm(self, action):
self._confirm.append(action)
def error(self, msg):
self._error.append(msg)
class SPMCase(TestCase, AdaptedConfigurationTestCaseMixin):
'''
Class for handling spm commands
'''
def _spm_build_files(self, config):
self.formula_dir = os.path.join(' '.join(config['file_roots']['base']), 'formulas')
self.formula_sls_dir = os.path.join(self.formula_dir, 'apache')
self.formula_sls = os.path.join(self.formula_sls_dir, 'apache.sls')
self.formula_file = os.path.join(self.formula_dir, 'FORMULA')
dirs = [self.formula_dir, self.formula_sls_dir]
for f_dir in dirs:
os.makedirs(f_dir)
import salt.utils
with salt.utils.fopen(self.formula_sls, 'w') as fp:
fp.write(textwrap.dedent('''\
install-apache:
pkg.installed:
- name: apache2
'''))
with salt.utils.fopen(self.formula_file, 'w') as fp:
fp.write(textwrap.dedent('''\
name: apache
os: RedHat, Debian, Ubuntu, Suse, FreeBSD
os_family: RedHat, Debian, Suse, FreeBSD
version: 201506
release: 2
summary: Formula for installing Apache
description: Formula for installing Apache
'''))
def _spm_config(self):
self._tmp_spm = tempfile.mkdtemp()
config = self.get_temp_config('minion', **{
@ -595,16 +645,36 @@ class SPMCase(TestCase, AdaptedConfigurationTestCaseMixin):
})
return config
def _spm_create_update_repo(self, config):
build_spm = self.run_spm('build', self.config, self.formula_dir)
c_repo = self.run_spm('create_repo', self.config,
self.config['spm_build_dir'])
repo_conf_dir = self.config['spm_repos_config'] + '.d'
os.makedirs(repo_conf_dir)
import salt.utils
with salt.utils.fopen(os.path.join(repo_conf_dir, 'spm.repo'), 'w') as fp:
fp.write(textwrap.dedent('''\
local_repo:
url: file://{0}
'''.format(self.config['spm_build_dir'])))
u_repo = self.run_spm('update_repo', self.config)
def _spm_client(self, config):
import salt.spm
ui = salt.spm.SPMCmdlineInterface()
client = salt.spm.SPMClient(ui, config)
self.ui = SPMTestUserInterface()
client = salt.spm.SPMClient(self.ui, config)
return client
def run_spm(self, cmd, config, arg=()):
def run_spm(self, cmd, config, arg=None):
client = self._spm_client(config)
spm_cmd = client.run([cmd, arg])
return spm_cmd
return self.ui._status
class ModuleCase(TestCase, SaltClientTestCaseMixin):