Remove unreachable not-found branch in dns-export-zone
The command loaded the zone with Zone.objects.get(...) and then tested
the result for truthiness:
nb_zone = Zone.objects.get(...)
if nb_zone:
...export...
else:
self.stderr.write('Zone not found in Netbox. Aborting')
Zone.objects.get() either returns a model instance (always truthy) or
raises Zone.DoesNotExist. It never returns a falsy value, so the else
branch was unreachable dead code. A missing zone is already handled
correctly: DoesNotExist is a subclass of Exception, which the
surrounding try/except catches and converts into a CommandError.
Drop the dead if/else and call export_bind_zone_file directly.
This commit is contained in:
1 parent
0277063dcc
commit
2276d770d1
1 file changed
-3
@@ -37,13 +37,10 @@ class Command(BaseCommand):
|
|||||||
view__name=view_name, name=zone_name
|
view__name=view_name, name=zone_name
|
||||||
)
|
)
|
||||||
|
|
||||||
if nb_zone:
|
|
||||||
export_bind_zone_file(nb_zone, file_path=file_path)
|
export_bind_zone_file(nb_zone, file_path=file_path)
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
self.style.SUCCESS(f"Zone '{zone_name}' exported to '{file_path}'")
|
self.style.SUCCESS(f"Zone '{zone_name}' exported to '{file_path}'")
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
self.stderr.write("Zone not found in Netbox. Aborting")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise CommandError(f"Failed to export zone: {e}")
|
raise CommandError(f"Failed to export zone: {e}")
|
||||||
Reference in new issue
Block a user