Merge "Train-only make tripleo_diff_exec py2-compatible" into stable/train

This commit is contained in:
Zuul 2021-03-03 12:13:37 +00:00 committed by Gerrit Code Review
commit a215f6098c
2 changed files with 14 additions and 10 deletions

View File

@ -111,9 +111,10 @@ def run(module):
try: try:
tmp_environment = os.environ.copy() tmp_environment = os.environ.copy()
tmp_environment.update(environment) tmp_environment.update(environment)
r = subprocess.run(command, shell=True, env=tmp_environment, r = subprocess.Popen(command, shell=True, env=tmp_environment,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True) universal_newlines=True)
cmd_stdout, cmd_stderr = r.communicate()
if r.returncode in return_codes: if r.returncode in return_codes:
results['changed'] = True results['changed'] = True
# copy old to bkup # copy old to bkup
@ -123,7 +124,7 @@ def run(module):
results['error'] = "Failed running command" results['error'] = "Failed running command"
results['msg'] = ("Error running %s. rc: %s, stdout: %s, " results['msg'] = ("Error running %s. rc: %s, stdout: %s, "
"stderr: %s" % (command, r.returncode, "stderr: %s" % (command, r.returncode,
r.stdout, r.stderr)) cmd_stdout, cmd_stderr))
except Exception as e: except Exception as e:
results['failed'] = True results['failed'] = True
results['error'] = traceback.format_exc() results['error'] = traceback.format_exc()

View File

@ -22,7 +22,7 @@ import mock
class TestTripleoDiffExec(tests_base.TestCase): class TestTripleoDiffExec(tests_base.TestCase):
@mock.patch.dict('os.environ', dict(), clear=True) @mock.patch.dict('os.environ', dict(), clear=True)
@mock.patch('shutil.copy2') @mock.patch('shutil.copy2')
@mock.patch('subprocess.run') @mock.patch('subprocess.Popen')
@mock.patch('filecmp.cmp') @mock.patch('filecmp.cmp')
@mock.patch('os.path.exists') @mock.patch('os.path.exists')
def test_first_run(self, mock_exists, mock_cmp, mock_run, mock_copy2): def test_first_run(self, mock_exists, mock_cmp, mock_run, mock_copy2):
@ -39,6 +39,7 @@ class TestTripleoDiffExec(tests_base.TestCase):
mock_module.exit_json = mock_exit mock_module.exit_json = mock_exit
mock_return = mock.MagicMock() mock_return = mock.MagicMock()
mock_return.returncode = 0 mock_return.returncode = 0
mock_return.communicate.return_value = (-1, -1)
mock_run.return_value = mock_return mock_run.return_value = mock_return
tripleo_diff_exec.run(mock_module) tripleo_diff_exec.run(mock_module)
mock_exit.assert_called_once_with(changed=True) mock_exit.assert_called_once_with(changed=True)
@ -49,7 +50,7 @@ class TestTripleoDiffExec(tests_base.TestCase):
@mock.patch.dict('os.environ', dict(), clear=True) @mock.patch.dict('os.environ', dict(), clear=True)
@mock.patch('shutil.copy2') @mock.patch('shutil.copy2')
@mock.patch('subprocess.run') @mock.patch('subprocess.Popen')
@mock.patch('filecmp.cmp') @mock.patch('filecmp.cmp')
@mock.patch('os.path.exists') @mock.patch('os.path.exists')
def test_no_change(self, mock_exists, mock_cmp, mock_run, mock_copy2): def test_no_change(self, mock_exists, mock_cmp, mock_run, mock_copy2):
@ -71,7 +72,7 @@ class TestTripleoDiffExec(tests_base.TestCase):
@mock.patch.dict('os.environ', dict(), clear=True) @mock.patch.dict('os.environ', dict(), clear=True)
@mock.patch('shutil.copy2') @mock.patch('shutil.copy2')
@mock.patch('subprocess.run') @mock.patch('subprocess.Popen')
@mock.patch('filecmp.cmp') @mock.patch('filecmp.cmp')
@mock.patch('os.path.exists') @mock.patch('os.path.exists')
def test_file_changed(self, mock_exists, mock_cmp, mock_run, mock_copy2): def test_file_changed(self, mock_exists, mock_cmp, mock_run, mock_copy2):
@ -88,6 +89,7 @@ class TestTripleoDiffExec(tests_base.TestCase):
mock_module.exit_json = mock_exit mock_module.exit_json = mock_exit
mock_return = mock.MagicMock() mock_return = mock.MagicMock()
mock_return.returncode = 0 mock_return.returncode = 0
mock_return.communicate.return_value = (-1, -1)
mock_run.return_value = mock_return mock_run.return_value = mock_return
tripleo_diff_exec.run(mock_module) tripleo_diff_exec.run(mock_module)
mock_run.assert_called_once_with( mock_run.assert_called_once_with(
@ -98,7 +100,7 @@ class TestTripleoDiffExec(tests_base.TestCase):
@mock.patch.dict('os.environ', dict(), clear=True) @mock.patch.dict('os.environ', dict(), clear=True)
@mock.patch('shutil.copy2') @mock.patch('shutil.copy2')
@mock.patch('subprocess.run') @mock.patch('subprocess.Popen')
@mock.patch('filecmp.cmp') @mock.patch('filecmp.cmp')
@mock.patch('os.path.exists') @mock.patch('os.path.exists')
def test_missing_state(self, mock_exists, mock_cmp, mock_run, mock_copy2): def test_missing_state(self, mock_exists, mock_cmp, mock_run, mock_copy2):
@ -121,7 +123,7 @@ class TestTripleoDiffExec(tests_base.TestCase):
@mock.patch.dict('os.environ', dict(), clear=True) @mock.patch.dict('os.environ', dict(), clear=True)
@mock.patch('shutil.copy2') @mock.patch('shutil.copy2')
@mock.patch('subprocess.run') @mock.patch('subprocess.Popen')
@mock.patch('filecmp.cmp') @mock.patch('filecmp.cmp')
@mock.patch('os.path.exists') @mock.patch('os.path.exists')
def test_exec_exception(self, mock_exists, mock_cmp, mock_run, mock_copy2): def test_exec_exception(self, mock_exists, mock_cmp, mock_run, mock_copy2):
@ -144,7 +146,7 @@ class TestTripleoDiffExec(tests_base.TestCase):
@mock.patch.dict('os.environ', dict(), clear=True) @mock.patch.dict('os.environ', dict(), clear=True)
@mock.patch('shutil.copy2') @mock.patch('shutil.copy2')
@mock.patch('subprocess.run') @mock.patch('subprocess.Popen')
@mock.patch('filecmp.cmp') @mock.patch('filecmp.cmp')
@mock.patch('os.path.exists') @mock.patch('os.path.exists')
def test_exec_failed(self, mock_exists, mock_cmp, mock_run, mock_copy2): def test_exec_failed(self, mock_exists, mock_cmp, mock_run, mock_copy2):
@ -160,6 +162,7 @@ class TestTripleoDiffExec(tests_base.TestCase):
mock_module.exit_json = mock_exit mock_module.exit_json = mock_exit
mock_return = mock.MagicMock() mock_return = mock.MagicMock()
mock_return.returncode = 1 mock_return.returncode = 1
mock_return.communicate.return_value = ('out', 'err')
mock_return.stdout = 'out' mock_return.stdout = 'out'
mock_return.stderr = 'err' mock_return.stderr = 'err'
mock_run.return_value = mock_return mock_run.return_value = mock_return