Commit dc4b1b95 authored by Lukas Burgey's avatar Lukas Burgey

Rename deployment models

parent 22d329d4
......@@ -57,5 +57,5 @@ admin.site.register(models.Service)
admin.site.register(models.SSHPublicKey)
admin.site.register(models.CredentialState)
admin.site.register(models.NewDeployment)
admin.site.register(models.NewDeploymentStateItem)
admin.site.register(models.Deployment)
admin.site.register(models.DeploymentState)
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend', '0022_newdeploymentstateitem_user'),
]
operations = [
migrations.RenameModel('NewDeployment', 'Deployment'),
migrations.RenameModel('NewDeploymentStateItem', 'DeploymentState'),
]
......@@ -139,12 +139,12 @@ class Service(models.Model):
try:
deployment = user.deployments.get(vo=vo)
deployment.service_added(self)
except NewDeployment.DoesNotExist:
except Deployment.DoesNotExist:
LOGGER.error('Inconsistency of vo deployment')
raise
class NewDeployment(models.Model):
class Deployment(models.Model):
user = models.ForeignKey(
User,
related_name='deployments',
......@@ -213,10 +213,10 @@ class NewDeployment(models.Model):
def create_state_items(self, site=None):
for service in self.services:
LOGGER.debug('create_state_items: creating NewDeploymentStateItem for service %s at sites %s', service, service.site.all())
LOGGER.debug('create_state_items: creating DeploymentState for service %s at sites %s', service, service.site.all())
if site is not None:
NewDeploymentStateItem.get_state_item(
DeploymentState.get_state_item(
parent=self,
user=self.user,
site=site,
......@@ -229,8 +229,8 @@ class NewDeployment(models.Model):
# raise ValueError('Cannot create state item for service without site')
for service_site in service.site.all():
# LOGGER.debug('create_state_items: creating NewDeploymentStateItems for service %s at site %s', service, service_site)
NewDeploymentStateItem.get_state_item(
# LOGGER.debug('create_state_items: creating DeploymentStates for service %s at site %s', service, service_site)
DeploymentState.get_state_item(
parent=self,
user=self.user,
site=service_site,
......@@ -290,8 +290,8 @@ class NewDeployment(models.Model):
def service_added(self, service):
LOGGER.debug(self.msg('Adding service {}'.format(service)))
for site in service.site.all():
# create new NewDeploymentStateItems
item = NewDeploymentStateItem.get_state_item(
# create new DeploymentStates
item = DeploymentState.get_state_item(
parent=self,
site=site,
service=service,
......@@ -302,8 +302,8 @@ class NewDeployment(models.Model):
def publish_to_client(self):
# avoiding circular dependencies here
from .serializers.clients import NewDeploymentSerializer
data = NewDeploymentSerializer(self).data
from .serializers.clients import DeploymentSerializer
data = DeploymentSerializer(self).data
msg = dumps(data)
if self.vo is not None:
......@@ -318,9 +318,9 @@ class NewDeployment(models.Model):
return
# avoiding circular dependencies here
from .serializers.webpage import NewDeploymentSerializer
from .serializers.webpage import DeploymentSerializer
msg = dumps({
'deployment': NewDeploymentSerializer(self).data,
'deployment': DeploymentSerializer(self).data,
})
RabbitMQInstance.load().publish_to_user(
self.user,
......@@ -353,9 +353,9 @@ class NewDeployment(models.Model):
)
class NewDeploymentStateItem(models.Model):
class DeploymentState(models.Model):
parent = models.ForeignKey(
NewDeployment,
Deployment,
related_name='state_items',
on_delete=models.CASCADE,
)
......@@ -638,7 +638,7 @@ class CredentialState(models.Model):
)
target = models.ForeignKey(
NewDeploymentStateItem,
DeploymentState,
related_name='credential_states',
on_delete=models.CASCADE,
)
......
......@@ -49,5 +49,5 @@ class CredentialStateSerializer(serializers.ModelSerializer):
# "exports"
from .webpage import NewDeploymentSerializer
from .webpage import DeploymentSerializer
from .clients import RabbitMQInstanceSerializer
......@@ -38,13 +38,13 @@ class UserSerializer(serializers.ModelSerializer):
]
class NewDeploymentSerializer(serializers.ModelSerializer):
class DeploymentSerializer(serializers.ModelSerializer):
user = UserSerializer()
vo = VOSerializer()
credentials = CredentialSerializer
class Meta:
model = models.NewDeployment
model = models.Deployment
fields = [
'state_target',
'id',
......
......@@ -30,7 +30,7 @@ class ServiceSerializer(serializers.ModelSerializer):
]
class NewDeploymentStateItemSerializer(serializers.ModelSerializer):
class DeploymentStateSerializer(serializers.ModelSerializer):
service = ServiceSerializer()
site = SiteSerializer()
questionnaire = serializers.JSONField()
......@@ -39,7 +39,7 @@ class NewDeploymentStateItemSerializer(serializers.ModelSerializer):
credential_states = backend_serializers.CredentialStateSerializer(many=True)
class Meta:
model = models.NewDeploymentStateItem
model = models.DeploymentState
fields = [
'state',
'id',
......@@ -53,13 +53,13 @@ class NewDeploymentStateItemSerializer(serializers.ModelSerializer):
]
class NewDeploymentSerializer(serializers.ModelSerializer):
class DeploymentSerializer(serializers.ModelSerializer):
sites = SiteSerializer(many=True)
services = ServiceSerializer(many=True)
state_items = NewDeploymentStateItemSerializer(many=True)
state_items = DeploymentStateSerializer(many=True)
class Meta:
model = models.NewDeployment
model = models.Deployment
fields = [
'state_target',
'services',
......@@ -89,7 +89,7 @@ class UserSerializer(serializers.ModelSerializer):
class UserStateSerializer(serializers.ModelSerializer):
vos = VOSerializer(many=True)
ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
deployments = NewDeploymentSerializer(many=True)
deployments = DeploymentSerializer(many=True)
services = ServiceSerializer(many=True)
class Meta:
......
......@@ -246,7 +246,7 @@ class DeploymentTest(TestCase):
user = models.User.objects.get(username=TEST_NAME)
service = models.Service.objects.get(name=TEST_SERVICE)
deployment = models.NewDeployment.get_deployment(
deployment = models.Deployment.get_deployment(
user,
service=service,
)
......@@ -256,7 +256,7 @@ class DeploymentTest(TestCase):
user = models.User.objects.get(username=TEST_NAME)
group = Group.objects.get(name=GROUP_NO_SERVICES)
deployment = models.NewDeployment.get_deployment(
deployment = models.Deployment.get_deployment(
user,
group=group,
)
......@@ -268,7 +268,7 @@ class DeploymentTest(TestCase):
user = models.User.objects.get(username=TEST_NAME)
group = Group.objects.get(name=GROUP_ONE_SERVICE)
deployment = models.NewDeployment.get_deployment(
deployment = models.Deployment.get_deployment(
user,
group=group,
)
......@@ -278,7 +278,7 @@ class DeploymentTest(TestCase):
user = models.User.objects.get(username=TEST_NAME)
group = Group.objects.get(name=GROUP_MULTIPLE_SERVICES)
deployment = models.NewDeployment.get_deployment(
deployment = models.Deployment.get_deployment(
user,
group=group,
)
......@@ -288,7 +288,7 @@ class DeploymentTest(TestCase):
user = models.User.objects.get(username=TEST_NAME)
service = models.Service.objects.get(name=BROKEN_SERVICE)
with self.assertRaises(ValueError):
models.NewDeployment.get_deployment(
models.Deployment.get_deployment(
user,
service=service,
)
......@@ -202,7 +202,7 @@ class User(AbstractUser):
self.deactivate()
# FIXME: deleting the user brings problems:
# the deletion cascades down to DeploymentState and NewDeploymentStateItem
# the deletion cascades down to DeploymentState and DeploymentState
# but these need to be conserved so all clients removals can be tracked
LOGGER.info(self.msg('Deleting'))
self.delete()
......
......@@ -8,7 +8,7 @@ from rest_framework.response import Response
from feudal.backend.auth.v1.models.vo import VO, Group, Entitlement
from ..models.serializers.clients import RabbitMQInstanceSerializer, NewDeploymentSerializer
from ..models.serializers.clients import RabbitMQInstanceSerializer, DeploymentSerializer
from .. import models
LOGGER = logging.getLogger(__name__)
......@@ -21,7 +21,7 @@ AUTHENTICATION_CLASSES = (BasicAuthentication, )
# The client fetches pending tasks
class DeploymentsView(generics.ListAPIView):
authentication_classes = AUTHENTICATION_CLASSES
serializer_class = NewDeploymentSerializer
serializer_class = DeploymentSerializer
def get_queryset(self):
return self.request.user.site.pending_tasks
......@@ -56,7 +56,7 @@ class ResponseView(views.APIView):
)
return response_view_error('unable to determine service')
# find the corresponding NewDeploymentStateItem for this response
# find the corresponding DeploymentState for this response
try:
state_item = client_site.state_items.get(
parent__id=int(state_id),
......@@ -69,9 +69,9 @@ class ResponseView(views.APIView):
return response_view_error(err)
return Response({})
except models.NewDeploymentStateItem.DoesNotExist:
except models.DeploymentState.DoesNotExist:
LOGGER.error('[ResponseView] No matching DStateItem')
return response_view_error('no matching NewDeploymentStateItem')
return response_view_error('no matching DeploymentState')
# the client has to fetch the configuration (like services etc.) here
......
......@@ -138,7 +138,7 @@ class DeploymentsViewTest(TestCase):
try:
dep = user.deployments.get(group=group)
self.assertEqual(dep.state_target, models.DEPLOYED)
except models.NewDeployment.DoesNotExist:
except models.Deployment.DoesNotExist:
self.fail('the user did not get the group deployment')
def test_group_remove_success(self):
......@@ -161,7 +161,7 @@ class DeploymentsViewTest(TestCase):
try:
dep = user.deployments.get(group=group)
self.assertEqual(dep.state_target, models.NOT_DEPLOYED)
except models.NewDeployment.DoesNotExist:
except models.Deployment.DoesNotExist:
self.fail('the user did not get the group deployment')
def test_service_add_success(self):
......@@ -183,7 +183,7 @@ class DeploymentsViewTest(TestCase):
try:
dep = user.deployments.get(service=service)
self.assertEqual(dep.state_target, models.DEPLOYED)
except models.NewDeployment.DoesNotExist:
except models.Deployment.DoesNotExist:
self.fail('the user did not get the service deployment')
def test_service_remove_success(self):
......@@ -206,5 +206,5 @@ class DeploymentsViewTest(TestCase):
try:
dep = user.deployments.get(service=service)
self.assertEqual(dep.state_target, models.NOT_DEPLOYED)
except models.NewDeployment.DoesNotExist:
except models.Deployment.DoesNotExist:
self.fail('the user did not get the service deployment')
......@@ -123,12 +123,12 @@ class DeploymentView(views.APIView):
deployment = None
if 'vo' in request.data:
deployment = models.NewDeployment.get_deployment(
deployment = models.Deployment.get_deployment(
request.user,
vo=VO.objects.get(id=request.data['vo']),
)
# elif 'service' in request.data:
# deployment = models.NewDeployment.get_deployment(
# deployment = models.Deployment.get_deployment(
# request.user,
# service=models.Service.objects.get(id=request.data['service']),
# )
......@@ -142,7 +142,7 @@ class DeploymentView(views.APIView):
deployment.save()
return Response(
serializers.NewDeploymentSerializer(deployment).data
serializers.DeploymentSerializer(deployment).data
)
......@@ -150,7 +150,7 @@ class QuestionnaireView(views.APIView):
def post(self, request):
state_item_id = request.query_params.get('id', '')
if state_item_id != '':
item = models.NewDeploymentStateItem.objects.filter(
item = models.DeploymentState.objects.filter(
id=int(state_item_id),
)
if item.exists():
......
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