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

Resolve "Felix dies if interface missing" on Alpine #902

Merged
merged 1 commit into from
Nov 19, 2015
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
7 changes: 6 additions & 1 deletion calico/felix/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ def interface_exists(interface):
futils.check_call(["ip", "link", "list", interface])
return True
except futils.FailedSystemCall as fsc:
if fsc.stderr.count("does not exist") != 0:
# If the interface doesn't exist, the error message varies by
# flavor of Linux:
# * Ubuntu/RHEL: "Device 'XYZ' does not exist"
# * Alpine: "ip: can't find device 'XYZ'"
if ("does not exist" in fsc.stderr) or \
("can't find device" in fsc.stderr):
return False
else:
# An error other than does not exist; just pass on up
Expand Down
18 changes: 13 additions & 5 deletions calico/felix/test/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ def test_interface_exists(self):
args = []
retcode = 1
stdout = ""
stderr = "Device \"%s\" does not exist." % tap
err = futils.FailedSystemCall("From test", args, retcode, stdout, stderr)

with mock.patch('calico.felix.futils.check_call', side_effect=err):
self.assertFalse(devices.interface_exists(tap))
futils.check_call.assert_called_with(["ip", "link", "list", tap])
# Check we correctly handle error messages for a missing interface,
# and do so for all supported flavors of Linux.
error_messages = [
"Device \"%s\" does not exist." % tap, # Ubuntu/RHEL
"ip: can't find device '%s'" % tap, # Alpine
]

for stderr in error_messages:
err = futils.FailedSystemCall("From test", args, retcode, stdout, stderr)

with mock.patch('calico.felix.futils.check_call', side_effect=err):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer getting the mock by doing as m_check_call; it's a bit more explicit

self.assertFalse(devices.interface_exists(tap))
futils.check_call.assert_called_with(["ip", "link", "list", tap])

with mock.patch('calico.felix.futils.check_call'):
self.assertTrue(devices.interface_exists(tap))
Expand Down