Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Porting #52670 to master again #57637

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions changelog/49078.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use ip command instead of ifup/ifdown.
10 changes: 4 additions & 6 deletions salt/modules/debian_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* http://www.debian.org/doc/manuals/debian-reference/ch05.en.html
"""

# Import python libs

import functools
import logging
Expand All @@ -15,11 +14,8 @@
import re
import time

# Import third party libs
import jinja2
import jinja2.exceptions

# Import salt libs
import salt.utils.dns
import salt.utils.files
import salt.utils.odict
Expand Down Expand Up @@ -1775,7 +1771,8 @@ def down(iface, iface_type):
# Slave devices are controlled by the master.
# Source 'interfaces' aren't brought down.
if iface_type not in ["slave", "source"]:
return __salt__["cmd.run"](["ifdown", iface])
cmd = ["ip", "link", "set", iface, "down"]
return __salt__["cmd.run"](cmd, python_shell=False)
return None


Expand Down Expand Up @@ -1836,7 +1833,8 @@ def up(iface, iface_type): # pylint: disable=C0103
# Slave devices are controlled by the master.
# Source 'interfaces' aren't brought up.
if iface_type not in ("slave", "source"):
return __salt__["cmd.run"](["ifup", iface])
cmd = ["ip", "link", "set", iface, "up"]
return __salt__["cmd.run"](cmd, python_shell=False)
return None


Expand Down
16 changes: 9 additions & 7 deletions tests/unit/modules/test_debian_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

import jinja2.exceptions
import salt.modules.debian_ip as debian_ip

# Import Salt Testing Libs
import salt.utils.files
import salt.utils.platform
from tests.support.helpers import slowTest
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, patch
from tests.support.mock import MagicMock, patch, sentinel
from tests.support.unit import TestCase, skipIf

try:
Expand Down Expand Up @@ -917,9 +915,12 @@ def test_down(self):
"""
self.assertEqual(debian_ip.down("eth0", "slave"), None)

mock = MagicMock(return_value="Salt")
mock = MagicMock(return_value=sentinel.ret)
with patch.dict(debian_ip.__salt__, {"cmd.run": mock}):
self.assertEqual(debian_ip.down("eth0", "eth"), "Salt")
self.assertEqual(debian_ip.down("eth0", "eth"), sentinel.ret)
self.assertEqual(
mock.call_args[0], (["ip", "link", "set", "eth0", "down"],)
)

# 'get_bond' function tests: 1

Expand Down Expand Up @@ -1031,9 +1032,10 @@ def test_up(self):
"""
self.assertEqual(debian_ip.down("eth0", "slave"), None)

mock = MagicMock(return_value="Salt")
mock = MagicMock(return_value=sentinel.ret)
with patch.dict(debian_ip.__salt__, {"cmd.run": mock}):
self.assertEqual(debian_ip.up("eth0", "eth"), "Salt")
self.assertEqual(debian_ip.up("eth0", "eth"), sentinel.ret)
self.assertEqual(mock.call_args[0], (["ip", "link", "set", "eth0", "up"],))

# 'get_network_settings' function tests: 1

Expand Down