On 07/08/14 17:05, Martin Basti wrote:
On 07/08/14 16:27, Petr Viktorin wrote:
On 08/07/2014 02:33 PM, Martin Basti wrote:
On 28/07/14 14:11, Petr Viktorin wrote:
On 07/09/2014 06:29 PM, Martin Basti wrote:
Patch attached.
Ticket: https://fedorahosted.org/freeipa/ticket/4164


Looks & works fine for me.
Can you also add a test for this?


Tests attached.
I also added tests with --ip-address parameter.


This works, thanks!
I have some comments however:

Variables like `name5` can have more descriptive names, so that you can look at the test definition and actually know what's being tested.

Some of the tests are independent (both in the sense that they don't need the other tests to be run, and that they test a different thing than the others); those can be in separate classes.


There are better things to do in IPA than making the tests perfect, so ACK if you want to push this as is.

Please wait, I will fix the names then, it'll be fast.

Updated patch attached.

--
Martin Basti

From a75948fb18b0b92d6cea6d414d6a3922a10babf1 Mon Sep 17 00:00:00 2001
From: Martin Basti <mba...@redhat.com>
Date: Thu, 7 Aug 2014 14:25:34 +0200
Subject: [PATCH] Tests: host tests with dns

Test for: https://fedorahosted.org/freeipa/ticket/4164
---
 ipatests/test_xmlrpc/test_host_plugin.py | 448 +++++++++++++++++++++++++++++++
 1 file changed, 448 insertions(+)

diff --git a/ipatests/test_xmlrpc/test_host_plugin.py b/ipatests/test_xmlrpc/test_host_plugin.py
index 725e8900fdd1eca2a0cda9fd88dc4e479970e62e..a98fed1b64853e548d489f1bc12d012d18f986a7 100644
--- a/ipatests/test_xmlrpc/test_host_plugin.py
+++ b/ipatests/test_xmlrpc/test_host_plugin.py
@@ -27,6 +27,7 @@ import tempfile
 from ipapython import ipautil
 from ipalib import api, errors, x509
 from ipapython.dn import DN
+from ipapython.dnsutil import DNSName
 from nose.tools import raises, assert_raises
 from nose.plugins.skip import SkipTest
 from ipatests.test_xmlrpc.xmlrpc_test import (Declarative, XMLRPC_test,
@@ -56,6 +57,82 @@ dn4 = DN(('fqdn',fqdn4),('cn','computers'),('cn','accounts'),
          api.env.basedn)
 invalidfqdn1 = u'foo_bar.lab.%s' % api.env.domain
 
+# DNS integration tests
+dnszone = u'zone-ipv6host.test'
+dnszone_absolute = dnszone + '.'
+dnszone_dnsname = DNSName(dnszone_absolute)
+dnszone_dn = DN(('idnsname', dnszone_absolute), api.env.container_dns, api.env.basedn)
+dnszone_ns = u'ns1.%s' % dnszone_absolute
+dnszone_ns_dnsname = DNSName(dnszone_ns)
+dnszone_rname = u'root.%s' % dnszone_absolute
+dnszone_rname_dnsname = DNSName(dnszone_rname)
+dnszone_ip = u'172.16.29.1'
+
+revzone = u'29.16.172.in-addr.arpa.'
+revzone_dnsname = DNSName(revzone)
+revzone_ip = u'172.16.29.0'
+revzone_ipprefix = u'172.16.29.'
+revzone_dn = DN(('idnsname', revzone), api.env.container_dns, api.env.basedn)
+
+revipv6zone = u'0.0.0.0.1.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.'
+revipv6zone_dnsname = DNSName(revipv6zone)
+revipv6zone_ip = u'2001:db8:1::'
+revipv6zone_ipprefix = u'2001:db8:1:'
+revipv6zone_dn = DN(('idnsname', revipv6zone), api.env.container_dns, api.env.basedn)
+
+arec = u'172.16.29.22'
+aaaarec = u'2001:db8:1::beef'
+
+arec2 = u'172.16.29.33'
+aaaarec2 = u'2001:db8:1::dead'
+
+ipv6only = u'testipv6onlyhost'
+ipv6only_dnsname = DNSName(ipv6only)
+ipv6only_dn = DN(('idnsname', ipv6only), dnszone_dn)
+ipv6only_host_fqdn = u'%s.%s' % (ipv6only, dnszone)
+ipv6only_host_dn = DN(('fqdn',ipv6only_host_fqdn),('cn','computers'),('cn','accounts'),
+         api.env.basedn)
+
+ipv4only = u'testipv4onlyhost'
+ipv4only_dnsname = DNSName(ipv4only)
+ipv4only_dn = DN(('idnsname', ipv4only), dnszone_dn)
+ipv4only_host_fqdn = u'%s.%s' % (ipv4only, dnszone)
+ipv4only_host_dn = DN(('fqdn',ipv4only_host_fqdn),('cn','computers'),('cn','accounts'),
+         api.env.basedn)
+
+ipv46both = u'testipv4and6host'
+ipv46both_dnsname = DNSName(ipv46both)
+ipv46both_dn = DN(('idnsname', ipv46both), dnszone_dn)
+ipv46both_host_fqdn = u'%s.%s' % (ipv46both, dnszone)
+ipv46both_host_dn = DN(('fqdn',ipv46both_host_fqdn),('cn','computers'),('cn','accounts'),
+         api.env.basedn)
+
+ipv4_fromip = u'withipv4addr'
+ipv4_fromip_ip = u'172.16.29.40'
+ipv4_fromip_arec = ipv4_fromip_ip
+ipv4_fromip_dnsname = DNSName(ipv4_fromip)
+ipv4_fromip_dn = DN(('idnsname', ipv4_fromip), dnszone_dn)
+ipv4_fromip_host_fqdn = u'%s.%s' % (ipv4_fromip, dnszone)
+ipv4_fromip_host_dn = DN(('fqdn',ipv4_fromip_host_fqdn),('cn','computers'),('cn','accounts'),
+         api.env.basedn)
+ipv4_fromip_ptr = u'40'
+ipv4_fromip_ptrrec = ipv4_fromip_host_fqdn + '.'
+ipv4_fromip_ptr_dnsname = DNSName(ipv4_fromip_ptr)
+ipv4_fromip_ptr_dn = DN(('idnsname', ipv4_fromip_ptr), revzone_dn)
+
+ipv6_fromip = u'withipv6addr'
+ipv6_fromip_ipv6 = u'2001:db8:1::9'
+ipv6_fromip_aaaarec = ipv6_fromip_ipv6
+ipv6_fromip_dnsname = DNSName(ipv6_fromip)
+ipv6_fromip_dn = DN(('idnsname', ipv6_fromip), dnszone_dn)
+ipv6_fromip_host_fqdn = u'%s.%s' % (ipv6_fromip, dnszone)
+ipv6_fromip_host_dn = DN(('fqdn',ipv6_fromip_host_fqdn),('cn','computers'),('cn','accounts'),
+         api.env.basedn)
+ipv6_fromip_ptr = u'9.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'
+ipv6_fromip_ptrrec = ipv6_fromip_host_fqdn + '.'
+ipv6_fromip_ptr_dnsname = DNSName(ipv6_fromip_ptr)
+ipv6_fromip_ptr_dn = DN(('idnsname', ipv6_fromip_ptr), revipv6zone_dn)
+
 sshpubkey = u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGAX3xAeLeaJggwTqMjxNwa6XHBUAikXPGMzEpVrlLDCZtv00djsFTBi38PkgxBJVkgRWMrcBsr/35lq7P6w8KGIwA8GI48Z0qBS2NBMJ2u9WQ2hjLN6GdMlo77O0uJY3251p12pCVIS/bHRSq8kHO2No8g7KA9fGGcagPfQH+ee3t7HUkpbQkFTmbPPN++r3V8oVUk5LxbryB3UIIVzNmcSIn3JrXynlvui4MixvrtX6zx+O/bBo68o8/eZD26QrahVbA09fivrn/4h3TM019Eu/c2jOdckfU3cHUV/3Tno5d6JicibyaoDDK7S/yjdn5jhaz8MSEayQvFkZkiF0L public key test'
 sshpubkeyfp = u'13:67:6B:BF:4E:A2:05:8E:AE:25:8B:A1:31:DE:6F:1B public key test (ssh-rsa)'
 
@@ -958,3 +1035,374 @@ class test_host_false_pwd_change(XMLRPC_test):
         # verify that it's gone
         with assert_raises(errors.NotFound):
             api.Command['host_show'](self.fqdn1)
+
+
+class test_host_dns(Declarative):
+
+    cleanup_commands = [
+        ('host_del', [ipv6only_host_fqdn], {}),
+        ('host_del', [ipv4only_host_fqdn], {}),
+        ('host_del', [ipv46both_host_fqdn], {}),
+        ('host_del', [ipv4_fromip_host_fqdn], {}),
+        ('host_del', [ipv6_fromip_host_fqdn], {}),
+        ('dnszone_del', [dnszone], {}),
+        ('dnszone_del', [revzone], {}),
+        ('dnszone_del', [revipv6zone], {}),
+    ]
+
+    tests = [
+        dict(
+            desc='Create zone %r' % dnszone,
+            command=(
+                'dnszone_add', [dnszone], {
+                    'idnssoamname': dnszone_ns,
+                    'idnssoarname': dnszone_rname,
+                    'ip_address' : dnszone_ip,
+                }
+            ),
+            expected={
+                'value': dnszone_dnsname,
+                'summary': None,
+                'result': {
+                    'dn': dnszone_dn,
+                    'idnsname': [dnszone_dnsname],
+                    'idnszoneactive': [u'TRUE'],
+                    'idnssoamname': [dnszone_ns_dnsname],
+                    'nsrecord': [dnszone_ns],
+                    'idnssoarname': [dnszone_rname_dnsname],
+                    'idnssoaserial': [fuzzy_digits],
+                    'idnssoarefresh': [fuzzy_digits],
+                    'idnssoaretry': [fuzzy_digits],
+                    'idnssoaexpire': [fuzzy_digits],
+                    'idnssoaminimum': [fuzzy_digits],
+                    'idnsallowdynupdate': [u'FALSE'],
+                    'idnsupdatepolicy': [u'grant %(realm)s krb5-self * A; '
+                                         u'grant %(realm)s krb5-self * AAAA; '
+                                         u'grant %(realm)s krb5-self * SSHFP;'
+                                         % dict(realm=api.env.realm)],
+                    'idnsallowtransfer': [u'none;'],
+                    'idnsallowquery': [u'any;'],
+                    'objectclass': objectclasses.dnszone,
+                },
+            },
+        ),
+
+
+        dict(
+            desc='Create reverse zone %r' % revzone,
+            command=(
+                'dnszone_add', [revzone], {
+                    'idnssoamname': dnszone_ns,
+                    'idnssoarname': dnszone_rname,
+                }
+            ),
+            expected={
+                'value': revzone_dnsname,
+                'summary': None,
+                'result': {
+                    'dn': revzone_dn,
+                    'idnsname': [revzone_dnsname],
+                    'idnszoneactive': [u'TRUE'],
+                    'idnssoamname': [dnszone_ns_dnsname],
+                    'nsrecord': [dnszone_ns],
+                    'idnssoarname': [dnszone_rname_dnsname],
+                    'idnssoaserial': [fuzzy_digits],
+                    'idnssoarefresh': [fuzzy_digits],
+                    'idnssoaretry': [fuzzy_digits],
+                    'idnssoaexpire': [fuzzy_digits],
+                    'idnssoaminimum': [fuzzy_digits],
+                    'idnsallowdynupdate': [u'FALSE'],
+                    'idnsupdatepolicy': [u'grant %(realm)s krb5-subdomain %(zone)s PTR;'
+                                         % dict(realm=api.env.realm, zone=revzone)],
+                    'idnsallowtransfer': [u'none;'],
+                    'idnsallowquery': [u'any;'],
+                    'objectclass': objectclasses.dnszone,
+                },
+            },
+        ),
+
+
+        dict(
+            desc='Create reverse zone %r' % revipv6zone,
+            command=(
+                'dnszone_add', [revipv6zone], {
+                    'idnssoamname': dnszone_ns,
+                    'idnssoarname': dnszone_rname,
+                }
+            ),
+            expected={
+                'value': revipv6zone_dnsname,
+                'summary': None,
+                'result': {
+                    'dn': revipv6zone_dn,
+                    'idnsname': [revipv6zone_dnsname],
+                    'idnszoneactive': [u'TRUE'],
+                    'idnssoamname': [dnszone_ns_dnsname],
+                    'nsrecord': [dnszone_ns],
+                    'idnssoarname': [dnszone_rname_dnsname],
+                    'idnssoaserial': [fuzzy_digits],
+                    'idnssoarefresh': [fuzzy_digits],
+                    'idnssoaretry': [fuzzy_digits],
+                    'idnssoaexpire': [fuzzy_digits],
+                    'idnssoaminimum': [fuzzy_digits],
+                    'idnsallowdynupdate': [u'FALSE'],
+                    'idnsupdatepolicy': [u'grant %(realm)s krb5-subdomain %(zone)s PTR;'
+                                         % dict(realm=api.env.realm, zone=revipv6zone)],
+                    'idnsallowtransfer': [u'none;'],
+                    'idnsallowquery': [u'any;'],
+                    'objectclass': objectclasses.dnszone,
+                },
+            },
+        ),
+
+
+        dict(
+            desc='Add A record to %r in zone %r' % (ipv6only, dnszone),
+            command=('dnsrecord_add', [dnszone, ipv6only], {'arecord': arec}),
+            expected={
+                'value': ipv6only_dnsname,
+                'summary': None,
+                'result': {
+                    'dn': ipv6only_dn,
+                    'idnsname': [ipv6only_dnsname],
+                    'arecord': [arec],
+                    'objectclass': objectclasses.dnsrecord,
+                },
+            },
+        ),
+
+
+        dict(
+            desc='Add A record to %r in zone %r' % (ipv4only, dnszone),
+            command=('dnsrecord_add', [dnszone, ipv4only], {'aaaarecord': aaaarec}),
+            expected={
+                'value': ipv4only_dnsname,
+                'summary': None,
+                'result': {
+                    'dn': ipv4only_dn,
+                    'idnsname': [ipv4only_dnsname],
+                    'aaaarecord': [aaaarec],
+                    'objectclass': objectclasses.dnsrecord,
+                },
+            },
+        ),
+
+
+        dict(
+            desc='Add A record to %r in zone %r' % (ipv46both, dnszone),
+            command=('dnsrecord_add', [dnszone, ipv46both], {'arecord': arec2,
+                                                    'aaaarecord': aaaarec}
+                     ),
+            expected={
+                'value': ipv46both_dnsname,
+                'summary': None,
+                'result': {
+                    'dn': ipv46both_dn,
+                    'idnsname': [ipv46both_dnsname],
+                    'arecord': [arec2],
+                    'aaaarecord': [aaaarec],
+                    'objectclass': objectclasses.dnsrecord,
+                },
+            },
+        ),
+
+
+        dict(
+            desc='Create %r (AAAA record exists)' % ipv6only_host_fqdn,
+            command=('host_add', [ipv6only_host_fqdn],
+                dict(
+                    description=u'Test host 5',
+                    l=u'Undisclosed location 5',
+                ),
+            ),
+            expected=dict(
+                value=ipv6only_host_fqdn,
+                summary=u'Added host "%s"' % ipv6only_host_fqdn,
+                result=dict(
+                    dn=ipv6only_host_dn,
+                    fqdn=[ipv6only_host_fqdn],
+                    description=[u'Test host 5'],
+                    l=[u'Undisclosed location 5'],
+                    krbprincipalname=[u'host/%s@%s' % (ipv6only_host_fqdn, api.env.realm)],
+                    objectclass=objectclasses.host,
+                    ipauniqueid=[fuzzy_uuid],
+                    managedby_host=[ipv6only_host_fqdn],
+                    has_keytab=False,
+                    has_password=False,
+                ),
+            ),
+        ),
+
+
+        dict(
+            desc='Create %r (A record exists)' % ipv4only_host_fqdn,
+            command=('host_add', [ipv4only_host_fqdn],
+                dict(
+                    description=u'Test host 6',
+                    l=u'Undisclosed location 6',
+                ),
+            ),
+            expected=dict(
+                value=ipv4only_host_fqdn,
+                summary=u'Added host "%s"' % ipv4only_host_fqdn,
+                result=dict(
+                    dn=ipv4only_host_dn,
+                    fqdn=[ipv4only_host_fqdn],
+                    description=[u'Test host 6'],
+                    l=[u'Undisclosed location 6'],
+                    krbprincipalname=[u'host/%s@%s' % (ipv4only_host_fqdn, api.env.realm)],
+                    objectclass=objectclasses.host,
+                    ipauniqueid=[fuzzy_uuid],
+                    managedby_host=[ipv4only_host_fqdn],
+                    has_keytab=False,
+                    has_password=False,
+                ),
+            ),
+        ),
+
+
+        dict(
+            desc='Create %r (A and AAAA records exist)' % ipv46both_host_fqdn,
+            command=('host_add', [ipv46both_host_fqdn],
+                dict(
+                    description=u'Test host 7',
+                    l=u'Undisclosed location 7',
+                ),
+            ),
+            expected=dict(
+                value=ipv46both_host_fqdn,
+                summary=u'Added host "%s"' % ipv46both_host_fqdn,
+                result=dict(
+                    dn=ipv46both_host_dn,
+                    fqdn=[ipv46both_host_fqdn],
+                    description=[u'Test host 7'],
+                    l=[u'Undisclosed location 7'],
+                    krbprincipalname=[u'host/%s@%s' % (ipv46both_host_fqdn, api.env.realm)],
+                    objectclass=objectclasses.host,
+                    ipauniqueid=[fuzzy_uuid],
+                    managedby_host=[ipv46both_host_fqdn],
+                    has_keytab=False,
+                    has_password=False,
+                ),
+            ),
+        ),
+
+
+        dict(
+            desc='Create %r with --from-ip option' % ipv4_fromip_host_fqdn,
+            command=('host_add', [ipv4_fromip_host_fqdn],
+                dict(
+                    description=u'Test host 8',
+                    l=u'Undisclosed location 8',
+                    ip_address=ipv4_fromip_ip,
+                ),
+            ),
+            expected=dict(
+                value=ipv4_fromip_host_fqdn,
+                summary=u'Added host "%s"' % ipv4_fromip_host_fqdn,
+                result=dict(
+                    dn=ipv4_fromip_host_dn,
+                    fqdn=[ipv4_fromip_host_fqdn],
+                    description=[u'Test host 8'],
+                    l=[u'Undisclosed location 8'],
+                    krbprincipalname=[u'host/%s@%s' % (ipv4_fromip_host_fqdn, api.env.realm)],
+                    objectclass=objectclasses.host,
+                    ipauniqueid=[fuzzy_uuid],
+                    managedby_host=[ipv4_fromip_host_fqdn],
+                    has_keytab=False,
+                    has_password=False,
+                ),
+            ),
+        ),
+
+
+        dict(
+            desc='Check if A record was created for host %r' % ipv4_fromip_host_fqdn,
+            command=('dnsrecord_show', [dnszone, ipv4_fromip], {}
+            ),
+            expected=dict(
+                value=ipv4_fromip_dnsname,
+                summary=None,
+                result=dict(
+                    dn=ipv4_fromip_dn,
+                    idnsname=[ipv4_fromip_dnsname],
+                    arecord=[ipv4_fromip_arec],
+                ),
+            ),
+        ),
+
+
+        dict(
+            desc='Check if PTR record was created for host %r' % ipv4_fromip_host_fqdn,
+            command=('dnsrecord_show', [revzone, ipv4_fromip_ptr], {}
+            ),
+            expected=dict(
+                value=ipv4_fromip_ptr_dnsname,
+                summary=None,
+                result=dict(
+                    dn=ipv4_fromip_ptr_dn,
+                    idnsname=[ipv4_fromip_ptr_dnsname],
+                    ptrrecord=[ipv4_fromip_ptrrec],
+                ),
+            ),
+        ),
+
+        dict(
+            desc='Create %r with --from-ip option (IPv6)' % ipv6_fromip_host_fqdn,
+            command=('host_add', [ipv6_fromip_host_fqdn],
+                dict(
+                    description=u'Test host 9',
+                    l=u'Undisclosed location 9',
+                    ip_address=ipv6_fromip_ipv6,
+                ),
+            ),
+            expected=dict(
+                value=ipv6_fromip_host_fqdn,
+                summary=u'Added host "%s"' % ipv6_fromip_host_fqdn,
+                result=dict(
+                    dn=ipv6_fromip_host_dn,
+                    fqdn=[ipv6_fromip_host_fqdn],
+                    description=[u'Test host 9'],
+                    l=[u'Undisclosed location 9'],
+                    krbprincipalname=[u'host/%s@%s' % (ipv6_fromip_host_fqdn, api.env.realm)],
+                    objectclass=objectclasses.host,
+                    ipauniqueid=[fuzzy_uuid],
+                    managedby_host=[ipv6_fromip_host_fqdn],
+                    has_keytab=False,
+                    has_password=False,
+                ),
+            ),
+        ),
+
+
+        dict(
+            desc='Check if AAAA record was created for host %r' % ipv6_fromip_host_fqdn,
+            command=('dnsrecord_show', [dnszone, ipv6_fromip], {}
+            ),
+            expected=dict(
+                value=ipv6_fromip_dnsname,
+                summary=None,
+                result=dict(
+                    dn=ipv6_fromip_dn,
+                    idnsname=[ipv6_fromip_dnsname],
+                    aaaarecord=[ipv6_fromip_aaaarec],
+                ),
+            ),
+        ),
+
+
+        dict(
+            desc='Check if PTR record was created for host %r' % ipv6_fromip_host_fqdn,
+            command=('dnsrecord_show', [revipv6zone, ipv6_fromip_ptr], {}
+            ),
+            expected=dict(
+                value=ipv6_fromip_ptr_dnsname,
+                summary=None,
+                result=dict(
+                    dn=ipv6_fromip_ptr_dn,
+                    idnsname=[ipv6_fromip_ptr_dnsname],
+                    ptrrecord=[ipv6_fromip_ptrrec],
+                ),
+            ),
+        ),
+    ]
-- 
1.8.3.1

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

Reply via email to