Exemplo n.º 1
0
    def test_target_sync(self):
        date = 1463154200
        older_date = datetime.fromtimestamp(1463154000)
        newer_date = datetime.fromtimestamp(1463154300)

        zones = [
            objects.Zone(name='a_zone.',
                         status='ACTIVE',
                         created_at=older_date),
            objects.Zone(name='b_zone.',
                         status='ACTIVE',
                         created_at=newer_date),
            objects.Zone(name='c_zone.',
                         status='DELETED',
                         created_at=older_date,
                         serial=1),
        ]

        self.service._delete_zone_on_target = mock.Mock()
        self.service._create_zone_on_target = mock.Mock()
        self.service._update_zone_on_target = mock.Mock()
        self.service.mdns_api.poll_for_serial_number = mock.Mock()

        target = mock.Mock()

        self.service._target_sync(self.context, zones, target, date)

        self.assertEqual(1, self.service._delete_zone_on_target.call_count)
        self.assertEqual(1, self.service._create_zone_on_target.call_count)
        self.assertEqual(1, self.service._update_zone_on_target.call_count)
Exemplo n.º 2
0
    def test_periodic_sync(self, ):
        self.service._fetch_healthy_zones = mock.Mock(return_value=[
            objects.Zone(name='a_zone.'),
            objects.Zone(name='b_zone.'),
            objects.Zone(name='c_zone.'),
        ])

        self.service.update_zone = mock.Mock()
        self.service._exceed_or_meet_threshold = mock.Mock(return_value=True)

        self.service.periodic_sync()

        self.assertEqual(3, self.service.update_zone.call_count)
Exemplo n.º 3
0
    def setUp(self):
        super(InfobloxBackendTestCase, self).setUp()
        self.base_address = 'https://localhost/wapi'

        self.context = self.get_context()
        self.zone = objects.Zone(
            id='e2bed4dc-9d01-11e4-89d3-123b93f75cba',
            name='example.com.',
            email='*****@*****.**',
        )

        self.target = {
            'id': '4588652b-50e7-46b9-b688-a9bad40a873e',
            'type': 'infoblox',
            'masters': [
                {'host': '1.1.1.1', 'port': 53},
            ],
            'options': [
                {'key': 'wapi_url', 'value': 'https://localhost/wapi/v2.0/'},
                {'key': 'username', 'value': 'test'},
                {'key': 'password', 'value': 'test'},
                {'key': 'ns_group', 'value': 'test'},
            ]
        }

        self.backend = impl_infoblox.InfobloxBackend(
            objects.PoolTarget.from_dict(self.target)
        )
Exemplo n.º 4
0
 def test_validate_primary_no_email(self):
     zone = objects.Zone(
         name='example.com.',
         type='PRIMARY',
     )
     with testtools.ExpectedException(exceptions.InvalidObject):
         zone.validate()
Exemplo n.º 5
0
    def setUp(self):
        super(AgentBackendTestCase, self).setUp()
        self.CONF.set_override('poll_timeout', 1, 'service:worker')
        self.CONF.set_override('poll_retry_interval', 4, 'service:worker')
        self.CONF.set_override('poll_max_retries', 5, 'service:worker')
        self.CONF.set_override('poll_delay', 6, 'service:worker')

        self.context = self.get_context()
        self.zone = objects.Zone(
            id='e2bed4dc-9d01-11e4-89d3-123b93f75cba',
            name='example.com.',
            email='*****@*****.**',
        )

        self.target = {
            'id':
            '4588652b-50e7-46b9-b688-a9bad40a873e',
            'type':
            'agent',
            'masters': [],
            'options': [
                {
                    'key': 'host',
                    'value': 2
                },
                {
                    'key': 'port',
                    'value': 3
                },
            ],
        }

        self.backend = agent.AgentPoolBackend(
            objects.PoolTarget.from_dict(self.target))
Exemplo n.º 6
0
    def setUp(self):
        super(NSD4BackendTestCase, self).setUp()

        keyfile = mock.sentinel.key
        certfile = mock.sentinel.cert

        self.context = self.get_context()
        self.zone = objects.Zone(
            id='e2bed4dc-9d01-11e4-89d3-123b93f75cba',
            name='example.com.',
            email='*****@*****.**',
        )

        self.port = 6969
        self.target = {
            'id': '4588652b-50e7-46b9-b688-a9bad40a873e',
            'type': 'nsd4',
            'masters': [
                {'host': '192.0.2.1', 'port': 53},
                {'host': '192.0.2.2', 'port': 35},
            ],
            'options': [
                {'key': 'keyfile', 'value': keyfile.name},
                {'key': 'certfile', 'value': certfile.name},
                {'key': 'pattern', 'value': 'test-pattern'},
                {'key': 'port', 'value': str(self.port)},
            ],
        }

        self.backend = impl_nsd4.NSD4Backend(
            objects.PoolTarget.from_dict(self.target)
        )
Exemplo n.º 7
0
def create_zone():
    id_ = generate_uuid()
    return objects.Zone(
        id=id_,
        name='%s-example.com.' % id_,
        email='*****@*****.**',
    )
    def test_audit_zone_update(self):
        zone = objects.Zone(
                id=AuditNotificationTest.zone__id,
                name='example.com.',
                type='PRIMARY',
                ttl=1
        )
        zone.ttl = 300

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

        expected = [{
            'changed_field': 'ttl',
            'new_data': '300',
            'old_data': '1',
            'recordset_name': None,
            '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)
Exemplo n.º 9
0
 def test_validate_secondary_with_masters_empty_list(self):
     masters = objects.ZoneMasterList()
     zone = objects.Zone(name='example.com.',
                         type='SECONDARY',
                         masters=masters)
     with testtools.ExpectedException(exceptions.InvalidObject):
         zone.validate()
Exemplo n.º 10
0
    def test_update_secondary(self):
        # Create a zone
        fixture = self.get_zone_fixture('SECONDARY', 0)

        zone = objects.Zone(**fixture)
        zone.email = cfg.CONF['service:central'].managed_resource_email

        # Create a zone
        zone = self.central_service.create_zone(self.admin_context, zone)

        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'])
Exemplo n.º 11
0
    def test_multiple_pools(self):
        zone = objects.Zone(name="example.com.",
                            type="PRIMARY",
                            email="*****@*****.**")

        attrs = {
            'find_pools.return_value':
            objects.PoolList.from_list([{
                "id":
                "794ccc2c-d751-44fe-b57f-8894c9f5c842"
            }, {
                "id":
                "5fabcd37-262c-4cf3-8625-7f419434b6df"
            }])
        }

        mock_storage = Mock(**attrs)

        test_scheduler = scheduler.get_scheduler(storage=mock_storage)

        zone.pool_id = test_scheduler.schedule_zone(self.context, zone)

        self.assertIn(zone.pool_id, [
            "794ccc2c-d751-44fe-b57f-8894c9f5c842",
            "5fabcd37-262c-4cf3-8625-7f419434b6df",
        ])
Exemplo n.º 12
0
    def setUp(self):
        super(PDNS4BackendTestCase, self).setUp()
        self.stdlog = fixtures.StandardLogging()
        self.useFixture(self.stdlog)

        self.base_address = 'http://*****:*****@example.com',
        )

        self.target = {
            'id': '4588652b-50e7-46b9-b688-a9bad40a873e',
            'type': 'pdns4',
            'masters': [
                {'host': '192.0.2.1', 'port': 53},
                {'host': '192.0.2.2', 'port': 35},
            ],
            'options': [
                {'key': 'api_endpoint', 'value': 'http://localhost:8081'},
                {'key': 'api_token', 'value': 'api_key'},
            ],
        }

        self.backend = impl_pdns4.PDNS4Backend(
            objects.PoolTarget.from_dict(self.target)
        )
Exemplo n.º 13
0
def create_zone():
    id_ = str(uuid.uuid4())
    return objects.Zone(
        id=id_,
        name='%s-example.com.' % id_,
        email='*****@*****.**',
    )
Exemplo n.º 14
0
    def setUp(self):
        super(DynECTTestsCase, self).setUp()

        self.base_address = 'https://api.dynect.net:443/REST'
        self.context = self.get_context()
        self.zone = objects.Zone(
            id='e2bed4dc-9d01-11e4-89d3-123b93f75cba',
            name='example.com.',
            email='*****@*****.**',
        )

        self.target = {
            'id':
            '4588652b-50e7-46b9-b688-a9bad40a873e',
            'type':
            'dyndns',
            'masters': [{
                'host': '192.0.2.1',
                'port': 53
            }],
            'options': [{
                'key': 'username',
                'value': 'example'
            }, {
                'key': 'password',
                'value': 'secret'
            }, {
                'key': 'customer_name',
                'value': 'customer'
            }],
        }

        self.backend = impl_dynect.DynECTBackend(
            objects.PoolTarget.from_dict(self.target))
Exemplo n.º 15
0
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')
    if soa.ttl == 0:
        soa.ttl = cfg.CONF['service:central'].min_ttl
    email = soa[0].rname.to_text(omit_final_dot=True)
    if six.PY3 and isinstance(email, bytes):
        email = email.decode('utf-8')
    email = email.replace('.', '@', 1)

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

    values = {
        'name': name,
        'email': email,
        'ttl': soa.ttl,
        'serial': soa[0].serial,
        'retry': soa[0].retry,
        'expire': soa[0].expire
    }

    zone = objects.Zone(**values)

    rrsets = dnspyrecords_to_recordsetlist(dnspython_zone.nodes)
    zone.recordsets = rrsets
    return zone
Exemplo n.º 16
0
    def setUp(self):
        super(PowerDNSBackendTestCase, self).setUp()

        self.zone = objects.Zone(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)
Exemplo n.º 17
0
    def test_validate_secondary_with_masters_none(self):
        zone = objects.Zone(name='example.com.',
                            type='SECONDARY',
                            masters=None)

        self.assertRaisesRegex(exceptions.InvalidObject,
                               'Provided object does not match schema',
                               zone.validate)
Exemplo n.º 18
0
 def test_validate_primary_no_email(self):
     zone = objects.Zone(
         name='example.com.',
         type='PRIMARY',
     )
     self.assertRaisesRegex(exceptions.InvalidObject,
                            'Provided object does not match schema',
                            zone.validate)
Exemplo n.º 19
0
 def test_masters_2(self):
     zone = objects.Zone(
         masters=objects.ZoneMasterList.from_list([{
             'host': '1.0.0.0'
         }, {
             'host': '2.0.0.0'
         }]))
     self.assertEqual(2, len(zone.masters))
Exemplo n.º 20
0
 def test_validate_secondary_with_ttl(self):
     masters = objects.ZoneMasterList()
     masters.append(objects.ZoneMaster.from_data("10.0.0.1:53"))
     zone = objects.Zone(name='example.com.',
                         type='SECONDARY',
                         ttl=600,
                         masters=masters)
     with testtools.ExpectedException(exceptions.InvalidObject):
         zone.validate()
Exemplo n.º 21
0
 def test_validate_primary_with_masters(self):
     masters = objects.ZoneMasterList()
     masters.append(objects.ZoneMaster.from_data("10.0.0.1:53"))
     zone = objects.Zone(name='example.com.',
                         type='PRIMARY',
                         email="*****@*****.**",
                         masters=masters)
     with testtools.ExpectedException(exceptions.InvalidObject):
         zone.validate()
Exemplo n.º 22
0
 def test_masters(self):
     zone = objects.Zone(
         masters=objects.ZoneMasterList.from_list([{
             'host': '1.0.0.0',
             'port': 53
         }]))
     self.assertEqual([{
         'host': '1.0.0.0',
         'port': 53
     }], zone.masters.to_list())
Exemplo n.º 23
0
    def test_call_notify_timeout(self, mock_notify):
        mock_notify.side_effect = dns.exception.Timeout()
        self.zone = objects.Zone(name='example.org.')
        self.actor = zone.SendNotify(
            self.executor,
            self.zone,
            self.target,
        )

        self.assertRaises(dns.exception.Timeout, self.actor)
Exemplo n.º 24
0
 def test_validate_secondary_with_ttl(self):
     masters = objects.ZoneMasterList()
     masters.append(objects.ZoneMaster.from_data("10.0.0.1:53"))
     zone = objects.Zone(name='example.com.',
                         type='SECONDARY',
                         ttl=600,
                         masters=masters)
     self.assertRaisesRegex(exceptions.InvalidObject,
                            'Provided object does not match schema',
                            zone.validate)
Exemplo n.º 25
0
 def test_validate_primary_with_masters(self):
     masters = objects.ZoneMasterList()
     masters.append(objects.ZoneMaster.from_data("10.0.0.1:53"))
     zone = objects.Zone(name='example.com.',
                         type='PRIMARY',
                         email="*****@*****.**",
                         masters=masters)
     self.assertRaisesRegex(exceptions.InvalidObject,
                            'Provided object does not match schema',
                            zone.validate)
Exemplo n.º 26
0
    def _get_secondary_zone(self, values=None, attributes=None, masters=None):
        attributes = attributes or []
        masters = masters or [{"host": "10.0.0.1", "port": 53}]
        fixture = self.get_zone_fixture("SECONDARY", values=values)
        fixture['email'] = cfg.CONF['service:central'].managed_resource_email

        zone = objects.Zone(**fixture)
        zone.attributes = objects.ZoneAttributeList().from_list(attributes)
        zone.masters = objects.ZoneMasterList().from_list(masters)
        return zone
Exemplo n.º 27
0
 def setUp(self):
     super(SchedulerPoolIDAttributeFilterTest, self).setUp()
     self.zone = objects.Zone(
         name="example.com.",
         type="PRIMARY",
         email="*****@*****.**",
         attributes=objects.ZoneAttributeList.from_list([{
             "key":
             "pool_id",
             "value":
             "6c346011-e581-429b-a7a2-6cdf0aba91c3"
         }]))
Exemplo n.º 28
0
    def test_call_delete(self, mock_notify):
        self.zone = objects.Zone(name='example.org.', action='DELETE')
        self.actor = zone.ZoneActionOnTarget(
            self.executor,
            self.context,
            self.zone,
            self.target,
        )

        self.assertTrue(self.actor())

        mock_notify.assert_not_called()
Exemplo n.º 29
0
    def test_get_master_by_ip(self):
        zone = objects.Zone(
            masters=objects.ZoneMasterList.from_list([{
                'host': '1.0.0.0',
                'port': 53
            }, {
                'host': '2.0.0.0',
                'port': 53
            }]))
        m = zone.get_master_by_ip('2.0.0.0').to_data()

        self.assertEqual('2.0.0.0:53', m)
Exemplo n.º 30
0
    def test_call_dont_notify(self, mock_notify):
        CONF.set_override('notify', False, 'service:worker')

        self.zone = objects.Zone(name='example.org.')
        self.actor = zone.SendNotify(
            self.executor,
            self.zone,
            self.target,
        )

        self.assertTrue(self.actor())

        mock_notify.assert_not_called()