Skip to content

Commit

Permalink
webui: make tests usable for various cases of hidden steps
Browse files Browse the repository at this point in the history
Make Installer class aware of hidden steps and update the methods
for moving between steps accordingly.
  • Loading branch information
rvykydal committed Nov 20, 2023
1 parent b425a02 commit 35d79c7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
13 changes: 7 additions & 6 deletions test/check-basic
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class TestBasic(anacondalib.VirtInstallMachineCase):
]

for step in steps:
i.click_step_on_sidebar(step)
if step not in i.hidden_steps:
i.click_step_on_sidebar(step)

i.reach(i.steps.REVIEW)

Expand All @@ -88,16 +89,16 @@ class TestBasic(anacondalib.VirtInstallMachineCase):
i = Installer(b, m)
r = Review(b)

pretend_live_iso(self)
pretend_live_iso(self, i)

# For live media the first screen is the installation-method
i.open(step="installation-method")
i.open()
i.reach(i.steps.INSTALLATION_METHOD)

# Back button should be disabled on the first screen
b.wait_visible(f"#installation-back-btn:not([aria-disabled={True}]")

# For live media in the review screen language details should still be displayed
i.reach(i.steps.REVIEW, hidden_steps=[i.steps.ACCOUNTS])
i.reach(i.steps.REVIEW)
r.check_language("English (United States)")

def testAboutModal(self):
Expand Down Expand Up @@ -205,7 +206,7 @@ class TestBasic(anacondalib.VirtInstallMachineCase):
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)

# FIXME: Remove PF5 specific selector: https://github.com/patternfly/patternfly-react/issues/9512
b.wait_not_present("#critical-error-bz-report-modal.pf-v5-c-modal-box")
Expand Down
33 changes: 16 additions & 17 deletions test/check-storage
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TestStorage(anacondalib.VirtInstallMachineCase, StorageHelpers):
s = Storage(b, self.machine)

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)

# Check the auto-selected disk's details
s.check_single_disk_destination("vda", "16.1 GB")
Expand Down Expand Up @@ -86,10 +86,10 @@ class TestStorage(anacondalib.VirtInstallMachineCase, StorageHelpers):

self.addCleanup(m.execute, "killall blivet-gui")

pretend_live_iso(self)
pretend_live_iso(self, i)

# For live media the first screen is the installation-method
i.open(step="installation-method")
i.open()
i.reach(i.steps.INSTALLATION_METHOD)

disk="vda"

Expand Down Expand Up @@ -221,7 +221,6 @@ class TestStorage(anacondalib.VirtInstallMachineCase, StorageHelpers):
p = Password(b, s.encryption_id_prefix)

i.open()
# Language selection

i.reach(i.steps.INSTALLATION_METHOD)

Expand Down Expand Up @@ -334,7 +333,7 @@ class TestStorageExtraDisks(anacondalib.VirtInstallMachineCase, StorageHelpers):
dev = dev.split("/")[-1]

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)

s.wait_no_disks_detected_not_present()

Expand Down Expand Up @@ -384,7 +383,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand Down Expand Up @@ -470,7 +469,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand Down Expand Up @@ -510,7 +509,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)

# Select first only vdb disk and verify that the partitioning request is correct
i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)

s.rescan_disks()

Expand Down Expand Up @@ -589,7 +588,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev1, True)])
Expand Down Expand Up @@ -654,7 +653,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

# select only vda and check that we don't try to unlock the LUKS partition on vdb
Expand Down Expand Up @@ -703,7 +702,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

# select only vda and check that we don't try to unlock the LUKS partition on vdb
Expand Down Expand Up @@ -759,7 +758,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand Down Expand Up @@ -887,7 +886,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()
s.wait_scenario_available("mount-point-mapping", False)

Expand Down Expand Up @@ -919,7 +918,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand Down Expand Up @@ -991,7 +990,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand All @@ -1018,7 +1017,7 @@ class TestStorageMountPointsEFI(anacondalib.VirtInstallMachineCase):
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand Down
24 changes: 17 additions & 7 deletions test/helpers/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ class InstallerSteps(UserDict):
_steps_callbacks[ACCOUNTS] = create_user

class Installer():
def __init__(self, browser, machine):
def __init__(self, browser, machine, hidden_steps=None):
self.browser = browser
self.machine = machine
self.steps = InstallerSteps()
self.hidden_steps = hidden_steps or []

@log_step(snapshot_before=True)
def begin_installation(self, should_fail=False, confirm_erase=True):
Expand All @@ -69,20 +70,22 @@ def begin_installation(self, should_fail=False, confirm_erase=True):
else:
self.wait_current_page(self.steps._steps_jump[current_page][0])

def reach(self, target_page, hidden_steps=None):
hidden_steps = hidden_steps or []
def _previous_pages(self, page):
return [k for k, v in self.steps._steps_jump.items() if page in v]

def reach(self, target_page):
path = []
prev_pages = [target_page]
current_page = self.get_current_page()

while current_page not in prev_pages:
page = prev_pages[0]
path.append(page)
prev_pages = [k for k, v in self.steps._steps_jump.items() if page in v]
prev_pages = self._previous_pages(page)

while self.get_current_page() != target_page:
next_page = path.pop()
if next_page not in hidden_steps:
if next_page not in self.hidden_steps:
self.next(next_page=next_page)
if next_page in self.steps._steps_callbacks:
self.steps._steps_callbacks[next_page](self.browser, self.machine)
Expand All @@ -93,6 +96,8 @@ def next(self, should_fail=False, next_page=""):
# If not explicitly specified, get the first item for next page from the steps dict
if not next_page:
next_page = self.steps._steps_jump[current_page][0]
while next_page in self.hidden_steps:
next_page = self.steps._steps_jump[next_page][0]

# Wait for a disk to be pre-selected before clicking 'Next'.
# FIXME: Find a better way.
Expand Down Expand Up @@ -124,12 +129,17 @@ def back(self, should_fail=False, previous_page=""):
self.wait_current_page(current_page)
else:
if not previous_page:
previous_page = [k for k, v in self.steps._steps_jump.items() if current_page in v][0]
previous_page = self._previous_pages(current_page)[0]
while previous_page in self.hidden_steps:
previous_page = self._previous_pages(previous_page)[0]

self.wait_current_page(previous_page)

@log_step()
def open(self, step="installation-language"):
def open(self, step=None):
step = step or self.steps.WELCOME
while step in self.hidden_steps:
step = self.steps._steps_jump[step][0]
self.browser.open(f"/cockpit/@localhost/anaconda-webui/index.html#/{step}")
self.wait_current_page(step)
# Ensure that the logo is visible before proceeding as pixel tests get racy otherwise
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def add_public_key(machine):
machine.execute(f"chmod 700 {sysroot_ssh}")
machine.write(authorized_keys, public_key, perm="0600")

def pretend_live_iso(test):
def pretend_live_iso(test, installer):
installer.hidden_steps.extend([installer.steps.ACCOUNTS, installer.steps.WELCOME])
test.restore_file('/run/anaconda/anaconda.conf')
test.machine.execute("sed -i 's/type = BOOT_ISO/type = LIVE_OS/g' /run/anaconda/anaconda.conf")

Expand Down

0 comments on commit 35d79c7

Please sign in to comment.