Browse Source

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.

Conflicts:
	tripleoclient/tests/workflows/test_deployment.py
	tripleoclient/workflows/deployment.py

Change-Id: I5a286cca6e48b0abc9cec3f15b2648977ae838c2
Related-Bug: rhbz#1734356
(cherry picked from commit b40c9e3b1c)
(cherry picked from commit 6055817d25)
tags/10.7.1
Sergii Golovatiuk 1 month ago
parent
commit
3de174d7b0

+ 6
- 3
tripleoclient/tests/workflows/test_deployment.py View File

@@ -51,9 +51,8 @@ class TestDeploymentWorkflows(utils.TestCommand):
51 51
     @mock.patch('tripleoclient.workflows.deployment.open')
52 52
     @mock.patch('tripleoclient.workflows.deployment.tempfile')
53 53
     @mock.patch('tripleoclient.workflows.deployment.subprocess.check_call')
54
-    def test_enable_ssh_admin(self, mock_check_call, mock_tempfile,
55
-                              mock_open, mock_rmtree, mock_sleep,
56
-                              mock_wait_for_ssh_port):
54
+    def test_enable_ssh_admin(self, mock_check_call, mock_tempfile, mock_open,
55
+                              mock_rmtree, mock_sleep, mock_wait_for_ssh_port):
57 56
         log = mock.Mock()
58 57
         hosts = 'a', 'b', 'c'
59 58
         ssh_user = 'test-user'
@@ -62,6 +61,8 @@ class TestDeploymentWorkflows(utils.TestCommand):
62 61
         mock_tempfile.mkdtemp.return_value = '/foo'
63 62
         mock_read = mock.Mock()
64 63
         mock_read.read.return_value = 'key'
64
+        mock_read.__enter__ = mock.Mock()
65
+        mock_read.__exit__ = mock.Mock()
65 66
         mock_open.return_value = mock_read
66 67
         mock_state = mock.Mock()
67 68
         mock_state.state = 'SUCCESS'
@@ -104,6 +105,8 @@ class TestDeploymentWorkflows(utils.TestCommand):
104 105
         mock_tempfile.mkdtemp.return_value = '/foo'
105 106
         mock_read = mock.Mock()
106 107
         mock_read.read.return_value = 'key'
108
+        mock_read.__enter__ = mock.Mock()
109
+        mock_read.__exit__ = mock.Mock()
107 110
         mock_open.return_value = mock_read
108 111
         mock_state = mock.Mock()
109 112
         mock_state.state = 'ERROR'

+ 13
- 2
tripleoclient/workflows/deployment.py View File

@@ -200,8 +200,19 @@ def enable_ssh_admin(log, clients, plan_name, hosts, ssh_user, ssh_key):
200 200
     try:
201 201
         tmp_key_command = ["ssh-keygen", "-N", "", "-t", "rsa", "-b", "4096",
202 202
                            "-f", tmp_key_private, "-C", tmp_key_comment]
203
-        subprocess.check_call(tmp_key_command, stderr=subprocess.STDOUT)
204
-        tmp_key_public_contents = open(tmp_key_public).read()
203
+        DEVNULL = open(os.devnull, 'w')
204
+        try:
205
+            subprocess.check_call(tmp_key_command, stdout=DEVNULL,
206
+                                  stderr=subprocess.STDOUT)
207
+        except subprocess.CalledProcessError as exc:
208
+            log.error("ssh-keygen has failed with return code {0}".
209
+                      format(exc.returncode))
210
+        else:
211
+            log.info("ssh-keygen has been run successfully")
212
+        DEVNULL.close()
213
+
214
+        with open(tmp_key_public) as pubkey:
215
+            tmp_key_public_contents = pubkey.read()
205 216
 
206 217
         for host in hosts:
207 218
             wait_for_ssh_port(host)

Loading…
Cancel
Save