Wrap the test in a try/finally to ensure that the keys get cleaned up.

We're seeing the keys appear later on in some tests, such as here:

integration.modules.saltutil.SaltUtilModuleTest.test_wheel_just_function
This commit is contained in:
Mike Place 2016-08-21 20:22:26 +09:00
parent 93182fabdc
commit ea8fb37b48

View File

@ -200,103 +200,103 @@ class CallTest(integration.ShellCase, testprogram.TestProgramCase, integration.S
'log_level_logfile': 'info', 'log_level_logfile': 'info',
'transport': self.master_opts['transport'], 'transport': self.master_opts['transport'],
} }
# Remove existing logfile
if os.path.isfile(logfile):
os.unlink(logfile)
start = datetime.now()
# Let's first test with a master running
with salt.utils.fopen(minion_config_file, 'w') as fh_:
fh_.write(
yaml.dump(minion_config, default_flow_style=False)
)
ret = self.run_script(
'salt-call',
'--config-dir {0} cmd.run "echo foo"'.format(
config_dir
)
)
try: try:
self.assertIn('local:', ret) # Remove existing logfile
except AssertionError: if os.path.isfile(logfile):
if os.path.isfile(minion_config_file): os.unlink(logfile)
os.unlink(minion_config_file)
# Let's remove our key from the master
if os.path.isfile(this_minion_key):
os.unlink(this_minion_key)
raise start = datetime.now()
# Let's first test with a master running
# Calculate the required timeout, since next will fail. with salt.utils.fopen(minion_config_file, 'w') as fh_:
# I needed this because after many attempts, I was unable to catch: fh_.write(
# WARNING: Master hostname: salt not found. Retrying in 30 seconds yaml.dump(minion_config, default_flow_style=False)
ellapsed = datetime.now() - start )
timeout = ellapsed.seconds + 3 ret = self.run_script(
'salt-call',
'--config-dir {0} cmd.run "echo foo"'.format(
config_dir
)
)
try:
self.assertIn('local:', ret)
except AssertionError:
if os.path.isfile(minion_config_file):
os.unlink(minion_config_file)
# Let's remove our key from the master
if os.path.isfile(this_minion_key):
os.unlink(this_minion_key)
# Now let's remove the master configuration raise
minion_config.pop('master')
minion_config.pop('master_port') # Calculate the required timeout, since next will fail.
with salt.utils.fopen(minion_config_file, 'w') as fh_: # I needed this because after many attempts, I was unable to catch:
fh_.write( # WARNING: Master hostname: salt not found. Retrying in 30 seconds
yaml.dump(minion_config, default_flow_style=False) ellapsed = datetime.now() - start
timeout = ellapsed.seconds + 3
# Now let's remove the master configuration
minion_config.pop('master')
minion_config.pop('master_port')
with salt.utils.fopen(minion_config_file, 'w') as fh_:
fh_.write(
yaml.dump(minion_config, default_flow_style=False)
)
out = self.run_script(
'salt-call',
'--config-dir {0} cmd.run "echo foo"'.format(
config_dir
),
timeout=timeout,
) )
out = self.run_script( try:
'salt-call', self.assertIn(
'--config-dir {0} cmd.run "echo foo"'.format( 'Process took more than {0} seconds to complete. '
config_dir 'Process Killed!'.format(timeout),
), out
timeout=timeout, )
) except AssertionError:
if os.path.isfile(minion_config_file):
os.unlink(minion_config_file)
# Let's remove our key from the master
if os.path.isfile(this_minion_key):
os.unlink(this_minion_key)
try: raise
self.assertIn(
'Process took more than {0} seconds to complete. ' # Should work with --local
'Process Killed!'.format(timeout), ret = self.run_script(
out 'salt-call',
'--config-dir {0} --local cmd.run "echo foo"'.format(
config_dir
),
timeout=15
) )
except AssertionError: try:
if os.path.isfile(minion_config_file): self.assertIn('local:', ret)
os.unlink(minion_config_file) except AssertionError:
# Let's remove our key from the master if os.path.isfile(minion_config_file):
if os.path.isfile(this_minion_key): os.unlink(minion_config_file)
os.unlink(this_minion_key) # Let's remove our key from the master
if os.path.isfile(this_minion_key):
os.unlink(this_minion_key)
raise
raise # Should work with local file client
minion_config['file_client'] = 'local'
# Should work with --local with salt.utils.fopen(minion_config_file, 'w') as fh_:
ret = self.run_script( fh_.write(
'salt-call', yaml.dump(minion_config, default_flow_style=False)
'--config-dir {0} --local cmd.run "echo foo"'.format( )
config_dir ret = self.run_script(
), 'salt-call',
timeout=15 '--config-dir {0} cmd.run "echo foo"'.format(
) config_dir
try: ),
self.assertIn('local:', ret) timeout=15
except AssertionError:
if os.path.isfile(minion_config_file):
os.unlink(minion_config_file)
# Let's remove our key from the master
if os.path.isfile(this_minion_key):
os.unlink(this_minion_key)
raise
# Should work with local file client
minion_config['file_client'] = 'local'
with salt.utils.fopen(minion_config_file, 'w') as fh_:
fh_.write(
yaml.dump(minion_config, default_flow_style=False)
) )
ret = self.run_script(
'salt-call',
'--config-dir {0} cmd.run "echo foo"'.format(
config_dir
),
timeout=15
)
try:
self.assertIn('local:', ret) self.assertIn('local:', ret)
finally: finally:
if os.path.isfile(minion_config_file): if os.path.isfile(minion_config_file):
@ -305,6 +305,7 @@ class CallTest(integration.ShellCase, testprogram.TestProgramCase, integration.S
if os.path.isfile(this_minion_key): if os.path.isfile(this_minion_key):
os.unlink(this_minion_key) os.unlink(this_minion_key)
def test_issue_7754(self): def test_issue_7754(self):
old_cwd = os.getcwd() old_cwd = os.getcwd()
config_dir = os.path.join(integration.TMP, 'issue-7754') config_dir = os.path.join(integration.TMP, 'issue-7754')