Merge "conman: Enable/disable ACS autoprovisioning."
diff --git a/conman/connection_manager.py b/conman/connection_manager.py
index 7379d88..708954f 100755
--- a/conman/connection_manager.py
+++ b/conman/connection_manager.py
@@ -188,7 +188,23 @@
run_duration_s=1, interface_update_period=5,
wifi_scan_period_s=120, wlan_retry_s=15, acs_update_wait_s=10):
- self.bridge = self.Bridge(bridge_interface, '10')
+ self._status_dir = status_dir
+ self._config_dir = config_dir
+ self._interface_status_dir = os.path.join(status_dir, 'interfaces')
+ self._moca_status_dir = moca_status_dir
+ self._wpa_control_interface = wpa_control_interface
+ self._run_duration_s = run_duration_s
+ self._interface_update_period = interface_update_period
+ self._wifi_scan_period_s = wifi_scan_period_s
+ self._wlan_retry_s = wlan_retry_s
+ self._acs_update_wait_s = acs_update_wait_s
+ self._wlan_configuration = {}
+
+ acs_autoprov_filepath = os.path.join(self._status_dir,
+ 'acs_autoprovisioning')
+ self.bridge = self.Bridge(
+ bridge_interface, '10',
+ acs_autoprovisioning_filepath=acs_autoprov_filepath)
# If we have multiple wcli interfaces, 5 GHz-only < both < 2.4 GHz-only.
def metric_for_bands(bands):
@@ -205,20 +221,8 @@
in get_client_interfaces().iteritems()],
key=lambda w: w.metric)
- self._status_dir = status_dir
- self._config_dir = config_dir
- self._interface_status_dir = os.path.join(status_dir, 'interfaces')
- self._moca_status_dir = moca_status_dir
- self._wpa_control_interface = wpa_control_interface
- self._run_duration_s = run_duration_s
- self._interface_update_period = interface_update_period
- self._wifi_scan_period_s = wifi_scan_period_s
for wifi in self.wifi:
wifi.last_wifi_scan_time = -self._wifi_scan_period_s
- self._wlan_retry_s = wlan_retry_s
- self._acs_update_wait_s = acs_update_wait_s
-
- self._wlan_configuration = {}
# Make sure all necessary directories exist.
for directory in (self._status_dir, self._config_dir,
diff --git a/conman/connection_manager_test.py b/conman/connection_manager_test.py
index c22fbeb..335f7ee 100755
--- a/conman/connection_manager_test.py
+++ b/conman/connection_manager_test.py
@@ -446,6 +446,11 @@
Args:
c: A ConnectionManager set up by @connection_manager_test.
"""
+ # This test only checks that this file gets created and deleted once each.
+ # ConnectionManager cares that the file is created *where* expected, but it is
+ # Bridge's responsbility to make sure its creation and deletion are generally
+ # correct; more thorough tests are in bridge_test in interface_test.py.
+ acs_autoprov_filepath = os.path.join(c._status_dir, 'acs_autoprovisioning')
# Initially, there is ethernet access (via explicit check of ethernet status,
# rather than the interface status file).
@@ -456,6 +461,7 @@
wvtest.WVPASS(c.acs())
wvtest.WVPASS(c.internet())
wvtest.WVPASS(c.bridge.current_route())
+ wvtest.WVPASS(os.path.exists(acs_autoprov_filepath))
wvtest.WVFAIL(c.wifi_for_band('2.4').current_route())
wvtest.WVFAIL(c.wifi_for_band('5').current_route())
@@ -465,6 +471,7 @@
wvtest.WVFAIL(c.acs())
wvtest.WVFAIL(c.internet())
wvtest.WVFAIL(c.bridge.current_route())
+ wvtest.WVFAIL(os.path.exists(acs_autoprov_filepath))
# Bring up moca, access.
c.set_moca(True)
diff --git a/conman/interface.py b/conman/interface.py
index 9b9c653..0f42e20 100755
--- a/conman/interface.py
+++ b/conman/interface.py
@@ -267,6 +267,8 @@
"""Represents the wired bridge."""
def __init__(self, *args, **kwargs):
+ self._acs_autoprovisioning_filepath = kwargs.pop(
+ 'acs_autoprovisioning_filepath')
super(Bridge, self).__init__(*args, **kwargs)
self._moca_stations = set()
@@ -296,6 +298,17 @@
self._moca_stations.remove(node_id)
self.moca = bool(self._moca_stations)
+ def add_route(self):
+ """We only want ACS autoprovisioning when we're using a wired route."""
+ super(Bridge, self).add_route()
+ open(self._acs_autoprovisioning_filepath, 'w')
+
+ def delete_route(self):
+ """We only want ACS autoprovisioning when we're using a wired route."""
+ if os.path.exists(self._acs_autoprovisioning_filepath):
+ os.unlink(self._acs_autoprovisioning_filepath)
+ super(Bridge, self).delete_route()
+
class Wifi(Interface):
"""Represents the wireless interface."""
diff --git a/conman/interface_test.py b/conman/interface_test.py
index 1e86125..f6e03d2 100755
--- a/conman/interface_test.py
+++ b/conman/interface_test.py
@@ -137,51 +137,66 @@
@wvtest.wvtest
def bridge_test():
"""Test Interface and Bridge."""
- b = Bridge('br0', '10')
- b.set_connection_check_result('succeed')
+ tmp_dir = tempfile.mkdtemp()
- wvtest.WVFAIL(b.acs())
- wvtest.WVFAIL(b.internet())
- wvtest.WVFAIL(b.current_route())
+ try:
+ autoprov_filepath = os.path.join(tmp_dir, 'autoprov')
+ b = Bridge('br0', '10', acs_autoprovisioning_filepath=autoprov_filepath)
+ b.set_connection_check_result('succeed')
- b.add_moca_station(0)
- b.set_gateway_ip('192.168.1.1')
- # Everything should fail because the interface is not initialized.
- wvtest.WVFAIL(b.acs())
- wvtest.WVFAIL(b.internet())
- wvtest.WVFAIL(b.current_route())
- b.initialize()
- wvtest.WVPASS(b.acs())
- wvtest.WVPASS(b.internet())
- wvtest.WVPASS(b.current_route())
+ wvtest.WVFAIL(b.acs())
+ wvtest.WVFAIL(b.internet())
+ wvtest.WVFAIL(b.current_route())
+ wvtest.WVFAIL(os.path.exists(autoprov_filepath))
- b.add_moca_station(1)
- wvtest.WVPASS(b.acs())
- wvtest.WVPASS(b.internet())
- wvtest.WVPASS(b.current_route())
+ b.add_moca_station(0)
+ b.set_gateway_ip('192.168.1.1')
+ # Everything should fail because the interface is not initialized.
+ wvtest.WVFAIL(b.acs())
+ wvtest.WVFAIL(b.internet())
+ wvtest.WVFAIL(b.current_route())
+ wvtest.WVFAIL(os.path.exists(autoprov_filepath))
+ b.initialize()
+ wvtest.WVPASS(b.acs())
+ wvtest.WVPASS(b.internet())
+ wvtest.WVPASS(b.current_route())
+ wvtest.WVPASS(os.path.exists(autoprov_filepath))
- b.remove_moca_station(0)
- b.remove_moca_station(1)
- wvtest.WVFAIL(b.acs())
- wvtest.WVFAIL(b.internet())
- wvtest.WVFAIL(b.current_route())
+ b.add_moca_station(1)
+ wvtest.WVPASS(b.acs())
+ wvtest.WVPASS(b.internet())
+ wvtest.WVPASS(b.current_route())
+ wvtest.WVPASS(os.path.exists(autoprov_filepath))
- b.add_moca_station(2)
- wvtest.WVPASS(b.acs())
- wvtest.WVPASS(b.internet())
- wvtest.WVPASS(b.current_route())
+ b.remove_moca_station(0)
+ b.remove_moca_station(1)
+ wvtest.WVFAIL(b.acs())
+ wvtest.WVFAIL(b.internet())
+ wvtest.WVFAIL(b.current_route())
+ wvtest.WVFAIL(os.path.exists(autoprov_filepath))
- b.set_connection_check_result('fail')
- b.update_routes()
- wvtest.WVFAIL(b.acs())
- wvtest.WVFAIL(b.internet())
- wvtest.WVFAIL(b.current_route())
+ b.add_moca_station(2)
+ wvtest.WVPASS(b.acs())
+ wvtest.WVPASS(b.internet())
+ wvtest.WVPASS(b.current_route())
+ wvtest.WVPASS(os.path.exists(autoprov_filepath))
- b.set_connection_check_result('restricted')
- b.update_routes()
- wvtest.WVPASS(b.acs())
- wvtest.WVFAIL(b.internet())
- wvtest.WVPASS(b.current_route())
+ b.set_connection_check_result('fail')
+ b.update_routes()
+ wvtest.WVFAIL(b.acs())
+ wvtest.WVFAIL(b.internet())
+ wvtest.WVFAIL(b.current_route())
+ wvtest.WVFAIL(os.path.exists(autoprov_filepath))
+
+ b.set_connection_check_result('restricted')
+ b.update_routes()
+ wvtest.WVPASS(b.acs())
+ wvtest.WVFAIL(b.internet())
+ wvtest.WVPASS(b.current_route())
+ wvtest.WVPASS(os.path.exists(autoprov_filepath))
+
+ finally:
+ shutil.rmtree(tmp_dir)
@wvtest.wvtest