Permalink
Browse files

Step one of adding internal support for RPKI roots to rpkid: split

Parent model into base Turtle model and derived Parent model.

svn path=/branches/tk705/; revision=6367
  • Loading branch information...
sraustein committed Apr 23, 2016
1 parent 772ff8e commit 0a712cef8857c6cfc53c2157ffaf5553d70c6472
View
@@ -217,10 +217,10 @@ tags: Makefile .FORCE
{ find rpki rp ca schemas -type f \( -name '*.[ch]' -o -name '*.py' -o -name '*.sql' -o -name '*.rnc' \) ! -name relaxng.py -print; find rp ca -type f -perm -1 ! -name '*~' -print | xargs grep -El '^#!.+python'; } | etags -
makemigrations:
RPKI_CONF=makemigrations.conf.$$$$ TEMP_DB=makemigrations.db.$$$$; export RPKI_CONF TEMP_DB; trap "rm -f $$RPKI_CONF $$TEMP_DB" 0; \
PYTHONPATH=. RPKI_CONF=makemigrations.conf.$$$$ TEMP_DB=makemigrations.db.$$$$; export PYTHONPATH RPKI_CONF TEMP_DB; trap "rm -f $$RPKI_CONF $$TEMP_DB" 0; \
${PYTHON} rp/config/rpki-confgen --read-xml rp/config/rpki-confgen.xml --autoconf --set myrpki::shared_sql_engine=sqlite3 \
--set myrpki::rpkid_sql_database=$$TEMP_DB --set myrpki::irdbd_sql_database=$$TEMP_DB --set myrpki::pubd_sql_database=$$TEMP_DB \
--pwgen myrpki::shared_sql_password --pwgen web_portal::secret-key --write-conf $$RPKI_CONF; \
for i in rpkid pubd irdb rcynic; do rp/config/rpki-manage makemigrations --settings rpki.django_settings.$$i; done
for i in rpkid pubd irdb rcynic; do django-admin makemigrations --settings rpki.django_settings.$$i; done
.FORCE:
View
@@ -152,7 +152,7 @@ class PollParentTask(AbstractTask):
def main(self):
logger.debug("%r: Polling parents", self)
for parent in self.tenant.parents.all():
for parent in rpki.rpkidb.models.Parent.objects.filter(tenant = self.tenant):
try:
logger.debug("%r: Executing list query", self)
list_r_msg = yield parent.up_down_list_query(rpkid = self.rpkid)
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rpkidb', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Turtle',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('parent_handle', models.SlugField(max_length=255)),
('repository', models.ForeignKey(related_name='parents', to='rpkidb.Repository')),
('tenant', models.ForeignKey(related_name='parents', to='rpkidb.Tenant')),
],
),
migrations.AlterUniqueTogether(
name='parent',
unique_together=set([]),
),
migrations.RemoveField(
model_name='parent',
name='id',
),
migrations.RenameField(
model_name='parent',
old_name='parent_handle',
new_name='old_parent_handle',
),
migrations.RenameField(
model_name='parent',
old_name='repository',
new_name='old_repository',
),
migrations.RenameField(
model_name='parent',
old_name='tenant',
new_name='old_tenant',
),
migrations.AddField(
model_name='parent',
name='turtle_ptr',
field=models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, default=0, serialize=False, to='rpkidb.Turtle'),
preserve_default=False,
),
migrations.AlterUniqueTogether(
name='turtle',
unique_together=set([('tenant', 'parent_handle')]),
),
]
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
def turtle_forward(apps, schema_editor):
Turtle = apps.get_model("rpkidb", "Turtle")
Parent = apps.get_model("rpkidb", "Parent")
db_alias = schema_editor.connection.alias
for parent in Parent.objects.using(db_alias).all():
turtle = Turtle.objects.using(db_alias).create(
parent_handle = parent.old_parent_handle,
tenant = parent.old_tenant,
repository = parent.old_repository)
parent.turtle_ptr = turtle
parent.save()
def turtle_reverse(apps, schema_editor):
Turtle = apps.get_model("rpkidb", "Turtle")
Parent = apps.get_model("rpkidb", "Parent")
db_alias = schema_editor.connection.alias
for parent in Parent.objects.using(db_alias).all():
parent.old_parent_handle = parent.turtle_ptr.parent_handle
parent.old_tenant = parent.turtle_ptr.tenant
parent.old_repository = parent.turtle_ptr.repository
parent.turtle_ptr = None
parent.save()
Turtle.objects.using(db_alias).all().delete()
class Migration(migrations.Migration):
dependencies = [
('rpkidb', '0002_add_turtle'),
]
operations = [
migrations.RunPython(turtle_forward, turtle_reverse)
]
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rpkidb', '0003_turtle_data'),
]
operations = [
migrations.RemoveField(
model_name='parent',
name='old_parent_handle',
),
migrations.RemoveField(
model_name='parent',
name='old_repository',
),
migrations.RemoveField(
model_name='parent',
name='old_tenant',
),
]
View
@@ -537,24 +537,34 @@ def call_pubd(self, rpkid, q_msg, handlers = None, length_check = True):
raise tornado.gen.Return(r_msg)
@xml_hooks
class Parent(models.Model):
# https://docs.djangoproject.com/en/1.9/topics/db/models/#multi-table-inheritance
class Turtle(models.Model):
# The parent-specific names here will need to change, but first
# step is testing whether the magic of multi-table inheritance
# causes all of this to Just Work until we change the field names.
parent_handle = models.SlugField(max_length = 255)
tenant = models.ForeignKey(Tenant, related_name = "parents")
repository = models.ForeignKey(Repository, related_name = "parents")
class Meta:
unique_together = ("tenant", "parent_handle")
@xml_hooks
class Parent(Turtle):
bpki_cert = CertificateField(null = True)
bpki_glue = CertificateField(null = True)
peer_contact_uri = models.TextField(null = True)
sia_base = models.TextField(null = True)
sender_name = models.TextField(null = True)
recipient_name = models.TextField(null = True)
last_cms_timestamp = SundialField(null = True)
tenant = models.ForeignKey(Tenant, related_name = "parents")
bsc = models.ForeignKey(BSC, related_name = "parents")
repository = models.ForeignKey(Repository, related_name = "parents")
objects = XMLManager()
class Meta:
unique_together = ("tenant", "parent_handle")
xml_template = XMLTemplate(
name = "parent",
handles = (BSC, Repository),

0 comments on commit 0a712ce

Please sign in to comment.