Add swarming lib and its integration test.

BUG=chromium:728397
TEST=Ran 'python runner.py --test_type integration',
Ran 'python runner.py --test_type integration --debug'.

Change-Id: I8c97fc90ab7b535451cedc5a6b2eaad868a5a803
diff --git a/utils.py b/utils.py
new file mode 100644
index 0000000..3872336
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,54 @@
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Module for use by any callers."""
+
+import logging
+
+import time
+
+
+DEFAULT_TIMEOUT_SEC = 10
+
+
+def wait_for_value(func, expected_value=None, exception_to_raise=(),
+                   timeout_sec=DEFAULT_TIMEOUT_SEC):
+  """Wait to return the value of func().
+
+  If |expected_value| is not set, return immediately.
+
+  If |expected_value| is set, polls the return value until |expected_value|
+  is reached, and returns that value.
+
+  Polling will stop after |timeout_sec| regardless of these thresholds.
+
+  Args:
+    func: function whose return value is to be waited on.
+    expected_value: wait for func to return this value.
+    exception_to_raise: exceptions that func() could raise.
+    timeout_sec: Number of seconds to wait before giving up and
+      returning whatever value func() last returned.
+
+  Returns:
+    The most recent return value of func().
+
+  Raises:
+    Unexpected exceptions: not exist in exception_to_raise.
+  """
+  value = None
+  start_time_sec = time.time()
+  while True:
+    time.sleep(0.1)
+    try:
+      value = func()
+      if (expected_value is None or
+          (expected_value is not None and value == expected_value)):
+        break
+
+      if time.time() - start_time_sec >= timeout_sec:
+        break
+    except exception_to_raise as e:
+      logging.warning(str(e))
+
+  return value