Project manager problems concerning the adding and removing projects

This commit fixes the _addProject() and _removeProject() methods.

Change-Id: Iebdb0f841f92aabfc947ba716fbe894ac4b9d1e0
Sem-Ver: bugfix
This commit is contained in:
Lisa Zangrando 2017-08-10 12:50:32 +02:00
parent 16f6a8e0b2
commit 91f82cc654
3 changed files with 51 additions and 34 deletions

View File

@ -96,7 +96,7 @@ class ProjectCommand(ExecuteCommand):
if args.s_quota: if args.s_quota:
headers.append("shared quota") headers.append("shared quota")
if args.queue: if args.queue:
headers.append("queue") headers.append("queue usage")
if args.share: if args.share:
headers.append("share") headers.append("share")
if args.ttl: if args.ttl:
@ -160,8 +160,8 @@ class ProjectCommand(ExecuteCommand):
share = project.getShare() share = project.getShare()
share_value = share.getValue() share_value = share.getValue()
share_norm = share.getNormalizedValue() share_norm = share.getNormalizedValue()
row.append("{:.2f}% | {:.2f}%".format(share_value, row.append("{:.2f}% | {:.2%}".format(share_value,
share_norm * 100)) share_norm))
if attribute == "TTL": if attribute == "TTL":
row.append(project.getTTL()) row.append(project.getTTL())
@ -195,22 +195,21 @@ class ProjectCommand(ExecuteCommand):
if attribute == "usage": if attribute == "usage":
data = project.getData() data = project.getData()
usage = "vcpus: {:.2f}% | ram: {:.2f}%".format( usage = "vcpus: {:.2%} | ram: {:.2%}".format(
data["effective_vcpus"] * 100, data["effective_vcpus"], data["effective_memory"])
data["effective_memory"] * 100)
row.append(usage) row.append(usage)
if attribute == "queue": if attribute == "queue usage":
data = project.getData() data = project.getData()
q_usage = data.get("queue_usage", 0) q_usage = data.get("queue_usage", 0)
q_size = data.get("queue_size", 0) q_size = data.get("queue_size", 0)
if q_size: if q_size:
usage = float(q_usage) / float(q_size) * 100 usage = float(q_usage) / float(q_size)
row.append("{:.2f}%".format(usage)) row.append("{:d} ({:.2%})".format(q_usage, usage))
else: else:
row.append("0%") row.append("0 (0%)")
table.append(row) table.append(row)
@ -300,19 +299,18 @@ class UserCommand(ExecuteCommand):
if attribute == "share": if attribute == "share":
share = user.getShare() share = user.getShare()
share_value = share.getValue()
share_norm = share.getNormalizedValue() share_norm = share.getNormalizedValue()
row.append("{:.2f}% | {:.2f}%".format(share_value,
share_norm * 100)) row.append("{:.2%}".format(share_norm))
if attribute == "priority": if attribute == "priority":
row.append(user.getPriority().getValue()) row.append(user.getPriority().getValue())
if attribute == "usage": if attribute == "usage":
data = user.getData() data = user.getData()
usage = "vcpus: {:.2f}% | ram: {:.2f}%".format( usage = "vcpus: {:.2%} | ram: {:.2%}".format(
data["actual_vcpus"] * 100, data["actual_vcpus"], data["actual_memory"])
data["actual_memory"] * 100)
row.append(usage) row.append(usage)

View File

@ -140,8 +140,9 @@ class ProjectManager(Manager):
project = self.getProject(id=prj_id) project = self.getProject(id=prj_id)
if project: if project:
project.removeUser(usr_id) user = project.removeUser(usr_id)
self.notify(event_type="USER_REMOVED", user=user) if user:
self.notify(event_type="USER_REMOVED", user=user)
elif event_type == "identity.user.deleted": elif event_type == "identity.user.deleted":
user_id = kwargs.get("resource_info", None) user_id = kwargs.get("resource_info", None)
@ -156,6 +157,14 @@ class ProjectManager(Manager):
except SynergyError as ex: except SynergyError as ex:
LOG.info(ex) LOG.info(ex)
elif event_type == "identity.project.deleted":
LOG.info(kwargs)
prj_id = kwargs.get("resource_info", None)
project = self.getProject(id=prj_id, name=prj_id)
if project:
self._removeProject(project)
def _parseNumber(self, value, default=None): def _parseNumber(self, value, default=None):
if not value: if not value:
return default return default
@ -168,8 +177,13 @@ class ProjectManager(Manager):
raise SynergyError("%r is not a number!" % str(value)) raise SynergyError("%r is not a number!" % str(value))
def _addProject(self, prj_id, prj_name, TTL, share): def _addProject(self, prj_id, prj_name, TTL, share):
project = None
if prj_id: if prj_id:
project = self.keystone_manager.getProject(prj_id) try:
project = self.keystone_manager.getProject(prj_id)
except SynergyError:
raise SynergyError("project not found in Keystone!")
elif prj_name: elif prj_name:
projects = self.keystone_manager.getProjects(name=prj_name) projects = self.keystone_manager.getProjects(name=prj_name)
@ -182,7 +196,7 @@ class ProjectManager(Manager):
raise SynergyError("missing project attributes") raise SynergyError("missing project attributes")
if not project: if not project:
raise SynergyError("project not found!") raise SynergyError("project not found in Keystone!")
prj_TTL = self._parseNumber(TTL, default=self.default_TTL) prj_TTL = self._parseNumber(TTL, default=self.default_TTL)
prj_share = self._parseNumber(share, 0) prj_share = self._parseNumber(share, 0)
@ -213,9 +227,14 @@ class ProjectManager(Manager):
finally: finally:
connection.close() connection.close()
users = self.keystone_manager.getUsers(prj_id=project.getId())
for user in users:
project.addUser(user)
self.projects[project.getId()] = project self.projects[project.getId()] = project
LOG.info("added project %s" % project.getName()) LOG.info("added project %r" % project.getName())
self.notify(event_type="PROJECT_ADDED", project=project) self.notify(event_type="PROJECT_ADDED", project=project)
return project return project
@ -255,13 +274,14 @@ class ProjectManager(Manager):
finally: finally:
connection.close() connection.close()
LOG.info("updated project %r" % project.getName())
self.notify(event_type="PROJECT_UPDATED", project=project) self.notify(event_type="PROJECT_UPDATED", project=project)
def _removeProject(self, project): def _removeProject(self, project, force=False):
if project.getId() not in self.projects.keys(): if not force:
raise SynergyError("project %s not found!" % project.getId()) if project.getId() not in self.projects.keys():
raise SynergyError("project %s not found!" % project.getId())
self.projects.pop(project.getId()) self.projects.pop(project.getId())
connection = self.db_engine.connect() connection = self.db_engine.connect()
trans = connection.begin() trans = connection.begin()
@ -279,7 +299,7 @@ class ProjectManager(Manager):
finally: finally:
connection.close() connection.close()
LOG.info("removed project %s" % project.getName()) LOG.info("removed project %r" % project.getName())
self.notify(event_type="PROJECT_REMOVED", project=project) self.notify(event_type="PROJECT_REMOVED", project=project)
def getProject(self, id=None, name=None): def getProject(self, id=None, name=None):
@ -336,7 +356,7 @@ NOT NULL PRIMARY KEY, name VARCHAR(64), share INT DEFAULT 0, TTL INT DEFAULT \
k_project = self.keystone_manager.getProject(project_id) k_project = self.keystone_manager.getProject(project_id)
if not k_project: if not k_project:
self.removeProject(project) self._removeProject(project)
continue continue
users = self.keystone_manager.getUsers(prj_id=project_id) users = self.keystone_manager.getUsers(prj_id=project_id)
@ -350,7 +370,10 @@ NOT NULL PRIMARY KEY, name VARCHAR(64), share INT DEFAULT 0, TTL INT DEFAULT \
except SynergyError as ex: except SynergyError as ex:
LOG.info("the project %s seems not to exist anymore! " LOG.info("the project %s seems not to exist anymore! "
"(reason=%s)" % (project.getName(), ex.message)) "(reason=%s)" % (project.getName(), ex.message))
self.removeProject(project) try:
self._removeProject(project, force=True)
except Exception as ex:
LOG.info(ex)
except SQLAlchemyError as ex: except SQLAlchemyError as ex:
raise SynergyError(ex.message) raise SynergyError(ex.message)
finally: finally:

View File

@ -63,11 +63,7 @@ class QueueManager(Manager):
raise SynergyError("command %r not supported!" % command) raise SynergyError("command %r not supported!" % command)
def task(self): def task(self):
try: pass
for queue in self.queues.values():
queue.updatePriority()
except Exception as ex:
LOG.error(ex)
def destroy(self): def destroy(self):
for queue in self.queues.values(): for queue in self.queues.values():