Encoding changes in tests for py3

In many cases we do need to be explicit about bytes vs. strings for
python 3 compatibility.

Change-Id: I9cbc5c73004d03f711f8a6e5752a0865ae55fb9f
diff --git a/tests/base.py b/tests/base.py
index f355e50..b668322 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -981,7 +981,7 @@
                     return
 
     def stop(self):
-        os.write(self.wake_write, '1\n')
+        os.write(self.wake_write, b'1\n')
 
 
 class FakeBuild(object):
@@ -1265,7 +1265,7 @@
         for queue in [self.high_queue, self.normal_queue, self.low_queue]:
             for job in queue:
                 if not hasattr(job, 'waiting'):
-                    if job.name.startswith('executor:execute'):
+                    if job.name.startswith(b'executor:execute'):
                         job.waiting = self.hold_jobs_in_queue
                     else:
                         job.waiting = False
@@ -1383,7 +1383,7 @@
             path = self.REQUEST_ROOT + '/' + oid
             try:
                 data, stat = self.client.get(path)
-                data = json.loads(data)
+                data = json.loads(data.decode('utf8'))
                 data['_oid'] = oid
                 reqs.append(data)
             except kazoo.exceptions.NoNodeError:
@@ -1399,7 +1399,7 @@
         for oid in sorted(nodeids):
             path = self.NODE_ROOT + '/' + oid
             data, stat = self.client.get(path)
-            data = json.loads(data)
+            data = json.loads(data.decode('utf8'))
             data['_oid'] = oid
             try:
                 lockfiles = self.client.get_children(path + '/lock')
@@ -1431,7 +1431,7 @@
                     image_id=None,
                     host_keys=["fake-key1", "fake-key2"],
                     executor='fake-nodepool')
-        data = json.dumps(data)
+        data = json.dumps(data).encode('utf8')
         path = self.client.create(path, data,
                                   makepath=True,
                                   sequence=True)
@@ -1460,7 +1460,7 @@
 
         request['state_time'] = time.time()
         path = self.REQUEST_ROOT + '/' + oid
-        data = json.dumps(request)
+        data = json.dumps(request).encode('utf8')
         self.log.debug("Fulfilling node request: %s %s" % (oid, data))
         self.client.set(path, data)
 
@@ -2202,8 +2202,9 @@
             if build.url is None:
                 self.log.debug("%s has not reported start" % build)
                 return False
+            # using internal ServerJob which offers no Text interface
             worker_build = self.executor_server.job_builds.get(
-                server_job.unique)
+                server_job.unique.decode('utf8'))
             if worker_build:
                 if worker_build.isWaiting():
                     continue
@@ -2307,7 +2308,7 @@
         start = time.time()
         while time.time() < (start + 5):
             for stat in self.statsd.stats:
-                k, v = stat.split(':')
+                k, v = stat.decode('utf-8').split(':')
                 if key == k:
                     if value is None and kind is None:
                         return
diff --git a/tests/unit/test_encryption.py b/tests/unit/test_encryption.py
index 4dda78b..b424769 100644
--- a/tests/unit/test_encryption.py
+++ b/tests/unit/test_encryption.py
@@ -41,14 +41,14 @@
 
     def test_pkcs1_oaep(self):
         "Verify encryption and decryption"
-        orig_plaintext = "some text to encrypt"
+        orig_plaintext = b"some text to encrypt"
         ciphertext = encryption.encrypt_pkcs1_oaep(orig_plaintext, self.public)
         plaintext = encryption.decrypt_pkcs1_oaep(ciphertext, self.private)
         self.assertEqual(orig_plaintext, plaintext)
 
     def test_openssl_pkcs1_oaep(self):
         "Verify that we can decrypt something encrypted with OpenSSL"
-        orig_plaintext = "some text to encrypt"
+        orig_plaintext = b"some text to encrypt"
         pem_public = encryption.serialize_rsa_public_key(self.public)
         public_file = tempfile.NamedTemporaryFile(delete=False)
         try:
diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py
index 61e9683..aaf7132 100755
--- a/tests/unit/test_scheduler.py
+++ b/tests/unit/test_scheduler.py
@@ -530,8 +530,8 @@
         queue = self.gearman_server.getQueue()
         self.assertEqual(len(self.builds), 0)
         self.assertEqual(len(queue), 1)
-        self.assertEqual(queue[0].name, 'executor:execute')
-        job_args = json.loads(queue[0].arguments)
+        self.assertEqual(queue[0].name, b'executor:execute')
+        job_args = json.loads(queue[0].arguments.decode('utf8'))
         self.assertEqual(job_args['job'], 'project-merge')
         self.assertEqual(job_args['items'][0]['number'], '%d' % A.number)
 
@@ -547,17 +547,23 @@
         self.assertEqual(len(queue), 6)
 
         self.assertEqual(
-            json.loads(queue[0].arguments)['job'], 'project-test1')
+            json.loads(queue[0].arguments.decode('utf8'))['job'],
+            'project-test1')
         self.assertEqual(
-            json.loads(queue[1].arguments)['job'], 'project-test2')
+            json.loads(queue[1].arguments.decode('utf8'))['job'],
+            'project-test2')
         self.assertEqual(
-            json.loads(queue[2].arguments)['job'], 'project-test1')
+            json.loads(queue[2].arguments.decode('utf8'))['job'],
+            'project-test1')
         self.assertEqual(
-            json.loads(queue[3].arguments)['job'], 'project-test2')
+            json.loads(queue[3].arguments.decode('utf8'))['job'],
+            'project-test2')
         self.assertEqual(
-            json.loads(queue[4].arguments)['job'], 'project-test1')
+            json.loads(queue[4].arguments.decode('utf8'))['job'],
+            'project-test1')
         self.assertEqual(
-            json.loads(queue[5].arguments)['job'], 'project-test2')
+            json.loads(queue[5].arguments.decode('utf8'))['job'],
+            'project-test2')
 
         self.release(queue[0])
         self.waitUntilSettled()
@@ -2227,7 +2233,7 @@
         self.assertIn('Cache-Control', headers)
         self.assertIn('Last-Modified', headers)
         self.assertIn('Expires', headers)
-        data = f.read()
+        data = f.read().decode('utf8')
 
         self.executor_server.hold_jobs_in_build = False
         self.executor_server.release()
@@ -2712,7 +2718,7 @@
         req = urllib.request.Request(
             "http://localhost:%s/tenant-one/status" % port)
         f = urllib.request.urlopen(req)
-        data = f.read()
+        data = f.read().decode('utf8')
 
         self.executor_server.hold_jobs_in_build = False
         # Stop queuing timer triggered jobs so that the assertions