Skip to content
Snippets Groups Projects
Commit ff7ddc87 authored by Robert Latta's avatar Robert Latta
Browse files

added check of known_hosts to export and relevant tests

parent fb62f19a
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,8 @@ CONFIG_SCHEMA = {
"otrs-export": {
"username": {"type": "string"},
"private-key": {"type": "string"},
"destination": {"type": "string"}
"destination": {"type": "string"},
"known-hosts": {"type": "string"}
},
"ims": {
"api": {"type": "string"},
......
......@@ -51,7 +51,7 @@ def export_data_for_otrs(self, files_to_export=None):
ims_config = InventoryTask.config["ims"]
otrs_config = InventoryTask.config["otrs-export"]
command_template = 'rsync -aP --rsh="ssh -l {user} -p 22 -i {key_file}" {source_dir}/* {destination}' # noqa
command_template = 'rsync -aP --rsh="ssh -l {user} -p 22 -i {key_file} -o \'UserKnownHostsFile {known_hosts}\'" {source_dir}/* {destination}' # noqa
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = Path(temp_dir)
......@@ -77,6 +77,7 @@ def export_data_for_otrs(self, files_to_export=None):
command = command_template.format(
user=otrs_config['username'],
key_file=otrs_config['private-key'],
known_hosts=otrs_config['known-hosts'],
source_dir=temp_dir,
destination=otrs_config['destination']
)
......
......@@ -50,7 +50,8 @@ def data_config_filename():
"otrs-export": {
"username": "otrs_username",
"private-key": "otrs_ky_loc",
"destination": "otrs_dest"
"destination": "otrs_dest",
"known-hosts": "otrs_known_hosts"
},
"ims": {
"api": "ims_api",
......
......@@ -33,11 +33,12 @@ def test_otrs_exports(data_config_filename, data_config, mocker):
args, kwargs = mocked_run.call_args
called_with = args[0]
t = 'rsync -aP --rsh="ssh -l {user} -p 22 -i {key_file}" .+\\/\\* {destination}' # noqa
t = r'^rsync -aP --rsh="ssh -l {user} -p 22 -i {key_file} -o \'UserKnownHostsFile {known_hosts}\'" /\w+/\w+/\* {destination}$' # noqa
p = t.format(
user=otrs_config['username'],
key_file=otrs_config['private-key'],
destination=otrs_config['destination'])
assert re.match(p, called_with)
destination=otrs_config['destination'],
known_hosts=otrs_config['known-hosts']
)
assert bool(re.match(p, called_with))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment