Use zk connection passed to OpenStack driver

We are passing the zk connection to the estimatedNodepoolQuotaUsed()
method of the OpenStack provider when we already have it passed into
the provider's start() method, but not saving it there. Let's save
that connection in start() and use it instead.

In a later change to the provider, we will make further use of it.

Change-Id: I013a28d6c46046497d8b04867c51a23f6fa49d39
This commit is contained in:
David Shrewsbury 2018-09-18 11:45:09 -04:00
parent da8a94d341
commit 4d71c45da6
2 changed files with 6 additions and 5 deletions

View File

@ -309,7 +309,7 @@ class OpenStackNodeRequestHandler(NodeRequestHandler):
# quota = <total nodepool quota> - <used quota> - <quota for node>
cloud_quota = self.manager.estimatedNodepoolQuota()
cloud_quota.subtract(
self.manager.estimatedNodepoolQuotaUsed(self.zk))
self.manager.estimatedNodepoolQuotaUsed())
cloud_quota.subtract(needed_quota)
self.log.debug("Predicted remaining provider quota: %s",
cloud_quota)
@ -324,7 +324,7 @@ class OpenStackNodeRequestHandler(NodeRequestHandler):
ram=self.pool.max_ram,
default=math.inf)
pool_quota.subtract(
self.manager.estimatedNodepoolQuotaUsed(self.zk, self.pool))
self.manager.estimatedNodepoolQuotaUsed(self.pool))
self.log.debug("Current pool quota: %s" % pool_quota)
pool_quota.subtract(needed_quota)
self.log.debug("Predicted remaining pool quota: %s", pool_quota)

View File

@ -48,6 +48,7 @@ class OpenStackProvider(Provider):
self._use_taskmanager = use_taskmanager
self._taskmanager = None
self._current_nodepool_quota = None
self._zk = None
def start(self, zk_conn):
if self._use_taskmanager:
@ -55,6 +56,7 @@ class OpenStackProvider(Provider):
self.provider.rate)
self._taskmanager.start()
self.resetClient()
self._zk = zk_conn
def stop(self):
if self._taskmanager:
@ -136,18 +138,17 @@ class OpenStackProvider(Provider):
def invalidateQuotaCache(self):
self._current_nodepool_quota['timestamp'] = 0
def estimatedNodepoolQuotaUsed(self, zk, pool=None):
def estimatedNodepoolQuotaUsed(self, pool=None):
'''
Sums up the quota used (or planned) currently by nodepool. If pool is
given it is filtered by the pool.
:param zk: the object to access zookeeper
:param pool: If given, filtered by the pool.
:return: Calculated quota in use by nodepool
'''
used_quota = QuotaInformation()
for node in zk.nodeIterator():
for node in self._zk.nodeIterator():
if node.provider == self.provider.name:
if pool and not node.pool == pool.name:
continue