From 2f183926ca46393d2ae6067deb6d1d13f14e41d0 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Fri, 15 Sep 2017 01:04:36 +0200 Subject: [PATCH] Support ram limit per pool Nodepool supports pretty generic limits on tenant and pool side. Make the ram limit configurable. Change-Id: Ie9f1ece75106fa936a737ed2b289188d9a594fb0 --- doc/source/configuration.rst | 5 +++ nodepool/driver/openstack/config.py | 3 ++ nodepool/driver/openstack/handler.py | 2 + .../tests/fixtures/node_quota_pool_ram.yaml | 39 +++++++++++++++++++ nodepool/tests/test_launcher.py | 3 ++ 5 files changed, 52 insertions(+) create mode 100644 nodepool/tests/fixtures/node_quota_pool_ram.yaml diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index c74666528..a6b5b3477 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -432,6 +432,11 @@ Example:: limit the number of servers. If not defined nodepool can create as many servers the tenant allows. + ``max-ram`` + Maximum ram usable from this pool. This can be used to limit the amount of + ram allocated by nodepool. If not defined nodepool can use as much ram as + the tenant allows. + ``availability-zones`` (list) A list of availability zones to use. diff --git a/nodepool/driver/openstack/config.py b/nodepool/driver/openstack/config.py index c8e51c9d2..a7aa40f44 100644 --- a/nodepool/driver/openstack/config.py +++ b/nodepool/driver/openstack/config.py @@ -63,6 +63,7 @@ class ProviderPool(ConfigValue): if (other.labels != self.labels or other.max_cores != self.max_cores or other.max_servers != self.max_servers or + other.max_ram != self.max_ram or other.azs != self.azs or other.networks != self.networks): return False @@ -159,6 +160,7 @@ class OpenStackProviderConfig(ProviderConfig): self.pools[pp.name] = pp pp.max_cores = pool.get('max-cores', None) pp.max_servers = pool.get('max-servers', None) + pp.max_ram = pool.get('max-ram', None) pp.azs = pool.get('availability-zones') pp.networks = pool.get('networks', []) pp.auto_floating_ip = bool(pool.get('auto-floating-ip', True)) @@ -242,6 +244,7 @@ class OpenStackProviderConfig(ProviderConfig): 'auto-floating-ip': bool, 'max-cores': int, 'max-servers': int, + 'max-ram': int, 'labels': [pool_label], 'availability-zones': [str], } diff --git a/nodepool/driver/openstack/handler.py b/nodepool/driver/openstack/handler.py index 39b3f4f1c..05fcd78fd 100644 --- a/nodepool/driver/openstack/handler.py +++ b/nodepool/driver/openstack/handler.py @@ -356,6 +356,7 @@ class OpenStackNodeRequestHandler(NodeRequestHandler): # to math.inf representing infinity that can be calculated with. pool_quota = QuotaInformation(cores=self.pool.max_cores, instances=self.pool.max_servers, + ram=self.pool.max_ram, default=math.inf) pool_quota.subtract( self.manager.estimatedNodepoolQuotaUsed(self.zk, self.pool)) @@ -388,6 +389,7 @@ class OpenStackNodeRequestHandler(NodeRequestHandler): # to math.inf representing infinity that can be calculated with. pool_quota = QuotaInformation(cores=self.pool.max_cores, instances=self.pool.max_servers, + ram=self.pool.max_ram, default=math.inf) pool_quota.subtract(needed_quota) return pool_quota.non_negative() diff --git a/nodepool/tests/fixtures/node_quota_pool_ram.yaml b/nodepool/tests/fixtures/node_quota_pool_ram.yaml new file mode 100644 index 000000000..608ff8d32 --- /dev/null +++ b/nodepool/tests/fixtures/node_quota_pool_ram.yaml @@ -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-ram: 16384 + 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 diff --git a/nodepool/tests/test_launcher.py b/nodepool/tests/test_launcher.py index afefd4d9a..1ee2b1fb2 100644 --- a/nodepool/tests/test_launcher.py +++ b/nodepool/tests/test_launcher.py @@ -233,6 +233,9 @@ class TestLauncher(tests.DBTestCase): self._test_node_assignment_at_quota( config='node_quota_pool_instances.yaml') + def test_node_assignment_at_pool_quota_ram(self): + self._test_node_assignment_at_quota( + config='node_quota_pool_ram.yaml') def test_node_assignment_at_cloud_cores_quota(self): self._test_node_assignment_at_quota(config='node_quota_cloud.yaml',