mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
[#56901] network.managed state failed to bring down lo ip alias
- Added support to lo ip alias in network.managed state - Added test case for the change
This commit is contained in:
parent
fd57240894
commit
b9ceb89e9d
3 changed files with 42 additions and 1 deletions
3
changelog/56901.fixed
Normal file
3
changelog/56901.fixed
Normal file
|
@ -0,0 +1,3 @@
|
|||
Added support to lo ip alias in network.managed state by checking if lo inet data
|
||||
from network.interfaces contains label with the name of managed interface.
|
||||
Return status True if match found.
|
|
@ -494,6 +494,19 @@ def managed(name, type, enabled=True, **kwargs):
|
|||
for second in interfaces[iface]["secondary"]:
|
||||
if second.get("label", "") == name:
|
||||
interface_status = True
|
||||
if iface == "lo":
|
||||
if "inet" in interfaces[iface]:
|
||||
inet_data = interfaces[iface]["inet"]
|
||||
if len(inet_data) > 1:
|
||||
for data in inet_data:
|
||||
if data.get("label", "") == name:
|
||||
interface_status = True
|
||||
if "inet6" in interfaces[iface]:
|
||||
inet6_data = interfaces[iface]["inet6"]
|
||||
if len(inet6_data) > 1:
|
||||
for data in inet6_data:
|
||||
if data.get("label", "") == name:
|
||||
interface_status = True
|
||||
if enabled:
|
||||
if "noifupdown" not in kwargs:
|
||||
if interface_status:
|
||||
|
|
|
@ -32,7 +32,11 @@ class MockNetwork(object):
|
|||
"""
|
||||
Mock interface method
|
||||
"""
|
||||
return {"salt": {"up": 1}}
|
||||
ifaces = {
|
||||
"salt": {"up": 1},
|
||||
"lo": {"up": 1, "inet": [{"label": "lo"}, {"label": "lo:alias1"}]},
|
||||
}
|
||||
return ifaces
|
||||
|
||||
|
||||
class MockGrains(object):
|
||||
|
@ -127,6 +131,27 @@ class NetworkTestCase(TestCase, LoaderModuleMockMixin):
|
|||
network.managed("salt", "stack", False), ret
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value=True)
|
||||
with patch.dict(network.__salt__, {"ip.down": mock}):
|
||||
with patch.dict(
|
||||
network.__salt__, {"saltutil.refresh_modules": mock}
|
||||
):
|
||||
change = {
|
||||
"interface": "--- \n+++ \n@@ -1 +1 @@\n-A\n+B",
|
||||
"status": "Interface lo:alias1 down",
|
||||
}
|
||||
ret.update(
|
||||
{
|
||||
"name": "lo:alias1",
|
||||
"comment": "Interface lo:alias1 updated.",
|
||||
"result": True,
|
||||
"changes": change,
|
||||
}
|
||||
)
|
||||
self.assertDictEqual(
|
||||
network.managed("lo:alias1", "eth", False), ret
|
||||
)
|
||||
|
||||
def test_routes(self):
|
||||
"""
|
||||
Test to manage network interface static routes.
|
||||
|
|
Loading…
Add table
Reference in a new issue