def setUp(self): super(PowerDNSBackendTestCase, self).setUp() self.domain = objects.Domain(id='e2bed4dc-9d01-11e4-89d3-123b93f75cba', name='example.com.', email='*****@*****.**') self.target = objects.PoolTarget.from_dict({ 'id': '4588652b-50e7-46b9-b688-a9bad40a873e', 'type': 'powerdns', 'masters': [{ 'host': '192.0.2.1', 'port': 53 }, { 'host': '192.0.2.2', 'port': 35 }], 'options': [{ 'key': 'connection', 'value': 'memory://', 'key': 'host', 'value': '192.0.2.3', 'key': 'port', 'value': 53 }], }) self.backend = impl_powerdns.PowerDNSBackend(self.target)
def create_zone(): id_ = str(uuid.uuid4()) return objects.Domain( id=id_, name='%s-example.com.' % id_, email='*****@*****.**', )
def test_update_secondary(self): # Create a zone fixture = self.get_domain_fixture('SECONDARY', 0) domain = objects.Domain(**fixture) domain.email = cfg.CONF['service:central'].managed_resource_email # Create a zone zone = self.central_service.create_domain(self.admin_context, domain) masters = ['10.0.0.1', '10.0.0.2'] # Prepare an update body body = {'masters': masters} response = self.client.patch_json('/zones/%s' % zone['id'], body, status=202) # Check the headers are what we expect self.assertEqual(202, response.status_int) self.assertEqual('application/json', response.content_type) # Check the body structure is what we expect self.assertIn('links', response.json) self.assertIn('self', response.json['links']) self.assertIn('status', response.json) # Check the values returned are what we expect self.assertIn('id', response.json) self.assertIsNotNone(response.json['updated_at']) self.assertEqual(masters, response.json['masters']) self.assertEqual(1, response.json['serial'])
def _get_secondary_domain(self, values=None, attributes=None): attributes = attributes or [] fixture = self.get_domain_fixture("SECONDARY", values=values) fixture['email'] = cfg.CONF['service:central'].managed_resource_email domain = objects.Domain(**fixture) domain.attributes = objects.DomainAttributeList() return domain
def test_masters_2(self): domain = objects.Domain( masters=objects.DomainMasterList.from_list([ {'host': '1.0.0.0'}, {'host': '2.0.0.0'} ]) ) self.assertEqual(len(domain.masters), 2)
def test_masters(self): domain = objects.Domain( masters=objects.DomainMasterList.from_list([ {'host': '1.0.0.0', 'port': 53} ]) ) self.assertEqual( domain.masters.to_list(), [{'host': '1.0.0.0', 'port': 53}])
def test_get_master_by_ip(self): domain = objects.Domain( masters=objects.DomainMasterList.from_list([ {'host': '1.0.0.0', 'port': 53}, {'host': '2.0.0.0', 'port': 53} ]) ) m = domain.get_master_by_ip('2.0.0.0').to_data() self.assertEqual(m, '2.0.0.0:53')
def create_domain(self, fixture=0, values=None, context=None): values = values or {} context = context or self.admin_context fixture = self.get_domain_fixture(fixture, values) if 'tenant_id' not in fixture: fixture['tenant_id'] = context.tenant return fixture, self.storage.create_domain(context, objects.Domain(**fixture))
def _get_secondary_domain(self, values=None, attributes=None, masters=None): attributes = attributes or [] masters = masters or [{"host": "10.0.0.1", "port": 53}] fixture = self.get_domain_fixture("SECONDARY", values=values) fixture['email'] = cfg.CONF['service:central'].managed_resource_email domain = objects.Domain(**fixture) domain.attributes = objects.DomainAttributeList().from_list(attributes) domain.masters = objects.DomainMasterList().from_list(masters) return domain
def create_domain(self, **kwargs): context = kwargs.pop('context', self.admin_context) fixture = kwargs.pop('fixture', 0) # We always need a server to create a domain.. try: self.create_server() except exceptions.DuplicateServer: pass values = self.get_domain_fixture(fixture=fixture, values=kwargs) if 'tenant_id' not in values: values['tenant_id'] = context.tenant domain = objects.Domain(**values) return self.central_service.create_domain(context, domain=domain)
def post_all(self): """Create Zone""" request = pecan.request response = pecan.response context = request.environ['context'] zone = request.body_dict # We need to check the zone type before validating the schema since if # it's the type is SECONDARY we need to set the email to the mgmt email if isinstance(zone, dict): if 'type' not in zone: zone['type'] = 'PRIMARY' if zone['type'] == 'SECONDARY': mgmt_email = CONF['service:central'].managed_resource_email zone['email'] = mgmt_email zone = DesignateAdapter.parse('API_v2', zone, objects.Domain()) zone.validate() # # TODO(ekarlso): Fix this once setter or so works. # masters = values.pop('masters', []) # zone = objects.Domain.from_dict(values) # zone.set_masters(masters) # Create the zone zone = self.central_api.create_domain(context, zone) # Prepare the response headers # If the zone has been created asynchronously if zone['status'] == 'PENDING': response.status_int = 202 else: response.status_int = 201 # Prepare and return the response body zone = DesignateAdapter.render('API_v2', zone, request=request) response.headers['Location'] = zone['links']['self'] return zone
def test_create_domain(self): values = { 'tenant_id': self.admin_context.tenant, 'name': 'example.net.', 'email': '*****@*****.**' } result = self.storage.create_domain(self.admin_context, domain=objects.Domain(**values)) self.assertIsNotNone(result['id']) self.assertIsNotNone(result['created_at']) self.assertIsNone(result['updated_at']) self.assertEqual(result['tenant_id'], self.admin_context.tenant) self.assertEqual(result['name'], values['name']) self.assertEqual(result['email'], values['email']) self.assertIn('status', result)
def test_delete_domain(self): context = self.get_context() domain = self.get_domain_fixture() # Since multi's delete fetches the domain from central to be able to # recreate it if something goes wrong, create the domain first self.backend.central_service.create_server( self.get_admin_context(), self.get_server_fixture()) self.backend.central_service.create_domain( context, objects.Domain(**domain)) self.backend.master.delete_domain = MagicMock( side_effect=exceptions.Backend) self.assertRaises(exceptions.Backend, self.backend.delete_domain, context, domain) self.assertEqual(self.backends.mock_calls, [call.slave.delete_domain(context, domain), call.master.delete_domain(context, domain), call.slave.create_domain(context, domain)])
def setUp(self): super(PowerDNSBackendTestCase, self).setUp() self.masters = [ '127.0.1.1:53', '127.0.1.2:53', ] self.domain = objects.Domain(id='e2bed4dc-9d01-11e4-89d3-123b93f75cba', name='example.com.', email='*****@*****.**') backend_options = [ objects.BackendOption(key="host", value="127.0.0.1"), objects.BackendOption(key="port", value=5353), objects.BackendOption(key="masters", value=self.masters), ] self.backend = impl_powerdns.PowerDNSBackend(backend_options)
def create_domain(): valid_attributes = ['name', 'email', 'ttl', 'description'] context = flask.request.environ.get('context') values = load_values(flask.request, valid_attributes) domain_schema.validate(values) central_api = central_rpcapi.CentralAPI.get_instance() # A V1 zone only supports being a primary (No notion of a type) values['type'] = 'PRIMARY' domain = central_api.create_domain(context, objects.Domain(**values)) response = flask.jsonify(domain_schema.filter(domain)) response.status_int = 201 response.location = flask.url_for('.get_domain', domain_id=domain['id']) return response
def from_dnspython_zone(dnspython_zone): # dnspython never builds a zone with more than one SOA, even if we give # it a zonefile that contains more than one soa = dnspython_zone.get_rdataset(dnspython_zone.origin, 'SOA') if soa is None: raise exceptions.BadRequest('An SOA record is required') email = soa[0].rname.to_text().rstrip('.') email = email.replace('.', '@', 1) values = { 'name': dnspython_zone.origin.to_text(), 'email': email, 'ttl': soa.ttl, 'serial': soa[0].serial, 'retry': soa[0].retry, 'expire': soa[0].expire } zone = objects.Domain(**values) rrsets = dnspyrecords_to_recordsetlist(dnspython_zone.nodes) zone.recordsets = rrsets return zone
def test_masters_none(self): domain = objects.Domain() with raises(exceptions.RelationNotLoaded): self.assertEqual(domain.masters, None)
def test_get_master_by_ip_none(self): domain = objects.Domain() m = domain.get_master_by_ip('2.0.0.0') self.assertEqual(m, False)
def test_validate_invalid_secondary(self): domain = objects.Domain( type='SECONDARY', ) with raises(exceptions.InvalidObject): domain.validate()
def test_update_domain(self): self.set_up_backend() context = self.get_context() domain = objects.Domain().from_dict(self.get_domain_fixture()) self.backend.update_domain(context, domain)
def create_test_domain(): return objects.Domain( name='www.example.org.', email='*****@*****.**', )