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

removed call of otrs-exports as a celery task; made the rsync call quiet

parent 32f5602a
No related branches found
No related tags found
No related merge requests found
......@@ -63,9 +63,9 @@ def send_exports():
response=html.escape(f'Bad value for <files> {files_value}'),
status=requests.codes.bad_request,
mimetype="text/html")
task = export_data_for_otrs.delay(
debug_uuid = export_data_for_otrs(
files_to_export=files_value, export_duplicates=duplicates)
return Response(
response=task.id,
response=f'Exports sent, search logs for {debug_uuid} for details',
status=requests.codes.ok,
mimetype="text/html")
......@@ -6,6 +6,7 @@ import tempfile
from datetime import datetime
from enum import IntFlag
from pathlib import Path
from uuid import uuid4
from inventory_provider.db import ims_data
from inventory_provider.db.ims import IMS
......@@ -48,6 +49,8 @@ class OTRSFiles(IntFlag):
@app.task(base=InventoryTask, bind=True, name='export_data_for_otrs')
@log_task_entry_and_exit
def export_data_for_otrs(self, files_to_export=None, export_duplicates=False):
debug_uuid = uuid4()
logger.debug(f'debug uuid: {debug_uuid}')
if files_to_export:
files_to_export = OTRSFiles(files_to_export)
else:
......@@ -56,7 +59,7 @@ def export_data_for_otrs(self, files_to_export=None, export_duplicates=False):
ims_config = InventoryTask.config["ims"]
otrs_config = InventoryTask.config["otrs-export"]
command_template = 'rsync -aP --rsh="ssh -l {user} -p 22 -i {key_file} -o \'UserKnownHostsFile {known_hosts}\'" {source_dir}/* {destination}' # noqa
command_template = 'rsync -aPq --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)
......@@ -88,3 +91,4 @@ def export_data_for_otrs(self, files_to_export=None, export_duplicates=False):
destination=otrs_config['destination']
)
subprocess.run(command, shell=True, check=True)
return debug_uuid
......@@ -33,7 +33,7 @@ def test_otrs_exports(data_config_filename, data_config, mocker):
args, kwargs = mocked_run.call_args
called_with = args[0]
t = r'^rsync -aP --rsh="ssh -l {user} -p 22 -i {key_file} -o \'UserKnownHostsFile {known_hosts}\'" /\S+/\* {destination}$' # noqa
t = r'^rsync -aPq --rsh="ssh -l {user} -p 22 -i {key_file} -o \'UserKnownHostsFile {known_hosts}\'" /\S+/\* {destination}$' # noqa
p = t.format(
user=otrs_config['username'],
......
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