Add a test for subnodes
Some misc changes related to running this: * Set log/stdout/err capture vars as in ZUUL * Give the main loop a configurable sleep value so tests can run faster * Fix a confusing typo in the node.yaml config Additionally, a better method for waiting for test completion is added which permits us to use assert statements in the tests. Change-Id: Icddd2afcd816dbd5ab955fa4ab5011ac8def8faf
This commit is contained in:
parent
fca89ee0a0
commit
92b9842951
@ -1,4 +1,4 @@
|
|||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
test_command=OS_TEST_TIMEOUT=60 ${PYTHON:-python} -m subunit.run discover -t ./ nodepool/tests/ $LISTOPT $IDOPTION
|
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} OS_LOG_CAPTURE=${OS_LOG_CAPTURE:-1} OS_TEST_TIMEOUT=60 ${PYTHON:-python} -m subunit.run discover -t ./ nodepool/tests/ $LISTOPT $IDOPTION
|
||||||
test_id_option=--load-list $IDFILE
|
test_id_option=--load-list $IDFILE
|
||||||
test_list_option=--list
|
test_list_option=--list
|
||||||
|
@ -836,9 +836,10 @@ class GearmanServer(ConfigValue):
|
|||||||
class NodePool(threading.Thread):
|
class NodePool(threading.Thread):
|
||||||
log = logging.getLogger("nodepool.NodePool")
|
log = logging.getLogger("nodepool.NodePool")
|
||||||
|
|
||||||
def __init__(self, configfile):
|
def __init__(self, configfile, watermark_sleep=WATERMARK_SLEEP):
|
||||||
threading.Thread.__init__(self, name='NodePool')
|
threading.Thread.__init__(self, name='NodePool')
|
||||||
self.configfile = configfile
|
self.configfile = configfile
|
||||||
|
self.watermark_sleep = watermark_sleep
|
||||||
self._stopped = False
|
self._stopped = False
|
||||||
self.config = None
|
self.config = None
|
||||||
self.zmq_context = None
|
self.zmq_context = None
|
||||||
@ -1275,7 +1276,7 @@ class NodePool(threading.Thread):
|
|||||||
self._run(session)
|
self._run(session)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.log.exception("Exception in main loop:")
|
self.log.exception("Exception in main loop:")
|
||||||
time.sleep(WATERMARK_SLEEP)
|
time.sleep(self.watermark_sleep)
|
||||||
|
|
||||||
def _run(self, session):
|
def _run(self, session):
|
||||||
self.checkForMissingImages(session)
|
self.checkForMissingImages(session)
|
||||||
|
@ -49,8 +49,10 @@ class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase):
|
|||||||
if os.environ.get('OS_STDERR_CAPTURE') in TRUE_VALUES:
|
if os.environ.get('OS_STDERR_CAPTURE') in TRUE_VALUES:
|
||||||
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
|
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
|
||||||
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
|
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
|
||||||
|
if os.environ.get('OS_LOG_CAPTURE') in TRUE_VALUES:
|
||||||
self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
|
self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
|
||||||
|
else:
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
self.useFixture(fixtures.NestedTempfile())
|
self.useFixture(fixtures.NestedTempfile())
|
||||||
|
|
||||||
|
|
||||||
|
4
nodepool/tests/fixtures/node.yaml
vendored
4
nodepool/tests/fixtures/node.yaml
vendored
@ -14,7 +14,7 @@ gearman-servers:
|
|||||||
|
|
||||||
labels:
|
labels:
|
||||||
- name: fake-label
|
- name: fake-label
|
||||||
image: fake-label
|
image: fake-image
|
||||||
min-ready: 1
|
min-ready: 1
|
||||||
providers:
|
providers:
|
||||||
- name: fake-provider
|
- name: fake-provider
|
||||||
@ -32,7 +32,7 @@ providers:
|
|||||||
- net-id: 'some-uuid'
|
- net-id: 'some-uuid'
|
||||||
rate: 0.0001
|
rate: 0.0001
|
||||||
images:
|
images:
|
||||||
- name: fake-label
|
- name: fake-image
|
||||||
base-image: 'Fake Precise'
|
base-image: 'Fake Precise'
|
||||||
min-ram: 8192
|
min-ram: 8192
|
||||||
name-filter: 'Fake'
|
name-filter: 'Fake'
|
||||||
|
53
nodepool/tests/fixtures/subnodes.yaml
vendored
Normal file
53
nodepool/tests/fixtures/subnodes.yaml
vendored
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
script-dir: .
|
||||||
|
dburi: '{dburi}'
|
||||||
|
|
||||||
|
cron:
|
||||||
|
check: '*/15 * * * *'
|
||||||
|
cleanup: '*/1 * * * *'
|
||||||
|
update-image: '14 2 * * *'
|
||||||
|
|
||||||
|
zmq-publishers:
|
||||||
|
- tcp://localhost:8881
|
||||||
|
|
||||||
|
gearman-servers:
|
||||||
|
- host: localhost
|
||||||
|
|
||||||
|
labels:
|
||||||
|
- name: fake-label
|
||||||
|
image: fake-image
|
||||||
|
min-ready: 2
|
||||||
|
providers:
|
||||||
|
- name: fake-provider
|
||||||
|
- name: multi-fake
|
||||||
|
image: fake-image
|
||||||
|
ready-script: multinode_setup.sh
|
||||||
|
subnodes: 2
|
||||||
|
min-ready: 2
|
||||||
|
providers:
|
||||||
|
- name: fake-provider
|
||||||
|
|
||||||
|
providers:
|
||||||
|
- name: fake-provider
|
||||||
|
keypair: 'if-present-use-this-keypair'
|
||||||
|
username: 'fake'
|
||||||
|
password: 'fake'
|
||||||
|
auth-url: 'fake'
|
||||||
|
project-id: 'fake'
|
||||||
|
max-servers: 96
|
||||||
|
pool: 'fake'
|
||||||
|
networks:
|
||||||
|
- net-id: 'some-uuid'
|
||||||
|
rate: 0.0001
|
||||||
|
images:
|
||||||
|
- name: fake-image
|
||||||
|
base-image: 'Fake Precise'
|
||||||
|
min-ram: 8192
|
||||||
|
name-filter: 'Fake'
|
||||||
|
setup: prepare_node_devstack.sh
|
||||||
|
|
||||||
|
targets:
|
||||||
|
- name: fake-target
|
||||||
|
jenkins:
|
||||||
|
url: https://jenkins.example.org/
|
||||||
|
user: fake
|
||||||
|
apikey: fake
|
@ -60,22 +60,53 @@ class TestNodepool(tests.DBTestCase):
|
|||||||
with db.getSession() as session:
|
with db.getSession() as session:
|
||||||
session.getNodes()
|
session.getNodes()
|
||||||
|
|
||||||
|
def waitForNodes(self, pool):
|
||||||
|
while True:
|
||||||
|
self.wait_for_threads()
|
||||||
|
with pool.getDB().getSession() as session:
|
||||||
|
needed = pool.getNeededNodes(session)
|
||||||
|
if not needed:
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
self.wait_for_threads()
|
||||||
|
|
||||||
def test_node(self):
|
def test_node(self):
|
||||||
"""Test that an image and node are created"""
|
"""Test that an image and node are created"""
|
||||||
configfile = self.setup_config('node.yaml')
|
configfile = self.setup_config('node.yaml')
|
||||||
pool = nodepool.nodepool.NodePool(configfile)
|
pool = nodepool.nodepool.NodePool(configfile, watermark_sleep=0.5)
|
||||||
pool.start()
|
pool.start()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
while True:
|
self.waitForNodes(pool)
|
||||||
self.wait_for_threads()
|
|
||||||
with pool.getDB().getSession() as session:
|
with pool.getDB().getSession() as session:
|
||||||
nodes = session.getNodes(provider_name='fake-provider',
|
nodes = session.getNodes(provider_name='fake-provider',
|
||||||
label_name='fake-label',
|
label_name='fake-label',
|
||||||
target_name='fake-target',
|
target_name='fake-target',
|
||||||
state=nodedb.READY)
|
state=nodedb.READY)
|
||||||
if len(nodes) == 1:
|
self.assertEqual(len(nodes), 1)
|
||||||
break
|
pool.stop()
|
||||||
nodes = session.getNodes()
|
|
||||||
time.sleep(1)
|
def test_subnodes(self):
|
||||||
self.wait_for_threads()
|
"""Test that an image and node are created"""
|
||||||
|
configfile = self.setup_config('subnodes.yaml')
|
||||||
|
pool = nodepool.nodepool.NodePool(configfile, watermark_sleep=0.5)
|
||||||
|
pool.start()
|
||||||
|
time.sleep(2)
|
||||||
|
self.waitForNodes(pool)
|
||||||
|
|
||||||
|
with pool.getDB().getSession() as session:
|
||||||
|
nodes = session.getNodes(provider_name='fake-provider',
|
||||||
|
label_name='fake-label',
|
||||||
|
target_name='fake-target',
|
||||||
|
state=nodedb.READY)
|
||||||
|
self.assertEqual(len(nodes), 2)
|
||||||
|
nodes = session.getNodes(provider_name='fake-provider',
|
||||||
|
label_name='multi-fake',
|
||||||
|
target_name='fake-target',
|
||||||
|
state=nodedb.READY)
|
||||||
|
self.assertEqual(len(nodes), 2)
|
||||||
|
for node in nodes:
|
||||||
|
self.assertEqual(len(node.subnodes), 2)
|
||||||
|
for subnode in node.subnodes:
|
||||||
|
self.assertEqual(subnode.state, nodedb.READY)
|
||||||
pool.stop()
|
pool.stop()
|
||||||
|
Loading…
Reference in New Issue
Block a user