From a2213f3f6d4312255c714d3ba4e2d0c95513f007 Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Thu, 27 Jul 2017 23:14:26 +1200 Subject: [PATCH] Fix relationship of function service mapping When deleting function, the service mapping record should be deleted automatically. Provide a helper script for resource clean up. Change-Id: Ie3db454b5bcfb74a0826f01c4626fb45fca58478 --- qinling/db/sqlalchemy/models.py | 9 +++------ tools/clear_resources.sh | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 tools/clear_resources.sh diff --git a/qinling/db/sqlalchemy/models.py b/qinling/db/sqlalchemy/models.py index 39c41b55..5c3a6165 100644 --- a/qinling/db/sqlalchemy/models.py +++ b/qinling/db/sqlalchemy/models.py @@ -65,9 +65,6 @@ class FunctionServiceMapping(model_base.QinlingModelBase): sa.String(36), sa.ForeignKey(Function.id, ondelete='CASCADE'), ) - function = relationship( - 'Function', uselist=False, back_populates="service" - ) service_url = sa.Column(sa.String(255), nullable=False) @@ -111,8 +108,8 @@ class Job(model_base.QinlingSecureModelBase): return d -Function.service = relationship("FunctionServiceMapping", - uselist=False, - back_populates="function") +# Delete service mapping automatically when deleting function. +Function.service = relationship("FunctionServiceMapping", uselist=False, + cascade="all, delete-orphan") Runtime.functions = relationship("Function", back_populates="runtime") Function.jobs = relationship("Job", back_populates="function") diff --git a/tools/clear_resources.sh b/tools/clear_resources.sh new file mode 100644 index 00000000..859ed5f2 --- /dev/null +++ b/tools/clear_resources.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env +set -e + +function delete_resources(){ + # Delete jobs + ids=$(openstack job list -f yaml -c Id | awk '{print $3}') + for id in $ids + do + openstack job delete $id + done + + # Delete executions + ids=$(openstack function execution list -f yaml -c Id | awk '{print $3}') + for id in $ids + do + openstack function execution delete $id + done + + # Delete functions + ids=$(openstack function list -f yaml -c Id | awk '{print $3}') + for id in $ids + do + openstack function delete $id + done + + # Delete runtimes + ids=$(openstack runtime list -f yaml -c Id | awk '{print $3}') + for id in $ids + do + openstack runtime delete $id + done +} + +delete_resources