|
2 | 2 |
|
3 | 3 | import fauxfactory |
4 | 4 | import pytest |
| 5 | +from dateutil import relativedelta |
5 | 6 |
|
6 | 7 | from . import tag_delete_from_category |
7 | 8 | from cfme import test_requirements |
8 | 9 | from cfme.automate.explorer.klass import ClassDetailsView |
9 | 10 | from cfme.automate.simulation import simulate |
| 11 | +from cfme.fixtures.automate import round_min |
10 | 12 | from cfme.rest.gen_data import users as _users |
11 | 13 | from cfme.services.service_catalogs import ServiceCatalogs |
12 | 14 | from cfme.utils.appliance.implementations.rest import ViaREST |
|
21 | 23 | pytestmark = [test_requirements.automate, pytest.mark.tier(2)] |
22 | 24 |
|
23 | 25 |
|
| 26 | +@pytest.fixture |
| 27 | +def custom_automate_setup(domain, namespace): |
| 28 | + auto_class = namespace.classes.create( |
| 29 | + name=fauxfactory.gen_alphanumeric(15, start="class_"), |
| 30 | + display_name=fauxfactory.gen_alpha(), |
| 31 | + description=fauxfactory.gen_alpha(), |
| 32 | + ) |
| 33 | + |
| 34 | + method = auto_class.methods.create( |
| 35 | + name=fauxfactory.gen_alphanumeric(15, start="method_"), |
| 36 | + location="inline", |
| 37 | + script='$evm.log(:info, "Hello World")', |
| 38 | + ) |
| 39 | + schema_field = { |
| 40 | + "name": fauxfactory.gen_alphanumeric(15, start="schema_"), |
| 41 | + "type": "Method", |
| 42 | + "data_type": "String", |
| 43 | + } |
| 44 | + auto_class.schema.add_fields(schema_field) |
| 45 | + |
| 46 | + instance = auto_class.instances.create( |
| 47 | + name=fauxfactory.gen_alphanumeric(15, start="instance_"), |
| 48 | + fields={schema_field["name"]: {"value": method.name}}, |
| 49 | + ) |
| 50 | + yield domain, namespace, auto_class, instance |
| 51 | + auto_class.delete() |
| 52 | + |
| 53 | + |
24 | 54 | @pytest.fixture(scope='function') |
25 | 55 | def original_class(domain): |
26 | 56 | # Take the 'Request' class and copy it for own purpose. |
@@ -797,3 +827,90 @@ def test_delete_tag_from_category(custom_instance): |
797 | 827 | "instance": instance.name, |
798 | 828 | }, |
799 | 829 | ) |
| 830 | + |
| 831 | + |
| 832 | +@pytest.mark.customer_scenario |
| 833 | +@pytest.mark.meta(automate=[1713072, 1745197]) |
| 834 | +def test_automate_task_schedule(appliance, custom_automate_setup, current_server_time, request): |
| 835 | + """ |
| 836 | + Polarion: |
| 837 | + assignee: dgaikwad |
| 838 | + initialEstimate: 1/8h |
| 839 | + caseposneg: positive |
| 840 | + casecomponent: Automate |
| 841 | + setup: |
| 842 | + 1. Create domain, namespace, class and instance |
| 843 | + 2. Also create automate method with below ruby code: |
| 844 | + >> $evm.log(:info, "Hello World") |
| 845 | + testSteps: |
| 846 | + 1. Go to Configuration > Settings > Zones > Schedules |
| 847 | + 2. Create schedule with required fields: |
| 848 | + >> Action - Automation Tasks |
| 849 | + >> Object Details(Request) - Call_Instance |
| 850 | + >> Attribute/Value Pairs |
| 851 | + >> domain - domain_name |
| 852 | + >> namespace - namespace_name |
| 853 | + >> class - class_name |
| 854 | + >> instance - instance_name |
| 855 | + >> Timer Options |
| 856 | + 3. Check automation logs more than 1 times |
| 857 | + expectedResults: |
| 858 | + 1. |
| 859 | + 2. |
| 860 | + 3. Automate method should be executed on scheduled time. |
| 861 | +
|
| 862 | + Bugzilla: |
| 863 | + 1713072 |
| 864 | + """ |
| 865 | + domain, namespace, auto_class, instance = custom_automate_setup |
| 866 | + current_time, tz_num = current_server_time |
| 867 | + start_date = current_time + relativedelta.relativedelta(minutes=5) |
| 868 | + view = navigate_to(appliance.collections.system_schedules, 'Add') |
| 869 | + available_list = view.form.time_zone.all_options |
| 870 | + tz_select = next(tz.text for tz in available_list if f'{tz_num[0:3]}:00'in tz.text) |
| 871 | + if round_min(start_date.minute) == 0: |
| 872 | + start_date = start_date + relativedelta.relativedelta(minutes=60 - start_date.minute) |
| 873 | + start_date_minute = str(start_date.minute) |
| 874 | + else: |
| 875 | + start_date_minute = str(round_min(start_date.minute)) |
| 876 | + |
| 877 | + attribute_value_pairs = { |
| 878 | + "domain": domain.name, |
| 879 | + "namespace": namespace.name, |
| 880 | + "class": auto_class.name, |
| 881 | + "instance": instance.name, |
| 882 | + } |
| 883 | + |
| 884 | + schedule = appliance.collections.system_schedules.create( |
| 885 | + name=fauxfactory.gen_alphanumeric(), |
| 886 | + description=fauxfactory.gen_alphanumeric(), |
| 887 | + action_type="Automation Tasks", |
| 888 | + request="Call_Instance", |
| 889 | + attribute_value_pairs=attribute_value_pairs, |
| 890 | + run_type="Hourly", |
| 891 | + time_zone=tz_select, |
| 892 | + start_hour=str(start_date.hour), |
| 893 | + start_minute=start_date_minute, |
| 894 | + ) |
| 895 | + |
| 896 | + @request.addfinalizer |
| 897 | + def _finalize(): |
| 898 | + try: |
| 899 | + schedule.delete_if_exists() |
| 900 | + except TypeError: |
| 901 | + # Delete failing only on PRT with type error |
| 902 | + pass |
| 903 | + |
| 904 | + matched_pattern = ".*INFO.* : Q-task_id.* Hello World" |
| 905 | + |
| 906 | + def _check_automation_log(): |
| 907 | + log = LogValidator("/var/www/miq/vmdb/log/automation.log", |
| 908 | + matched_patterns=[matched_pattern] |
| 909 | + ) |
| 910 | + log.start_monitoring() |
| 911 | + log.validate(wait="15m") |
| 912 | + |
| 913 | + _check_automation_log() |
| 914 | + next_run_date = start_date + relativedelta.relativedelta(minutes=-5, hours=1) |
| 915 | + appliance.ssh_client.run_command(f"date {next_run_date.strftime('%m%d%H%M%Y')}") |
| 916 | + _check_automation_log() |
0 commit comments