Commit 428f1341 authored by Lukas Burgey's avatar Lukas Burgey

Fix state changes of state items

parent fcc7fad9
......@@ -25,11 +25,16 @@ class DeploymentSerializer(serializers.ModelSerializer):
user = UserSerializer()
service = ServiceSerializer()
ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
ssh_keys_to_remove = backend_serializers.SSHPublicKeySerializer(many=True)
#ssh_keys_to_remove = backend_serializers.SSHPublicKeySerializer(many=True)
class Meta:
model = models.Deployment
fields = ['user', 'service', 'ssh_keys', 'ssh_keys_to_remove']
fields = [
'user',
'service',
'ssh_keys',
#'ssh_keys_to_remove',
]
class DeploymentsSerializer(serializers.Serializer):
......
......@@ -64,7 +64,7 @@ class DeploymentStateSerializer(serializers.ModelSerializer):
class DeploymentSerializer(serializers.ModelSerializer):
service = ServiceSerializer()
ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
ssh_keys_to_remove = backend_serializers.SSHPublicKeySerializer(many=True)
#ssh_keys_to_remove = backend_serializers.SSHPublicKeySerializer(many=True)
states = DeploymentStateSerializer(many=True)
class Meta:
......@@ -72,7 +72,7 @@ class DeploymentSerializer(serializers.ModelSerializer):
fields = [
'service',
'ssh_keys',
'ssh_keys_to_remove',
#'ssh_keys_to_remove',
'states',
'id',
]
......
......@@ -563,10 +563,19 @@ class Deployment(models.Model):
on_delete=models.SET_NULL,
null=True,
)
group = models.ForeignKey(
Service,
related_name='groups_deployments',
on_delete=models.CASCADE,
null=True,
blank=True,
)
service = models.ForeignKey(
Service,
related_name='deployments',
on_delete=models.CASCADE,
null=True,
blank=True,
)
ssh_keys = models.ManyToManyField(
SSHPublicKey,
......@@ -580,11 +589,19 @@ class Deployment(models.Model):
# get a deployment for a user/service.
# if it does not exist it is created
@classmethod
def get_deployment(cls, user, service):
query = cls.objects.filter(
user=user,
service=service,
)
def get_deployment(cls, user, service=None, group=None):
query = None
if service is not None:
query = cls.objects.filter(
user=user,
service=service,
)
elif group is not None:
query = cls.objects.filter(
user=user,
group=group,
)
if query.exists():
return query.first()
......@@ -875,11 +892,14 @@ class DeploymentStateItem(models.Model):
# update values
if status == 'deployed':
self.credentials = output.get('credentials', {})
elif status == 'removed':
self.save()
elif status == 'not_deployed':
self.credentials = credential_default()
self.questionnaire = questionnaire_default()
self.save()
elif status == 'questionnaire':
self.questionnaire = output.get('questionnaire', {})
self.save()
elif status == 'rejected':
pass
elif status == 'failed':
......
......@@ -129,7 +129,7 @@ class DeploymentTest(TestCase):
# execute deployment
for item in state.state_items.all():
item.client_deployed()
item.client_response({'status':'deployed'})
self.assertTrue(state.target_reached)
......@@ -140,6 +140,6 @@ class DeploymentTest(TestCase):
# execute removals
for item in state.state_items.all():
item.client_removed()
item.client_response({'status':'not_deployed'})
self.assertTrue(state.target_reached)
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