Browse Source

Disable `pty` allocation for SSH commands

The pty was needed for older minion images, but is no longer required,
so set `get_pty` to `False` on all SSH commands.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 2 weeks ago
parent
commit
b5371e04fc

+ 5 - 5
coriolis/osmorphing/base.py

@@ -395,12 +395,12 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
             utils.exec_ssh_cmd(
                 self._conn,
                 "sudo chmod +x %s" % script_path,
-                get_pty=True)
+                get_pty=False)
 
             utils.exec_ssh_cmd(
                 self._conn,
                 'sudo "%s" "%s"' % (script_path, self._os_root_dir),
-                get_pty=True)
+                get_pty=False)
         except Exception as err:
             raise exception.CoriolisException(
                 "Failed to run user script.") from err
@@ -446,7 +446,7 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
             timeout = self._osmorphing_operation_timeout
         try:
             return utils.exec_ssh_cmd(
-                self._ssh, cmd, environment=self._environment, get_pty=True,
+                self._ssh, cmd, environment=self._environment, get_pty=False,
                 timeout=timeout)
         except exception.MinionMachineCommandTimeout as ex:
             raise exception.OSMorphingSSHOperationTimeout(
@@ -458,7 +458,7 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
         try:
             return utils.exec_ssh_cmd_chroot(
                 self._ssh, self._os_root_dir, cmd,
-                environment=self._environment, get_pty=True, timeout=timeout)
+                environment=self._environment, get_pty=False, timeout=timeout)
         except exception.MinionMachineCommandTimeout as ex:
             raise exception.OSMorphingSSHOperationTimeout(
                 cmd=cmd, timeout=timeout) from ex
@@ -477,7 +477,7 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
         self._exec_cmd_chroot("cp /%s /%s" % (tmp_file, chroot_path))
         self._exec_cmd_chroot("rm /%s" % tmp_file)
         utils.exec_ssh_cmd(
-            self._ssh, "sudo sync", self._environment, get_pty=True)
+            self._ssh, "sudo sync", self._environment, get_pty=False)
 
     def _enable_systemd_service(self, service_name):
         self._exec_cmd_chroot("systemctl enable %s.service" % service_name)

+ 2 - 2
coriolis/osmorphing/osdetect/base.py

@@ -86,7 +86,7 @@ class BaseLinuxOSDetectTools(BaseOSDetectTools):
             timeout = self._osdetect_operation_timeout
         try:
             return utils.exec_ssh_cmd(
-                self._conn, cmd, environment=self._environment, get_pty=True,
+                self._conn, cmd, environment=self._environment, get_pty=False,
                 timeout=timeout)
         except exception.MinionMachineCommandTimeout as ex:
             raise exception.OSMorphingSSHOperationTimeout(
@@ -98,7 +98,7 @@ class BaseLinuxOSDetectTools(BaseOSDetectTools):
         try:
             return utils.exec_ssh_cmd_chroot(
                 self._conn, self._os_root_dir, cmd,
-                environment=self._environment, get_pty=True, timeout=timeout)
+                environment=self._environment, get_pty=False, timeout=timeout)
         except exception.MinionMachineCommandTimeout as ex:
             raise exception.OSMorphingSSHOperationTimeout(
                 cmd=cmd, timeout=timeout) from ex

+ 4 - 4
coriolis/osmorphing/osmount/base.py

@@ -127,7 +127,7 @@ class BaseSSHOSMountTools(BaseOSMountTools):
             timeout = self._osmount_operation_timeout
         try:
             return utils.exec_ssh_cmd(self._ssh, cmd, self._environment,
-                                      get_pty=True, timeout=timeout)
+                                      get_pty=False, timeout=timeout)
         except exception.MinionMachineCommandTimeout as ex:
             raise exception.OSMorphingSSHOperationTimeout(
                 cmd=cmd, timeout=timeout) from ex
@@ -148,7 +148,7 @@ class BaseSSHOSMountTools(BaseOSMountTools):
                 self._ssh,
                 env_cmd,
                 environment=self._environment,
-                get_pty=True,
+                get_pty=False,
                 timeout=timeout,
             )
         except exception.MinionMachineCommandTimeout as ex:
@@ -764,12 +764,12 @@ class BaseLinuxOSMountTools(luks_mixin.LinuxLUKSMixin, BaseSSHOSMountTools):
             utils.exec_ssh_cmd(
                 self._ssh,
                 "sudo chmod +x %s" % script_path,
-                get_pty=True)
+                get_pty=False)
 
             utils.exec_ssh_cmd(
                 self._ssh,
                 f'sudo "{script_path}"',
-                get_pty=True)
+                get_pty=False)
         except Exception as err:
             raise exception.CoriolisException(
                 "Failed to run user script.") from err

+ 13 - 13
coriolis/providers/backup_writers.py

@@ -100,7 +100,7 @@ def _disable_lvm2_lvmetad(ssh):
         utils.exec_ssh_cmd(
             ssh,
             'sudo sed -i "s/use_lvmetad.*=.*1/use_lvmetad = 0/g" '
-            '%s' % cfg, get_pty=True)
+            '%s' % cfg, get_pty=False)
         # NOTE: lvm2-lvmetad is the name of the lvmetad service
         # on both debian and RHEL based systems. It needs to be stopped
         # before we begin disk replication. We disable it in the config
@@ -108,12 +108,12 @@ def _disable_lvm2_lvmetad(ssh):
         # a dependency. As the service may not actually exist, even though
         # the config is present, we ignore errors when stopping it.
         utils.ignore_exceptions(utils.exec_ssh_cmd)(
-            ssh, "sudo service lvm2-lvmetad stop", get_pty=True)
+            ssh, "sudo service lvm2-lvmetad stop", get_pty=False)
         # disable volume groups. Any volume groups that have volumes in use
         # will remain online. However, volume groups belonging to disks
         # that have been synced at least once, will be deactivated.
         utils.ignore_exceptions(utils.exec_ssh_cmd)(
-            ssh, "sudo vgchange -an", get_pty=True)
+            ssh, "sudo vgchange -an", get_pty=False)
 
 
 def _disable_lvm_metad_udev_rule(ssh):
@@ -131,7 +131,7 @@ def _disable_lvm_metad_udev_rule(ssh):
     ]
     for path in rule_paths:
         if utils.test_ssh_path(ssh, path):
-            utils.exec_ssh_cmd(ssh, "sudo rm %s" % path, get_pty=True)
+            utils.exec_ssh_cmd(ssh, "sudo rm %s" % path, get_pty=False)
 
 
 def _check_deserialize_key(key):
@@ -1021,7 +1021,7 @@ class HTTPBackupWriterBootstrapper(object):
             "sudo iptables -I INPUT -p tcp --dport %(port)s -j ACCEPT" % {
                 "port": self._writer_port})
         try:
-            utils.exec_ssh_cmd(ssh, cmd, get_pty=True)
+            utils.exec_ssh_cmd(ssh, cmd, get_pty=False)
         except exception.CoriolisException:
             LOG.warn(
                 "Could not inject TCP FW rule. Error was: %s",
@@ -1030,7 +1030,7 @@ class HTTPBackupWriterBootstrapper(object):
     def _add_firewalld_port(self, ssh):
         cmd = "sudo firewall-cmd --add-port=%s/tcp" % self._writer_port
         try:
-            utils.exec_ssh_cmd(ssh, cmd, get_pty=True)
+            utils.exec_ssh_cmd(ssh, cmd, get_pty=False)
         except exception.CoriolisException:
             LOG.warn("Could not add TCP port to firewalld. Error was: %s",
                      utils.get_exception_details())
@@ -1038,7 +1038,7 @@ class HTTPBackupWriterBootstrapper(object):
     def _change_binary_se_context(self, ssh):
         cmd = "sudo chcon -t bin_t %s" % self._writer_cmd
         try:
-            utils.exec_ssh_cmd(ssh, cmd, get_pty=True)
+            utils.exec_ssh_cmd(ssh, cmd, get_pty=False)
         except exception.CoriolisException:
             LOG.warn("Could not change SELinux context of writer binary. "
                      "Error was:%s", utils.get_exception_details())
@@ -1061,12 +1061,12 @@ class HTTPBackupWriterBootstrapper(object):
                     ssh,
                     "sudo mv %s %s" % (
                         remote_tmp_path, self._writer_cmd),
-                    get_pty=True
+                    get_pty=False
                 )
                 utils.exec_ssh_cmd(
                     ssh,
                     "sudo chmod +x %s" % self._writer_cmd,
-                    get_pty=True
+                    get_pty=False
                 )
             finally:
                 sftp.close()
@@ -1075,7 +1075,7 @@ class HTTPBackupWriterBootstrapper(object):
         with open(local_file, 'wb') as fd:
             utils.exec_ssh_cmd(
                 ssh,
-                "sudo chmod +r %s" % remote_file, get_pty=True)
+                "sudo chmod +r %s" % remote_file, get_pty=False)
             data = utils.retry_on_error()(
                 utils.read_ssh_file)(ssh, remote_file)
             fd.write(data)
@@ -1103,7 +1103,7 @@ class HTTPBackupWriterBootstrapper(object):
 
         if not all(exist):
             utils.exec_ssh_cmd(
-                ssh, "sudo mkdir -p %s" % remote_base_dir, get_pty=True)
+                ssh, "sudo mkdir -p %s" % remote_base_dir, get_pty=False)
             utils.exec_ssh_cmd(
                 ssh,
                 "sudo %(writer_cmd)s generate-certificates -output-dir "
@@ -1112,7 +1112,7 @@ class HTTPBackupWriterBootstrapper(object):
                     "cert_dir": remote_base_dir,
                     "extra_hosts": self._ip,
                 },
-                get_pty=True)
+                get_pty=False)
 
         return {
             "srv_crt": remote_srv_crt,
@@ -1124,7 +1124,7 @@ class HTTPBackupWriterBootstrapper(object):
 
     def _read_remote_file_sudo(self, remote_path):
         contents = utils.exec_ssh_cmd(
-            self._ssh, 'sudo cat "%s"' % remote_path, get_pty=True)
+            self._ssh, 'sudo cat "%s"' % remote_path, get_pty=False)
         return contents
 
     def _init_writer(self, ssh, cert_paths):

+ 12 - 12
coriolis/providers/replicator.py

@@ -567,7 +567,7 @@ class Replicator(object):
         sftp = paramiko.SFTPClient.from_transport(ssh.get_transport())
         sftp.put(localPath, tmp)
         utils.exec_ssh_cmd(
-            ssh, "sudo mv %s %s" % (tmp, remotePath), get_pty=True)
+            ssh, "sudo mv %s %s" % (tmp, remotePath), get_pty=False)
         sftp.close()
 
     def _copy_replicator_cmd(self, ssh):
@@ -575,7 +575,7 @@ class Replicator(object):
             utils.get_resources_bin_dir(), 'replicator')
         self._copy_file(ssh, local_path, REPLICATOR_PATH)
         utils.exec_ssh_cmd(
-            ssh, "sudo chmod +x %s" % REPLICATOR_PATH, get_pty=True)
+            ssh, "sudo chmod +x %s" % REPLICATOR_PATH, get_pty=False)
 
     def _setup_replicator_group(self, ssh, group_name=REPLICATOR_GROUP_NAME):
         """ Sets up a group with the given name and adds the
@@ -589,14 +589,14 @@ class Replicator(object):
                 "group": REPLICATOR_GROUP_NAME})
         if int(group_exists) == 0:
             utils.exec_ssh_cmd(
-                ssh, "sudo groupadd %s" % group_name, get_pty=True)
+                ssh, "sudo groupadd %s" % group_name, get_pty=False)
             # NOTE: this is required in order for the user we connected
             # as to be able to read the certs:
             # NOTE2: the group change will only take effect after we reconnect:
             utils.exec_ssh_cmd(
                 ssh, "sudo usermod -aG %s %s" % (
                     REPLICATOR_GROUP_NAME, self._conn_info['username']),
-                get_pty=True)
+                get_pty=False)
 
         return int(group_exists) == 1
 
@@ -610,10 +610,10 @@ class Replicator(object):
             utils.exec_ssh_cmd(
                 ssh, "sudo useradd -m -s /bin/bash -g %s %s" % (
                     REPLICATOR_GROUP_NAME, REPLICATOR_USERNAME),
-                get_pty=True)
+                get_pty=False)
             utils.exec_ssh_cmd(
                 ssh, "sudo usermod -aG disk %s" % REPLICATOR_USERNAME,
-                get_pty=True)
+                get_pty=False)
 
     def _exec_replicator(self, ssh, port, certs, state_file):
         cmdline = ("%(replicator_path)s run -hash-method=%(hash_method)s "
@@ -682,7 +682,7 @@ class Replicator(object):
         force_fetch = False
         if not all(exist):
             utils.exec_ssh_cmd(
-                ssh, "sudo mkdir -p %s" % remote_base_dir, get_pty=True)
+                ssh, "sudo mkdir -p %s" % remote_base_dir, get_pty=False)
             utils.exec_ssh_cmd(
                 ssh,
                 "sudo %(replicator_cmd)s gen-certs -output-dir "
@@ -691,17 +691,17 @@ class Replicator(object):
                     "cert_dir": remote_base_dir,
                     "extra_hosts": ip,
                 },
-                get_pty=True)
+                get_pty=False)
             utils.exec_ssh_cmd(
                 ssh, "sudo chown -R %(user)s:%(group)s %(cert_dir)s" % {
                     "cert_dir": remote_base_dir,
                     "user": REPLICATOR_USERNAME,
                     "group": REPLICATOR_GROUP_NAME
-                }, get_pty=True)
+                }, get_pty=False)
             utils.exec_ssh_cmd(
                 ssh, "sudo chmod -R g+r %(cert_dir)s" % {
                     "cert_dir": remote_base_dir,
-                }, get_pty=True)
+                }, get_pty=False)
             force_fetch = True
 
         exists = []
@@ -731,7 +731,7 @@ class Replicator(object):
     def _change_binary_se_context(self, ssh):
         cmd = "sudo chcon -t bin_t %s" % REPLICATOR_PATH
         try:
-            utils.exec_ssh_cmd(ssh, cmd, get_pty=True)
+            utils.exec_ssh_cmd(ssh, cmd, get_pty=False)
         except exception.CoriolisException:
             LOG.warn("Could not change SELinux context of replicator binary. "
                      "Error was:%s", utils.get_exception_details())
@@ -742,7 +742,7 @@ class Replicator(object):
         state_file = self._get_replicator_state_file()
         self._copy_file(ssh, state_file, REPLICATOR_STATE)
         utils.exec_ssh_cmd(
-            ssh, "sudo chmod 755 %s" % REPLICATOR_STATE, get_pty=True)
+            ssh, "sudo chmod 755 %s" % REPLICATOR_STATE, get_pty=False)
         os.remove(state_file)
 
         args = self._parse_replicator_conn_info(self._conn_info)

+ 4 - 4
coriolis/tests/osmorphing/osdetect/test_base.py

@@ -118,7 +118,7 @@ class BaseLinuxOSDetectToolsTestCase(test_base.CoriolisBaseTestCase):
 
         mock_exec_ssh_cmd.assert_called_once_with(
             self.base_os_detect._conn, mock.sentinel.cmd,
-            environment=self.base_os_detect._environment, get_pty=True,
+            environment=self.base_os_detect._environment, get_pty=False,
             timeout=120)
 
         self.assertEqual(result, mock_exec_ssh_cmd.return_value)
@@ -129,7 +129,7 @@ class BaseLinuxOSDetectToolsTestCase(test_base.CoriolisBaseTestCase):
 
         mock_exec_ssh_cmd.assert_called_once_with(
             self.base_os_detect._conn, mock.sentinel.cmd,
-            environment=self.base_os_detect._environment, get_pty=True,
+            environment=self.base_os_detect._environment, get_pty=False,
             timeout=self.base_os_detect._osdetect_operation_timeout)
 
         self.assertEqual(result, mock_exec_ssh_cmd.return_value)
@@ -152,7 +152,7 @@ class BaseLinuxOSDetectToolsTestCase(test_base.CoriolisBaseTestCase):
         mock_exec_ssh_cmd_chroot.assert_called_once_with(
             self.base_os_detect._conn, self.base_os_detect._os_root_dir,
             mock.sentinel.cmd, environment=self.base_os_detect._environment,
-            get_pty=True, timeout=120)
+            get_pty=False, timeout=120)
 
         self.assertEqual(result, mock_exec_ssh_cmd_chroot.return_value)
 
@@ -163,7 +163,7 @@ class BaseLinuxOSDetectToolsTestCase(test_base.CoriolisBaseTestCase):
         mock_exec_ssh_cmd_chroot.assert_called_once_with(
             self.base_os_detect._conn, self.base_os_detect._os_root_dir,
             mock.sentinel.cmd, environment=self.base_os_detect._environment,
-            get_pty=True,
+            get_pty=False,
             timeout=self.base_os_detect._osdetect_operation_timeout)
 
         self.assertEqual(result, mock_exec_ssh_cmd_chroot.return_value)

+ 4 - 4
coriolis/tests/osmorphing/osmount/test_base.py

@@ -142,7 +142,7 @@ class BaseSSHOSMountToolsTestCase(test_base.CoriolisBaseTestCase):
         result = self.base_os_mount_tools._exec_cmd(self.cmd, timeout=120)
 
         mock_exec_ssh_cmd.assert_called_once_with(
-            self.base_os_mount_tools._ssh, self.cmd, {}, get_pty=True,
+            self.base_os_mount_tools._ssh, self.cmd, {}, get_pty=False,
             timeout=120)
 
         self.assertEqual(result, mock_exec_ssh_cmd.return_value)
@@ -152,7 +152,7 @@ class BaseSSHOSMountToolsTestCase(test_base.CoriolisBaseTestCase):
         result = self.base_os_mount_tools._exec_cmd(self.cmd)
 
         mock_exec_ssh_cmd.assert_called_once_with(
-            self.base_os_mount_tools._ssh, self.cmd, {}, get_pty=True,
+            self.base_os_mount_tools._ssh, self.cmd, {}, get_pty=False,
             timeout=self.base_os_mount_tools._osmount_operation_timeout)
 
         self.assertEqual(result, mock_exec_ssh_cmd.return_value)
@@ -174,7 +174,7 @@ class BaseSSHOSMountToolsTestCase(test_base.CoriolisBaseTestCase):
 
         mock_exec_ssh_cmd.assert_called_once_with(
             self.base_os_mount_tools._ssh, "sudo apt-get update -y",
-            environment={}, get_pty=True, timeout=120)
+            environment={}, get_pty=False, timeout=120)
         self.assertEqual(result, mock_exec_ssh_cmd.return_value)
 
     @mock.patch.object(base.utils, 'exec_ssh_cmd')
@@ -198,7 +198,7 @@ class BaseSSHOSMountToolsTestCase(test_base.CoriolisBaseTestCase):
         self.assertNotIn("sudo -E", cmd)
         mock_exec_ssh_cmd.assert_called_once_with(
             self.base_os_mount_tools._ssh, cmd, environment=environment,
-            get_pty=True,
+            get_pty=False,
             timeout=self.base_os_mount_tools._osmount_operation_timeout)
 
     @mock.patch.object(base.utils, 'exec_ssh_cmd')

+ 8 - 8
coriolis/tests/osmorphing/test_base.py

@@ -270,10 +270,10 @@ class BaseLinuxOSMorphingToolsTestBase(test_base.CoriolisBaseTestCase):
             self.conn, script_path, user_script)
         mock_exec_ssh_cmd.assert_has_calls([
             mock.call(self.conn, "sudo chmod +x %s" % script_path,
-                      get_pty=True),
+                      get_pty=False),
             mock.call(self.conn, 'sudo "%s" "%s"' % (
                 script_path, self.os_morphing_tools._os_root_dir),
-                get_pty=True)])
+                get_pty=False)])
 
     @mock.patch.object(base.utils, 'write_ssh_file')
     @mock.patch.object(base.utils, 'exec_ssh_cmd')
@@ -374,7 +374,7 @@ class BaseLinuxOSMorphingToolsTestBase(test_base.CoriolisBaseTestCase):
 
         mock_exec_ssh_cmd.assert_called_once_with(
             self.os_morphing_tools._ssh, mock.sentinel.cmd,
-            environment=self.os_morphing_tools._environment, get_pty=True,
+            environment=self.os_morphing_tools._environment, get_pty=False,
             timeout=120)
 
         self.assertEqual(result, mock_exec_ssh_cmd.return_value)
@@ -385,7 +385,7 @@ class BaseLinuxOSMorphingToolsTestBase(test_base.CoriolisBaseTestCase):
 
         mock_exec_ssh_cmd.assert_called_once_with(
             self.os_morphing_tools._ssh, mock.sentinel.cmd,
-            environment=self.os_morphing_tools._environment, get_pty=True,
+            environment=self.os_morphing_tools._environment, get_pty=False,
             timeout=self.os_morphing_tools._osmorphing_operation_timeout)
         self.assertEqual(result, mock_exec_ssh_cmd.return_value)
 
@@ -405,7 +405,7 @@ class BaseLinuxOSMorphingToolsTestBase(test_base.CoriolisBaseTestCase):
         mock_exec_ssh_cmd_chroot.assert_called_once_with(
             self.os_morphing_tools._ssh, self.os_morphing_tools._os_root_dir,
             mock.sentinel.cmd, environment=self.os_morphing_tools._environment,
-            get_pty=True, timeout=120)
+            get_pty=False, timeout=120)
         self.assertEqual(result, mock_exec_ssh_cmd_chroot.return_value)
 
     @mock.patch.object(base.utils, 'exec_ssh_cmd_chroot')
@@ -415,7 +415,7 @@ class BaseLinuxOSMorphingToolsTestBase(test_base.CoriolisBaseTestCase):
         mock_exec_ssh_cmd_chroot.assert_called_once_with(
             self.os_morphing_tools._ssh, self.os_morphing_tools._os_root_dir,
             mock.sentinel.cmd, environment=self.os_morphing_tools._environment,
-            get_pty=True,
+            get_pty=False,
             timeout=self.os_morphing_tools._osmorphing_operation_timeout)
         self.assertEqual(result, mock_exec_ssh_cmd_chroot.return_value)
 
@@ -440,7 +440,7 @@ class BaseLinuxOSMorphingToolsTestBase(test_base.CoriolisBaseTestCase):
 
         mock_exec_ssh_cmd_chroot.assert_called_once_with(
             self.os_morphing_tools._ssh, self.os_morphing_tools._os_root_dir,
-            mock.sentinel.cmd, environment=environment, get_pty=True,
+            mock.sentinel.cmd, environment=environment, get_pty=False,
             timeout=self.os_morphing_tools._osmorphing_operation_timeout)
 
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
@@ -477,7 +477,7 @@ class BaseLinuxOSMorphingToolsTestBase(test_base.CoriolisBaseTestCase):
             mock.call('rm /tmp/%s' % mock_uuid.return_value)])
         mock_exec_ssh_cmd.assert_called_once_with(
             self.os_morphing_tools._ssh, 'sudo sync',
-            self.os_morphing_tools._environment, get_pty=True)
+            self.os_morphing_tools._environment, get_pty=False)
 
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
     def test__enable_systemd_service(self, mock_exec_cmd_chroot):

+ 13 - 13
coriolis/tests/providers/test_backup_writers.py

@@ -39,10 +39,10 @@ class BackupWritersTestCase(test_base.CoriolisBaseTestCase):
             mock.call(
                 self.mock_ssh,
                 'sudo sed -i "s/use_lvmetad.*=.*1/use_lvmetad = 0/g" %s' %
-                cfg, get_pty=True),
+                cfg, get_pty=False),
             mock.call(self.mock_ssh,
-                      'sudo service lvm2-lvmetad stop', get_pty=True),
-            mock.call(self.mock_ssh, 'sudo vgchange -an', get_pty=True)]
+                      'sudo service lvm2-lvmetad stop', get_pty=False),
+            mock.call(self.mock_ssh, 'sudo vgchange -an', get_pty=False)]
         mock_exec_ssh_cmd.assert_has_calls(expected_calls)
 
     @mock.patch('coriolis.utils.test_ssh_path')
@@ -65,7 +65,7 @@ class BackupWritersTestCase(test_base.CoriolisBaseTestCase):
 
         expected_calls = [
             mock.call(self.mock_ssh, 'sudo rm %s' % rule_path,
-                      get_pty=True)
+                      get_pty=False)
             for rule_path in rule_paths]
         mock_exec_ssh_cmd.assert_has_calls(expected_calls)
 
@@ -1357,7 +1357,7 @@ class HTTPBackupWriterBootstrapperTestcase(test_base.CoriolisBaseTestCase):
             "accept || "
             "sudo iptables -I INPUT -p tcp --dport %(port)s -j ACCEPT" % {
                 "port": self.writer_port},
-            get_pty=True)
+            get_pty=False)
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     def test__inject_dport_allow_rule_with_exception(self, mock_exec_ssh_cmd):
@@ -1374,7 +1374,7 @@ class HTTPBackupWriterBootstrapperTestcase(test_base.CoriolisBaseTestCase):
         mock_exec_ssh_cmd.assert_called_once_with(
             self._ssh,
             "sudo firewall-cmd --add-port=%s/tcp" %
-            self.writer_port, get_pty=True)
+            self.writer_port, get_pty=False)
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     def test__add_firewalld_port_with_exception(self, mock_exec_ssh_cmd):
@@ -1390,7 +1390,7 @@ class HTTPBackupWriterBootstrapperTestcase(test_base.CoriolisBaseTestCase):
 
         mock_exec_ssh_cmd.assert_called_once_with(
             self._ssh,
-            'sudo chcon -t bin_t /usr/bin/coriolis-writer', get_pty=True)
+            'sudo chcon -t bin_t /usr/bin/coriolis-writer', get_pty=False)
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     def test__change_binary_se_context_with_exception(self, mock_exec_ssh_cmd):
@@ -1440,11 +1440,11 @@ class HTTPBackupWriterBootstrapperTestcase(test_base.CoriolisBaseTestCase):
             mock.call(
                 self._ssh, "sudo mv %s %s" % (
                     remote_tmp_path, self.bootstrapper._writer_cmd),
-                get_pty=True
+                get_pty=False
             ),
             mock.call(
                 self._ssh, "sudo chmod +x %s" % self.bootstrapper._writer_cmd,
-                get_pty=True)])
+                get_pty=False)])
         mock_sftp.close.assert_called_once()
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
@@ -1472,7 +1472,7 @@ class HTTPBackupWriterBootstrapperTestcase(test_base.CoriolisBaseTestCase):
             data.assert_called_once_with(mock.sentinel.local_file, 'wb')
             mock_exec_ssh_cmd.assert_called_once_with(
                 self._ssh, "sudo chmod +r %s" % mock.sentinel.remote_file,
-                get_pty=True)
+                get_pty=False)
 
             data.return_value.write.assert_called_once_with(
                 mock_read_ssh_file.return_value)
@@ -1504,7 +1504,7 @@ class HTTPBackupWriterBootstrapperTestcase(test_base.CoriolisBaseTestCase):
         self.bootstrapper._setup_certificates(self._ssh)
 
         mock_exec_ssh_cmd.assert_any_call(
-            self._ssh, "sudo mkdir -p /etc/coriolis-writer", get_pty=True)
+            self._ssh, "sudo mkdir -p /etc/coriolis-writer", get_pty=False)
         mock_exec_ssh_cmd.assert_any_call(
             self._ssh,
             "sudo %(writer_cmd)s generate-certificates -output-dir "
@@ -1513,7 +1513,7 @@ class HTTPBackupWriterBootstrapperTestcase(test_base.CoriolisBaseTestCase):
                 "cert_dir": "/etc/coriolis-writer",
                 "extra_hosts": self.bootstrapper._ip,
             },
-            get_pty=True)
+            get_pty=False)
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     def test__read_remote_file_sudo(self, mock_exec_ssh_cmd):
@@ -1522,7 +1522,7 @@ class HTTPBackupWriterBootstrapperTestcase(test_base.CoriolisBaseTestCase):
 
         mock_exec_ssh_cmd.assert_called_once_with(
             self._ssh, 'sudo cat "%s"' % mock.sentinel.remote_path,
-            get_pty=True)
+            get_pty=False)
         self.assertEqual(
             result, mock_exec_ssh_cmd.return_value)
 

+ 13 - 13
coriolis/tests/providers/test_replicator.py

@@ -798,7 +798,7 @@ class ReplicatorTestCase(test_base.CoriolisBaseTestCase):
         mock_exec_ssh_cmd.assert_called_once_with(
             self._ssh, "sudo mv %s %s" % (
                 mock_mktemp.return_value, mock.sentinel.remotePath),
-            get_pty=True)
+            get_pty=False)
         mock_sftp.close.assert_called_once()
 
     @mock.patch.object(os.path, 'join')
@@ -819,7 +819,7 @@ class ReplicatorTestCase(test_base.CoriolisBaseTestCase):
         mock_exec_ssh_cmd.assert_called_once_with(
             self._ssh, "sudo chmod +x %s" %
             replicator_module.REPLICATOR_PATH,
-            get_pty=True)
+            get_pty=False)
 
     @mock.patch.object(replicator_module.utils, 'exec_ssh_cmd')
     def test_setup_replicator_group(self, mock_exec_ssh_cmd):
@@ -848,10 +848,10 @@ class ReplicatorTestCase(test_base.CoriolisBaseTestCase):
                       "echo 1 || echo 0" %
                       replicator_module.REPLICATOR_GROUP_NAME),
             mock.call(self._ssh,
-                      "sudo groupadd %s" % group_name, get_pty=True),
+                      "sudo groupadd %s" % group_name, get_pty=False),
             mock.call(self._ssh, "sudo usermod -aG %s %s" % (
                 replicator_module.REPLICATOR_GROUP_NAME,
-                self.conn_info["username"]), get_pty=True)])
+                self.conn_info["username"]), get_pty=False)])
 
         self.assertFalse(result)
 
@@ -881,10 +881,10 @@ class ReplicatorTestCase(test_base.CoriolisBaseTestCase):
                       "sudo useradd -m -s /bin/bash -g %s %s" %
                       (replicator_module.REPLICATOR_USERNAME,
                        replicator_module.REPLICATOR_GROUP_NAME),
-                      get_pty=True),
+                      get_pty=False),
             mock.call(self._ssh,
                       "sudo usermod -aG disk %s" %
-                      replicator_module.REPLICATOR_USERNAME, get_pty=True)])
+                      replicator_module.REPLICATOR_USERNAME, get_pty=False)])
 
     @mock.patch.object(replicator_module.utils, 'create_service')
     def test__exec_replicator_cmd(self, mock_create_service):
@@ -951,18 +951,18 @@ class ReplicatorTestCase(test_base.CoriolisBaseTestCase):
 
         expected_calls = [
             mock.call(self._ssh, "sudo mkdir -p %s" %
-                      replicator_module.REPLICATOR_DIR, get_pty=True),
+                      replicator_module.REPLICATOR_DIR, get_pty=False),
             mock.call(self._ssh, "sudo %s gen-certs -output-dir"
                       % replicator_module.REPLICATOR_PATH +
                       " %s -certificate-hosts 127.0.0.1,%s" %
                       (replicator_module.REPLICATOR_DIR, self.conn_info['ip']),
-                      get_pty=True),
+                      get_pty=False),
             mock.call(self._ssh, "sudo chown -R %s:%s %s" %
                       (replicator_module.REPLICATOR_USERNAME,
                        replicator_module.REPLICATOR_GROUP_NAME,
-                       replicator_module.REPLICATOR_DIR), get_pty=True),
+                       replicator_module.REPLICATOR_DIR), get_pty=False),
             mock.call(self._ssh, "sudo chmod -R g+r %s" %
-                      replicator_module.REPLICATOR_DIR, get_pty=True)]
+                      replicator_module.REPLICATOR_DIR, get_pty=False)]
 
         mock_exec_ssh_cmd.assert_has_calls(expected_calls)
         self.assertEqual(mock_fetch_remote_file.call_count, 3)
@@ -1003,12 +1003,12 @@ class ReplicatorTestCase(test_base.CoriolisBaseTestCase):
             mock.call(
                 self._ssh,
                 "sudo chmod 755 %s" % replicator_module.REPLICATOR_STATE,
-                get_pty=True
+                get_pty=False
             ),
             mock.call(
                 self._ssh,
                 "sudo chcon -t bin_t /usr/bin/replicator",
-                get_pty=True
+                get_pty=False
             ),
         ])
         mock_os_remove.assert_called_once_with(
@@ -1040,7 +1040,7 @@ class ReplicatorTestCase(test_base.CoriolisBaseTestCase):
         mock_exec_ssh_cmd.assert_called_once_with(
             self._ssh,
             "sudo chcon -t bin_t %s" % replicator_module.REPLICATOR_PATH,
-            get_pty=True)
+            get_pty=False)
 
     @mock.patch.object(replicator_module.utils, 'exec_ssh_cmd')
     def test__change_binary_se_context_with_exception(self, mock_exec_ssh_cmd):

+ 20 - 20
coriolis/tests/test_utils.py

@@ -629,7 +629,7 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
         utils.check_fs(self.mock_ssh, "ext4", "/dev/sda1")
 
         self.mock_ssh.exec_command.assert_called_once_with(
-            "sudo fsck -p -t ext4 /dev/sda1", environment=None, get_pty=True,
+            "sudo fsck -p -t ext4 /dev/sda1", environment=None, get_pty=False,
             timeout=None)
 
     @mock.patch.object(utils, 'exec_ssh_cmd')
@@ -640,7 +640,7 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
                           self.mock_ssh, "ext4", "/dev/sda1")
 
         mock_exec_ssh_cmd.assert_called_once_with(
-            self.mock_ssh, "sudo fsck -p -t ext4 /dev/sda1", get_pty=True)
+            self.mock_ssh, "sudo fsck -p -t ext4 /dev/sda1", get_pty=False)
 
     @mock.patch.object(utils, 'exec_ssh_cmd')
     def test_run_xfs_repair(self, mock_exec_ssh_cmd):
@@ -651,11 +651,11 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
         expected_calls = [
             mock.call(self.mock_ssh, "mktemp -d"),
             mock.call(self.mock_ssh, "sudo mount /dev/sda1 /tmp/tmp_dir",
-                      get_pty=True),
+                      get_pty=False),
             mock.call(self.mock_ssh, "sudo umount /tmp/tmp_dir",
-                      get_pty=True),
+                      get_pty=False),
             mock.call(self.mock_ssh, "sudo xfs_repair /dev/sda1",
-                      get_pty=True),
+                      get_pty=False),
         ]
         mock_exec_ssh_cmd.assert_has_calls(expected_calls)
 
@@ -1142,13 +1142,13 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
                                                     mock.ANY)
         mock_exec_ssh_cmd.assert_has_calls([
             mock.call(self.mock_ssh, 'sudo mv /tmp/uuid.service '
-                      '/lib/systemd/system/svc_name.service', get_pty=True),
+                      '/lib/systemd/system/svc_name.service', get_pty=False),
             mock.call(self.mock_ssh, 'sudo restorecon -v '
-                      '/lib/systemd/system/svc_name.service', get_pty=True),
+                      '/lib/systemd/system/svc_name.service', get_pty=False),
             mock.call(self.mock_ssh, 'sudo systemctl daemon-reload',
-                      get_pty=True),
+                      get_pty=False),
             mock.call(self.mock_ssh, 'sudo systemctl start svc_name',
-                      get_pty=True)])
+                      get_pty=False)])
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     @mock.patch('coriolis.utils.write_ssh_file')
@@ -1169,7 +1169,7 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
         mock_exec_ssh_cmd.assert_has_calls([
             mock.call(self.mock_ssh, 'sudo mv /tmp/uuid.service '
                       '/usr/lib/systemd/system/svc_name.service',
-                      get_pty=True)])
+                      get_pty=False)])
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     @mock.patch('coriolis.utils.test_ssh_path')
@@ -1184,7 +1184,7 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
             mock.call(self.mock_ssh,
                       '/lib/systemd/system/svc_name.service')])
         mock_exec_ssh_cmd.assert_called_once_with(
-            self.mock_ssh, 'sudo systemctl start svc_name', get_pty=True)
+            self.mock_ssh, 'sudo systemctl start svc_name', get_pty=False)
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     @mock.patch('coriolis.utils.write_ssh_file')
@@ -1244,13 +1244,13 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
 
         mock_exec_ssh_cmd.assert_has_calls([
             mock.call(self.mock_ssh, 'sudo mv /tmp/uuid.service '
-                      '/lib/systemd/system/svc_name.service', get_pty=True),
+                      '/lib/systemd/system/svc_name.service', get_pty=False),
             mock.call(self.mock_ssh, 'sudo restorecon -v '
-                      '/lib/systemd/system/svc_name.service', get_pty=True),
+                      '/lib/systemd/system/svc_name.service', get_pty=False),
             mock.call(self.mock_ssh, 'sudo systemctl daemon-reload',
-                      get_pty=True),
+                      get_pty=False),
             mock.call(self.mock_ssh, 'sudo systemctl start svc_name',
-                      get_pty=True)])
+                      get_pty=False)])
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     @mock.patch('coriolis.utils.write_ssh_file')
@@ -1272,7 +1272,7 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
                                                     mock.ANY)
         mock_exec_ssh_cmd.assert_has_calls([
             mock.call(self.mock_ssh, 'sudo mv /tmp/uuid.conf '
-                      '/etc/init/svc_name.conf', get_pty=True),
+                      '/etc/init/svc_name.conf', get_pty=False),
             mock.call(self.mock_ssh, 'start svc_name')])
 
     @mock.patch('coriolis.utils.test_ssh_path')
@@ -1308,7 +1308,7 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
 
         mock_exec_ssh_cmd.assert_has_calls([
             mock.call(self.mock_ssh, 'sudo mv /tmp/uuid.conf '
-                      '/etc/init/svc_name.conf', get_pty=True),
+                      '/etc/init/svc_name.conf', get_pty=False),
             mock.call(self.mock_ssh, 'start svc_name')])
 
     @mock.patch('coriolis.utils._write_systemd')
@@ -1358,7 +1358,7 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
         mock_test_ssh.assert_called_once_with(self.mock_ssh,
                                               '/lib/systemd/system')
         mock_exec_ssh_cmd.assert_called_once_with(
-            self.mock_ssh, 'sudo systemctl restart svc_name', get_pty=True)
+            self.mock_ssh, 'sudo systemctl restart svc_name', get_pty=False)
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     @mock.patch('coriolis.utils.test_ssh_path')
@@ -1392,7 +1392,7 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
         mock_test_ssh.assert_called_once_with(self.mock_ssh,
                                               '/lib/systemd/system')
         mock_exec_ssh_cmd.assert_called_once_with(
-            self.mock_ssh, 'sudo systemctl start svc_name', get_pty=True)
+            self.mock_ssh, 'sudo systemctl start svc_name', get_pty=False)
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     @mock.patch('coriolis.utils.test_ssh_path')
@@ -1426,7 +1426,7 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
         mock_test_ssh.assert_called_once_with(self.mock_ssh,
                                               '/lib/systemd/system')
         mock_exec_ssh_cmd.assert_called_once_with(
-            self.mock_ssh, 'sudo systemctl stop svc_name', get_pty=True)
+            self.mock_ssh, 'sudo systemctl stop svc_name', get_pty=False)
 
     @mock.patch('coriolis.utils.exec_ssh_cmd')
     @mock.patch('coriolis.utils.test_ssh_path')

+ 16 - 15
coriolis/utils.py

@@ -324,7 +324,8 @@ def list_ssh_dir(ssh, remote_path):
         LOG.warning(
             "SFTP listdir failed, falling back to shell command. "
             "Error: %s", get_exception_details())
-        output = exec_ssh_cmd(ssh, "sudo ls -1 %s" % remote_path, get_pty=True)
+        output = exec_ssh_cmd(
+            ssh, "sudo ls -1 %s" % remote_path, get_pty=False)
         return [f for f in output.splitlines() if f.strip()]
 
 
@@ -351,7 +352,7 @@ def check_env_command(ssh):
     """
 
     try:
-        exec_ssh_cmd(ssh, "command -v env", get_pty=True)
+        exec_ssh_cmd(ssh, "command -v env", get_pty=False)
     except (exception.SSHCommandFailed,
             exception.SSHCommandNotFoundException) as ex:
         raise exception.CoriolisException(
@@ -452,7 +453,7 @@ def check_fs(ssh, fs_type, dev_path):
     try:
         out = exec_ssh_cmd(
             ssh, "sudo fsck -p -t %s %s" % (fs_type, dev_path),
-            get_pty=True)
+            get_pty=False)
         LOG.debug("File system checked:\n%s", out)
     except Exception:
         LOG.warn("Checking file system returned an error:\n%s" % (
@@ -467,14 +468,14 @@ def run_xfs_repair(ssh, dev_path):
         LOG.debug("mounting %s on %s" % (dev_path, tmp_dir))
         mount_out = exec_ssh_cmd(
             ssh, "sudo mount %s %s" % (dev_path, tmp_dir),
-            get_pty=True)
+            get_pty=False)
         LOG.debug("mount returned: %s" % mount_out)
         LOG.debug("Umounting %s" % tmp_dir)
         umount_out = exec_ssh_cmd(
-            ssh, "sudo umount %s" % tmp_dir, get_pty=True)
+            ssh, "sudo umount %s" % tmp_dir, get_pty=False)
         LOG.debug("umounting returned: %s" % umount_out)
         out = exec_ssh_cmd(
-            ssh, "sudo xfs_repair %s" % dev_path, get_pty=True)
+            ssh, "sudo xfs_repair %s" % dev_path, get_pty=False)
         LOG.debug("File system repaired:\n%s", out)
     except Exception as ex:
         LOG.warn("xfs_repair returned an error:\n%s", str(ex))
@@ -859,22 +860,22 @@ def _write_systemd(ssh, cmdline, svcname, run_as=None, start=True):
     if test_ssh_path(ssh, serviceFilePath):
         if start:
             exec_ssh_cmd(
-                ssh, "sudo systemctl start %s" % svcname, get_pty=True)
+                ssh, "sudo systemctl start %s" % svcname, get_pty=False)
         return
 
     def _reload_and_start(start=True):
         exec_ssh_cmd(
             ssh, "sudo systemctl daemon-reload",
-            get_pty=True)
+            get_pty=False)
         if start:
             exec_ssh_cmd(
                 ssh, "sudo systemctl start %s" % svcname,
-                get_pty=True)
+                get_pty=False)
 
     def _correct_selinux_label():
         cmd = "sudo restorecon -v %s" % serviceFilePath
         try:
-            exec_ssh_cmd(ssh, cmd, get_pty=True)
+            exec_ssh_cmd(ssh, cmd, get_pty=False)
         except exception.CoriolisException:
             LOG.warn(
                 "Could not relabel service '%s'. SELinux might not be "
@@ -896,7 +897,7 @@ def _write_systemd(ssh, cmdline, svcname, run_as=None, start=True):
     exec_ssh_cmd(
         ssh,
         "sudo mv /tmp/%s.service %s" % (name, serviceFilePath),
-        get_pty=True)
+        get_pty=False)
     _correct_selinux_label()
     _reload_and_start(start=start)
 
@@ -920,7 +921,7 @@ def _write_upstart(ssh, cmdline, svcname, run_as=None, start=True):
     exec_ssh_cmd(
         ssh,
         "sudo mv /tmp/%s.conf %s" % (name, serviceFilePath),
-        get_pty=True)
+        get_pty=False)
     if start:
         exec_ssh_cmd(ssh, "start %s" % svcname)
 
@@ -948,7 +949,7 @@ def create_service(ssh, cmdline, svcname, run_as=None, start=True):
 
 def restart_service(ssh, svcname):
     if _has_systemd(ssh):
-        exec_ssh_cmd(ssh, "sudo systemctl restart %s" % svcname, get_pty=True)
+        exec_ssh_cmd(ssh, "sudo systemctl restart %s" % svcname, get_pty=False)
     elif test_ssh_path(ssh, "/etc/init"):
         exec_ssh_cmd(ssh, "restart %s" % svcname)
     else:
@@ -957,7 +958,7 @@ def restart_service(ssh, svcname):
 
 def start_service(ssh, svcname):
     if _has_systemd(ssh):
-        exec_ssh_cmd(ssh, "sudo systemctl start %s" % svcname, get_pty=True)
+        exec_ssh_cmd(ssh, "sudo systemctl start %s" % svcname, get_pty=False)
     elif test_ssh_path(ssh, "/etc/init"):
         exec_ssh_cmd(ssh, "start %s" % svcname)
     else:
@@ -966,7 +967,7 @@ def start_service(ssh, svcname):
 
 def stop_service(ssh, svcname):
     if _has_systemd(ssh):
-        exec_ssh_cmd(ssh, "sudo systemctl stop %s" % svcname, get_pty=True)
+        exec_ssh_cmd(ssh, "sudo systemctl stop %s" % svcname, get_pty=False)
     elif test_ssh_path(ssh, "/etc/init"):
         exec_ssh_cmd(ssh, "stop %s" % svcname)
     else: