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

metadeploy_publish presents clear errors when plans are not available #3684

Merged
merged 7 commits into from
Oct 24, 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
11 changes: 9 additions & 2 deletions cumulusci/tasks/metadeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,21 @@ def _init_task(self):
Path(self.labels_path).mkdir(parents=True, exist_ok=True)

if plan_name := self.options.get("plan"):
if self.project_config.lookup(f"plans__{plan_name}") is None:
raise TaskOptionsError(
f"Plan {plan_name} not found in project configuration"
)
plan_configs = {
plan_name: self.project_config.lookup(f"plans__{plan_name}")
}
self.plan_configs = plan_configs
else:
self.plan_configs = self.project_config.plans
# Handled exception for no plan
if self.plan_configs is None or len(self.plan_configs) == 0:
raise CumulusCIException(
"No plan found to publish in project configuration"
)

self._load_labels()

Expand All @@ -107,7 +116,6 @@ def _run_task(self):
raise CumulusCIException(
f"No slug found in MetaDeploy for product {product} from {repo_url}"
)

if not self.dry_run:
version = self._find_or_create_version(product)
if self.labels_path and "slug" in product:
Expand Down Expand Up @@ -138,7 +146,6 @@ def _run_task(self):
)
project_config.set_keychain(self.project_config.keychain)

# Create each plan
for plan_name, plan_config in self.plan_configs.items():
self._add_plan_labels(
plan_name=plan_name,
Expand Down
42 changes: 42 additions & 0 deletions cumulusci/tasks/tests/test_metadeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,14 @@ def test_find_product__not_found(self):
)
project_config = create_project_config()
project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO"
project_config.config["plans"] = {
"install": {
"title": "Test Install",
"slug": "install",
"tier": "primary",
"steps": {1: {"flow": "install_prod"}},
}
}
project_config.keychain.set_service(
"metadeploy",
"test_alias",
Expand Down Expand Up @@ -485,6 +493,37 @@ def test_init_task__named_plan(self):
task._init_task()
assert expected_plans == task.plan_configs

@pytest.mark.parametrize(
"options, errortype,errormsg",
[
(
{"tag": "release/1.0"},
CumulusCIException,
"No plan found to publish in project configuration",
),
(
{"tag": "release/1.0", "plan": "install"},
TaskOptionsError,
"Plan install not found in project configuration",
),
],
)
def test_init_task_no_plan(self, options, errortype, errormsg):
project_config = create_project_config()
project_config.config["project"]["git"]["repo_url"] = "EXISTING_REPO"
project_config.keychain.set_service(
"metadeploy",
"test_alias",
ServiceConfig({"url": "https://metadeploy", "token": "TOKEN"}),
)
task_config = TaskConfig({"options": options})
task = Publish(project_config, task_config)
with pytest.raises(
errortype,
match=errormsg,
):
task._init_task()

@responses.activate
def test_find_or_create_plan_template__not_found(self):
responses.add(
Expand Down Expand Up @@ -540,6 +579,9 @@ def test_freeze_steps__skip(self):
"tier": "primary",
"steps": {1: {"task": "None"}},
}
project_config.config["plans"] = {
"Test Install": plan_config,
}
task_config = TaskConfig({"options": {"tag": "release/1.0"}})
task = Publish(project_config, task_config)
task._init_task()
Expand Down
Loading