Fix integration.modules.test_state.StateModuleTest.test_exclude

test_exclude shares file paths with test_include, and while I can't
reproduce the failures, it is likely that improperly cleaned-up files
from test_include are causing the failures in test_exclude. This is
backed up by the fact that the state.sls return data from the
salt-runtests.log shows no trace of the "to-include-test" file
(suggesting it was excluded as expected), yet os.path.isfile() returns
True for this path, causing the test to fail.

This commit uses a distinct base dir for both tests, which should keep
this sort of failure from happening.
This commit is contained in:
Erik Johnson 2017-12-24 11:52:20 -06:00 committed by rallytime
parent fb87010461
commit 8bc17e0d7a
No known key found for this signature in database
GPG key ID: E8F1A4B90D0DEA19
4 changed files with 27 additions and 45 deletions

View file

@ -4,7 +4,6 @@ exclude:
include:
- include-test
{{ salt['runtests_helpers.get_salt_temp_dir_for_path']('exclude-test') }}:
file:
- managed
{{ pillar['exclude-test'] }}:
file.managed:
- source: salt://testfile

View file

@ -1,7 +1,6 @@
include:
- to-include-test
{{ salt['runtests_helpers.get_salt_temp_dir_for_path']('include-test') }}:
file:
- managed
{{ pillar['include-test'] }}:
file.managed:
- source: salt://testfile

View file

@ -1,4 +1,3 @@
{{ salt['runtests_helpers.get_salt_temp_dir_for_path']('to-include-test') }}:
file:
- managed
{{ pillar['to-include-test'] }}:
file.managed:
- source: salt://testfile

View file

@ -4,6 +4,7 @@
from __future__ import absolute_import
import os
import shutil
import tempfile
import textwrap
import threading
import time
@ -325,44 +326,28 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
os.unlink(testfile)
def test_include(self):
fnames = (
os.path.join(TMP, 'include-test'),
os.path.join(TMP, 'to-include-test')
)
exclude_test_file = os.path.join(
TMP, 'exclude-test'
)
try:
ret = self.run_function('state.sls', mods='include-test')
self.assertSaltTrueReturn(ret)
for fname in fnames:
self.assertTrue(os.path.isfile(fname))
self.assertFalse(os.path.isfile(exclude_test_file))
finally:
for fname in list(fnames) + [exclude_test_file]:
if os.path.isfile(fname):
os.remove(fname)
tempdir = tempfile.mkdtemp(dir=TMP)
self.addCleanup(shutil.rmtree, tempdir, ignore_errors=True)
pillar = {}
for path in ('include-test', 'to-include-test', 'exclude-test'):
pillar[path] = os.path.join(tempdir, path)
ret = self.run_function('state.sls', mods='include-test', pillar=pillar)
self.assertSaltTrueReturn(ret)
self.assertTrue(os.path.isfile(pillar['include-test']))
self.assertTrue(os.path.isfile(pillar['to-include-test']))
self.assertFalse(os.path.isfile(pillar['exclude-test']))
def test_exclude(self):
fnames = (
os.path.join(TMP, 'include-test'),
os.path.join(TMP, 'exclude-test')
)
to_include_test_file = os.path.join(
TMP, 'to-include-test'
)
try:
ret = self.run_function('state.sls', mods='exclude-test')
self.assertSaltTrueReturn(ret)
for fname in fnames:
self.assertTrue(os.path.isfile(fname))
self.assertFalse(os.path.isfile(to_include_test_file))
finally:
for fname in list(fnames) + [to_include_test_file]:
if os.path.isfile(fname):
os.remove(fname)
tempdir = tempfile.mkdtemp(dir=TMP)
self.addCleanup(shutil.rmtree, tempdir, ignore_errors=True)
pillar = {}
for path in ('include-test', 'exclude-test', 'to-include-test'):
pillar[path] = os.path.join(tempdir, path)
ret = self.run_function('state.sls', mods='exclude-test', pillar=pillar)
self.assertSaltTrueReturn(ret)
self.assertTrue(os.path.isfile(pillar['include-test']))
self.assertTrue(os.path.isfile(pillar['exclude-test']))
self.assertFalse(os.path.isfile(pillar['to-include-test']))
@skipIf(salt.utils.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed')
def test_issue_2068_template_str(self):