outposts: add handler for e2e tests when schema is updated already

This commit is contained in:
Jens Langhammer 2020-11-04 15:36:31 +01:00
parent e5e2615f15
commit fb5e210af8
1 changed files with 14 additions and 9 deletions

View File

@ -6,7 +6,7 @@ import django.db.models.deletion
from django.apps.registry import Apps
from django.db import migrations, models
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.core.exceptions import FieldError
import passbook.lib.models
@ -27,14 +27,19 @@ def migrate_to_service_connection(apps: Apps, schema_editor: BaseDatabaseSchemaE
docker = DockerServiceConnection.objects.filter(local=True)
k8s = KubernetesServiceConnection.objects.filter(local=True)
for outpost in (
Outpost.objects.using(db_alias).all().exclude(deployment_type="custom")
):
if outpost.deployment_type == "kubernetes":
outpost.service_connection = k8s
elif outpost.deployment_type == "docker":
outpost.service_connection = docker
outpost.save()
try:
for outpost in (
Outpost.objects.using(db_alias).all().exclude(deployment_type="custom")
):
if outpost.deployment_type == "kubernetes":
outpost.service_connection = k8s
elif outpost.deployment_type == "docker":
outpost.service_connection = docker
outpost.save()
except FieldError:
# This is triggered during e2e tests when this function is called on an already-upgraded
# schema
pass
class Migration(migrations.Migration):