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
This commit is contained in:
Lingxian Kong 2017-07-27 23:14:26 +12:00
parent 30c8e7dd60
commit a2213f3f6d
2 changed files with 37 additions and 6 deletions

View File

@ -65,9 +65,6 @@ class FunctionServiceMapping(model_base.QinlingModelBase):
sa.String(36), sa.String(36),
sa.ForeignKey(Function.id, ondelete='CASCADE'), sa.ForeignKey(Function.id, ondelete='CASCADE'),
) )
function = relationship(
'Function', uselist=False, back_populates="service"
)
service_url = sa.Column(sa.String(255), nullable=False) service_url = sa.Column(sa.String(255), nullable=False)
@ -111,8 +108,8 @@ class Job(model_base.QinlingSecureModelBase):
return d return d
Function.service = relationship("FunctionServiceMapping", # Delete service mapping automatically when deleting function.
uselist=False, Function.service = relationship("FunctionServiceMapping", uselist=False,
back_populates="function") cascade="all, delete-orphan")
Runtime.functions = relationship("Function", back_populates="runtime") Runtime.functions = relationship("Function", back_populates="runtime")
Function.jobs = relationship("Job", back_populates="function") Function.jobs = relationship("Job", back_populates="function")

34
tools/clear_resources.sh Normal file
View File

@ -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