From 8702a93fcfc282ce74f4e78d6960406fc9cf2beb Mon Sep 17 00:00:00 2001 From: Peter Ondrejka Date: Wed, 1 Nov 2023 13:47:15 +0100 Subject: [PATCH] remove accidentally cherry-picked file (#13025) remove accidentaly cherry-picked file --- tests/foreman/api/test_notifications.py | 227 ------------------------ 1 file changed, 227 deletions(-) delete mode 100644 tests/foreman/api/test_notifications.py diff --git a/tests/foreman/api/test_notifications.py b/tests/foreman/api/test_notifications.py deleted file mode 100644 index a8b4c24ebf8..00000000000 --- a/tests/foreman/api/test_notifications.py +++ /dev/null @@ -1,227 +0,0 @@ -"""Test class for Notifications API - -:Requirement: Notifications - -:CaseAutomation: Automated - -:CaseLevel: Acceptance - -:CaseComponent: Notifications - -:Team: Endeavour - -:TestType: Functional - -:CaseImportance: High - -:Upstream: No -""" -from mailbox import mbox -from re import findall -from tempfile import mkstemp - -from fauxfactory import gen_string -import pytest -from wait_for import TimedOutError, wait_for - -from robottelo.config import settings -from robottelo.constants import DEFAULT_LOC, DEFAULT_ORG -from robottelo.utils.issue_handlers import is_open - - -@pytest.fixture -def admin_user_with_localhost_email(target_sat): - """Admin user with e-mail set to `root@localhost`.""" - user = target_sat.api.User( - admin=True, - default_organization=DEFAULT_ORG, - default_location=DEFAULT_LOC, - description='created by nailgun', - login=gen_string("alphanumeric"), - password=gen_string("alphanumeric"), - mail='root@localhost', - ).create() - user.mail_enabled = True - user.update() - - yield user - - user.delete() - - -@pytest.fixture -def reschedule_long_running_tasks_notification(target_sat): - """Reschedule long-running tasks checker from midnight (default) to every minute. - Reset it back after the test. - """ - default_cron_schedule = '0 0 * * *' - every_minute_cron_schedule = '* * * * *' - - assert ( - target_sat.execute( - f"FOREMAN_TASKS_CHECK_LONG_RUNNING_TASKS_CRONLINE='{every_minute_cron_schedule}' " - "foreman-rake foreman_tasks:reschedule_long_running_tasks_checker" - ).status - == 0 - ) - - yield - - assert ( - target_sat.execute( - f"FOREMAN_TASKS_CHECK_LONG_RUNNING_TASKS_CRONLINE='{default_cron_schedule}' " - "foreman-rake foreman_tasks:reschedule_long_running_tasks_checker" - ).status - == 0 - ) - - -@pytest.fixture -def start_postfix_service(target_sat): - """Start postfix service (disabled by default).""" - assert target_sat.execute('systemctl start postfix').status == 0 - - -@pytest.fixture -def clean_root_mailbox(target_sat): - """Backup & purge local mailbox of the Satellite's root@localhost user. - Restore it afterwards. - """ - root_mailbox = '/var/spool/mail/root' - root_mailbox_backup = f'{root_mailbox}-{gen_string("alphanumeric")}.bak' - target_sat.execute(f'cp -f {root_mailbox} {root_mailbox_backup}') - target_sat.execute(f'truncate -s 0 {root_mailbox}') - - yield root_mailbox - - target_sat.execute(f'mv -f {root_mailbox_backup} {root_mailbox}') - - -@pytest.fixture -def wait_for_long_running_task_mail(target_sat, clean_root_mailbox, long_running_task): - """Wait until the long-running task ID is found in the Satellite's mbox file.""" - timeout = 300 - try: - wait_for( - func=target_sat.execute, - func_args=[f'grep --quiet {long_running_task["task"]["id"]} {clean_root_mailbox}'], - fail_condition=lambda res: res.status == 0, - timeout=timeout, - delay=5, - ) - except TimedOutError: - raise AssertionError( - f'No notification e-mail with long-running task ID {long_running_task["task"]["id"]} ' - f'has arrived to {clean_root_mailbox} after {timeout} seconds.' - ) - return True - - -@pytest.fixture -def root_mailbox_copy(target_sat, clean_root_mailbox, wait_for_long_running_task_mail): - """Parsed local system copy of the Satellite's root user mailbox. - - :returns: :class:`mailbox.mbox` instance - """ - assert wait_for_long_running_task_mail - result = target_sat.execute(f'cat {clean_root_mailbox}') - assert result.status == 0, f'Could not read mailbox {clean_root_mailbox} on Satellite host.' - mbox_content = result.stdout - _, local_mbox_file = mkstemp() - with open(local_mbox_file, 'w') as fh: - fh.writelines(mbox_content) - return mbox(path=local_mbox_file) - - -@pytest.fixture -def long_running_task(target_sat): - """Create an async task and set its start time and last report time to two days ago. - After the test finishes, the task is cancelled. - """ - template_id = ( - target_sat.api.JobTemplate() - .search(query={'search': 'name="Run Command - Script Default"'})[0] - .id - ) - job = target_sat.api.JobInvocation().run( - synchronous=False, - data={ - 'job_template_id': template_id, - 'organization': DEFAULT_ORG, - 'location': DEFAULT_LOC, - 'inputs': { - 'command': 'sleep 300', - }, - 'targeting_type': 'static_query', - 'search_query': f'name = {target_sat.hostname}', - 'password': settings.server.ssh_password, - }, - ) - sql_date_2_days_ago = "now() - INTERVAL \'2 days\'" - result = target_sat.execute( - "su - postgres -c \"psql foreman postgres <