Allow to pass custom reason in NetworkInUse exception

In order to pass custom reason like what ports are
being used on the network, need to allow the Exception
to except "reason" argument.

Related-Bug: #1953716
Change-Id: I264cda4ac8d5a737e172a62fa2761fd14fc746f3
This commit is contained in:
2021-12-15 14:09:47 +05:30
parent 48345c6e3c
commit 6a922e45b0
2 changed files with 16 additions and 1 deletions

View File

@@ -177,9 +177,18 @@ class NetworkInUse(InUse):
network.
:param net_id: The UUID of the network requested.
:param reason: Details on why the operation failed. If None, a default
reason is used indicating one or more ports still in use
on the network.
"""
message = _("Unable to complete operation on network %(net_id)s. "
"There are one or more ports still in use on the network.")
"%(reason)s.")
def __init__(self, **kwargs):
if 'reason' not in kwargs:
kwargs['reason'] = _("There are one or more ports still in use "
"on the network")
super().__init__(**kwargs)
class SubnetInUse(InUse):

View File

@@ -129,6 +129,12 @@ class TestExceptions(base.BaseTestCase):
"There are one or more ports still in use on the network."),
net_id="foo")
def test_network_in_use_custom_reason(self):
self._check_nexc(
ne.NetworkInUse,
_("Unable to complete operation on network foo. not full."),
net_id="foo", reason="not full")
def test_subnet_in_use(self):
self._check_nexc(
ne.SubnetInUse,