salt/tests/integration/spm/test_build.py

87 lines
2.9 KiB
Python
Raw Normal View History

2017-10-18 21:15:42 +00:00
# -*- coding: utf-8 -*-
'''
Tests for the spm build utility
'''
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
2017-10-18 21:15:42 +00:00
import os
import shutil
2017-10-27 17:03:01 +00:00
# Import Salt libs
2017-11-06 03:39:40 +00:00
import salt.utils.files
import salt.utils.path
2017-10-27 17:03:01 +00:00
2017-10-18 21:15:42 +00:00
# Import Salt Testing libs
from tests.support.case import SPMCase, ModuleCase
2017-10-18 21:15:42 +00:00
from tests.support.helpers import destructiveTest
2017-10-26 14:09:33 +00:00
from tests.support.unit import skipIf
2017-10-18 21:15:42 +00:00
@destructiveTest
class SPMBuildTest(SPMCase, ModuleCase):
2017-10-18 21:15:42 +00:00
'''
Validate the spm build command
'''
def setUp(self):
self.config = self._spm_config()
2017-10-23 16:25:46 +00:00
self._spm_build_files(self.config)
2017-10-18 21:15:42 +00:00
def test_spm_build(self):
'''
test spm build
'''
2017-11-06 03:39:40 +00:00
self.run_spm('build', self.config, self.formula_dir)
2017-10-18 21:15:42 +00:00
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']))
2017-11-06 03:39:40 +00:00
@skipIf(salt.utils.path.which('fallocate') is None, 'fallocate not installed')
def test_spm_build_big_file(self):
'''
test spm build with a big file
'''
# check to make sure there is enough space to run this test
check_space = self.run_function('status.diskusage', ['/tmp'])
space = check_space['/tmp']['available']
if space < 3000000000:
self.skipTest('Not enough space on host to run this test')
2017-11-06 03:39:40 +00:00
self.run_function('cmd.run',
['fallocate -l 1G {0}'.format(os.path.join(self.formula_sls_dir,
'bigfile.txt'))])
self.run_spm('build', self.config, self.formula_dir)
spm_file = os.path.join(self.config['spm_build_dir'], 'apache-201506-2.spm')
2017-11-06 03:39:40 +00:00
self.run_spm('install', self.config, spm_file)
get_files = self.run_spm('files', self.config, 'apache')
files = ['apache.sls', 'bigfile.txt']
for sls in files:
self.assertIn(sls, ' '.join(get_files))
def test_spm_build_exclude(self):
'''
test spm build while excluding directory
'''
git_dir = os.path.join(self.formula_sls_dir, '.git')
os.makedirs(git_dir)
files = ['donotbuild1', 'donotbuild2', 'donotbuild3']
for git_file in files:
2017-11-06 03:39:40 +00:00
with salt.utils.files.fopen(os.path.join(git_dir, git_file), 'w') as fp:
fp.write('Please do not include me in build')
2017-11-06 03:39:40 +00:00
self.run_spm('build', self.config, self.formula_dir)
spm_file = os.path.join(self.config['spm_build_dir'], 'apache-201506-2.spm')
2017-11-06 03:39:40 +00:00
self.run_spm('install', self.config, spm_file)
get_files = self.run_spm('files', self.config, 'apache')
for git_file in files:
self.assertNotIn(git_file, ' '.join(get_files))
2017-10-18 21:15:42 +00:00
def tearDown(self):
shutil.rmtree(self._tmp_spm)