def _update_zones(self, pool): LOG.info("Updating zone masters for pool: {}".format(pool.id)) def __get_masters_from_pool(pool): masters = [] for target in pool.targets: for master in target.get("masters", []): master = {'host': master['host'], 'port': master['port']} found = False for existing_master in masters: if master == existing_master: found = True if not found: masters.append(master) return masters policy.init() self.context.all_tenants = True zones = self.central_api.find_zones(self.context, criterion={'pool_id': pool.id}) for zone in zones: zone.masters = objects.ZoneMasterList().from_list( __get_masters_from_pool(pool)) self.central_api.update_zone(self.context, zone)
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()
def test_validate_secondary_with_masters_empty_list(self): masters = objects.ZoneMasterList() zone = objects.Zone(name='example.com.', type='SECONDARY', masters=masters) self.assertRaisesRegex(exceptions.InvalidObject, 'Provided object does not match schema', zone.validate)
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()
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()
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
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)
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)
def _parse_object(cls, values, object, *args, **kwargs): if 'masters' in values: object.masters = objects.adapters.DesignateAdapter.parse( cls.ADAPTER_FORMAT, values['masters'], objects.ZoneMasterList(), *args, **kwargs) del values['masters'] return super(ZoneAPIv2Adapter, cls)._parse_object(values, object, *args, **kwargs)