On Wed, 2012-05-30 at 18:01 +0200, Jan Cholasta wrote:
> On 29.5.2012 16:59, Martin Kosek wrote:
> > On Tue, 2012-05-29 at 16:40 +0200, Jan Cholasta wrote:
> >> On 29.5.2012 16:01, Martin Kosek wrote:
> >>> This option will make renaming DNS records much easier.
> >>> Add a unit test for this new functionality.
> >>>
> >>> https://fedorahosted.org/freeipa/ticket/2600
> >>>
> >>
> >> I wonder, how hard would it be to modify the patch to allow --rename on
> >> all objects, as requested in<https://fedorahosted.org/freeipa/ticket/2466>?
> >>
> >> Honza
> >>
> >
> > Not sure, but it would require a lot of testing. As you can see in a
> > case of dnsrecord object, it may need more changes than just adding
> > rdn_is_primary_key=True to LDAPObjects. I assume there is a reason why
> > we deferred this effort for now.
> >
> > Martin
> >
> 
> OK.
> 
> Regarding the patch:
> 
> 1) When I do:
> 
>      $ ipa dnsrecord-mod example.com @ --rename test
> 
> it returns an error:
> 
>      ipa: ERROR: @: DNS resource record not found
> 
> and the zone "example.com" is renamed to "test".
> 
> 2) The patch needs to be rebased.
> 
> Honza
> 

Patch is rebased. I also fixed a case when user tries to rename DNS zone
root record (good catch btw.) and added a test case for that.

Martin
>From e262728e3c0d9f547b7960da6bd1e13a5d7c40b3 Mon Sep 17 00:00:00 2001
From: Martin Kosek <mko...@redhat.com>
Date: Tue, 29 May 2012 15:58:36 +0200
Subject: [PATCH] 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
---
 API.txt                              |    3 ++-
 VERSION                              |    2 +-
 ipalib/plugins/dns.py                |   14 +++++++++++++-
 tests/test_xmlrpc/test_dns_plugin.py |   34 +++++++++++++++++++++++++++++++---
 4 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/API.txt b/API.txt
index 3cc25b24ef0e6896a70ab75e4ba717381d89b8c9..ba5aa1037e5d9b8661326afe4e6f984d52cc3cc8 100644
--- a/API.txt
+++ b/API.txt
@@ -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)
diff --git a/VERSION b/VERSION
index 1ea26c1dfb0c9ce7b928324f528f1557cbc6ab68..9e14c8cf46b8d39f955be952ce62173f4d9d453c 100644
--- a/VERSION
+++ b/VERSION
@@ -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 e2b5995b9dce4dbe252fb4bfe86c546cd279600a..192cc051c77725067292772014c15c608fb8c4d2 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 8aeaede50b68db70b1cd99cfec52e3fcb7fa6c6f..b18ca90817fafdd9c8709d101ba191d5e970450e 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''},
             },
         ),
-- 
1.7.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to