Fix provider-label association
Providers should not build node types for which they are not configured. We were not checking to see if a provider was listed within a label definition before building the node. This caused ANY provider to build a node of that type. Change-Id: I3538b7ced7452c15e2309bc4253e6c13d4c83b84
This commit is contained in:
@@ -600,6 +600,23 @@ class NodeRequestHandler(object):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _invalidNodeTypes(self):
|
||||||
|
'''
|
||||||
|
Return any node types that are invalid for this provider.
|
||||||
|
|
||||||
|
:returns: A list of node type names that are invalid, or an empty
|
||||||
|
list if all are valid.
|
||||||
|
'''
|
||||||
|
invalid = []
|
||||||
|
for ntype in self.request.node_types:
|
||||||
|
if ntype not in self.labels:
|
||||||
|
invalid.append(ntype)
|
||||||
|
else:
|
||||||
|
label = self.labels[ntype]
|
||||||
|
if self.provider.name not in label.providers.keys():
|
||||||
|
invalid.append(ntype)
|
||||||
|
return invalid
|
||||||
|
|
||||||
def _countNodes(self):
|
def _countNodes(self):
|
||||||
'''
|
'''
|
||||||
Query ZooKeeper to determine the number of provider nodes launched.
|
Query ZooKeeper to determine the number of provider nodes launched.
|
||||||
@@ -733,6 +750,11 @@ class NodeRequestHandler(object):
|
|||||||
declined_reasons.append('images are not available')
|
declined_reasons.append('images are not available')
|
||||||
if len(self.request.node_types) > self.provider.max_servers:
|
if len(self.request.node_types) > self.provider.max_servers:
|
||||||
declined_reasons.append('it would exceed quota')
|
declined_reasons.append('it would exceed quota')
|
||||||
|
invalid_types = self._invalidNodeTypes()
|
||||||
|
if invalid_types:
|
||||||
|
declined_reasons.append('node type(s) [%s] not available' %
|
||||||
|
','.join(invalid_types))
|
||||||
|
|
||||||
if declined_reasons:
|
if declined_reasons:
|
||||||
self.log.debug("Declining node request %s because %s",
|
self.log.debug("Declining node request %s because %s",
|
||||||
self.request.id, ', '.join(declined_reasons))
|
self.request.id, ', '.join(declined_reasons))
|
||||||
|
|||||||
73
nodepool/tests/fixtures/node_label_provider.yaml
vendored
Normal file
73
nodepool/tests/fixtures/node_label_provider.yaml
vendored
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
elements-dir: .
|
||||||
|
images-dir: '{images_dir}'
|
||||||
|
|
||||||
|
cron:
|
||||||
|
check: '*/15 * * * *'
|
||||||
|
cleanup: '*/1 * * * *'
|
||||||
|
|
||||||
|
zookeeper-servers:
|
||||||
|
- host: {zookeeper_host}
|
||||||
|
port: {zookeeper_port}
|
||||||
|
chroot: {zookeeper_chroot}
|
||||||
|
|
||||||
|
labels:
|
||||||
|
- name: fake-label
|
||||||
|
image: fake-image
|
||||||
|
min-ready: 1
|
||||||
|
providers:
|
||||||
|
- name: fake-provider2
|
||||||
|
|
||||||
|
providers:
|
||||||
|
- name: fake-provider
|
||||||
|
region-name: fake-region
|
||||||
|
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
|
||||||
|
min-ram: 8192
|
||||||
|
name-filter: 'Fake'
|
||||||
|
meta:
|
||||||
|
key: value
|
||||||
|
key2: value
|
||||||
|
- name: fake-provider2
|
||||||
|
region-name: fake-region
|
||||||
|
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
|
||||||
|
min-ram: 8192
|
||||||
|
name-filter: 'Fake'
|
||||||
|
meta:
|
||||||
|
key: value
|
||||||
|
key2: value
|
||||||
|
|
||||||
|
targets:
|
||||||
|
- name: fake-target
|
||||||
|
|
||||||
|
diskimages:
|
||||||
|
- name: fake-image
|
||||||
|
elements:
|
||||||
|
- fedora
|
||||||
|
- vm
|
||||||
|
release: 21
|
||||||
|
env-vars:
|
||||||
|
TMPDIR: /opt/dib_tmp
|
||||||
|
DIB_IMAGE_CACHE: /opt/dib_cache
|
||||||
|
DIB_CLOUD_IMAGES: http://download.fedoraproject.org/pub/fedora/linux/releases/test/21-Beta/Cloud/Images/x86_64/
|
||||||
|
BASE_IMAGE_FILE: Fedora-Cloud-Base-20141029-21_Beta.x86_64.qcow2
|
||||||
@@ -666,3 +666,15 @@ class TestNodepool(tests.DBTestCase):
|
|||||||
with pool.getDB().getSession() as session:
|
with pool.getDB().getSession() as session:
|
||||||
node = session.getNode(2)
|
node = session.getNode(2)
|
||||||
self.assertEqual(node, None)
|
self.assertEqual(node, None)
|
||||||
|
|
||||||
|
def test_label_provider(self):
|
||||||
|
"""Test that only providers listed in the label satisfy the request"""
|
||||||
|
configfile = self.setup_config('node_label_provider.yaml')
|
||||||
|
pool = self.useNodepool(configfile, watermark_sleep=1)
|
||||||
|
self._useBuilder(configfile)
|
||||||
|
pool.start()
|
||||||
|
self.waitForImage('fake-provider', 'fake-image')
|
||||||
|
self.waitForImage('fake-provider2', 'fake-image')
|
||||||
|
nodes = self.waitForNodes('fake-label')
|
||||||
|
self.assertEqual(len(nodes), 1)
|
||||||
|
self.assertEqual(nodes[0].provider, 'fake-provider2')
|
||||||
|
|||||||
Reference in New Issue
Block a user