mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Add spm build test
This commit is contained in:
parent
88a776d9d2
commit
1541376c4f
1
tests/integration/spm/__init__.py
Normal file
1
tests/integration/spm/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
65
tests/integration/spm/test_build.py
Normal file
65
tests/integration/spm/test_build.py
Normal file
@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Tests for the spm build utility
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
import shutil
|
||||
import textwrap
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.case import SPMCase
|
||||
from tests.support.helpers import destructiveTest
|
||||
|
||||
# Import Salt Libraries
|
||||
import salt.utils
|
||||
|
||||
|
||||
@destructiveTest
|
||||
class SPMBuildTest(SPMCase):
|
||||
'''
|
||||
Validate the spm build command
|
||||
'''
|
||||
def setUp(self):
|
||||
self.config = self._spm_config()
|
||||
self.formula_dir = os.path.join(' '.join(self.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 formula_dir in dirs:
|
||||
os.makedirs(formula_dir)
|
||||
|
||||
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 test_spm_build(self):
|
||||
'''
|
||||
test spm build
|
||||
'''
|
||||
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')
|
||||
# Make sure .spm file gets created
|
||||
self.assertTrue(os.path.exists(spm_file))
|
||||
# Make sure formula path dir is created
|
||||
self.assertTrue(os.path.isdir(self.config['formula_path']))
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self._tmp_spm)
|
@ -564,6 +564,49 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
|
||||
timeout=timeout)
|
||||
|
||||
|
||||
class SPMCase(TestCase, AdaptedConfigurationTestCaseMixin):
|
||||
'''
|
||||
Class for handling spm commands
|
||||
'''
|
||||
|
||||
def _spm_config(self):
|
||||
self._tmp_spm = tempfile.mkdtemp()
|
||||
config = self.get_temp_config('minion', **{
|
||||
'spm_logfile': os.path.join(self._tmp_spm, 'log'),
|
||||
'spm_repos_config': os.path.join(self._tmp_spm, 'etc', 'spm.repos'),
|
||||
'spm_cache_dir': os.path.join(self._tmp_spm, 'cache'),
|
||||
'spm_build_dir': os.path.join(self._tmp_spm, 'build'),
|
||||
'spm_build_exclude': ['.git'],
|
||||
'spm_db_provider': 'sqlite3',
|
||||
'spm_files_provider': 'local',
|
||||
'spm_db': os.path.join(self._tmp_spm, 'packages.db'),
|
||||
'extension_modules': os.path.join(self._tmp_spm, 'modules'),
|
||||
'file_roots': {'base': [self._tmp_spm, ]},
|
||||
'formula_path': os.path.join(self._tmp_spm, 'spm'),
|
||||
'pillar_path': os.path.join(self._tmp_spm, 'pillar'),
|
||||
'reactor_path': os.path.join(self._tmp_spm, 'reactor'),
|
||||
'assume_yes': True,
|
||||
'force': False,
|
||||
'verbose': False,
|
||||
'cache': 'localfs',
|
||||
'cachedir': os.path.join(self._tmp_spm, 'cache'),
|
||||
'spm_repo_dups': 'ignore',
|
||||
'spm_share_dir': os.path.join(self._tmp_spm, 'share'),
|
||||
})
|
||||
return config
|
||||
|
||||
def _spm_client(self, config):
|
||||
import salt.spm
|
||||
ui = salt.spm.SPMCmdlineInterface()
|
||||
client = salt.spm.SPMClient(ui, config)
|
||||
return client
|
||||
|
||||
def run_spm(self, cmd, config, arg=(), minion_tgt='minion'):
|
||||
client = self._spm_client(config)
|
||||
spm_cmd = client.run([cmd, arg])
|
||||
return spm_cmd
|
||||
|
||||
|
||||
class ModuleCase(TestCase, SaltClientTestCaseMixin):
|
||||
'''
|
||||
Execute a module function
|
||||
|
Loading…
Reference in New Issue
Block a user