From 99b7e7e5ee3b86f8c845e1190084228360688d90 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 30 Apr 2013 17:08:08 +0100 Subject: [PATCH 1/4] Add a regression test for NetworkManager's "not quite offline" states We were only testing the intersection of ConnMan and NM functionality, but NM actually has a bit more. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=56635 Signed-off-by: Simon McVittie --- tests/twisted/Makefile.am | 3 +++ tests/twisted/account-manager/connectivity.py | 23 +++++++++++++++++++++++ tests/twisted/fakeconnectivity.py | 16 ++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index 7542e46..ed95405 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -147,7 +147,9 @@ endif if HAVE_NM HAVE_CONNECTIVITY_PYBOOL = True +HAVE_NM_PYBOOL = True else +HAVE_NM_PYBOOL = False if HAVE_CONNMAN HAVE_CONNECTIVITY_PYBOOL = True else @@ -158,6 +160,7 @@ endif config.py: Makefile $(AM_V_GEN) { \ echo "HAVE_MCE = $(HAVE_MCE_PYBOOL)"; \ + echo "HAVE_NM = $(HAVE_NM_PYBOOL)"; \ echo "HAVE_CONNECTIVITY = $(HAVE_CONNECTIVITY_PYBOOL)"; \ } > $@ diff --git a/tests/twisted/account-manager/connectivity.py b/tests/twisted/account-manager/connectivity.py index 0f1c340..0198545 100644 --- a/tests/twisted/account-manager/connectivity.py +++ b/tests/twisted/account-manager/connectivity.py @@ -92,6 +92,29 @@ def test(q, bus, mc): args=list(requested_presence[1:])), ]) + if config.HAVE_NM: + # If NetworkManager tells us that it is going to disconnect soon, + # the connection should be banished. GNetworkMonitor can't tell us + # that; either it's online or it isn't. + mc.connectivity.go_indeterminate() + q.expect('dbus-method-call', method='Disconnect') + + mc.connectivity.go_offline() + + # When we turn the network back on, MC should try to sign us back on. + # In the process, our RequestedPresence should not have been + # trampled on, as below. + mc.connectivity.go_online() + expect_fakecm_connection(q, bus, mc, account, params, + has_presence=True, + expect_before_connect=[ + EventPattern('dbus-method-call', method='SetPresence', + args=list(requested_presence[1:])), + ]) + + assertEquals(requested_presence, + account.Properties.Get(cs.ACCOUNT, 'RequestedPresence')) + # If we turn the network off, the connection should be banished. mc.connectivity.go_offline() q.expect('dbus-method-call', method='Disconnect') diff --git a/tests/twisted/fakeconnectivity.py b/tests/twisted/fakeconnectivity.py index c144452..ccc62e5 100644 --- a/tests/twisted/fakeconnectivity.py +++ b/tests/twisted/fakeconnectivity.py @@ -98,8 +98,11 @@ class FakeConnectivity(object): def ConnMan_GetProperties(self, e): self.q.dbus_return(e.message, self.Connman_props(), signature='a{sv}') - def change_state(self, online): - if online: + def change_state(self, online, indeterminate=False): + if indeterminate: + self.nm_state = self.NM_STATE_DISCONNECTING + # keep the previous ConnMan state + elif online: self.nm_state = self.NM_STATE_CONNECTED_GLOBAL self.connman_state = self.CONNMAN_ONLINE else: @@ -112,11 +115,16 @@ class FakeConnectivity(object): self.q.dbus_emit(self.NM_PATH, self.NM_INTERFACE, 'StateChanged', self.nm_state, signature='u') - self.q.dbus_emit(self.CONNMAN_PATH, self.CONNMAN_INTERFACE, - 'PropertyChanged', "State", self.connman_state, signature='sv') + + if not indeterminate: + self.q.dbus_emit(self.CONNMAN_PATH, self.CONNMAN_INTERFACE, + 'PropertyChanged', "State", self.connman_state, signature='sv') def go_online(self): self.change_state(True) def go_offline(self): self.change_state(False) + + def go_indeterminate(self): + self.change_state(None, True) -- 1.7.10.4