Skip to content

Commit

Permalink
updated the check for the cluster restore to use the config instead of .
Browse files Browse the repository at this point in the history
  • Loading branch information
philipfischbacher committed Apr 16, 2024
1 parent 3e98d9a commit f422199
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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

0 comments on commit f422199

Please sign in to comment.