Skip to content

Commit

Permalink
Refactor and fix SSH service restart on OSMount worker SSH env config…
Browse files Browse the repository at this point in the history
…uration

On newer Ubuntu (starting with 24.04) Server images, `sshd` service name has
been changed to `ssh`. This patch handles this rename and refactors it into
the base OSMount class, in order for it to be picked up for all Linux OSMount
minions.
  • Loading branch information
Dany9966 committed Jul 31, 2024
1 parent e735358 commit c215168
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
12 changes: 10 additions & 2 deletions coriolis/osmorphing/osmount/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from coriolis import exception
from coriolis import utils


LOG = logging.getLogger(__name__)

MAJOR_COLUMN_INDEX = 4
Expand Down Expand Up @@ -96,7 +95,16 @@ def setup(self):
self._connect()

def _allow_ssh_env_vars(self):
pass
self._exec_cmd('sudo sed -i -e "\$aAcceptEnv *" /etc/ssh/sshd_config')
try:
utils.restart_service(self._ssh, "sshd")
except exception.CoriolisException:
# Newer Ubuntu distros renamed this service to `ssh`
LOG.warning(
"Could not restart service sshd. Attempting to restart ssh "
"service")
utils.restart_service(self._ssh, 'ssh')
return True

def _exec_cmd(self, cmd, timeout=None):
if not timeout:
Expand Down
5 changes: 0 additions & 5 deletions coriolis/osmorphing/osmount/redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,3 @@ def setup(self):
self._exec_cmd("sudo -E yum install -y lvm2 psmisc")
self._exec_cmd("sudo modprobe dm-mod")
self._exec_cmd("sudo rm -f /etc/lvm/devices/system.devices")

def _allow_ssh_env_vars(self):
self._exec_cmd('sudo sed -i -e "\$aAcceptEnv *" /etc/ssh/sshd_config')
utils.restart_service(self._ssh, "sshd")
return True
5 changes: 0 additions & 5 deletions coriolis/osmorphing/osmount/ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,3 @@ def setup(self):
"install lvm2 psmisc -y")

self._exec_cmd("sudo modprobe dm-mod")

def _allow_ssh_env_vars(self):
self._exec_cmd('sudo sed -i -e "\$aAcceptEnv *" /etc/ssh/sshd_config')
utils.restart_service(self._ssh, "sshd")
return True
8 changes: 6 additions & 2 deletions coriolis/tests/osmorphing/osmount/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ def test__connect(self, mock_wait_for_port_connectivity, mock_ssh_client):
self.conn_info['ip'], 22)
)

def test_setup(self):
@mock.patch.object(base.BaseSSHOSMountTools, '_allow_ssh_env_vars')
@mock.patch.object(base.BaseSSHOSMountTools, '_connect')
def test_setup(self, mock_connect, mock_allow_ssh_vars):
self.base_os_mount_tools.setup()
self.ssh.close_assert_called_once()
mock_allow_ssh_vars.return_value = True
self.ssh.close.assert_called_once_with()
mock_connect.assert_called_once_with()

@mock.patch.object(base.utils, 'exec_ssh_cmd')
def test__exec_cmd(self, mock_exec_ssh_cmd):
Expand Down

0 comments on commit c215168

Please sign in to comment.