mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
228c987b76
This fixes #8856.
102 lines
3.0 KiB
Python
102 lines
3.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
import os
|
|
import tempfile
|
|
import textwrap
|
|
|
|
from distutils.dir_util import copy_tree
|
|
|
|
# Import third party libs
|
|
import yaml
|
|
|
|
# Import Salt Testing libs
|
|
from salttesting import TestCase
|
|
from salttesting.helpers import ensure_in_syspath
|
|
from salttesting.mock import MagicMock
|
|
|
|
ensure_in_syspath('../../')
|
|
import integration
|
|
import shutil
|
|
|
|
# Import Salt libs
|
|
from salt.modules import zcbuildout as modbuildout
|
|
from salt.states import zcbuildout as buildout
|
|
from salt.modules import cmdmod as cmd
|
|
from salt.exceptions import CommandExecutionError, SaltInvocationError
|
|
|
|
ROOT = os.path.join(os.path.dirname(integration.__file__),
|
|
'files/file/base/buildout')
|
|
|
|
|
|
modbuildout.__env__ = 'base'
|
|
modbuildout.__opts__ = {'test': False}
|
|
modbuildout.__salt__ = {
|
|
'cmd.run_all': cmd.run_all,
|
|
'cmd.run': cmd.run,
|
|
'cmd.retcode': cmd.retcode,
|
|
'buildout.buildout': modbuildout.buildout,
|
|
}
|
|
buildout.__env__ = 'base'
|
|
buildout.__opts__ = {'test': False}
|
|
buildout.__salt__ = {
|
|
'cmd.run_all': cmd.run_all,
|
|
'cmd.run': cmd.run,
|
|
'cmd.retcode': cmd.retcode,
|
|
'buildout.buildout': modbuildout.buildout,
|
|
}
|
|
|
|
|
|
class Base(TestCase):
|
|
def setUp(self):
|
|
super(Base, self).setUp()
|
|
self.tdir = tempfile.mkdtemp()
|
|
copy_tree(ROOT, self.tdir)
|
|
|
|
def tearDown(self):
|
|
super(Base, self).tearDown()
|
|
if os.path.isdir(self.tdir):
|
|
shutil.rmtree(self.tdir)
|
|
|
|
|
|
class BuildoutTestCase(Base):
|
|
|
|
def test_quiet(self):
|
|
c_dir = os.path.join(self.tdir, 'c')
|
|
cret = buildout.installed(c_dir, quiet=True)
|
|
self.assertTrue(cret['result'])
|
|
self.assertFalse('OUTPUT:' in cret['comment'])
|
|
self.assertFalse('Log summary:' in cret['comment'])
|
|
|
|
def test_error(self):
|
|
b_dir = os.path.join(self.tdir, 'e')
|
|
ret = buildout.installed(b_dir)
|
|
self.assertTrue(
|
|
'We did not get any expectable '
|
|
'answer from buildout'
|
|
in ret['comment'])
|
|
self.assertTrue(
|
|
'An internal error occurred due to a bug in'
|
|
' either zc.buildout '
|
|
in ret['comment'])
|
|
self.assertFalse(ret['result'])
|
|
|
|
def test_installed(self):
|
|
b_dir = os.path.join(self.tdir, 'b')
|
|
ret = buildout.installed(b_dir, onlyif='/bin/false')
|
|
self.assertEqual(ret['comment'], '\nonlyif execution failed')
|
|
self.assertEqual(ret['result'], True)
|
|
self.assertTrue('/b' in ret['name'])
|
|
b_dir = os.path.join(self.tdir, 'b')
|
|
ret = buildout.installed(b_dir, unless='/bin/true')
|
|
self.assertEqual(ret['comment'], '\nunless execution succeeded')
|
|
self.assertEqual(ret['result'], True)
|
|
self.assertTrue('/b' in ret['name'])
|
|
ret = buildout.installed(b_dir)
|
|
self.assertEqual(ret['result'], True)
|
|
self.assertTrue('OUTPUT:' in ret['comment'])
|
|
self.assertTrue('Log summary:' in ret['comment'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
from integration import run_tests
|
|
run_tests(BuildoutTestCase, needs_daemon=False)
|