Listen for ownership-taken signal on DBus
Many tests that touch on device Ownership were using a
function that simply watched for the presence of policy
and owner key files to indicate that the session_manager
had completed the ownership-taking process on the sign-in
of the first user. This could be tricked, though, in the
case of the UI being restarted between the test clearing
these files and then checking for them again. Stop using
this and switch to watching for signals announcing that
ownership has been taken, which the session_manager has
sent all along anyhow.
BUG=chromium:355664
TEST=login_*Ownership*
Change-Id: I54000c426cfb1aef8fd1518f9cdadec2b42c6500
Reviewed-on: https://chromium-review.googlesource.com/194142
Reviewed-by: Chris Masone <cmasone@chromium.org>
Commit-Queue: Chris Masone <cmasone@chromium.org>
Tested-by: Chris Masone <cmasone@chromium.org>
diff --git a/client/common_lib/cros/policy.py b/client/common_lib/cros/policy.py
index 09a4e23..b039a7a 100644
--- a/client/common_lib/cros/policy.py
+++ b/client/common_lib/cros/policy.py
@@ -2,11 +2,12 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import dbus, sys
+import dbus, gobject, sys
import common
from autotest_lib.client.common_lib import error
-from autotest_lib.client.cros import login, ownership
+from autotest_lib.client.common_lib.cros import session_manager
+from autotest_lib.client.cros import ownership
"""Utility class for tests that generate, push and fetch policies.
@@ -165,8 +166,10 @@
@raises error.TestFail if policy push failed.
"""
+ listener = session_manager.OwnershipSignalListener(gobject.MainLoop())
+ listener.listen_for_new_policy()
sm.StorePolicy(dbus.ByteArray(policy_string), byte_arrays=True)
- login.wait_for_ownership()
+ listener.wait_for_signals(desc='Policy push.')
retrieved_policy = sm.RetrievePolicy(byte_arrays=True)
if retrieved_policy != policy_string:
diff --git a/client/common_lib/cros/session_manager.py b/client/common_lib/cros/session_manager.py
index 5457b02..4b8d6a5 100644
--- a/client/common_lib/cros/session_manager.py
+++ b/client/common_lib/cros/session_manager.py
@@ -114,20 +114,36 @@
@param g_mail_loop: glib main loop object.
"""
super(OwnershipSignalListener, self).__init__(g_main_loop)
+ self._listen_for_new_key = False
self._got_new_key = False
+ self._listen_for_new_policy = False
self._got_new_policy = False
+
def listen_for_new_key_and_policy(self):
"""Set to listen for signals indicating new owner key and device policy.
"""
+ self._listen_for_new_key = self._listen_for_new_policy = True
self.listen_to_signal(self.__handle_new_key, 'SetOwnerKeyComplete')
self.listen_to_signal(self.__handle_new_policy,
'PropertyChangeComplete')
+ self.reset_signal_state()
+
+
+ def listen_for_new_policy(self):
+ """Set to listen for signal indicating new device policy.
+ """
+ self._listen_for_new_key = False
+ self._listen_for_new_policy = True
+ self.listen_to_signal(self.__handle_new_policy,
+ 'PropertyChangeComplete')
+ self.reset_signal_state()
def reset_signal_state(self):
"""Resets internal signal tracking state."""
- self._got_new_policy = self._got_new_key = False
+ self._got_new_key = not self._listen_for_new_key
+ self._got_new_policy = not self._listen_for_new_policy
def all_signals_received(self):