Skip to content
Snippets Groups Projects
Verified Commit 3e483c53 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

Infoblox error behaviour more loose

Don't raise exception when allocating existing host/network or deleting non-existent ones
parent fae59e17
No related branches found
No related tags found
1 merge request!199Remove cancelation workflow
Pipeline #86209 passed
...@@ -19,10 +19,6 @@ class AllocationError(Exception): ...@@ -19,10 +19,6 @@ class AllocationError(Exception):
"""Raised when Infoblox failed to allocate a resource.""" """Raised when Infoblox failed to allocate a resource."""
class DeletionError(Exception):
"""Raised when Infoblox failed to delete a resource."""
def _setup_connection() -> tuple[connector.Connector, IPAMParams]: def _setup_connection() -> tuple[connector.Connector, IPAMParams]:
"""Set up a new connection with an Infoblox instance. """Set up a new connection with an Infoblox instance.
...@@ -158,7 +154,7 @@ def delete_network(ip_network: ipaddress.IPv4Network | ipaddress.IPv6Network) -> ...@@ -158,7 +154,7 @@ def delete_network(ip_network: ipaddress.IPv4Network | ipaddress.IPv6Network) ->
network.delete() network.delete()
else: else:
msg = f"Could not find network {ip_network}, nothing has been deleted." msg = f"Could not find network {ip_network}, nothing has been deleted."
raise DeletionError(msg) logger.warning(msg)
def allocate_host( def allocate_host(
...@@ -253,8 +249,9 @@ def create_host_by_ip( ...@@ -253,8 +249,9 @@ def create_host_by_ip(
:term:`GSO`. :term:`GSO`.
""" """
if not hostname_available(hostname): if not hostname_available(hostname):
msg = f"Cannot allocate new host, FQDN {hostname} already taken." msg = f"FQDN {hostname} already taken, nothing to be done."
raise AllocationError(msg) logger.warning(msg)
return
conn, oss = _setup_connection() conn, oss = _setup_connection()
ipv6_object = objects.IP.create(ip=str(ipv6_address), mac=NULL_MAC, configure_for_dhcp=False) ipv6_object = objects.IP.create(ip=str(ipv6_address), mac=NULL_MAC, configure_for_dhcp=False)
...@@ -331,7 +328,7 @@ def delete_host_by_ip(ip_addr: ipaddress.IPv4Address | ipaddress.IPv6Address) -> ...@@ -331,7 +328,7 @@ def delete_host_by_ip(ip_addr: ipaddress.IPv4Address | ipaddress.IPv6Address) ->
host.delete() host.delete()
else: else:
msg = f"Could not find host at {ip_addr}, nothing has been deleted." msg = f"Could not find host at {ip_addr}, nothing has been deleted."
raise DeletionError(msg) logger.warning(msg)
def delete_host_by_fqdn(fqdn: str) -> None: def delete_host_by_fqdn(fqdn: str) -> None:
...@@ -348,4 +345,4 @@ def delete_host_by_fqdn(fqdn: str) -> None: ...@@ -348,4 +345,4 @@ def delete_host_by_fqdn(fqdn: str) -> None:
host.delete() host.delete()
else: else:
msg = f"Could not find host at {fqdn}, nothing has been deleted." msg = f"Could not find host at {fqdn}, nothing has been deleted."
raise DeletionError(msg) logger.warning(msg)
...@@ -15,7 +15,6 @@ from orchestrator.forms import FormPage ...@@ -15,7 +15,6 @@ from orchestrator.forms import FormPage
from orchestrator.forms.validators import Choice, Label, UniqueConstrainedList from orchestrator.forms.validators import Choice, Label, UniqueConstrainedList
from orchestrator.targets import Target from orchestrator.targets import Target
from orchestrator.types import FormGenerator, State, UUIDstr from orchestrator.types import FormGenerator, State, UUIDstr
from orchestrator.utils.errors import ProcessFailureError
from orchestrator.utils.json import json_dumps from orchestrator.utils.json import json_dumps
from orchestrator.workflow import StepList, conditional, done, init, inputstep from orchestrator.workflow import StepList, conditional, done, init, inputstep
from orchestrator.workflows.steps import resync, store_process_subscription, unsync from orchestrator.workflows.steps import resync, store_process_subscription, unsync
...@@ -28,7 +27,6 @@ from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlock ...@@ -28,7 +27,6 @@ from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlock
from gso.products.product_types.iptrunk import Iptrunk from gso.products.product_types.iptrunk import Iptrunk
from gso.products.product_types.router import Router from gso.products.product_types.router import Router
from gso.services import infoblox from gso.services import infoblox
from gso.services.infoblox import DeletionError
from gso.services.lso_client import execute_playbook, lso_interaction from gso.services.lso_client import execute_playbook, lso_interaction
from gso.services.netbox_client import NetboxClient from gso.services.netbox_client import NetboxClient
from gso.services.subscriptions import get_active_router_subscriptions from gso.services.subscriptions import get_active_router_subscriptions
...@@ -609,12 +607,7 @@ def update_ipam(subscription: Iptrunk, replace_index: int, new_node: Router, new ...@@ -609,12 +607,7 @@ def update_ipam(subscription: Iptrunk, replace_index: int, new_node: Router, new
v6_addr = subscription.iptrunk.iptrunk_ipv6_network[replace_index + 1] v6_addr = subscription.iptrunk.iptrunk_ipv6_network[replace_index + 1]
# Out with the old # Out with the old
try: infoblox.delete_host_by_ip(subscription.iptrunk.iptrunk_ipv4_network[replace_index])
infoblox.delete_host_by_ip(subscription.iptrunk.iptrunk_ipv4_network[replace_index])
except DeletionError as e:
msg = "Failed to delete record from Infoblox."
raise ProcessFailureError(msg) from e
# And in with the new # And in with the new
new_fqdn = f"{new_lag_interface}-0.{new_node.router.router_fqdn}" new_fqdn = f"{new_lag_interface}-0.{new_node.router.router_fqdn}"
comment = str(subscription.subscription_id) comment = str(subscription.subscription_id)
......
import ipaddress import ipaddress
import logging
import re import re
from os import PathLike from os import PathLike
...@@ -7,7 +8,7 @@ import responses ...@@ -7,7 +8,7 @@ import responses
from requests import codes from requests import codes
from gso.services import infoblox from gso.services import infoblox
from gso.services.infoblox import AllocationError, DeletionError from gso.services.infoblox import AllocationError
def _set_up_network_responses(): def _set_up_network_responses():
...@@ -216,17 +217,16 @@ def test_delete_good_network(data_config_filename: PathLike): ...@@ -216,17 +217,16 @@ def test_delete_good_network(data_config_filename: PathLike):
@responses.activate @responses.activate
def test_delete_non_existent_network(data_config_filename: PathLike): def test_delete_non_existent_network(data_config_filename: PathLike, caplog):
responses.add( responses.add(
method=responses.GET, method=responses.GET,
url="https://10.0.0.1/wapi/v2.12/network?network=10.255.255.0%2F26&_return_fields=comment%2Cextattrs%2Cnetwork%" url="https://10.0.0.1/wapi/v2.12/network?network=10.255.255.0%2F26&_return_fields=comment%2Cextattrs%2Cnetwork%"
"2Cnetwork_view", "2Cnetwork_view",
json=[], json=[],
) )
caplog.set_level(logging.WARNING)
with pytest.raises(DeletionError) as e: infoblox.delete_network(ipaddress.IPv4Network("10.255.255.0/26"))
infoblox.delete_network(ipaddress.IPv4Network("10.255.255.0/26")) assert "Could not find network 10.255.255.0/26, nothing has been deleted." in caplog.text
assert e.value.args[0] == "Could not find network 10.255.255.0/26, nothing has been deleted."
@responses.activate @responses.activate
...@@ -277,21 +277,19 @@ def test_delete_good_host(data_config_filename: PathLike): ...@@ -277,21 +277,19 @@ def test_delete_good_host(data_config_filename: PathLike):
@responses.activate @responses.activate
def test_delete_bad_host(data_config_filename: PathLike): def test_delete_bad_host(data_config_filename: PathLike, caplog):
responses.add( responses.add(
method=responses.GET, method=responses.GET,
url=re.compile(r".+"), url=re.compile(r".+"),
json=[], json=[],
) )
caplog.set_level(logging.WARNING)
with pytest.raises(DeletionError) as e: infoblox.delete_host_by_ip(ipaddress.IPv4Address("10.255.255.1"))
infoblox.delete_host_by_ip(ipaddress.IPv4Address("10.255.255.1")) assert "Could not find host at 10.255.255.1, nothing has been deleted." in caplog.text
assert e.value.args[0] == "Could not find host at 10.255.255.1, nothing has been deleted."
with pytest.raises(DeletionError) as e: infoblox.delete_host_by_ip(ipaddress.IPv6Address("dead:beef::1"))
infoblox.delete_host_by_ip(ipaddress.IPv6Address("dead:beef::1")) assert "Could not find host at dead:beef::1, nothing has been deleted." in caplog.text
assert e.value.args[0] == "Could not find host at dead:beef::1, nothing has been deleted."
with pytest.raises(DeletionError) as e: infoblox.delete_host_by_fqdn("fake.host.net")
infoblox.delete_host_by_fqdn("fake.host.net") assert "Could not find host at fake.host.net, nothing has been deleted." in caplog.text
assert e.value.args[0] == "Could not find host at fake.host.net, nothing has been deleted."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment