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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import annotations

import ipaddress
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -128,6 +129,9 @@ def archive(self) -> None:
router.save(ignore_permissions=True)
if pool:
pool.gateway = None
# A direct provider pool hands out its whole prefix.
if pool.source == "Provider":
pool.allocation_prefix_length = ipaddress.ip_network(pool.prefix, strict=False).prefixlen
pool.save(ignore_permissions=True)

frappe.msgprint(_("IPv6 Router Server {0} is archived.").format(self.name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,19 @@ def test_archive_queues_the_pool_detach_instead_of_running_it(self) -> None:
pool.queue_reconcile.assert_called_once_with()
pool.reconcile.assert_not_called()
self.assertEqual(router.status, "Archived")

def test_archive_returns_a_provider_pool_to_one_allocation(self) -> None:
pool = MagicMock(source="Provider", prefix="2001:db8::/80", allocation_prefix_length=128)
router = MagicMock(status="Failed", virtual_machine=None, pool=pool)
with (
patch.object(router_module, "_validate_system_manager"),
patch.object(router_module, "ipv6_router_lifecycle_lock", return_value=nullcontext()),
patch.object(router_module.frappe, "get_doc", return_value=router),
patch.object(router_module.frappe.db, "exists", return_value=False),
patch.object(router_module.frappe, "msgprint"),
):
IPv6RouterServer.archive(SimpleNamespace(doctype="IPv6 Router Server", name="ipv6-router-001"))

self.assertIsNone(pool.gateway)
self.assertEqual(pool.allocation_prefix_length, 80)
pool.save.assert_called_once_with(ignore_permissions=True)
Loading