Suppress output for ssh-keygen
ssh-keygen has private key which shouldn't be visible in output. This
patch change the behaviour to print only exit code on failure. Also this
patch closes file descriptor once key is read.
Change-Id: I5a286cca6e48b0abc9cec3f15b2648977ae838c2
Related-Bug: rhbz#1734356
(cherry picked from commit b40c9e3b1c
)
This commit is contained in:
parent
ffb86df965
commit
6055817d25
|
@ -52,16 +52,16 @@ class TestDeploymentWorkflows(utils.TestCommand):
|
||||||
@mock.patch('tripleoclient.workflows.deployment.open')
|
@mock.patch('tripleoclient.workflows.deployment.open')
|
||||||
@mock.patch('tripleoclient.workflows.deployment.tempfile')
|
@mock.patch('tripleoclient.workflows.deployment.tempfile')
|
||||||
@mock.patch('tripleoclient.workflows.deployment.subprocess.check_call')
|
@mock.patch('tripleoclient.workflows.deployment.subprocess.check_call')
|
||||||
def test_enable_ssh_admin(self, mock_check_call, mock_tempfile,
|
def test_enable_ssh_admin(self, mock_check_call, mock_tempfile, mock_open,
|
||||||
mock_open, mock_rmtree, mock_sleep,
|
mock_rmtree, mock_sleep, mock_wait_for_ssh_port):
|
||||||
mock_wait_for_ssh_port):
|
|
||||||
log = mock.Mock()
|
log = mock.Mock()
|
||||||
hosts = 'a', 'b', 'c'
|
hosts = 'a', 'b', 'c'
|
||||||
ssh_user = 'test-user'
|
ssh_user = 'test-user'
|
||||||
ssh_key = 'test-key'
|
ssh_key = 'test-key'
|
||||||
|
|
||||||
mock_tempfile.mkdtemp.return_value = '/foo'
|
mock_tempfile.mkdtemp.return_value = '/foo'
|
||||||
mock_open.return_value = FakeFile('key')
|
mock_open.side_effect = [FakeFile('DEVNULL'), FakeFile('pubkey'),
|
||||||
|
FakeFile('key')]
|
||||||
mock_state = mock.Mock()
|
mock_state = mock.Mock()
|
||||||
mock_state.state = 'SUCCESS'
|
mock_state.state = 'SUCCESS'
|
||||||
self.workflow.executions.get.return_value = mock_state
|
self.workflow.executions.get.return_value = mock_state
|
||||||
|
@ -101,7 +101,8 @@ class TestDeploymentWorkflows(utils.TestCommand):
|
||||||
ssh_key = 'test-key'
|
ssh_key = 'test-key'
|
||||||
|
|
||||||
mock_tempfile.mkdtemp.return_value = '/foo'
|
mock_tempfile.mkdtemp.return_value = '/foo'
|
||||||
mock_open.side_effect = [FakeFile('pubkey'), FakeFile('privkey')]
|
mock_open.side_effect = [FakeFile('DEVNULL'), FakeFile('pubkey'),
|
||||||
|
FakeFile('privkey')]
|
||||||
mock_state = mock.Mock()
|
mock_state = mock.Mock()
|
||||||
mock_state.state = 'ERROR'
|
mock_state.state = 'ERROR'
|
||||||
mock_state.to_dict.return_value = dict(state_info='an error')
|
mock_state.to_dict.return_value = dict(state_info='an error')
|
||||||
|
|
|
@ -225,7 +225,17 @@ def enable_ssh_admin(log, clients, plan_name, hosts, ssh_user, ssh_key):
|
||||||
try:
|
try:
|
||||||
tmp_key_command = ["ssh-keygen", "-N", "", "-t", "rsa", "-b", "4096",
|
tmp_key_command = ["ssh-keygen", "-N", "", "-t", "rsa", "-b", "4096",
|
||||||
"-f", tmp_key_private, "-C", tmp_key_comment]
|
"-f", tmp_key_private, "-C", tmp_key_comment]
|
||||||
subprocess.check_call(tmp_key_command, stderr=subprocess.STDOUT)
|
DEVNULL = open(os.devnull, 'w')
|
||||||
|
try:
|
||||||
|
subprocess.check_call(tmp_key_command, stdout=DEVNULL,
|
||||||
|
stderr=subprocess.STDOUT)
|
||||||
|
except subprocess.CalledProcessError as exc:
|
||||||
|
log.error("ssh-keygen has failed with return code {0}".
|
||||||
|
format(exc.returncode))
|
||||||
|
else:
|
||||||
|
log.info("ssh-keygen has been run successfully")
|
||||||
|
DEVNULL.close()
|
||||||
|
|
||||||
with open(tmp_key_public) as pubkey:
|
with open(tmp_key_public) as pubkey:
|
||||||
tmp_key_public_contents = pubkey.read()
|
tmp_key_public_contents = pubkey.read()
|
||||||
with open(tmp_key_private) as privkey:
|
with open(tmp_key_private) as privkey:
|
||||||
|
|
Loading…
Reference in New Issue