Skip to content

Commit

Permalink
Triggering Assessment Workflow from Installer based on User Prompt (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
prajin-29 authored and dmoore247 committed Mar 23, 2024
1 parent 87de35d commit ba3c9c6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/databricks/labs/ucx/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def _configure_new_installation(self) -> WorkspaceConfig:

# Check if terraform is being used
is_terraform_used = self._prompts.confirm("Do you use Terraform to deploy your infrastructure?")

config = WorkspaceConfig(
inventory_database=inventory_database,
workspace_group_regex=configure_groups.workspace_group_regex,
Expand Down Expand Up @@ -403,9 +404,14 @@ def run(self):
self.create_jobs,
],
)

readme_url = self._create_readme()
logger.info(f"Installation completed successfully! Please refer to the {readme_url} for the next steps.")

if self._prompts.confirm("Do you want to trigger assessment job ?"):
logger.info("Triggering the assessment workflow")
self._trigger_workflow("assessment")

def config_file_link(self):
return self._installation.workspace_link('config.yml')

Expand Down Expand Up @@ -1004,6 +1010,14 @@ def validate_and_run(self, step: str):
if not self.validate_step(step):
self.run_workflow(step)

def _trigger_workflow(self, step: str):
job_id = int(self._state.jobs[step])
job_url = f"{self._ws.config.host}#job/{job_id}"
logger.debug(f"triggering {step} job: {self._ws.config.host}#job/{job_id}")
self._ws.jobs.run_now(job_id)
if self._prompts.confirm(f"Open {step} Job url that just triggered ? {job_url}"):
webbrowser.open(job_url)


if __name__ == "__main__":
logger = get_logger(__file__)
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,30 @@ def test_save_config_should_include_databases(ws, mock_installation):
)


def test_triggering_assessment_wf(ws, mocker, mock_installation):
ws.jobs.run_now = mocker.Mock()
mocker.patch("webbrowser.open")
sql_backend = MockBackend()
prompts = MockPrompts(
{
r".*": "",
r"Do you want to trigger assessment job ?.*": "yes",
r"Open assessment Job url that just triggered ?.*": "yes",
}
)
workspace_installation = WorkspaceInstallation(
WorkspaceConfig(inventory_database="ucx", policy_id='123'),
mock_installation,
sql_backend,
create_autospec(WheelsV2),
ws,
prompts,
timedelta(seconds=1),
PRODUCT_INFO,
)
workspace_installation.run()


def test_runs_upgrades_on_too_old_version(ws, any_prompt):
existing_installation = MockInstallation(
{
Expand Down

0 comments on commit ba3c9c6

Please sign in to comment.