Merge "Support cores limit per pool" into feature/zuulv3

This commit is contained in:
Zuul 2017-12-13 21:33:32 +00:00 committed by Gerrit Code Review
commit 2a9c608905
5 changed files with 55 additions and 2 deletions

View File

@ -422,6 +422,11 @@ Example::
**optional**
``max-cores``
Maximum number of cores usable from this pool. This can be used to limit
usage of the tenant. If not defined nodepool can use all cores up to the
quota of the tenant.
``max-servers``
Maximum number of servers spawnable from this pool. This can be used to
limit the number of servers. If not defined nodepool can create as many

View File

@ -61,6 +61,7 @@ class ProviderLabel(ConfigValue):
class ProviderPool(ConfigValue):
def __eq__(self, other):
if (other.labels != self.labels or
other.max_cores != self.max_cores or
other.max_servers != self.max_servers or
other.azs != self.azs or
other.networks != self.networks):
@ -159,6 +160,7 @@ class OpenStackProviderConfig(ProviderConfig):
pp.name = pool['name']
pp.provider = self
self.pools[pp.name] = pp
pp.max_cores = pool.get('max-cores', None)
pp.max_servers = pool.get('max-servers', None)
pp.azs = pool.get('availability-zones')
pp.networks = pool.get('networks', [])
@ -244,6 +246,7 @@ class OpenStackProviderConfig(ProviderConfig):
'name': str,
'networks': [str],
'auto-floating-ip': bool,
'max-cores': int,
'max-servers': int,
'labels': [pool_label],
'availability-zones': [str],

View File

@ -355,7 +355,8 @@ class OpenStackNodeRequestHandler(NodeRequestHandler):
# Now calculate pool specific quota. Values indicating no quota default
# to math.inf representing infinity that can be calculated with.
pool_quota = QuotaInformation(instances=self.pool.max_servers,
pool_quota = QuotaInformation(cores=self.pool.max_cores,
instances=self.pool.max_servers,
default=math.inf)
pool_quota.subtract(
self.manager.estimatedNodepoolQuotaUsed(self.zk, self.pool))
@ -386,7 +387,8 @@ class OpenStackNodeRequestHandler(NodeRequestHandler):
# Now calculate pool specific quota. Values indicating no quota default
# to math.inf representing infinity that can be calculated with.
pool_quota = QuotaInformation(instances=self.pool.max_servers,
pool_quota = QuotaInformation(cores=self.pool.max_cores,
instances=self.pool.max_servers,
default=math.inf)
pool_quota.subtract(needed_quota)
return pool_quota.non_negative()

View File

@ -0,0 +1,39 @@
elements-dir: .
images-dir: '{images_dir}'
zookeeper-servers:
- host: {zookeeper_host}
port: {zookeeper_port}
chroot: {zookeeper_chroot}
labels:
- name: fake-label
min-ready: 0
providers:
- name: fake-provider
cloud: fake
driver: fake
region-name: fake-region
rate: 0.0001
diskimages:
- name: fake-image
pools:
- name: main
max-cores: 8
labels:
- name: fake-label
diskimage: fake-image
min-ram: 8192
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

View File

@ -226,6 +226,10 @@ class TestLauncher(tests.DBTestCase):
self.assertEqual(req2.state, zk.FULFILLED)
self.assertEqual(len(req2.nodes), 2)
def test_node_assignment_at_pool_quota_cores(self):
self._test_node_assignment_at_quota(
config='node_quota_pool_cores.yaml')
def test_node_assignment_at_pool_quota_instances(self):
self._test_node_assignment_at_quota(
config='node_quota_pool_instances.yaml')