From 3d31f4c37c5e8f88963881368fb77f6b48f0fd01 Mon Sep 17 00:00:00 2001 From: Satyajit Bulage Date: Tue, 16 Jul 2019 00:09:05 +0530 Subject: [PATCH 1/6] Fixed Ansible Service tests. --- .../ansible/test_embedded_ansible_services.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cfme/tests/ansible/test_embedded_ansible_services.py b/cfme/tests/ansible/test_embedded_ansible_services.py index 0076c34445..b1e5c886c5 100644 --- a/cfme/tests/ansible/test_embedded_ansible_services.py +++ b/cfme/tests/ansible/test_embedded_ansible_services.py @@ -277,7 +277,12 @@ def test_service_ansible_playbook_bundle(appliance, ansible_catalog_item): @pytest.mark.tier(2) def test_service_ansible_playbook_provision_in_requests( - appliance, ansible_catalog_item, ansible_service, ansible_service_request, request + appliance, + ansible_catalog_item, + ansible_service_catalog, + ansible_service, + ansible_service_request, + request, ): """Tests if ansible playbook service provisioning is shown in service requests. @@ -288,7 +293,7 @@ def test_service_ansible_playbook_provision_in_requests( initialEstimate: 1/6h tags: ansible_embed """ - ansible_service.order() + ansible_service_catalog.order() ansible_service_request.wait_for_request() cat_item_name = ansible_catalog_item.name request_descr = "Provisioning Service [{0}] from [{0}]".format(cat_item_name) @@ -450,7 +455,7 @@ def _finalize(): @pytest.mark.tier(3) def test_service_ansible_playbook_plays_table( - ansible_service_request, ansible_service, soft_assert + ansible_service_catalog, ansible_service, ansible_service_request, soft_assert ): """Plays table in provisioned and retired service should contain at least one row. @@ -461,12 +466,12 @@ def test_service_ansible_playbook_plays_table( initialEstimate: 1/6h tags: ansible_embed """ - ansible_service.order() + ansible_service_catalog.order() ansible_service_request.wait_for_request() view = navigate_to(ansible_service, "Details") - soft_assert(view.provisioning.plays.row_count > 1, "Plays table in provisioning tab is empty") + soft_assert(view.provisioning.plays.row_count >= 1, "Plays table in provisioning tab is empty") ansible_service.retire() - soft_assert(view.provisioning.plays.row_count > 1, "Plays table in retirement tab is empty") + soft_assert(view.retirement.plays.row_count >= 1, "Plays table in retirement tab is empty") @pytest.mark.tier(3) @@ -520,7 +525,7 @@ def test_service_ansible_playbook_pass_extra_vars( pre = stdout.text json_str = pre.split("--------------------------------") result_dict = json.loads(json_str[5].replace('", "', "").replace('\\"', '"').replace( - '\\, "', '",').split('" ] } PLAY')[0]) + '\\, "', '",').replace("\\", "").split('" ] } PLAY')[0]) assert result_dict["some_var"] == "some_value" From 7a0c3cc15c2aaa8633e55c23129299f5237534f2 Mon Sep 17 00:00:00 2001 From: Satyajit Bulage Date: Mon, 22 Jul 2019 15:54:26 +0530 Subject: [PATCH 2/6] Converted scope of module and added description for multiple replaces. --- cfme/tests/ansible/test_embedded_ansible_services.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cfme/tests/ansible/test_embedded_ansible_services.py b/cfme/tests/ansible/test_embedded_ansible_services.py index b1e5c886c5..0a24430092 100644 --- a/cfme/tests/ansible/test_embedded_ansible_services.py +++ b/cfme/tests/ansible/test_embedded_ansible_services.py @@ -523,6 +523,9 @@ def test_service_ansible_playbook_pass_extra_vars( stdout = getattr(view, action).standart_output stdout.wait_displayed() pre = stdout.text + # Standard output has several sections splitted by -------------------------------- + # Required data is located in 6th section + # Then we need to replace or remove some characters to get a parsable json string json_str = pre.split("--------------------------------") result_dict = json.loads(json_str[5].replace('", "', "").replace('\\"', '"').replace( '\\, "', '",').replace("\\", "").split('" ] } PLAY')[0]) From 44d2e94700a05c314e60ad390b7d262e8fa978ed Mon Sep 17 00:00:00 2001 From: Satyajit Bulage Date: Thu, 25 Jul 2019 17:22:01 +0530 Subject: [PATCH 3/6] Added "Retired Services" navigations in Service to support Retired view. --- cfme/services/myservice/ui.py | 40 +++++++++++++++++++ .../ansible/test_embedded_ansible_services.py | 1 + 2 files changed, 41 insertions(+) diff --git a/cfme/services/myservice/ui.py b/cfme/services/myservice/ui.py index 539aba743c..33c2880c7a 100644 --- a/cfme/services/myservice/ui.py +++ b/cfme/services/myservice/ui.py @@ -163,6 +163,26 @@ def is_displayed(self): self.title.text == 'Service "{}"'.format(self.context['object'].name)) +class MyServiceRetiredView(MyServicesView): + """ is_displayed for Retired view. """ + + @property + def is_displayed(self): + return self.in_myservices and self.myservice.is_opened + + +class MyServiceRetiredDetailsView(MyServiceDetailView): + """ is_displayed for RetiredDetails view. """ + + @property + def is_displayed(self): + return ( + self.in_myservices + and self.myservice.is_opened + and self.title.text == 'Service "{}"'.format(self.context["object"].name) + ) + + class EditMyServiceView(ServiceEditForm): title = Text('#explorer_title_text') @@ -422,6 +442,26 @@ def step(self, *args, **kwargs): 'Set Retirement Dates for this Service') +@navigator.register(MyService, 'Retired') +class MyServiceRetired(CFMENavigateStep): + VIEW = MyServiceRetiredView + + prerequisite = NavigateToSibling('All') + + def step(self, *args, **kwargs): + self.prerequisite_view.myservice.tree.click_path('Retired Services') + + +@navigator.register(MyService, 'RetiredDetails') +class MyServiceRetiredDetails(CFMENavigateStep): + VIEW = MyServiceRetiredDetailsView + + prerequisite = NavigateToSibling('Retired') + + def step(self, *args, **kwargs): + self.prerequisite_view.entities.get_entity(name=self.obj.name, surf_pages=True).click() + + @navigator.register(MyService, 'Reconfigure') class MyServiceReconfigure(CFMENavigateStep): VIEW = ReconfigureServiceView diff --git a/cfme/tests/ansible/test_embedded_ansible_services.py b/cfme/tests/ansible/test_embedded_ansible_services.py index 0a24430092..122fa27870 100644 --- a/cfme/tests/ansible/test_embedded_ansible_services.py +++ b/cfme/tests/ansible/test_embedded_ansible_services.py @@ -471,6 +471,7 @@ def test_service_ansible_playbook_plays_table( view = navigate_to(ansible_service, "Details") soft_assert(view.provisioning.plays.row_count >= 1, "Plays table in provisioning tab is empty") ansible_service.retire() + view = navigate_to(ansible_service, "RetiredDetails") soft_assert(view.retirement.plays.row_count >= 1, "Plays table in retirement tab is empty") From 177f7e0e33d8b0b59d14c16ba4fa171d5844fb65 Mon Sep 17 00:00:00 2001 From: Satyajit Bulage Date: Thu, 25 Jul 2019 23:00:59 +0530 Subject: [PATCH 4/6] Added view to provisioning and retirement action. --- cfme/tests/ansible/test_embedded_ansible_services.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cfme/tests/ansible/test_embedded_ansible_services.py b/cfme/tests/ansible/test_embedded_ansible_services.py index 122fa27870..7c244519e7 100644 --- a/cfme/tests/ansible/test_embedded_ansible_services.py +++ b/cfme/tests/ansible/test_embedded_ansible_services.py @@ -515,12 +515,16 @@ def test_service_ansible_playbook_pass_extra_vars( """ ansible_service_catalog.order() ansible_service_request.wait_for_request() - if action == "retirement": - ansible_service.retire() - view = navigate_to(ansible_service, "Details") # To avoid NoSuchElementException if action == "provisioning": + view = navigate_to(ansible_service, "Details") view.provisioning_tab.click() + + if action == "retirement": + ansible_service.retire() + view = navigate_to(ansible_service, "RetiredDetails") + view.retirement_tab.click() + stdout = getattr(view, action).standart_output stdout.wait_displayed() pre = stdout.text From 3e87ea275b613933fa5a5e7b413b41798aef5870 Mon Sep 17 00:00:00 2001 From: Satyajit Bulage Date: Tue, 10 Sep 2019 19:17:22 +0530 Subject: [PATCH 5/6] Updated time for retirement. --- cfme/services/myservice/ui.py | 2 +- cfme/tests/ansible/test_embedded_ansible_services.py | 6 ++++++ widgetastic_manageiq/__init__.py | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cfme/services/myservice/ui.py b/cfme/services/myservice/ui.py index 33c2880c7a..3fda224abc 100644 --- a/cfme/services/myservice/ui.py +++ b/cfme/services/myservice/ui.py @@ -179,7 +179,7 @@ def is_displayed(self): return ( self.in_myservices and self.myservice.is_opened - and self.title.text == 'Service "{}"'.format(self.context["object"].name) + and self.title.text == f'Service "{self.context["object"].name}"' ) diff --git a/cfme/tests/ansible/test_embedded_ansible_services.py b/cfme/tests/ansible/test_embedded_ansible_services.py index 7c244519e7..3b530a721c 100644 --- a/cfme/tests/ansible/test_embedded_ansible_services.py +++ b/cfme/tests/ansible/test_embedded_ansible_services.py @@ -523,6 +523,12 @@ def test_service_ansible_playbook_pass_extra_vars( if action == "retirement": ansible_service.retire() view = navigate_to(ansible_service, "RetiredDetails") + wait_for( + lambda: view.retirement_tab.is_displayed, + delay=20, + fail_func=view.toolbar.reload.click(), + timeout=120 + ) view.retirement_tab.click() stdout = getattr(view, action).standart_output diff --git a/widgetastic_manageiq/__init__.py b/widgetastic_manageiq/__init__.py index b04df441df..1135a5a185 100644 --- a/widgetastic_manageiq/__init__.py +++ b/widgetastic_manageiq/__init__.py @@ -289,8 +289,8 @@ class MultiBoxSelect(View): """ - available_options = Select(id=Parameter("@available_items")) - chosen_options = Select(id=Parameter("@chosen_items")) + available_options = Select(locator='//div[contains(text(), "Unassigned:")]/select') + chosen_options = Select(locator='//div[contains(text(), "Selected:")]/select') move_into_button = Button(**{"data-submit": Parameter("@move_into")}) move_from_button = Button(**{"data-submit": Parameter("@move_from")}) From 4f7acdf7afc66b77c2dbb9cb4bbaf1b40cd6ceda Mon Sep 17 00:00:00 2001 From: Satyajit Bulage Date: Tue, 1 Oct 2019 19:56:00 +0530 Subject: [PATCH 6/6] Removed finalizer from multiple tests by using funcscope fixures. --- .../ansible/test_embedded_ansible_services.py | 188 +++++------------- 1 file changed, 52 insertions(+), 136 deletions(-) diff --git a/cfme/tests/ansible/test_embedded_ansible_services.py b/cfme/tests/ansible/test_embedded_ansible_services.py index 3b530a721c..4af1d80091 100644 --- a/cfme/tests/ansible/test_embedded_ansible_services.py +++ b/cfme/tests/ansible/test_embedded_ansible_services.py @@ -12,7 +12,6 @@ from cfme.infrastructure.provider.rhevm import RHEVMProvider from cfme.infrastructure.provider.virtualcenter import VMwareProvider from cfme.markers.env_markers.provider import ONE_PER_TYPE -from cfme.services.myservice import MyService from cfme.utils import conf from cfme.utils.appliance.implementations.ui import navigate_to from cfme.utils.blockers import BZ @@ -276,14 +275,8 @@ def test_service_ansible_playbook_bundle(appliance, ansible_catalog_item): @pytest.mark.tier(2) -def test_service_ansible_playbook_provision_in_requests( - appliance, - ansible_catalog_item, - ansible_service_catalog, - ansible_service, - ansible_service_request, - request, -): +def test_service_ansible_playbook_provision_in_requests(appliance, ansible_catalog_item, +ansible_service_catalog, ansible_service_funcscope, ansible_service_request_funcscope, request): """Tests if ansible playbook service provisioning is shown in service requests. Polarion: @@ -294,23 +287,9 @@ def test_service_ansible_playbook_provision_in_requests( tags: ansible_embed """ ansible_service_catalog.order() - ansible_service_request.wait_for_request() - cat_item_name = ansible_catalog_item.name - request_descr = "Provisioning Service [{0}] from [{0}]".format(cat_item_name) - service_request = appliance.collections.requests.instantiate(description=request_descr) - service_id = appliance.rest_api.collections.service_requests.get(description=request_descr) - - @request.addfinalizer - def _finalize(): - service = MyService(appliance, cat_item_name) - if service_request.exists(): - service_request.wait_for_request() - appliance.rest_api.collections.service_requests.action.delete(id=service_id.id) - - if service.exists: - service.delete() + ansible_service_request_funcscope.wait_for_request() - assert service_request.exists() + assert ansible_service_request_funcscope.exists() @pytest.mark.tier(2) @@ -407,20 +386,11 @@ def test_service_ansible_retirement_remove_resources( ids=[value[0] for value in SERVICE_CATALOG_VALUES], ) @pytest.mark.parametrize("action", ["provisioning", "retirement"]) -def test_service_ansible_playbook_order_retire( - appliance, - ansible_catalog_item, - ansible_service_catalog, - ansible_service_request, - ansible_service, - host_type, - order_value, - result, - action, - request -): +def test_service_ansible_playbook_order_retire(appliance, ansible_catalog_item, +ansible_service_catalog, ansible_service_request_funcscope, ansible_service_funcscope, host_type, +order_value, result, action, request): """Test ordering and retiring ansible playbook service against default host, blank field and - unavailable host. + unavailable host. Polarion: assignee: sbulage @@ -431,32 +401,17 @@ def test_service_ansible_playbook_order_retire( """ ansible_service_catalog.ansible_dialog_values = {"hosts": order_value} ansible_service_catalog.order() - ansible_service_request.wait_for_request() - cat_item_name = ansible_catalog_item.name - request_descr = "Provisioning Service [{0}] from [{0}]".format(cat_item_name) - service_request = appliance.collections.requests.instantiate(description=request_descr) - service_id = appliance.rest_api.collections.service_requests.get(description=request_descr) - - @request.addfinalizer - def _finalize(): - service = MyService(appliance, cat_item_name) - if service_request.exists(): - service_request.wait_for_request() - appliance.rest_api.collections.service_requests.action.delete(id=service_id.id) - - if service.exists: - service.delete() + ansible_service_request_funcscope.wait_for_request() if action == "retirement": - ansible_service.retire() - view = navigate_to(ansible_service, "Details") + ansible_service_funcscope.retire() + view = navigate_to(ansible_service_funcscope, "Details") assert result == view.provisioning.details.get_text_of("Hosts") @pytest.mark.tier(3) -def test_service_ansible_playbook_plays_table( - ansible_service_catalog, ansible_service, ansible_service_request, soft_assert -): +def test_service_ansible_playbook_plays_table(ansible_service_catalog, ansible_service_funcscope, +ansible_service_request_funcscope, soft_assert): """Plays table in provisioned and retired service should contain at least one row. Polarion: @@ -467,11 +422,11 @@ def test_service_ansible_playbook_plays_table( tags: ansible_embed """ ansible_service_catalog.order() - ansible_service_request.wait_for_request() - view = navigate_to(ansible_service, "Details") + ansible_service_request_funcscope.wait_for_request() + view = navigate_to(ansible_service_funcscope, "Details") soft_assert(view.provisioning.plays.row_count >= 1, "Plays table in provisioning tab is empty") - ansible_service.retire() - view = navigate_to(ansible_service, "RetiredDetails") + ansible_service_funcscope.retire() + view = navigate_to(ansible_service_funcscope, "RetiredDetails") soft_assert(view.retirement.plays.row_count >= 1, "Plays table in retirement tab is empty") @@ -501,7 +456,7 @@ def test_service_ansible_playbook_order_credentials( @pytest.mark.tier(3) @pytest.mark.parametrize("action", ["provisioning", "retirement"]) def test_service_ansible_playbook_pass_extra_vars( - ansible_service_catalog, ansible_service_request, ansible_service, action + ansible_service_catalog, ansible_service_request_funcscope, ansible_service_funcscope, action ): """Test if extra vars passed into ansible during ansible playbook service provision and retirement. @@ -514,20 +469,20 @@ def test_service_ansible_playbook_pass_extra_vars( tags: ansible_embed """ ansible_service_catalog.order() - ansible_service_request.wait_for_request() + ansible_service_request_funcscope.wait_for_request() # To avoid NoSuchElementException if action == "provisioning": - view = navigate_to(ansible_service, "Details") + view = navigate_to(ansible_service_funcscope, "Details") view.provisioning_tab.click() if action == "retirement": - ansible_service.retire() - view = navigate_to(ansible_service, "RetiredDetails") + ansible_service_funcscope.retire() + view = navigate_to(ansible_service_funcscope, "RetiredDetails") wait_for( lambda: view.retirement_tab.is_displayed, - delay=20, + delay=50, fail_func=view.toolbar.reload.click(), - timeout=120 + timeout=180 ) view.retirement_tab.click() @@ -624,7 +579,7 @@ def test_custom_button_ansible_credential_list( @pytest.mark.tier(3) def test_ansible_group_id_in_payload( - ansible_service_catalog, ansible_service_request, ansible_service + ansible_service_catalog, ansible_service_request_funcscope, ansible_service_funcscope ): """Test if group id is presented in manageiq payload. @@ -644,8 +599,8 @@ def test_ansible_group_id_in_payload( tags: ansible_embed """ ansible_service_catalog.order() - ansible_service_request.wait_for_request() - view = navigate_to(ansible_service, "Details") + ansible_service_request_funcscope.wait_for_request() + view = navigate_to(ansible_service_funcscope, "Details") stdout = view.provisioning.standart_output wait_for(lambda: stdout.is_displayed, timeout=10) pre = stdout.text @@ -674,15 +629,9 @@ def test_ansible_group_id_in_payload( or (credential[0] == "Azure" and provider.one_of(AzureProvider)) ) ) -def test_embed_tower_exec_play_against( - appliance, - request, - ansible_catalog_item, - ansible_service, - ansible_service_catalog, - credential, - provider_credentials, -): +def test_embed_tower_exec_play_against(appliance, request, ansible_catalog_item, +ansible_service_catalog, credential, provider_credentials, ansible_service_funcscope, +ansible_service_request_funcscope): """ Polarion: assignee: sbulage @@ -691,6 +640,7 @@ def test_embed_tower_exec_play_against( initialEstimate: 1/4h tags: ansible_embed """ + old_playbook_value = ansible_catalog_item.provisioning playbook = credential[2] with update(ansible_catalog_item): ansible_catalog_item.provisioning = { @@ -702,26 +652,17 @@ def test_embed_tower_exec_play_against( @request.addfinalizer def _revert(): with update(ansible_catalog_item): - ansible_catalog_item.provisioning = { - "playbook": "dump_all_variables.yml", - "cloud_type": "", - } - - service = MyService(appliance, ansible_catalog_item.name) - if service_request.exists(): - service_request.wait_for_request() - appliance.rest_api.collections.service_requests.action.delete(id=service_id.id) - if service.exists: - service.delete() + ansible_catalog_item.provisioning["playbook"] = old_playbook_value["playbook"] service_request = ansible_service_catalog.order() service_request.wait_for_request(num_sec=300, delay=20) - request_descr = "Provisioning Service [{0}] from [{0}]".format(ansible_catalog_item.name) - service_request = appliance.collections.requests.instantiate(description=request_descr) - service_id = appliance.rest_api.collections.service_requests.get(description=request_descr) - view = navigate_to(ansible_service, "Details") - assert view.provisioning.results.get_text_of("Status") == "successful" + view = navigate_to(ansible_service_funcscope, "Details") + assert ( + view.provisioning.results.get_text_of("Status") == "successful" + if appliance.version < "5.11" + else "Finished" + ) @pytest.mark.tier(2) @@ -737,15 +678,8 @@ def _revert(): ], ) @pytest.mark.meta(automates=[BZ(1460788)]) -def test_service_ansible_verbosity( - appliance, - request, - ansible_catalog_item, - ansible_service_catalog, - ansible_service_request, - ansible_service, - verbosity, -): +def test_service_ansible_verbosity(appliance, request, ansible_catalog_item, +ansible_service_catalog, ansible_service_request_funcscope, ansible_service_funcscope, verbosity): """Check if the different Verbosity levels can be applied to service and monitor the std out Bugzilla: @@ -767,31 +701,15 @@ def test_service_ansible_verbosity( # Start Log check or given pattern log.start_monitoring() - @request.addfinalizer - def _revert(): - service = MyService(appliance, ansible_catalog_item.name) - if ansible_service_request.exists(): - ansible_service_request.wait_for_request() - appliance.rest_api.collections.service_requests.action.delete( - id=service_request.id - ) - if service.exists: - service.delete() - ansible_service_catalog.order() - ansible_service_request.wait_for_request() - # 'request_descr' and 'service_request' being used in finalizer to remove - # first service request - request_descr = "Provisioning Service [{0}] from [{0}]".format(ansible_catalog_item.name) - service_request = appliance.rest_api.collections.service_requests.get( - description=request_descr - ) + ansible_service_request_funcscope.wait_for_request() + # Searching string '"verbosity"=>0' (example) in evm.log as Standard Output # is being logging in evm.log assert log.validate(wait="60s") logger.info("Pattern found {}".format(log.matched_patterns)) - view = navigate_to(ansible_service, "Details") + view = navigate_to(ansible_service_funcscope, "Details") assert verbosity[0] == view.provisioning.details.get_text_of("Verbosity") assert verbosity[0] == view.retirement.details.get_text_of("Verbosity") @@ -828,14 +746,8 @@ def test_ansible_service_linked_vm( @pytest.mark.tier(1) -def test_ansible_service_order_vault_credentials( - appliance, - request, - ansible_catalog_item, - ansible_service_catalog, - ansible_service_request, - ansible_service, -): +def test_ansible_service_order_vault_credentials(appliance, request, ansible_catalog_item, +ansible_service_catalog, ansible_service_request_funcscope, ansible_service_funcscope): """ Add vault password and test in the playbook that encrypted yml can be decrypted. @@ -868,11 +780,15 @@ def _revert(): vault_creds.delete_if_exists() ansible_service_catalog.order() - ansible_service_request.wait_for_request() + ansible_service_request_funcscope.wait_for_request() - view = navigate_to(ansible_service, "Details") + view = navigate_to(ansible_service_funcscope, "Details") assert view.provisioning.credentials.get_text_of("Vault") == vault_creds.name - assert view.provisioning.results.get_text_of("Status") == "successful" + assert ( + view.provisioning.results.get_text_of("Status") == "successful" + if appliance.version < "5.11" + else "Finished" + ) @pytest.mark.tier(3)