Skip to content

Commit

Permalink
Merge pull request #902 from projectcalico/awlc/alpine-missing-iface-fix
Browse files Browse the repository at this point in the history
Resolve "Felix dies if interface missing" on Alpine
  • Loading branch information
alexwlchan committed Nov 19, 2015
2 parents 3d2c9bc + fdfc50d commit 2a36f87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion calico/felix/devices.py
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
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):
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

0 comments on commit 2a36f87

Please sign in to comment.