Commit c332f7bc authored by Nikolai Kristiansen's avatar Nikolai Kristiansen
Browse files

Sync scripts work again with ipv4

parent 8d537dfb
A Django app for managing computer equipment. A Django app for managing computer equipment.
## Installation ## Installation
sudo apt-get install libmysqlclient-dev python-dev libldap2-dev libsasl2-dev bind9utils sudo apt install libmysqlclient-dev python-dev libldap2-dev libsasl2-dev bind9utils
virtualenv venv virtualenv venv
. venv/bin/activate . venv/bin/activate
pip install -r requirements.txt pip install -r requirements.txt
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
"domain_serial": 2015100301, "domain_serial": 2015100301,
"domain_refresh": 28800, "domain_refresh": 28800,
"domain_name": "edb.technology", "domain_name": "edb.technology",
"domain_filename": "/tmp/mdb/bind/edb.technology", "domain_filename": "/tmp/bind-db.edb.technology",
"domain_minimum_ttl": 86400, "domain_minimum_ttl": 86400,
"domain_expire": 604800, "domain_expire": 604800,
"domain_soa": "sega.neuf.no", "domain_soa": "sega.neuf.no",
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
"netmask": "255.255.255.0", "netmask": "255.255.255.0",
"dhcp_dynamic_start": "10.0.3.2", "dhcp_dynamic_start": "10.0.3.2",
"domain_admin": "sysadmin@neuf.no", "domain_admin": "sysadmin@neuf.no",
"domain_filename": "/tmp/mdb/bind/3.0.10.in-addr.arpa", "domain_filename": "/tmp/bind-db.3.0.10.in-addr.arpa",
"domain_minimum_ttl": 86400, "domain_minimum_ttl": 86400,
"domain_expire": 604800, "domain_expire": 604800,
"dhcp_dynamic": true, "dhcp_dynamic": true,
......
...@@ -222,17 +222,15 @@ class DhcpConfig(models.Model): ...@@ -222,17 +222,15 @@ class DhcpConfig(models.Model):
# time to write host definitions # time to write host definitions
for subnet in self.ip4subnet_set.all(): for subnet in self.ip4subnet_set.all():
for ip4address in subnet.ip4address_set.all(): for ip4address in subnet.ip4address_set.all():
if ip4address.interface_set.count() == 0: if not hasattr(ip4address, 'interface') or not ip4address.interface.dhcp_client:
continue continue
interface = ip4address.interface_set.get() _if = ip4address.interface
if not interface.dhcp_client: content += "\nhost %s {\n" % _if.host.hostname
continue content += "\thardware ethernet %s;\n" % _if.macaddr
content += "\nhost %s {\n" % interface.host.hostname
content += "\thardware ethernet %s;\n" % interface.macaddr
content += "\tfixed-address %s.%s;\n" % \ content += "\tfixed-address %s.%s;\n" % \
(interface.host.hostname, interface.domain.domain_name) (_if.host.hostname, _if.domain.domain_name)
if len(interface.pxe_filename) > 0: if len(_if.pxe_filename) > 0:
content += "\tfilename \"%s\";\n" % interface.pxe_filename content += "\tfilename \"%s\";\n" % _if.pxe_filename
content += "}\n" content += "}\n"
return content return content
...@@ -388,26 +386,18 @@ class Ip4Subnet(models.Model): ...@@ -388,26 +386,18 @@ class Ip4Subnet(models.Model):
content += ";\n" content += ";\n"
for addr in self.ip4address_set.all(): for addr in self.ip4address_set.all():
if addr.interface_set.count() == 0 and generate_unassigned: """ Get PTR records for each v4 address in subnet """
if hasattr(addr, 'interface') and addr.interface.domain:
hostname = "%s.%s" % (
addr.interface.host.hostname,
addr.interface.domain.domain_name)
content += "%-20s\tIN\tPTR\t%s.\n" % \
(addr.address.split(".")[3], hostname)
elif not hasattr(addr, 'interface') and generate_unassigned:
content += "%s\tIN\tPTR\t%s.%s\n" % ( content += "%s\tIN\tPTR\t%s.%s\n" % (
addr.address, addr.address,
addr.address.split(".")[3], addr.address.split(".")[3],
"dhcp.neuf.no.") "dhcp.neuf.no.")
continue
for interface in addr.interface_set.all():
if interface.domain is None and generate_unassigned:
content += "%s\tIN\tPTR\t%s.%s.\n" % (
addr.address,
addr.address.split(".")[3],
"dhcp.neuf.no")
else:
hostname = "%s.%s" % (
interface.host.hostname,
interface.domain.domain_name)
content += "%-20s\tIN\tPTR\t%s.\n" % \
(addr.address.split(".")[3], hostname)
return content return content
......
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management import call_command
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test import TestCase from django.test import TestCase, LiveServerTestCase
from django.utils import six
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
...@@ -36,3 +38,19 @@ class UnitTests(TestCase): ...@@ -36,3 +38,19 @@ class UnitTests(TestCase):
def test_host_as_pxe_files(self): def test_host_as_pxe_files(self):
host = Host.objects.first() host = Host.objects.first()
self.assertEqual(len(host.as_pxe_files()), 1) self.assertEqual(len(host.as_pxe_files()), 1)
class RunManagementCommands(TestCase):
fixtures = ['test_data']
def test_zone_sync(self):
expected_zone_file = ''
with six.BytesIO() as f:
call_command('zone-sync', debug=True, stdout=f)
# TODO check expected_zone_file
def test_dhcp_sync(self):
expected_dhcp_file = ''
with six.BytesIO() as f:
call_command('dhcp-sync', ('--debug',), stdout=f)
# TODO check expected_dhcp_file
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