Commit ed9af36f authored by lukas.burgey's avatar lukas.burgey

Use a signal to inform states about deleted deployments

parent f895855a
......@@ -7,6 +7,8 @@ from logging import getLogger
from django.conf import settings
from django.db import models
from django.db.models.signals import pre_delete
from django.dispatch import receiver
from django_mysql.models import JSONField
from polymorphic.models import PolymorphicModel
......@@ -261,6 +263,7 @@ class VODeployment(Deployment):
class ServiceDeployment(Deployment):
service = models.ForeignKey(
......@@ -309,6 +312,18 @@ class ServiceDeployment(Deployment):,
@receiver(pre_delete, sender=VODeployment)
@receiver(pre_delete, sender=ServiceDeployment)
def inform_states_about_deletion(sender, instance=None, **kwargs):
_ = sender
_ = kwargs
states = list(instance.states.all())
LOGGER.debug(instance.msg('Deleted deployment still has states: {}'.format(states)))
instance.state_target = NOT_DEPLOYED
class DeploymentState(models.Model):
deployments = models.ManyToManyField(
......@@ -538,6 +553,7 @@ class DeploymentState(models.Model):
# called when one of our deployments changes its state_target or when we are first created
def dep_target_changed(self):
LOGGER.debug(self.msg('Deployment changed'))
LOGGER.debug('My target: %s - My state: %s - My deps: %s', self.state_target, self.state, self.deployments.all())
for cred_state in self.credential_states.all():
......@@ -367,14 +367,12 @@ def test_both_service_and_vo_deployments_delete(pending_vo_deployment, pending_s
# delete first dep
# still pending as there is still the service deployment
assert state.is_pending
# delete second dep
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment