Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and fix SSH service restart on OSMount worker SSH env configuration #333

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading