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:
@@ -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):
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user