def test_audit_rrset_delete(self):
        rrset = objects.RecordSet(
            name='foo.example.com.',
            type='PRIMARY',
            records=objects.RecordList.from_list([]),
            zone_id='123',
            zone_name='example.com.',
            id='1',
        )

        result = rrset
        event = 'dns.recordset.delete'
        args = (
            '123',
            '1',
        )
        kwargs = {'wumbo': 'mumbo'}

        expected = [{
            'changed_field': None,
            'new_data': None,
            'old_data': None,
            'recordset_name': 'foo.example.com.',
            'zone_id': '123',
            'zone_name': 'example.com.'
        }]
        driver_result = self.driver.emit(event, self.context, result, args,
                                         kwargs)
        self.assertEqual(driver_result, expected)
Beispiel #2
0
    def test_parse_rrset_object_preserves_changes(self):
        old_ip = '1.1.1.1'
        new_ip = '8.8.8.8'
        original_records = objects.RecordList(objects=[
            objects.Record(data=old_ip),
        ])

        record_set = objects.RecordSet(name='www.example.org.',
                                       type='A',
                                       records=original_records)

        body = {'records': [new_ip]}

        record_set = DesignateAdapter.parse('API_v2', body, record_set)
        self.assertIn('records', record_set.obj_what_changed())

        def get_data(record_list):
            return set([r.data for r in record_list])

        self.assertEqual({old_ip},
                         get_data(
                             record_set.obj_get_original_value('records')))

        self.assertEqual({new_ip},
                         get_data(record_set.obj_get_changes()['records']))
    def test_audit_rrset_update_records(self):
        rrset = objects.RecordSet(
                name='foo.example.com.',
                type='PRIMARY',
                records=objects.RecordList.from_list(
                    [{'data': '192.168.1.1'}]),
                zone_id=AuditNotificationTest.zone__id,
                zone_name='example.com.'
        )

        rrset.records = objects.RecordList.from_list(
            [{'data': '192.168.1.2'}])

        result = rrset
        event = 'dns.recordset.update'
        args = (rrset,)
        kwargs = {'wumbo': 'mumbo'}

        expected = [{
            'changed_field': 'records',
            'new_data': '192.168.1.2',
            'old_data': '192.168.1.1',
            'recordset_name': 'foo.example.com.',
            'zone_id': AuditNotificationTest.zone__id,
            'zone_name': 'example.com.'
        }]
        driver_result = self.driver.emit(
            event, self.context, result, args, kwargs)
        self.assertEqual(driver_result, expected)
    def test_audit_rrset_update_other(self):
        rrset = objects.RecordSet(name='foo.example.com.',
                                  type='PRIMARY',
                                  records=objects.RecordList.from_list([{
                                      'data':
                                      '192.168.1.1'
                                  }]),
                                  zone_id='123',
                                  zone_name='example.com.',
                                  ttl=300)

        rrset.ttl = 400

        result = rrset
        event = 'dns.recordset.update'
        args = (rrset, )
        kwargs = {'wumbo': 'mumbo'}

        expected = [{
            'changed_field': 'ttl',
            'new_data': '400',
            'old_data': '300',
            'recordset_name': 'foo.example.com.',
            'zone_id': '123',
            'zone_name': 'example.com.'
        }]
        driver_result = self.driver.emit(event, self.context, result, args,
                                         kwargs)
        self.assertEqual(driver_result, expected)
Beispiel #5
0
def create_test_recordset():
    record_set = objects.RecordSet(name='www.example.org.',
                                   type='A',
                                   records=objects.RecordList(objects=[
                                       objects.Record(data='192.0.2.1'),
                                       objects.Record(data='192.0.2.2'),
                                   ]))
    return record_set
Beispiel #6
0
 def test_status_deleted(self):
     record_set = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[
             objects.Record(data='192.0.2.2', status='DELETED'),
         ]))
     self.assertEqual('DELETED', record_set.status)
Beispiel #7
0
 def test_action_create(self):
     record_set = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[
             objects.Record(data='192.0.2.1', action='CREATE'),
         ]))
     self.assertEqual('CREATE', record_set.action)
Beispiel #8
0
 def test_status_active(self):
     record_set = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[
             objects.Record(data='192.0.2.3', status='ACTIVE'),
         ]))
     self.assertEqual('ACTIVE', record_set.status)
Beispiel #9
0
    def test__convert_to_rrset_no_records(self):
        zone = objects.Zone.from_dict({'ttl': 1234})
        recordset = objects.RecordSet(name='www.example.org.',
                                      type='A',
                                      records=objects.RecordList(objects=[]))

        r_rrset = self.handler._convert_to_rrset(zone, recordset)
        self.assertIsNone(r_rrset)
Beispiel #10
0
    def test_validate_mx_signed_zero(self):
        rs = objects.RecordSet(
            name='www.example.org.',
            type='MX',
            records=objects.RecordList(objects=[
                objects.Record(data='-0 mail.example.org.', status='ACTIVE'),
            ]))

        self.assertRaises(InvalidObject, rs.validate)
Beispiel #11
0
 def test_managed(self):
     record_set = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[
             objects.Record(data='192.0.2.1', managed=True),
             objects.Record(data='192.0.2.2'),
         ]))
     self.assertTrue(record_set.managed)
Beispiel #12
0
 def test_action(self):
     action = 'CREATE'
     rs = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[
             objects.Record(data='192.0.2.1', action=action),
         ]))
     self.assertEqual(action, rs.action)
Beispiel #13
0
 def test_status_pending2(self):
     rs = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[
             objects.Record(data='192.0.2.3', status='ACTIVE'),
             objects.Record(data='192.0.2.2', status='PENDING'),
         ]))
     self.assertEqual('PENDING', rs.status)
Beispiel #14
0
 def test_action_delete_only(self):
     record_set = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[
             objects.Record(data='192.0.2.1', action='DELETE'),
             objects.Record(data='192.0.2.2', action='DELETE'),
         ]))
     self.assertEqual('DELETE', record_set.action)
Beispiel #15
0
 def test_action_delete_plus_update(self):
     rs = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[
             objects.Record(data='192.0.2.1', action='DELETE'),
             objects.Record(data='192.0.2.2', action='UPDATE'),
         ]))
     self.assertEqual('UPDATE', rs.action)
Beispiel #16
0
    def create_recordset(self, domain, type='A', **kwargs):
        context = kwargs.pop('context', self.admin_context)
        fixture = kwargs.pop('fixture', 0)

        values = self.get_recordset_fixture(domain['name'],
                                            type=type,
                                            fixture=fixture,
                                            values=kwargs)
        return self.central_service.create_recordset(
            context, domain['id'], recordset=objects.RecordSet(**values))
Beispiel #17
0
    def test__convert_to_rrset(self):
        zone = objects.Zone.from_dict({'ttl': 1234})
        recordset = objects.RecordSet(name='www.example.org.',
                                      type='A',
                                      records=objects.RecordList(objects=[
                                          objects.Record(data='192.0.2.1'),
                                          objects.Record(data='192.0.2.2'),
                                      ]))

        r_rrset = self.handler._convert_to_rrset(zone, recordset)
        self.assertEqual(2, len(r_rrset))
Beispiel #18
0
    def test_validate_sshfp_signed_zero_fptype(self):
        record_set = objects.RecordSet(
            name='www.example.org.', type='SSHFP',
            records=objects.RecordList(objects=[
                objects.Record(
                    data='0 -0 72d30d211ce8c464de2811e534de23b9be9b4dc4',
                    status='ACTIVE'),
            ])
        )

        self.assertRaises(InvalidObject, record_set.validate)
Beispiel #19
0
 def test_status_error(self):
     statuses = ('ERROR', 'PENDING', 'ACTIVE')
     for s1, s2, s3 in itertools.permutations(statuses):
         record_set = objects.RecordSet(
             name='www.example.org.',
             type='A',
             records=objects.RecordList(objects=[
                 objects.Record(data='192.0.2.1', status=s1),
                 objects.Record(data='192.0.2.2', status=s2),
                 objects.Record(data='192.0.2.3', status=s3),
             ]))
         self.assertEqual(record_set.status, 'ERROR')
Beispiel #20
0
 def test__handle_record_query_forbidden(self):
     self.storage.find_recordset.return_value = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[
             objects.Record(data='192.0.2.2'),
         ]))
     self.storage.find_zone.side_effect = exceptions.Forbidden
     request = dns.message.make_query('www.example.org.', dns.rdatatype.A)
     request.environ = dict(context='ctx')
     response = tuple(self.handler._handle_record_query(request))
     self.assertEqual(1, len(response))
     self.assertEqual(dns.rcode.REFUSED, response[0].rcode())
Beispiel #21
0
 def test__handle_record_query_empty_recordlist(self):
     # bug #1550441
     self.storage.find_recordset.return_value = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[]))
     request = dns.message.make_query('www.example.org.', dns.rdatatype.A)
     request.environ = dict(context='ctx')
     response_gen = self.handler._handle_record_query(request)
     for r in response_gen:
         # This was raising an exception due to bug #1550441
         out = r.to_wire(max_size=65535)
         self.assertEqual(33, len(out))
Beispiel #22
0
    def create_recordset(self,
                         domain,
                         type='A',
                         fixture=0,
                         values=None,
                         context=None):
        values = values or {}
        context = context or self.admin_context

        fixture = self.get_recordset_fixture(domain['name'], type, fixture,
                                             values)
        return fixture, self.storage.create_recordset(
            context, domain['id'], objects.RecordSet(**fixture))
Beispiel #23
0
    def test_create_recordset(self):
        domain_fixture, domain = self.create_domain()

        values = {'name': 'www.%s' % domain['name'], 'type': 'A'}

        result = self.storage.create_recordset(
            self.admin_context,
            domain['id'],
            recordset=objects.RecordSet(**values))

        self.assertIsNotNone(result['id'])
        self.assertIsNotNone(result['created_at'])
        self.assertIsNone(result['updated_at'])

        self.assertEqual(result['name'], values['name'])
        self.assertEqual(result['type'], values['type'])
Beispiel #24
0
def dnspythonrecord_to_recordset(rname, rdataset):
    record_type = rdatatype.to_text(rdataset.rdtype)

    # Create the other recordsets
    values = {'name': rname.to_text(), 'type': record_type}

    if rdataset.ttl != 0L:
        values['ttl'] = rdataset.ttl

    rrset = objects.RecordSet(**values)
    rrset.records = objects.RecordList()

    for rdata in rdataset:
        rr = objects.Record(data=rdata.to_text())
        rrset.records.append(rr)
    return rrset
Beispiel #25
0
 def test_status_many_expect_active(self):
     rs = objects.RecordSet(
         name='www.example.org.',
         type='A',
         records=objects.RecordList(objects=[
             objects.Record(data='192.0.2.2', status='ACTIVE'),
             objects.Record(data='192.0.2.3', status='DELETED'),
             objects.Record(data='192.0.2.4', status='DELETED'),
             objects.Record(data='192.0.2.5', status='DELETED'),
             objects.Record(data='192.0.2.6', status='ACTIVE'),
             objects.Record(data='192.0.2.7', status='ACTIVE'),
             objects.Record(data='192.0.2.8', status='DELETED'),
             objects.Record(data='192.0.2.9', status='ACTIVE'),
             objects.Record(data='192.0.2.10', status='ACTIVE'),
         ]))
     self.assertEqual('ACTIVE', rs.status)
Beispiel #26
0
    def test_status_error(self):
        statuses = ('ERROR', 'PENDING', 'ACTIVE')
        failed = False
        for s1, s2, s3 in itertools.permutations(statuses):
            rs = objects.RecordSet(
                name='www.example.org.',
                type='A',
                records=objects.RecordList(objects=[
                    objects.Record(data='192.0.2.1', status=s1),
                    objects.Record(data='192.0.2.2', status=s2),
                    objects.Record(data='192.0.2.3', status=s3),
                ]))
            if rs.status != 'ERROR':
                failed = True
                print("test_status_error failed for %s %s %s: %s" %
                      (s1, s2, s3, rs.status))

        self.assertFalse(failed)
Beispiel #27
0
def _find_or_create_recordset(context, domain_id, name, type, ttl):
    central_api = central_rpcapi.CentralAPI.get_instance()

    criterion = {"id": domain_id, "type": "PRIMARY"}
    central_api.find_domain(context, criterion=criterion)

    try:
        recordset = _find_recordset(context, domain_id, name, type)
    except exceptions.RecordSetNotFound:
        # Create an empty recordset
        values = {
            'name': name,
            'type': type,
            'ttl': ttl,
        }

        recordset = central_api.create_recordset(context, domain_id,
                                                 objects.RecordSet(**values))

    return recordset
Beispiel #28
0
def dnspythonrecord_to_recordset(rname, rdataset):
    record_type = rdatatype.to_text(rdataset.rdtype)

    name = rname.to_text()
    if six.PY3 and isinstance(name, bytes):
        name = name.decode('utf-8')

    # Create the other recordsets

    values = {'name': name, 'type': record_type}
    if rdataset.ttl != 0:
        values['ttl'] = rdataset.ttl

    rrset = objects.RecordSet(**values)
    rrset.records = objects.RecordList()

    for rdata in rdataset:
        rr = objects.Record(data=rdata.to_text())
        rrset.records.append(rr)
    return rrset
Beispiel #29
0
def _find_or_create_recordset(context, domain_id, name, type, ttl):
    central_api = central_rpcapi.CentralAPI.get_instance()

    criterion = {"id": domain_id, "type": "PRIMARY"}
    central_api.find_domain(context, criterion=criterion)

    try:
        # Attempt to create an empty recordset
        values = {
            'name': name,
            'type': type,
            'ttl': ttl,
        }

        recordset = central_api.create_recordset(context, domain_id,
                                                 objects.RecordSet(**values))

    except exceptions.DuplicateRecordSet:
        # Fetch the existing recordset
        recordset = _find_recordset(context, domain_id, name, type)

    return recordset
Beispiel #30
0
    def test_parse_rrset_object_preserves_changes_multiple_rrs(self):
        old_ips = ['1.1.1.1', '2.2.2.2']
        new_ips = ['2.2.2.2', '8.8.8.8']
        original_records = objects.RecordList(
            objects=[objects.Record(data=ip) for ip in old_ips])

        rs = objects.RecordSet(name='www.example.org.',
                               type='A',
                               records=original_records)

        body = {'records': new_ips}

        rs = DesignateAdapter.parse('API_v2', body, rs)
        self.assertIn('records', rs.obj_what_changed())

        def get_data(record_list):
            return set([r.data for r in record_list])

        self.assertEqual(set(old_ips),
                         get_data(rs.obj_get_original_value('records')))

        self.assertEqual(set(new_ips),
                         get_data(rs.obj_get_changes()['records']))