mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Add rename option for DNS records
This option will make renaming DNS records much easier. Add a unit test for this new functionality. https://fedorahosted.org/freeipa/ticket/2600
This commit is contained in:
3
API.txt
3
API.txt
@@ -867,7 +867,7 @@ output: ListOfEntries('result', (<type 'list'>, <type 'tuple'>), Gettext('A list
|
|||||||
output: Output('count', <type 'int'>, None)
|
output: Output('count', <type 'int'>, None)
|
||||||
output: Output('truncated', <type 'bool'>, None)
|
output: Output('truncated', <type 'bool'>, None)
|
||||||
command: dnsrecord_mod
|
command: dnsrecord_mod
|
||||||
args: 2,115,3
|
args: 2,116,3
|
||||||
arg: Str('dnszoneidnsname', cli_name='dnszone', query=True, required=True)
|
arg: Str('dnszoneidnsname', cli_name='dnszone', query=True, required=True)
|
||||||
arg: Str('idnsname', attribute=True, cli_name='name', multivalue=False, primary_key=True, query=True, required=True)
|
arg: Str('idnsname', attribute=True, cli_name='name', multivalue=False, primary_key=True, query=True, required=True)
|
||||||
option: Int('dnsttl', attribute=True, autofill=False, cli_name='ttl', multivalue=False, required=False)
|
option: Int('dnsttl', attribute=True, autofill=False, cli_name='ttl', multivalue=False, required=False)
|
||||||
@@ -985,6 +985,7 @@ option: Flag('structured', autofill=True, default=False)
|
|||||||
option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui')
|
option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui')
|
||||||
option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui')
|
option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui')
|
||||||
option: Str('version?', exclude='webui')
|
option: Str('version?', exclude='webui')
|
||||||
|
option: Str('rename', cli_name='rename', multivalue=False, primary_key=True, required=False)
|
||||||
output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), None)
|
output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), None)
|
||||||
output: Entry('result', <type 'dict'>, Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None))
|
output: Entry('result', <type 'dict'>, Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None))
|
||||||
output: Output('value', <type 'unicode'>, None)
|
output: Output('value', <type 'unicode'>, None)
|
||||||
|
|||||||
2
VERSION
2
VERSION
@@ -79,4 +79,4 @@ IPA_DATA_VERSION=20100614120000
|
|||||||
# #
|
# #
|
||||||
########################################################
|
########################################################
|
||||||
IPA_API_VERSION_MAJOR=2
|
IPA_API_VERSION_MAJOR=2
|
||||||
IPA_API_VERSION_MINOR=36
|
IPA_API_VERSION_MINOR=37
|
||||||
|
|||||||
@@ -1843,6 +1843,7 @@ class dnsrecord(LDAPObject):
|
|||||||
object_name_plural = _('DNS resource records')
|
object_name_plural = _('DNS resource records')
|
||||||
object_class = ['top', 'idnsrecord']
|
object_class = ['top', 'idnsrecord']
|
||||||
default_attributes = ['idnsname'] + _record_attributes
|
default_attributes = ['idnsname'] + _record_attributes
|
||||||
|
rdn_is_primary_key = True
|
||||||
|
|
||||||
label = _('DNS Resource Records')
|
label = _('DNS Resource Records')
|
||||||
label_singular = _('DNS Resource Record')
|
label_singular = _('DNS Resource Record')
|
||||||
@@ -1960,7 +1961,7 @@ class dnsrecord(LDAPObject):
|
|||||||
return dns_masters
|
return dns_masters
|
||||||
|
|
||||||
def has_cli_options(self, options, no_option_msg, allow_empty_attrs=False):
|
def has_cli_options(self, options, no_option_msg, allow_empty_attrs=False):
|
||||||
if any(k in options for k in ('setattr', 'addattr', 'delattr')):
|
if any(k in options for k in ('setattr', 'addattr', 'delattr', 'rename')):
|
||||||
return
|
return
|
||||||
|
|
||||||
has_options = False
|
has_options = False
|
||||||
@@ -2250,6 +2251,11 @@ class dnsrecord_mod(LDAPUpdate):
|
|||||||
return super(dnsrecord_mod, self).args_options_2_entry(*keys, **options)
|
return super(dnsrecord_mod, self).args_options_2_entry(*keys, **options)
|
||||||
|
|
||||||
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
||||||
|
if options.get('rename') and self.obj.is_pkey_zone_record(*keys):
|
||||||
|
# zone rename is not allowed
|
||||||
|
raise errors.ValidationError(name='rename',
|
||||||
|
error=_('DNS zone root record cannot be renamed'))
|
||||||
|
|
||||||
# check if any attr should be updated using structured instead of replaced
|
# check if any attr should be updated using structured instead of replaced
|
||||||
# format is recordname : (old_value, new_parts)
|
# format is recordname : (old_value, new_parts)
|
||||||
updated_attrs = {}
|
updated_attrs = {}
|
||||||
@@ -2306,6 +2312,9 @@ class dnsrecord_mod(LDAPUpdate):
|
|||||||
|
|
||||||
# remove if empty
|
# remove if empty
|
||||||
if not self.obj.is_pkey_zone_record(*keys):
|
if not self.obj.is_pkey_zone_record(*keys):
|
||||||
|
rename = options.get('rename')
|
||||||
|
if rename is not None:
|
||||||
|
keys = keys[:-1] + (rename,)
|
||||||
dn = self.obj.get_dn(*keys, **options)
|
dn = self.obj.get_dn(*keys, **options)
|
||||||
ldap = self.obj.backend
|
ldap = self.obj.backend
|
||||||
(dn_, old_entry) = ldap.get_entry(
|
(dn_, old_entry) = ldap.get_entry(
|
||||||
@@ -2412,6 +2421,9 @@ class dnsrecord_del(LDAPUpdate):
|
|||||||
if any(flag in option.flags for flag in \
|
if any(flag in option.flags for flag in \
|
||||||
('dnsrecord_part', 'dnsrecord_extra',)):
|
('dnsrecord_part', 'dnsrecord_extra',)):
|
||||||
continue
|
continue
|
||||||
|
elif option.name in ('rename', ):
|
||||||
|
# options only valid for dnsrecord-mod
|
||||||
|
continue
|
||||||
elif isinstance(option, DNSRecord):
|
elif isinstance(option, DNSRecord):
|
||||||
yield option.clone(option_group=None)
|
yield option.clone(option_group=None)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ revdnszone1_ip = u'80.142.15.0/24'
|
|||||||
revdnszone1_dn = DN(('idnsname',revdnszone1),('cn','dns'),api.env.basedn)
|
revdnszone1_dn = DN(('idnsname',revdnszone1),('cn','dns'),api.env.basedn)
|
||||||
dnsres1 = u'testdnsres'
|
dnsres1 = u'testdnsres'
|
||||||
dnsres1_dn = DN(('idnsname',dnsres1), dnszone1_dn)
|
dnsres1_dn = DN(('idnsname',dnsres1), dnszone1_dn)
|
||||||
|
dnsres1_renamed = u'testdnsres-renamed'
|
||||||
dnsrev1 = u'80'
|
dnsrev1 = u'80'
|
||||||
dnsrev1_dn = DN(('idnsname',dnsrev1), revdnszone1_dn)
|
dnsrev1_dn = DN(('idnsname',dnsrev1), revdnszone1_dn)
|
||||||
dnsrev2 = u'81'
|
dnsrev2 = u'81'
|
||||||
@@ -68,6 +69,7 @@ class test_dns(Declarative):
|
|||||||
cleanup_commands = [
|
cleanup_commands = [
|
||||||
('dnszone_del', [dnszone1], {}),
|
('dnszone_del', [dnszone1], {}),
|
||||||
('dnsrecord_del', [dnszone1, dnsres1], {'del_all' : True}),
|
('dnsrecord_del', [dnszone1, dnsres1], {'del_all' : True}),
|
||||||
|
('dnsrecord_del', [dnszone1, dnsres1_renamed], {'del_all' : True}),
|
||||||
('dnszone_del', [dnszone2], {}),
|
('dnszone_del', [dnszone2], {}),
|
||||||
('dnszone_del', [revdnszone1], {}),
|
('dnszone_del', [revdnszone1], {}),
|
||||||
('dnsconfig_mod', [], {'idnsforwarders' : None,
|
('dnsconfig_mod', [], {'idnsforwarders' : None,
|
||||||
@@ -845,11 +847,37 @@ class test_dns(Declarative):
|
|||||||
),
|
),
|
||||||
|
|
||||||
dict(
|
dict(
|
||||||
desc='Delete record %r in zone %r' % (dnsres1, dnszone1),
|
desc='Try to to rename DNS zone %r root record' % (dnszone1),
|
||||||
command=('dnsrecord_del', [dnszone1, dnsres1], {'del_all': True }),
|
command=('dnsrecord_mod', [dnszone1, u'@'], {'rename': dnsres1_renamed,}),
|
||||||
|
expected=errors.ValidationError(name='rename',
|
||||||
|
error=u'DNS zone root record cannot be renamed')
|
||||||
|
),
|
||||||
|
|
||||||
|
dict(
|
||||||
|
desc='Rename DNS record %r to %r' % (dnsres1, dnsres1_renamed),
|
||||||
|
command=('dnsrecord_mod', [dnszone1, dnsres1], {'rename': dnsres1_renamed,}),
|
||||||
expected={
|
expected={
|
||||||
'value': dnsres1,
|
'value': dnsres1,
|
||||||
'summary': u'Deleted record "%s"' % dnsres1,
|
'summary': None,
|
||||||
|
'result': {
|
||||||
|
'idnsname': [dnsres1_renamed],
|
||||||
|
'arecord': [u'10.10.0.1'],
|
||||||
|
'cnamerecord': [u'foo-1.example.com.'],
|
||||||
|
'kxrecord': [u'1 foo-1'],
|
||||||
|
'txtrecord': [u'foo bar'],
|
||||||
|
'nsecrecord': [dnszone1 + u' TXT A'],
|
||||||
|
'nsrecord': [u'does.not.exist'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
dict(
|
||||||
|
desc='Delete record %r in zone %r' % (dnsres1_renamed, dnszone1),
|
||||||
|
command=('dnsrecord_del', [dnszone1, dnsres1_renamed], {'del_all': True }),
|
||||||
|
expected={
|
||||||
|
'value': dnsres1_renamed,
|
||||||
|
'summary': u'Deleted record "%s"' % dnsres1_renamed,
|
||||||
'result': {'failed': u''},
|
'result': {'failed': u''},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user