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

rbxcloud: gracefully handle arping errors #262

Merged
merged 3 commits into from
Mar 31, 2020
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
17 changes: 12 additions & 5 deletions cloudinit/sources/DataSourceRbxCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ def gratuitous_arp(items, distro):
if distro.name in ['fedora', 'centos', 'rhel']:
source_param = '-s'
for item in items:
_sub_arp([
'-c', '2',
source_param, item['source'],
item['destination']
])
try:
_sub_arp([
'-c', '2',
source_param, item['source'],
item['destination']
])
except util.ProcessExecutionError as error:
# warning, because the system is able to function properly
# despite no success - some ARP table may be waiting for
# expiration, but the system may continue
LOG.warning('Failed to arping from "%s" to "%s": %s',
item['source'], item['destination'], error)


def get_md():
Expand Down
30 changes: 30 additions & 0 deletions tests/unittests/test_datasource/test_rbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from cloudinit import distros
from cloudinit.sources import DataSourceRbxCloud as ds
from cloudinit.tests.helpers import mock, CiTestCase, populate_dir
from cloudinit import util

DS_PATH = "cloudinit.sources.DataSourceRbxCloud"

Expand Down Expand Up @@ -199,6 +200,35 @@ def test_handle_rhel_like_arping(self, m_subp):
m_subp.call_args_list
)

@mock.patch(
DS_PATH + '.util.subp',
side_effect=util.ProcessExecutionError()
)
def test_continue_on_arping_error(self, m_subp):
"""Continue when command error"""
items = [
{
'destination': '172.17.0.2',
'source': '172.16.6.104'
},
{
'destination': '172.17.0.2',
'source': '172.16.6.104',
},
]
ds.gratuitous_arp(items, self._fetch_distro('ubuntu'))
self.assertEqual([
mock.call([
'arping', '-c', '2', '-S',
'172.16.6.104', '172.17.0.2'
]),
mock.call([
'arping', '-c', '2', '-S',
'172.16.6.104', '172.17.0.2'
])
], m_subp.call_args_list
)


def populate_cloud_metadata(path, data):
populate_dir(path, {'cloud.json': json.dumps(data)})
Expand Down