declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys");
- declare(suffix, "get-all-domains-query", "Retrieve all domains", "select records.domain_id, records.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from records, domains where records.domain_id=domains.id and records.type='SOA' and (records.disabled=0 OR %d)");
+ declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR %d");
declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=%d");
declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, '%s', '%s', %d, '%s', '%s')");
declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys");
- declare(suffix, "get-all-domains-query", "Retrieve all domains", "select records.domain_id, records.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from records, domains where records.domain_id=domains.id and records.type='SOA' and (records.disabled=0 OR 1=%d)");
+ declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR 1=%d");
declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,\"comment\" FROM comments WHERE domain_id=%d");
declare(suffix, "insert-comment-query", "", "INSERT INTO comments (id, domain_id, name, type, modified_at, account, \"comment\") VALUES (comments_id_sequence.nextval, %d, '%s', '%s', %d, '%s', '%s')");
declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys");
- declare(suffix, "get-all-domains-query", "Retrieve all domains", "select records.domain_id, records.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from records, domains where records.domain_id=domains.id and records.type='SOA' and (records.disabled=false OR %d::bool)");
+ declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR %d::bool");
declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=%d");
declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, E'%s', E'%s', %d, E'%s', E'%s')");
declare(suffix,"delete-tsig-key-query","", "delete from tsigkeys where name='%s'");
declare(suffix,"get-tsig-keys-query","", "select name,algorithm, secret from tsigkeys");
- declare(suffix, "get-all-domains-query", "Retrieve all domains", "select records.domain_id, records.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from records, domains where records.domain_id=domains.id and records.type='SOA' and (records.disabled=0 OR %d)");
+ declare(suffix, "get-all-domains-query", "Retrieve all domains", "select domains.id, domains.name, records.content, domains.type, domains.master, domains.notified_serial, domains.last_check from domains LEFT JOIN records ON records.domain_id=domains.id AND records.type='SOA' AND records.name=domains.name WHERE records.disabled=0 OR %d");
declare(suffix, "list-comments-query", "", "SELECT domain_id,name,type,modified_at,account,comment FROM comments WHERE domain_id=%d");
declare(suffix, "insert-comment-query", "", "INSERT INTO comments (domain_id, name, type, modified_at, account, comment) VALUES (%d, '%s', '%s', %d, '%s', '%s')");
rr.ttl = ::arg().asNum("default-ttl");
rr.priority = 0;
- if (!have_soa) {
+ if (!have_soa && zonekind != DomainInfo::Slave) {
// synthesize a SOA record so the zone "really" exists
SOAData sd;
for k in ('name', 'masters', 'kind'):
self.assertIn(k, data)
self.assertEquals(data[k], payload[k])
+ print "payload:", payload
+ print "data:", data
+ # Because slave zones don't get a SOA, we need to test that they'll show up in the zone list.
+ r = self.session.get(self.url("/servers/localhost/zones"))
+ zonelist = r.json()
+ print "zonelist:", zonelist
+ self.assertIn(payload['name'], [zone['name'] for zone in zonelist])
+ # Also test that fetching the zone works.
+ r = self.session.get(self.url("/servers/localhost/zones/" + data['id']))
+ data = r.json()
+ print "zone (fetched):", data
+ for k in ('name', 'masters', 'kind'):
+ self.assertIn(k, data)
+ self.assertEquals(data[k], payload[k])
+ self.assertEqual(data['serial'], 0)
+ self.assertEqual(data['records'], [])
+
+ def test_delete_slave_zone(self):
+ payload, data = self.create_zone(kind='Slave', nameservers=None, masters=['127.0.0.2'])
+ r = self.session.delete(self.url("/servers/localhost/zones/" + data['id']))
+ r.raise_for_status()
def test_get_zone_with_symbols(self):
payload, data = self.create_zone(name='foo/bar.'+unique_zone_name())