Merge branch '2019.2.1' into gce_cloud_test

This commit is contained in:
Akmod 2019-08-05 14:28:52 -06:00 committed by GitHub
commit 0e2621e2c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 82 additions and 17 deletions

View File

@ -807,11 +807,25 @@ class SignalHandlingMultiprocessingProcess(MultiprocessingProcess):
msg += '. Exiting'
log.debug(msg)
if HAS_PSUTIL:
process = psutil.Process(self.pid)
if hasattr(process, 'children'):
for child in process.children(recursive=True):
if child.is_running():
child.terminate()
try:
process = psutil.Process(self.pid)
if hasattr(process, 'children'):
for child in process.children(recursive=True):
try:
if child.is_running():
child.terminate()
except psutil.NoSuchProcess:
log.warn(
'Unable to kill child of process %d, it does '
'not exist. My pid is %d',
self.pid, os.getpid()
)
except psutil.NoSuchProcess:
log.warn(
'Unable to kill children of process %d, it does not exist.'
'My pid is %d',
self.pid, os.getpid()
)
sys.exit(salt.defaults.exitcodes.EX_OK)
def start(self):

View File

@ -6,6 +6,8 @@
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
import os
import logging
import time
# Import Salt Testing Libs
from tests.support.case import ShellCase
@ -16,6 +18,7 @@ from tests.support.helpers import expensiveTest, generate_random_name
# Import Salt Libs
from salt.config import cloud_providers_config
from salt.utils.versions import LooseVersion
from salt.ext.six.moves import range
TIMEOUT = 500
@ -34,6 +37,8 @@ PROVIDER_NAME = 'azure'
PROFILE_NAME = 'azure-test'
REQUIRED_AZURE = '0.11.1'
log = logging.getLogger(__name__)
def __has_required_azure():
'''
@ -129,18 +134,29 @@ class AzureTest(ShellCase):
timeout=TIMEOUT)
raise
# delete the instance
try:
self.assertIn(
INSTANCE_NAME + ':',
[i.strip() for i in self.run_cloud(
'-d {0} --assume-yes'.format(
INSTANCE_NAME
), timeout=TIMEOUT
)]
)
except AssertionError:
raise
# Try up to 10 times to delete the instance since it might not be
# available for deletion right away.
for num_try in range(10):
# delete the instance
try:
self.assertIn(
INSTANCE_NAME + ':',
[i.strip() for i in self.run_cloud(
'-d {0} --assume-yes'.format(
INSTANCE_NAME
), timeout=TIMEOUT
)]
)
except AssertionError:
# The deletion did not succeed, wait 10s and try again
if num_try < 9:
log.warning('Unable to delete azure instance on try %d', num_try)
time.sleep(10)
else:
raise
else:
# The deletion succeeded
break
def tearDown(self):
'''

View File

@ -24,6 +24,7 @@ import salt.utils.process
# Import 3rd-party libs
from salt.ext import six
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
import psutil
def die(func):
@ -233,3 +234,37 @@ class TestProcess(TestCase):
salt.utils.process.daemonize_if({})
self.assertTrue(salt.utils.process.daemonize.called)
# pylint: enable=assignment-from-none
@skipIf(sys.platform.startswith('win'), 'pickling nested function errors on Windows')
class TestSignalHandlingMultiprocessingProcess(TestCase):
@skipIf(NO_MOCK, NO_MOCK_REASON)
def test_process_does_not_exist(self):
def Process(pid):
raise psutil.NoSuchProcess(pid)
def target():
os.kill(os.getpid(), signal.SIGTERM)
try:
with patch('psutil.Process', Process):
proc = salt.utils.process.SignalHandlingMultiprocessingProcess(target=target)
proc.start()
except psutil.NoSuchProcess:
assert False, "psutil.NoSuchProcess raised"
@skipIf(NO_MOCK, NO_MOCK_REASON)
def test_process_children_do_not_exist(self):
def children(*args, **kwargs):
raise psutil.NoSuchProcess(1)
def target():
os.kill(os.getpid(), signal.SIGTERM)
try:
with patch('psutil.Process.children', children):
proc = salt.utils.process.SignalHandlingMultiprocessingProcess(target=target)
proc.start()
except psutil.NoSuchProcess:
assert False, "psutil.NoSuchProcess raised"