Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added checking for index out of range. #429

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 9 additions & 7 deletions src/databricks/labs/ucx/assessment/crawlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
_AZURE_SP_CONF_FAILURE_MSG = "Uses azure service principal credentials config in"
_SECRET_LIST_LENGTH = 3
_CLIENT_ENDPOINT_LENGTH = 6
_INIT_SCRIPT_DBFS_PATH = 2


@dataclass
Expand Down Expand Up @@ -86,13 +87,14 @@ class GlobalInitScriptInfo:

def _get_init_script_data(w, init_script_info):
if init_script_info.dbfs:
file_api_format_destination = init_script_info.dbfs.destination.split(":")[1]
if file_api_format_destination:
try:
data = w.dbfs.read(file_api_format_destination).data
return base64.b64decode(data).decode("utf-8")
except Exception:
return None
if len(init_script_info.dbfs.destination.split(":")) == _INIT_SCRIPT_DBFS_PATH:
file_api_format_destination = init_script_info.dbfs.destination.split(":")[1]
if file_api_format_destination:
try:
data = w.dbfs.read(file_api_format_destination).data
return base64.b64decode(data).decode("utf-8")
except Exception:
return None
if init_script_info.workspace:
workspace_file_destination = init_script_info.workspace.destination
if workspace_file_destination:
Expand Down
157 changes: 157 additions & 0 deletions tests/unit/assessment/test_assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2318,3 +2318,160 @@ def test_list_all_pipeline_with_conf_spn_secret_unavlbl(mocker):
result_set = AzureServicePrincipalCrawler(ws, MockBackend(), "ucx")._list_all_pipeline_with_spn_in_spark_conf()

assert len(result_set) == 0


def test_cluster_init_script_check_dbfs(mocker):
sample_clusters = [
ClusterDetails(
autoscale=AutoScale(min_workers=1, max_workers=6),
cluster_source=ClusterSource.UI,
spark_context_id=5134472582179565315,
spark_env_vars=None,
spark_version="12.3.x-cpu-ml-scala2.12",
cluster_id="0810-225833-atlanta69",
cluster_name="Tech Summit FY24 Cluster-1",
init_scripts=[
InitScriptInfo(
dbfs=DbfsStorageInfo(destination="dbfs:"),
s3=None,
volumes=None,
workspace=None,
),
InitScriptInfo(
dbfs=DbfsStorageInfo(destination="dbfs"),
s3=None,
volumes=None,
workspace=None,
),
InitScriptInfo(
dbfs=DbfsStorageInfo(destination=":/users/[email protected]/init_scripts/test.sh"),
s3=None,
volumes=None,
workspace=None,
),
InitScriptInfo(
dbfs=None,
s3=None,
volumes=None,
workspace=WorkspaceStorageInfo(
destination="/Users/[email protected]/init_script_1.sh"
),
),
],
)
]
ws = mocker.Mock()
ws.clusters.list.return_value = sample_clusters
ws.dbfs.read().data = "JXNoCmVjaG8gIj0="
init_crawler = ClustersCrawler(ws, MockBackend(), "ucx").snapshot()
assert len(init_crawler) == 1


def test_job_cluster_init_script_check_dbfs():
sample_jobs = [
BaseJob(
created_time=1694536604319,
creator_user_name="[email protected]",
job_id=536591785949415,
settings=JobSettings(
compute=None,
continuous=None,
tasks=[
Task(
task_key="Ingest",
existing_cluster_id="0807-225846-avon493",
notebook_task=NotebookTask(
notebook_path="/Users/[email protected]/Customers/Example/Test/Load"
),
timeout_seconds=0,
)
],
timeout_seconds=0,
),
),
BaseJob(
created_time=1694536604321,
creator_user_name="[email protected]",
job_id=536591785949416,
settings=JobSettings(
compute=None,
continuous=None,
tasks=[
Task(
task_key="Ingest",
existing_cluster_id="0810-229933-chicago99",
notebook_task=NotebookTask(
notebook_path="/Users/[email protected]/Customers/Example/Test/Load"
),
timeout_seconds=0,
)
],
timeout_seconds=0,
),
),
BaseJob(
created_time=1694536604319,
creator_user_name="[email protected]",
job_id=536591785949417,
settings=JobSettings(
compute=None,
continuous=None,
tasks=[
Task(
task_key="Ingest",
existing_cluster_id="0811-929933-maine96",
notebook_task=NotebookTask(
notebook_path="/Users/[email protected]/Customers/Example/Test/Load"
),
timeout_seconds=0,
)
],
timeout_seconds=0,
),
),
]

sample_clusters = [
ClusterDetails(
init_scripts=[
InitScriptInfo(
dbfs=DbfsStorageInfo(destination="dbfs"),
s3=None,
volumes=None,
workspace=None,
),
InitScriptInfo(
dbfs=DbfsStorageInfo(destination="dbfs:"),
s3=None,
volumes=None,
workspace=None,
),
InitScriptInfo(
dbfs=DbfsStorageInfo(destination=":/users/[email protected]/init_scripts/test.sh"),
s3=None,
volumes=None,
workspace=None,
),
InitScriptInfo(
dbfs=None,
s3=None,
volumes=None,
workspace=WorkspaceStorageInfo(
destination="/Users/[email protected]/init_script_1.sh"
),
),
],
autoscale=AutoScale(min_workers=1, max_workers=6),
spark_context_id=5134472582179566666,
spark_env_vars=None,
spark_version="13.3.x-cpu-ml-scala2.12",
cluster_id="0807-225846-avon493",
cluster_source=ClusterSource.JOB,
)
]
ws = Mock()
ws.workspace.export().content = "JXNoCmVjaG8gIj0="
result_set = JobsCrawler(ws, MockBackend(), "ucx")._assess_jobs(
sample_jobs, {c.cluster_id: c for c in sample_clusters}
)
assert len(result_set) == 3