diff options
author | Martin Kosek <mkosek@redhat.com> | 2012-05-29 15:58:36 +0200 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2012-05-31 12:45:47 +0200 |
commit | 5b465811ce15e26d4c05c589601eebee1b9e984d (patch) | |
tree | e2c5efbe9660a5ba5d7d80e08dc441cdb8613cc0 | |
parent | 8d00d7c13038abc152afbd46c96108753506fb77 (diff) | |
download | freeipa-5b465811ce15e26d4c05c589601eebee1b9e984d.tar.gz freeipa-5b465811ce15e26d4c05c589601eebee1b9e984d.tar.xz freeipa-5b465811ce15e26d4c05c589601eebee1b9e984d.zip |
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
-rw-r--r-- | API.txt | 3 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | ipalib/plugins/dns.py | 14 | ||||
-rw-r--r-- | tests/test_xmlrpc/test_dns_plugin.py | 34 |
4 files changed, 47 insertions, 6 deletions
@@ -867,7 +867,7 @@ output: ListOfEntries('result', (<type 'list'>, <type 'tuple'>), Gettext('A list output: Output('count', <type 'int'>, None) output: Output('truncated', <type 'bool'>, None) command: dnsrecord_mod -args: 2,115,3 +args: 2,116,3 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) 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('raw', autofill=True, cli_name='raw', default=False, 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: Entry('result', <type 'dict'>, Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None)) output: Output('value', <type 'unicode'>, None) @@ -79,4 +79,4 @@ IPA_DATA_VERSION=20100614120000 # # ######################################################## IPA_API_VERSION_MAJOR=2 -IPA_API_VERSION_MINOR=36 +IPA_API_VERSION_MINOR=37 diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index e2b5995b9..192cc051c 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -1843,6 +1843,7 @@ class dnsrecord(LDAPObject): object_name_plural = _('DNS resource records') object_class = ['top', 'idnsrecord'] default_attributes = ['idnsname'] + _record_attributes + rdn_is_primary_key = True label = _('DNS Resource Records') label_singular = _('DNS Resource Record') @@ -1960,7 +1961,7 @@ class dnsrecord(LDAPObject): return dns_masters 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 has_options = False @@ -2250,6 +2251,11 @@ class dnsrecord_mod(LDAPUpdate): return super(dnsrecord_mod, self).args_options_2_entry(*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 # format is recordname : (old_value, new_parts) updated_attrs = {} @@ -2306,6 +2312,9 @@ class dnsrecord_mod(LDAPUpdate): # remove if empty 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) ldap = self.obj.backend (dn_, old_entry) = ldap.get_entry( @@ -2412,6 +2421,9 @@ class dnsrecord_del(LDAPUpdate): if any(flag in option.flags for flag in \ ('dnsrecord_part', 'dnsrecord_extra',)): continue + elif option.name in ('rename', ): + # options only valid for dnsrecord-mod + continue elif isinstance(option, DNSRecord): yield option.clone(option_group=None) continue diff --git a/tests/test_xmlrpc/test_dns_plugin.py b/tests/test_xmlrpc/test_dns_plugin.py index 8aeaede50..b18ca9081 100644 --- a/tests/test_xmlrpc/test_dns_plugin.py +++ b/tests/test_xmlrpc/test_dns_plugin.py @@ -40,6 +40,7 @@ revdnszone1_ip = u'80.142.15.0/24' revdnszone1_dn = DN(('idnsname',revdnszone1),('cn','dns'),api.env.basedn) dnsres1 = u'testdnsres' dnsres1_dn = DN(('idnsname',dnsres1), dnszone1_dn) +dnsres1_renamed = u'testdnsres-renamed' dnsrev1 = u'80' dnsrev1_dn = DN(('idnsname',dnsrev1), revdnszone1_dn) dnsrev2 = u'81' @@ -68,6 +69,7 @@ class test_dns(Declarative): cleanup_commands = [ ('dnszone_del', [dnszone1], {}), ('dnsrecord_del', [dnszone1, dnsres1], {'del_all' : True}), + ('dnsrecord_del', [dnszone1, dnsres1_renamed], {'del_all' : True}), ('dnszone_del', [dnszone2], {}), ('dnszone_del', [revdnszone1], {}), ('dnsconfig_mod', [], {'idnsforwarders' : None, @@ -845,11 +847,37 @@ class test_dns(Declarative): ), dict( - desc='Delete record %r in zone %r' % (dnsres1, dnszone1), - command=('dnsrecord_del', [dnszone1, dnsres1], {'del_all': True }), + desc='Try to to rename DNS zone %r root record' % (dnszone1), + 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={ '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''}, }, ), |