Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[1LP][RFR] Add support for cancel and nav_away to Host.update() and test_infrastructure_hosts_crud #10090

Merged
merged 26 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a815c4b
Create draft of rewrite of test_infrastructure_hosts_crud to edit onl…
prichard77 Dec 11, 2019
e56209a
Fix flake8 issues
prichard77 Dec 12, 2019
c095a0d
Reorder imports
prichard77 Dec 12, 2019
21d47e8
Removing outdated BZ lable
prichard77 Dec 12, 2019
cc08ea5
Add from_details kwarg to host.update
prichard77 Apr 23, 2020
402c630
Update host.update nav to support edit from hosts view
prichard77 Apr 23, 2020
8aa24cf
Update Host.update to support edit from hosts view
prichard77 May 1, 2020
8876350
Put view.is_displayed back into Host.update()
prichard77 May 1, 2020
c959976
Add support for cancel and nav_away to Host.update() and test_infrast…
prichard77 May 4, 2020
52545d0
Reorder import
prichard77 May 4, 2020
dbfcddc
Move pytest.fail up into test and add support for nav_away_changes
prichard77 May 5, 2020
66b36c4
Fix missing quote in parameter list
prichard77 May 5, 2020
9ffa5fe
Add explicit kwarg to host.delete and update format of random string
prichard77 May 5, 2020
b820454
Remove delete from update doc block
prichard77 May 5, 2020
024b151
Updated Host.update() and test_infrastructure_hosts_crud to use kwarg…
prichard77 May 7, 2020
287629b
Update nav_away and cancel kwargs in call to Hosts.update()
prichard77 May 7, 2020
f9fe748
Added BZ to exception log msg and added details on crud_actions to do…
prichard77 May 12, 2020
463973a
Remove newline in docblock for test_infrastructure_hosts_compare
prichard77 May 13, 2020
65d4c46
Add comments to and rearrange structure of test_infrastructure_hosts_…
prichard77 May 13, 2020
0f4ae4d
Add more comments and update docblock for clarity
prichard77 May 13, 2020
401ee6a
Update kwargs and associated logic to make from_hosts the one off exc…
prichard77 May 13, 2020
5ecc395
Remove nav_away and changes kwargs from Host.update()
prichard77 May 14, 2020
00ca912
Rewrite test_infrastructure_hosts_crud to not use parameterization of…
prichard77 May 14, 2020
155afde
Set from_details default to True in Host.update() and set it to True …
prichard77 May 14, 2020
16f7747
Update from_details logic and remove cancel kwarg assignements to the…
prichard77 May 15, 2020
de75db5
Combine multi lines into one where applicable
prichard77 May 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cfme/common/host_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class HostEditView(HostFormView):
@property
def is_displayed(self):
return (
self.logged_in_as_current_user and self.navigation.currently_selected == [
self.in_compute_infrastructure_hosts and self.navigation.currently_selected == [
'Compute', 'Infrastructure', 'Hosts'] and self.title.text == 'Info/Settings')


Expand Down
32 changes: 26 additions & 6 deletions cfme/infrastructure/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,35 @@ def __init__(self, **kwargs):
super(Host.Credential, self).__init__(**kwargs)
self.ipmi = kwargs.get('ipmi')

def update(self, updates, validate_credentials=False, from_details=True):
def update(self, updates, validate_credentials=False, from_hosts=False,
cancel=False, nav_away=False, changes=True):
"""Updates a host in the UI. Better to use utils.update.update context manager than call
this directly.

Args:
updates (dict): fields that are changing.
updates (dict): fields that are changing.
validate_credentials (bool): if True, validate host credentials
from_hosts (bool): if True, select 'Edit Selected items' from hosts view
else, select 'Edit Selected items' from details view
cancel (bool): click cancel button to cancel the edit if True
nav_away (bool): navigate away from edit view before saving if True
changes (bool): expecting saved changes if True
"""
if from_details:
view = navigate_to(self, "Edit")
else:
if from_hosts:
view = navigate_to(self.parent, "All")
view.entities.get_entity(name=self.name, surf_pages=True).ensure_checked()
view.toolbar.configuration.item_select('Edit Selected items')
view = self.create_view(HostEditView)
assert view.is_displayed
else:
view = navigate_to(self, "Edit")
if nav_away and not changes:
# navigate away before any changes have been made in the edit view
view.navigation.select('Compute', 'Infrastructure', 'Hosts',
handle_alert=False)
view = self.create_view(HostsView)
assert view.is_displayed
return
changed = view.fill({
"name": updates.get("name"),
"hostname": updates.get("hostname") or updates.get("ip_address"),
Expand Down Expand Up @@ -136,7 +150,13 @@ def update(self, updates, validate_credentials=False, from_details=True):
if validate_credentials:
view.endpoints.ipmi.validate_button.click()
view.flash.assert_no_error()
changed = any([changed, credentials_changed, ipmi_credentials_changed])
if nav_away and changes:
# navigate away here after changes have been made in the edit view
view = navigate_to(self.parent, "All")
assert view.is_displayed
return
changed = False if cancel else any([changed, credentials_changed,
mshriver marked this conversation as resolved.
Show resolved Hide resolved
ipmi_credentials_changed])
if changed:
view.save_button.click()
logger.debug("Trying to save update for host with id: %s", str(self.get_db_id))
Expand Down
69 changes: 55 additions & 14 deletions cfme/tests/infrastructure/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fauxfactory
import pytest
from wait_for import TimedOutError
from widgetastic.exceptions import UnexpectedAlertPresentException

from cfme import test_requirements
from cfme.base.credential import Credential
Expand Down Expand Up @@ -86,7 +87,6 @@ def navigate_and_select_quads(provider):

Returns:
view: the provider nodes view, quadicons already selected"""
# TODO: prichard navigate instead of creating views and consider creaing EditableMixin
hosts_view = navigate_to(provider, 'ProviderNodes')
assert hosts_view.is_displayed
[h.ensure_checked() for h in hosts_view.entities.get_all()]
Expand Down Expand Up @@ -462,6 +462,8 @@ def test_infrastructure_hosts_compare(appliance, setup_provider_min_hosts, provi
casecomponent: Infra
caseimportance: high
initialEstimate: 1/6h
Bugzilla:
1746214
"""

h_coll = locals()[hosts_collection].collections.hosts
Expand All @@ -487,6 +489,7 @@ def test_infrastructure_hosts_navigation_after_download_from_compare(
initialEstimate: 1/3h
Bugzilla:
1747545

"""
h_coll = locals()[hosts_collection].collections.hosts
hosts_view = h_coll.compare_entities(provider, entities_list=h_coll.all()[:num_hosts])
Expand Down Expand Up @@ -526,26 +529,64 @@ def test_add_ipmi_refresh(appliance, setup_provider):


@test_requirements.infra_hosts
@pytest.mark.parametrize("crud_action", ['edit_from_hosts', 'edit_from_details', 'remove'])
@pytest.mark.meta(automates=[1634794])
@pytest.mark.parametrize("crud_action", ['edit_from_hosts', 'edit_from_details', 'cancel',
'nav_away_changes', 'nav_away_no_changes', 'remove'])
john-dupuy marked this conversation as resolved.
Show resolved Hide resolved
def test_infrastructure_hosts_crud(appliance, setup_provider, crud_action):
"""
mshriver marked this conversation as resolved.
Show resolved Hide resolved
crud_action: (All are edit actions except for 'remove')
'edit_from_hosts' : select host and click edit dropdown from the hosts view to edit
'edit_from_details' : click edit dropdown from the details view of host to edit
'cancel' : click the cancel button before saving edits
'nav_away_changes' : navigate away from the edit view after making changes (not saved)
'nav_away_no_changes' : navigate away from the edit view without having made changes
'remove' : remove the host
Polarion:
assignee: prichard
casecomponent: Infra
caseimportance: low
initialEstimate: 1/6h
Bugzilla:
1634794
"""
host = appliance.collections.hosts.all()[0]
mshriver marked this conversation as resolved.
Show resolved Hide resolved
if crud_action != 'remove':
stamp = fauxfactory.gen_alphanumeric()
new_custom_id = f'Edit host data. {stamp}'

with update(host, from_details=(crud_action == 'edit_from_details')):
host.custom_ident = new_custom_id

assert host.custom_ident == new_custom_id
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
"Custom Identifier") == new_custom_id
else:
host.delete()
if crud_action == 'remove':
host.delete(cancel=True)
host.delete(cancel=False)
else:
if crud_action in ['cancel', 'nav_away_changes', 'nav_away_no_changes']:
# In these cases we need to capture the existing/initial custom id to check later that
# no changes were made.
try:
existing_custom_id = navigate_to(host, 'Details').entities.summary(
"Properties").get_text_of("Custom Identifier")
except NameError:
existing_custom_id = None
# begin core/common edit steps
new_custom_id = f'Edit host data. {fauxfactory.gen_alphanumeric()}'
try:
with update(host,
from_hosts=(crud_action == 'edit_from_hosts'),
cancel=(crud_action == 'cancel'),
nav_away=(crud_action in ['nav_away_changes', 'nav_away_no_changes']),
changes=(crud_action == 'nav_away_changes')
):
host.custom_ident = new_custom_id
except UnexpectedAlertPresentException as e:
mshriver marked this conversation as resolved.
Show resolved Hide resolved
if crud_action in ['cancel', 'nav_away_no_changes'] and "Abandon changes" in e.msg:
pytest.fail("Abandon changes alert displayed, but no changes made. BZ1634794")
else:
raise
# now verify changes were made or not made according to scenario
if crud_action in ['cancel', 'nav_away_changes', 'nav_away_no_changes']:
# No changes are expected. Comparing to existing value captured above.
try:
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
"Custom Identifier") == existing_custom_id
except NameError:
if existing_custom_id:
raise
else:
# Changes are expected so compare to edited value.
assert navigate_to(host, 'Details').entities.summary("Properties").get_text_of(
"Custom Identifier") == new_custom_id