Skip to content

Commit dd445f1

Browse files
authored
Merge pull request #72 from stirlingbridge/dboreham/check-dns-zone-exists
Check the DNS zone actually exists at the provider
2 parents 7160301 + 92d0176 commit dd445f1

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

machine/subcommands/create.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
from machine.types import TAG_MACHINE_SESSION_PREFIX
1313

1414

15+
def _validate_dns_zone(provider, dns_zone):
16+
available_zones = provider.list_domains()
17+
if dns_zone not in available_zones:
18+
zones_str = ", ".join(available_zones) if available_zones else "none"
19+
fatal_error(f"Error: DNS zone '{dns_zone}' not found in {provider.provider_name}. Available zones: {zones_str}")
20+
21+
1522
@click.command(help="Create a machine")
1623
@click.option("--name", "-n", required=True, metavar="<MACHINE-NAME>", help="Name for new machine")
1724
@click.option("--tag", "-t", metavar="<TAG-TEXT>", help="tag to be applied to new machine")
@@ -34,6 +41,9 @@ def command(context, name, tag, type, region, machine_size, image, wait_for_ip,
3441
if update_dns and not config.dns_zone:
3542
fatal_error("Error: DNS update requested but no zone configured")
3643

44+
if update_dns and config.dns_zone:
45+
_validate_dns_zone(provider, config.dns_zone)
46+
3747
user_data = None
3848
if initialize:
3949
if not type:

tests/test_e2e.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,31 @@ def instance(config_file, session_id):
255255
# ---------------------------------------------------------------------------
256256

257257

258+
class TestDnsZonePreFlight:
259+
"""Verify that create fails fast when the configured DNS zone does not exist."""
260+
261+
def test_create_fails_for_nonexistent_dns_zone(self, tmp_path, session_id):
262+
bogus_zone = f"bogus-{uuid.uuid4().hex[:8]}.example"
263+
cfg_path = tmp_path / "config.yml"
264+
_write_config(cfg_path, **{"dns-zone": bogus_zone})
265+
266+
result = run_machine(
267+
"create",
268+
"--name",
269+
_unique_name(),
270+
"--type",
271+
"e2e-basic",
272+
"--no-initialize",
273+
"--update-dns",
274+
config_file=cfg_path,
275+
session_id=session_id,
276+
)
277+
assert result.returncode != 0, "Expected create to fail for nonexistent DNS zone"
278+
combined = result.stdout + result.stderr
279+
assert bogus_zone in combined, f"Error should mention the bogus zone '{bogus_zone}'"
280+
assert "not found" in combined.lower(), "Error should indicate zone was not found"
281+
282+
258283
class TestInstanceLifecycle:
259284
"""Create one instance with all features and verify each aspect independently.
260285

0 commit comments

Comments
 (0)