Skip to content

Commit

Permalink
Add support for scan_timeout configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ruda committed Jul 3, 2024
1 parent 0840606 commit 5cb58a6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions camayoc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

default_dynaconf_validators = [
Validator("camayoc.run_scans", default=False),
Validator("camayoc.scan_timeout", default=600),
Validator("quipucords_server.hostname", default=""),
Validator("quipucords_server.https", default=False),
Validator("quipucords_server.port", default=8000),
Expand Down
5 changes: 5 additions & 0 deletions camayoc/tests/qpc/ui/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ def ui_client(page):
page_errors = [f"- {err}" for err in client.page_errors]
fail_msg = "\n".join(fail_msg + page_errors)
pytest.fail(fail_msg)


@pytest.fixture(scope="session")
def ui_download_timeout():
return settings.camayoc.scan_timeout
6 changes: 4 additions & 2 deletions camayoc/tests/qpc/ui/test_endtoend.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def source_names():

@pytest.mark.nightly_only
@pytest.mark.parametrize("source_name", source_names())
def test_end_to_end(tmp_path, cleaning_data_provider, ui_client: Client, source_name):
def test_end_to_end(
tmp_path, cleaning_data_provider, ui_client: Client, source_name, ui_download_timeout
):
"""End-to-end test using web user interface.
:id: f187fbd0-021c-4563-9691-61e54eb272bf
Expand Down Expand Up @@ -90,7 +92,7 @@ def test_end_to_end(tmp_path, cleaning_data_provider, ui_client: Client, source_
.add_source(source_dto)
.trigger_scan(trigger_scan_dto)
.navigate_to(MainMenuPages.SCANS)
.download_scan(trigger_scan_dto.scan_form.scan_name)
.download_scan(trigger_scan_dto.scan_form.scan_name, ui_download_timeout)
.logout()
)

Expand Down
4 changes: 2 additions & 2 deletions camayoc/tests/qpc/ui/test_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def scan_names():

@pytest.mark.pr_only
@pytest.mark.parametrize("scan_name", scan_names())
def test_download_scan(tmp_path, scans, ui_client: Client, scan_name):
def test_download_scan(tmp_path, scans, ui_client: Client, scan_name, ui_download_timeout):
"""Download finished scan and verify basic content properties.
:id: 66abf967-24f1-43cb-9375-c1a5e519a0e6
Expand All @@ -54,7 +54,7 @@ def test_download_scan(tmp_path, scans, ui_client: Client, scan_name):
ui_client.begin()
.login(data_factories.LoginFormDTOFactory())
.navigate_to(MainMenuPages.SCANS)
.download_scan(finished_scan.definition.name)
.download_scan(finished_scan.definition.name, ui_download_timeout)
.logout()
)

Expand Down
1 change: 1 addition & 0 deletions camayoc/types/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class CamayocOptions(BaseModel):
run_scans: Optional[bool] = False
scan_timeout: Optional[int] = 600


class QuipucordsServerOptions(BaseModel):
Expand Down
8 changes: 4 additions & 4 deletions camayoc/ui/models/pages/scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@


class ScanListElem(AbstractListItem):
def download_scan(self) -> Download:
def download_scan(self, timeout: int) -> Download:
scan_locator = "td[class*=-c-table__action] button[data-ouia-component-id=download]"
timeout_start = time.monotonic()
while 10 * 60 > (time.monotonic() - timeout_start):
while timeout > (time.monotonic() - timeout_start):
try:
with self.locator.page.expect_download() as download_info:
self.locator.locator(scan_locator).click(timeout=10_000)
Expand All @@ -38,8 +38,8 @@ class ScansMainPage(MainPageMixin):
@creates_toast
@service
@record_action
def download_scan(self, scan_name: str) -> ScansMainPage:
def download_scan(self, scan_name: str, timeout: int) -> ScansMainPage:
scan: ScanListElem = self._get_item(scan_name)
downloaded_report = scan.download_scan()
downloaded_report = scan.download_scan(timeout)
self._client.downloaded_files.append(downloaded_report)
return self

0 comments on commit 5cb58a6

Please sign in to comment.