Run geard for nodepool tests
By running a geard as a fixture we can make tests which depend on gearman. Change-Id: Ia72e73cc78f291dcb514284496e174bc9ad7dc62
This commit is contained in:
parent
7978bd9847
commit
23d62acf55
@ -19,6 +19,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import pymysql
|
import pymysql
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
@ -26,6 +27,7 @@ import tempfile
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
|
import gear
|
||||||
import testresources
|
import testresources
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
@ -38,6 +40,64 @@ class LoggingPopen(subprocess.Popen):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FakeGearmanServer(gear.Server):
|
||||||
|
def __init__(self):
|
||||||
|
self.hold_jobs_in_queue = False
|
||||||
|
super(FakeGearmanServer, self).__init__(0)
|
||||||
|
|
||||||
|
def getJobForConnection(self, connection, peek=False):
|
||||||
|
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('build:'):
|
||||||
|
job.waiting = self.hold_jobs_in_queue
|
||||||
|
else:
|
||||||
|
job.waiting = False
|
||||||
|
if job.waiting:
|
||||||
|
continue
|
||||||
|
if job.name in connection.functions:
|
||||||
|
if not peek:
|
||||||
|
queue.remove(job)
|
||||||
|
connection.related_jobs[job.handle] = job
|
||||||
|
job.worker_connection = connection
|
||||||
|
job.running = True
|
||||||
|
return job
|
||||||
|
return None
|
||||||
|
|
||||||
|
def release(self, regex=None):
|
||||||
|
released = False
|
||||||
|
qlen = (len(self.high_queue) + len(self.normal_queue) +
|
||||||
|
len(self.low_queue))
|
||||||
|
self.log.debug("releasing queued job %s (%s)" % (regex, qlen))
|
||||||
|
for job in self.getQueue():
|
||||||
|
cmd, name = job.name.split(':')
|
||||||
|
if cmd != 'build':
|
||||||
|
continue
|
||||||
|
if not regex or re.match(regex, name):
|
||||||
|
self.log.debug("releasing queued job %s" %
|
||||||
|
job.unique)
|
||||||
|
job.waiting = False
|
||||||
|
released = True
|
||||||
|
else:
|
||||||
|
self.log.debug("not releasing queued job %s" %
|
||||||
|
job.unique)
|
||||||
|
if released:
|
||||||
|
self.wakeConnections()
|
||||||
|
qlen = (len(self.high_queue) + len(self.normal_queue) +
|
||||||
|
len(self.low_queue))
|
||||||
|
self.log.debug("done releasing queued jobs %s (%s)" % (regex, qlen))
|
||||||
|
|
||||||
|
|
||||||
|
class GearmanServerFixture(fixtures.Fixture):
|
||||||
|
def setUp(self):
|
||||||
|
super(GearmanServerFixture, self).setUp()
|
||||||
|
self.gearman_server = FakeGearmanServer()
|
||||||
|
self.addCleanup(self.shutdownGearman)
|
||||||
|
|
||||||
|
def shutdownGearman(self):
|
||||||
|
self.gearman_server.shutdown()
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase):
|
class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BaseTestCase, self).setUp()
|
super(BaseTestCase, self).setUp()
|
||||||
@ -194,6 +254,10 @@ class DBTestCase(BaseTestCase):
|
|||||||
self.useFixture(f)
|
self.useFixture(f)
|
||||||
self.dburi = f.dburi
|
self.dburi = f.dburi
|
||||||
|
|
||||||
|
gearman_fixture = GearmanServerFixture()
|
||||||
|
self.useFixture(gearman_fixture)
|
||||||
|
self.gearman_server = gearman_fixture.gearman_server
|
||||||
|
|
||||||
def setup_config(self, filename):
|
def setup_config(self, filename):
|
||||||
images_dir = fixtures.TempDir()
|
images_dir = fixtures.TempDir()
|
||||||
self.useFixture(images_dir)
|
self.useFixture(images_dir)
|
||||||
@ -202,7 +266,8 @@ class DBTestCase(BaseTestCase):
|
|||||||
config = open(configfile).read()
|
config = open(configfile).read()
|
||||||
(fd, path) = tempfile.mkstemp()
|
(fd, path) = tempfile.mkstemp()
|
||||||
os.write(fd, config.format(dburi=self.dburi,
|
os.write(fd, config.format(dburi=self.dburi,
|
||||||
images_dir=images_dir.path))
|
images_dir=images_dir.path,
|
||||||
|
gearman_port=self.gearman_server.port))
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
5
nodepool/tests/fixtures/leaked_node.yaml
vendored
5
nodepool/tests/fixtures/leaked_node.yaml
vendored
@ -10,8 +10,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label
|
- name: fake-label
|
||||||
|
5
nodepool/tests/fixtures/node.yaml
vendored
5
nodepool/tests/fixtures/node.yaml
vendored
@ -10,8 +10,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label
|
- name: fake-label
|
||||||
|
5
nodepool/tests/fixtures/node_az.yaml
vendored
5
nodepool/tests/fixtures/node_az.yaml
vendored
@ -10,8 +10,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label
|
- name: fake-label
|
||||||
|
5
nodepool/tests/fixtures/node_cmd.yaml
vendored
5
nodepool/tests/fixtures/node_cmd.yaml
vendored
@ -10,8 +10,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label1
|
- name: fake-label1
|
||||||
|
5
nodepool/tests/fixtures/node_dib.yaml
vendored
5
nodepool/tests/fixtures/node_dib.yaml
vendored
@ -12,8 +12,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-dib-label
|
- name: fake-dib-label
|
||||||
|
@ -12,8 +12,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label
|
- name: fake-label
|
||||||
|
@ -12,8 +12,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label
|
- name: fake-label
|
||||||
|
@ -12,8 +12,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label
|
- name: fake-label
|
||||||
|
5
nodepool/tests/fixtures/node_dib_vhd.yaml
vendored
5
nodepool/tests/fixtures/node_dib_vhd.yaml
vendored
@ -12,8 +12,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-dib-label
|
- name: fake-dib-label
|
||||||
|
@ -12,8 +12,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label
|
- name: fake-label
|
||||||
|
5
nodepool/tests/fixtures/node_ipv6.yaml
vendored
5
nodepool/tests/fixtures/node_ipv6.yaml
vendored
@ -9,8 +9,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label1
|
- name: fake-label1
|
||||||
|
5
nodepool/tests/fixtures/node_osc.yaml
vendored
5
nodepool/tests/fixtures/node_osc.yaml
vendored
@ -10,8 +10,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label
|
- name: fake-label
|
||||||
|
5
nodepool/tests/fixtures/subnodes.yaml
vendored
5
nodepool/tests/fixtures/subnodes.yaml
vendored
@ -10,8 +10,9 @@ cron:
|
|||||||
zmq-publishers:
|
zmq-publishers:
|
||||||
- tcp://localhost:8881
|
- tcp://localhost:8881
|
||||||
|
|
||||||
#gearman-servers:
|
gearman-servers:
|
||||||
# - host: localhost
|
- host: localhost
|
||||||
|
port: {gearman_port}
|
||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label
|
- name: fake-label
|
||||||
|
Loading…
x
Reference in New Issue
Block a user