Skip to content
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
6 changes: 3 additions & 3 deletions commodore/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def reconstruct_api_response(target_yml):
def _full_target(cluster, components, catalog):
cluster_facts = cluster['facts']
for required_fact in ['distribution', 'cloud']:
if required_fact not in cluster_facts:
if required_fact not in cluster_facts or not cluster_facts[required_fact]:
raise click.ClickException(f"Required fact '{required_fact}' not set")

cluster_distro = cluster_facts['distribution']
Expand All @@ -58,9 +58,9 @@ def _full_target(cluster, components, catalog):
global_defaults = ['global.common',
f"global.distribution.{cluster_distro}",
f"global.cloud.{cloud_provider}"]
if 'region' in cluster_facts:
if 'region' in cluster_facts and cluster_facts['region']:
Comment thread
simu marked this conversation as resolved.
global_defaults.append(f"global.cloud.{cloud_provider}.{cluster_facts['region']}")
if 'lieutenant-instance' in cluster_facts:
if 'lieutenant-instance' in cluster_facts and cluster_facts['lieutenant-instance']:
Comment thread
simu marked this conversation as resolved.
global_defaults.append(
f"global.lieutenant-instance.{cluster_facts['lieutenant-instance']}")
global_defaults.append(f"{customer}.{cluster_id}")
Expand Down
13 changes: 13 additions & 0 deletions tests/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def test_optional_fact_region(data):
assert f"global.cloud.{facts['cloud']}.{facts['region']}" in target['classes']


def test_optional_fact_region_empty(data):
data['cluster']['facts']['region'] = ''
target = cluster._full_target(data['cluster'], data['components'], data['catalog'])
facts = data['cluster']['facts']
assert f"global.cloud.{facts['cloud']}.{facts['region']}" not in target['classes']


def test_optional_fact_lieutenant_instance(data):
data['cluster']['facts']['lieutenant-instance'] = 'lieutenant-dev'
target = cluster._full_target(data['cluster'], data['components'], data['catalog'])
Expand All @@ -64,6 +71,12 @@ def test_missing_facts(data):
cluster._full_target(data['cluster'], data['components'], data['catalog'])


def test_empty_facts(data):
data['cluster']['facts']['cloud'] = ''
with pytest.raises(click.ClickException):
cluster._full_target(data['cluster'], data['components'], data['catalog'])


def test_reconstruct_api_response(tmp_path):
targetyml = tmp_path / 'cluster.yml'
with open(targetyml, 'w') as file:
Expand Down