blob: fe4eaa76913b61b0fca97043650459590c42011e [file] [log] [blame]
Joshua Hesketh66f9f602013-08-14 11:28:10 +10001#!/usr/bin/python2
2#
3# Copyright 2013 Rackspace Australia
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
Joshua Heskethef72b8a2013-08-12 11:17:14 +100016
Joshua Heskethef72b8a2013-08-12 11:17:14 +100017
Joshua Hesketh66f9f602013-08-14 11:28:10 +100018import json
19import os
20import testtools
Joshua Hesketh0d9a8c02013-08-14 12:38:14 +100021import time
22from fakes import FakeGearmanManager, FakeGearmanServer, FakeRealDbUpgradeRunner
Joshua Heskethef72b8a2013-08-12 11:17:14 +100023
Joshua Hesketh66f9f602013-08-14 11:28:10 +100024CONFIG_DIR = os.path.join(os.path.dirname(__file__), 'etc')
25with open(os.path.join(CONFIG_DIR, 'config.json'), 'r') as config_stream:
26 CONFIG = json.load(config_stream)
Joshua Heskethef72b8a2013-08-12 11:17:14 +100027
Joshua Heskethef72b8a2013-08-12 11:17:14 +100028
Joshua Hesketh66f9f602013-08-14 11:28:10 +100029class TestGearmanManager(testtools.TestCase):
30 def setUp(self):
31 super(TestGearmanManager, self).setUp()
32 self.config = CONFIG
Joshua Hesketh66f9f602013-08-14 11:28:10 +100033 self.gearman_server = FakeGearmanServer(
34 self.config['zuul_server']['gearman_port'])
Joshua Hesketh0d9a8c02013-08-14 12:38:14 +100035 self.config['zuul_server']['gearman_port'] = self.gearman_server.port
36
37 self.task = FakeRealDbUpgradeRunner(self.config, self)
38 self.tasks = dict(FakeRealDbUpgradeRunner_worker=self.task)
Joshua Hesketh66f9f602013-08-14 11:28:10 +100039
40 self.gearman_manager = FakeGearmanManager(self.config,
41 self.tasks,
42 self)
43
44 def test_manager_function_registered(self):
45 """ Check the manager is set up correctly and registered with the
46 gearman server with an appropriate function """
Joshua Hesketh0d9a8c02013-08-14 12:38:14 +100047
48 # Give the gearman server up to 5 seconds to register the function
49 for x in range(500):
50 time.sleep(0.01)
51 if len(self.gearman_server.functions) > 0:
52 break
53
54 hostname = os.uname()[1]
55 function_name = 'stop:turbo-hipster-manager-%s' % hostname
56
57 self.assertIn(function_name, self.gearman_server.functions)
58
59 def test_task_registered_with_manager(self):
60 """ Check the FakeRealDbUpgradeRunner_worker task is registered """
61 self.assertIn('FakeRealDbUpgradeRunner_worker',
62 self.gearman_manager.tasks.keys())
63
64 def test_stop_task(self):
65 """ Check that the manager successfully stops a task when requested
66 """
Joshua Hesketh66f9f602013-08-14 11:28:10 +100067 pass
Joshua Heskethef72b8a2013-08-12 11:17:14 +100068
69if __name__ == '__main__':
70 unittest.main()