Skip to content

Commit

Permalink
Make host remove a bit safer to use. (#211)
Browse files Browse the repository at this point in the history
## The problem...

It was much too easy to do `host remove foo -f` and have it bite in the worst possible way.

## The solution?

In this PR, `-force` is no longer a catch-all for making `host remove`, well, remove the host. If the host has cnames, ptrs, mx, srvs or ipadresses across multiple vlans, the user needs to declare a desire to override each of these explicitly via the new option `-override`.

## Supported input

Accepted overrides are `cname`, `ipadress`, `mx`, `srv`, `ptr`, `naptr`. Invalid overrides offered as parameters to `-override` are errors and the command will report on the unexpected input and stop before executing anything.

The choice to have these as textual inputs is intended with the explicit goal of making their use require more than tab-completing an option.

## Example usage

`host remove foo -force -override cname,ipaddress,mx`.

This would allow deletion / removal of a host with cnames, ipadresses across different vlans, and mx set. However, any ptr or srv RRs will still cause the deletion to cancel.

## Example warning from `host remove`

```
WARNING: : bar.example.org requires force and cnames as overrides for deletion:
  1 cnames, override with 'cname'
    - fubar.example.org
  multiple ipaddresses on the same VLAN. Must use 'force'."
```

## Notes:

1. `-force` alone works on multiple ipadresses from the same VLAN.
2. `-override` requires the presence of `-force`. The documentation states this both from expanded inline help and `host remove -h`.


---------

Co-authored-by: pederhan <[email protected]>
  • Loading branch information
terjekv and pederhan authored Feb 29, 2024
1 parent 930aae7 commit 32af34b
Show file tree
Hide file tree
Showing 5 changed files with 3,513 additions and 122 deletions.
47 changes: 46 additions & 1 deletion ci/testsuite
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ dhcp assoc foo aa:bb:cc:dd:ee:ff # should fail, the host has two IPs of differen
host aaaa_remove foo 2001:db9::5
host aaaa_add foo 2001:db8::5 -f
dhcp assoc foo aa:bb:cc:dd:ee:ff # should work, the host now has two IPs of different types on the same VLAN.

host remove foo -f
network remove 10.0.0.0/24 -f
network remove 2001:db8::/64 -f
Expand Down Expand Up @@ -234,6 +233,7 @@ host a_show baz
host aaaa_add bar 2001:db8::/64 # must force
host aaaa_add bar 2001:db8::11 -f
host aaaa_add bar 2001:db8::12 -macaddress 11:22:33:44:55:67 -f
host remove bar # should fail, because it has multiple addresses, must force
host aaaa_show bar
host aaaa_change -old 2001:db8::11 -new 2001:db8::13 bar
host aaaa_change -old 2001:db8::12 -new 2001:db8::14 bar # has mac addr, should keep it assigned to the new ip
Expand All @@ -242,6 +242,7 @@ host aaaa_move -ip 2001:db8::14 -fromhost bar -tohost baz
host a_show baz
# CNAME
host cname_add bar fubar
host remove bar # should fail, because it has a cname record, must force and override with 'cname'
host cname_show bar
host cname_remove bar fubar
# HINFO
Expand All @@ -255,6 +256,7 @@ host loc_remove baz
# MX
host mx_add baz 10 mail.example.org
host mx_show baz
host remove baz # Should fail, because it has an MX record, must force and override with 'mx'
host mx_remove baz 10 mail.example.org
# NAPTR
host naptr_add -name baz -preference 16384 -order 3 -flag u -service "SIP" -regex "[abc]+" -replacement "wonk"
Expand Down Expand Up @@ -293,6 +295,49 @@ host remove *.example.org
host remove bar -f
host remove baz -f
host remove clover

# Test handling of overrides
# MX
host add foo -ip 10.0.0.10 -contact "[email protected]"
host mx_add foo 10 mail.example.org
host remove foo # Should fail, because it has an MX record, must force and override with 'mx'
host remove foo -force -override mx

# PTR
host add foo -ip 10.0.0.10 -contact "[email protected]"
host ptr_add 10.0.0.11 foo.example.org
host remove foo # Should fail, because it has a PTR record, must force and override with 'ptr'
host remove foo -force -override ptr

# NAPTR
host add foo -ip 10.0.0.10 -contact "[email protected]"
host naptr_add -name foo -preference 16384 -order 3 -flag u -service "SIP" -regex "[abc]+" -replacement "wonk"
host remove foo
host remove foo -force -override naptr

# SRV
host add foo -ip 10.0.0.10 -contact "[email protected]"
host srv_add -name "_sip._tcp.example.org" -priority 10 -weight 5 -port 3456 -host foo.example.org
host remove foo # Should fail, because it has an SRV record, must force and override with 'srv'
host remove foo -force -override srv

# CNAME
host add foo -ip 10.0.0.10 -contact "[email protected]"
host cname_add foo fubar
host remove foo # Should fail, because it has a CNAME record, must force and override with 'cname'
host remove foo -force -override cname

# All of the above
host add foo -ip 10.0.0.10 -contact "[email protected]"
host mx_add foo 10 mail.example.org
host ptr_add 10.0.0.11 foo.example.org
host naptr_add -name foo -preference 16384 -order 3 -flag u -service "SIP" -regex "[abc]+" -replacement "wonk"
host srv_add -name "_sip._tcp.example.org" -priority 10 -weight 5 -port 3456 -host foo.example.org
host cname_add foo fubar
host remove foo # Should fail, because it has multiple records, must force and override with everything.
host remove foo -force -override mx,ptr,naptr,srv,cname


network remove 10.0.0.0/24 -f
network remove 2001:db8::/64 -f

Expand Down
Loading

0 comments on commit 32af34b

Please sign in to comment.