summaryrefslogtreecommitdiff
path: root/tests/test_worker_manager.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_worker_manager.py')
-rw-r--r--tests/test_worker_manager.py77
1 files changed, 4 insertions, 73 deletions
diff --git a/tests/test_worker_manager.py b/tests/test_worker_manager.py
index ff0733f..741f223 100644
--- a/tests/test_worker_manager.py
+++ b/tests/test_worker_manager.py
@@ -1,5 +1,3 @@
-#!/usr/bin/python2
-#
# Copyright 2013 Rackspace Australia
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -14,81 +12,14 @@
# License for the specific language governing permissions and limitations
# under the License.
-
-import fixtures
-import gear
-import logging
import os
-import testtools
import time
-import yaml
-
-import turbo_hipster.task_plugins.gate_real_db_upgrade.task
-import turbo_hipster.worker_server
+import base
import fakes
-logging.basicConfig(level=logging.DEBUG,
- format='%(asctime)s %(name)-32s '
- '%(levelname)-8s %(message)s')
-
-
-class TestWithGearman(testtools.TestCase):
-
- log = logging.getLogger("TestWithGearman")
- def setUp(self):
- super(TestWithGearman, self).setUp()
- self.config = None
- self.worker_server = None
- self.gearman_server = gear.Server(0)
-
- def start_server(self):
- if not self.config:
- self._load_config_fixture()
- # Grab the port so the clients can connect to it
- self.config['zuul_server']['gearman_port'] = self.gearman_server.port
-
- self.worker_server = turbo_hipster.worker_server.Server(self.config)
- self.worker_server.setup_logging()
- self.worker_server.start()
- t0 = time.time()
- while time.time() - t0 < 10:
- if self.worker_server.services_started:
- break
- time.sleep(0.01)
- if not self.worker_server.services_started:
- self.fail("Failed to start worker_service services")
-
- def tearDown(self):
- if self.worker_server and not self.worker_server.stopped():
- self.worker_server.shutdown()
- self.gearman_server.shutdown()
- super(TestWithGearman, self).tearDown()
-
- def _load_config_fixture(self, config_name='default-config.yaml'):
- config_dir = os.path.join(os.path.dirname(__file__), 'etc')
- with open(os.path.join(config_dir, config_name), 'r') as config_stream:
- self.config = yaml.safe_load(config_stream)
-
- # Set all of the working dirs etc to a writeable temp dir
- temp_path = self.useFixture(fixtures.TempDir()).path
- for config_dir in ['debug_log', 'jobs_working_dir', 'git_working_dir',
- 'pip_download_cache']:
- if config_dir in self.config:
- if self.config[config_dir][0] == '/':
- self.config[config_dir] = self.config[config_dir][1:]
- self.config[config_dir] = os.path.join(temp_path,
- self.config[config_dir])
- if self.config['publish_logs']['type'] == 'local':
- if self.config['publish_logs']['path'][0] == '/':
- self.config['publish_logs']['path'] = \
- self.config['publish_logs']['path'][1:]
- self.config['publish_logs']['path'] = os.path.join(
- temp_path, self.config[config_dir])
-
-
-class TestWorkerServer(TestWithGearman):
+class TestWorkerServer(base.TestWithGearman):
def test_plugins_load(self):
"Test the configured plugins are loaded"
@@ -144,7 +75,7 @@ class TestWorkerServer(TestWithGearman):
self.assertFalse(self.worker_server.zuul_manager.stopped())
-class TestZuulClient(TestWithGearman):
+class TestZuulClient(base.TestWithGearman):
def test_setup_gearman_worker(self):
"Make sure the client is registered as a worker with gearman"
pass
@@ -212,7 +143,7 @@ class TestZuulClient(TestWithGearman):
self.assertTrue(self.worker_server.stopped())
-class TestZuulManager(TestWithGearman):
+class TestZuulManager(base.TestWithGearman):
def test_registered_functions(self):
"Test the correct functions are registered with gearman"