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

Updated the check for the cluster restore to use the use_sudo_for_restore config instead of use_sudo #749

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion medusa/restore_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def _build_restore_cmd(self):
'{in_place} {keep_auth} %s {verify} --backup-name {backup} --temp-dir {temp_dir} ' \
'{use_sstableloader} {keyspaces} {tables}' \
.format(work=self.work_dir,
sudo='sudo' if medusa.utils.evaluate_boolean(self.config.cassandra.use_sudo) else '',
sudo='sudo' if medusa.utils.evaluate_boolean(self.config.storage.use_sudo_for_restore) else '',
config=f'--config-file {self.config.file_path}' if self.config.file_path else '',
in_place=in_place_option,
keep_auth=keep_auth_option,
Expand Down
13 changes: 8 additions & 5 deletions tests/restore_cluster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def _build_config_parser():

config = configparser.ConfigParser(interpolation=None)
config['storage'] = {
'host_file_separator': ','
'host_file_separator': ',',
'use_sudo_for_restore': 'True',
}
config['cassandra'] = {
'config_file': os.path.join(os.path.dirname(__file__),
Expand Down Expand Up @@ -359,15 +360,15 @@ def test_build_restore_command_default(self):
"""Ensure that a restore uses sudo by default"""
cmd = self.default_restore_job._build_restore_cmd()
# sudo is enabled by default
assert evaluate_boolean(self.medusa_config.cassandra.use_sudo)
assert evaluate_boolean(self.medusa_config.storage.use_sudo_for_restore)
# Ensure that Kubernetes mode is not enabled in default test config
assert not evaluate_boolean(self.medusa_config.kubernetes.enabled if self.medusa_config.kubernetes else False)
assert 'sudo' in cmd

def test_build_restore_command_without_sudo(self):
"""Ensure that a restore can be done without using sudo"""
config = self._build_config_parser()
config['cassandra']['use_sudo'] = 'False'
config['storage']['use_sudo_for_restore'] = 'False'

medusa_config = MedusaConfig(
file_path=None,
Expand All @@ -382,8 +383,10 @@ def test_build_restore_command_without_sudo(self):
)
restore_job = RestoreJob(Mock(), medusa_config, self.tmp_dir, None, None, False, False, None)
cmd = restore_job._build_restore_cmd()
assert not evaluate_boolean(medusa_config.cassandra.use_sudo)
assert 'sudo' not in cmd, 'command line should not contain sudo when use_sudo is explicitly set to False'
assert not evaluate_boolean(medusa_config.storage.use_sudo_for_restore)
assert 'sudo' not in cmd, (
'command line should not contain sudo when use_sudo_for_restore is explicitly set to False'
)

def test_build_restore_command_kubernetes(self):
"""Ensure Kubernetes mode does not generate a command line with sudo"""
Expand Down
Loading