summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/plugins/host.py12
-rw-r--r--tests/test_xmlrpc/objectclasses.py10
-rw-r--r--tests/test_xmlrpc/test_host_plugin.py66
3 files changed, 85 insertions, 3 deletions
diff --git a/ipalib/plugins/host.py b/ipalib/plugins/host.py
index d72f53051..320cf34f7 100644
--- a/ipalib/plugins/host.py
+++ b/ipalib/plugins/host.py
@@ -40,7 +40,7 @@ def validate_host(ugettext, fqdn):
Require at least one dot in the hostname (to support localhost.localdomain)
"""
if fqdn.find('.') == -1:
- return 'Fully-qualified hostname required'
+ return _('Fully-qualified hostname required')
return None
@@ -181,11 +181,17 @@ class host_del(LDAPDelete):
msg_summary = _('Deleted host "%(value)s"')
def pre_callback(self, ldap, dn, *keys, **options):
+ # If we aren't given a fqdn, find it
+ if validate_host(None, keys[-1]) is not None:
+ hostentry = api.Command['host_show'](keys[-1])['result']
+ fqdn = hostentry['fqdn'][0]
+ else:
+ fqdn = keys[-1]
# Remove all service records for this host
truncated = True
while truncated:
try:
- ret = api.Command['service_find'](keys[-1])
+ ret = api.Command['service_find'](fqdn)
truncated = ret['truncated']
services = ret['result']
except errors.NotFound:
@@ -194,7 +200,7 @@ class host_del(LDAPDelete):
for entry_attrs in services:
principal = entry_attrs['krbprincipalname'][0]
(service, hostname, realm) = split_principal(principal)
- if hostname.lower() == keys[-1]:
+ if hostname.lower() == fqdn:
api.Command['service_del'](principal)
return dn
diff --git a/tests/test_xmlrpc/objectclasses.py b/tests/test_xmlrpc/objectclasses.py
index 857147dc3..8e389e7cb 100644
--- a/tests/test_xmlrpc/objectclasses.py
+++ b/tests/test_xmlrpc/objectclasses.py
@@ -71,3 +71,13 @@ taskgroup = [
u'groupofnames',
u'top'
]
+
+service = [
+ u'krbprincipal',
+ u'krbprincipalaux',
+ u'krbticketpolicyaux',
+ u'ipaobject',
+ u'ipaservice',
+ u'pkiuser',
+ u'top',
+]
diff --git a/tests/test_xmlrpc/test_host_plugin.py b/tests/test_xmlrpc/test_host_plugin.py
index de30b77be..36e920b09 100644
--- a/tests/test_xmlrpc/test_host_plugin.py
+++ b/tests/test_xmlrpc/test_host_plugin.py
@@ -28,13 +28,17 @@ from tests.test_xmlrpc import objectclasses
fqdn1 = u'testhost1.%s' % api.env.domain
+short1 = u'testhost1'
dn1 = u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn1, api.env.basedn)
+service1 = u'dns/%s@%s' % (fqdn1, api.env.realm)
+service1dn = u'krbprincipalname=%s,cn=services,cn=accounts,%s' % (service1.lower(), api.env.basedn)
class test_host(Declarative):
cleanup_commands = [
('host_del', [fqdn1], {}),
+ ('service_del', [service1], {}),
]
tests = [
@@ -252,4 +256,66 @@ class test_host(Declarative):
expected=errors.NotFound(reason='no such entry'),
),
+ # Test deletion using a non-fully-qualified hostname. Services
+ # associated with this host should also be removed.
+ dict(
+ desc='Re-create %r' % fqdn1,
+ command=('host_add', [fqdn1],
+ dict(
+ description=u'Test host 1',
+ l=u'Undisclosed location 1',
+ ),
+ ),
+ expected=dict(
+ value=fqdn1,
+ summary=u'Added host "%s"' % fqdn1,
+ result=dict(
+ dn=dn1,
+ fqdn=[fqdn1],
+ description=[u'Test host 1'],
+ l=[u'Undisclosed location 1'],
+ krbprincipalname=[u'host/%s@%s' % (fqdn1, api.env.realm)],
+ objectclass=objectclasses.host,
+ ipauniqueid=[fuzzy_uuid],
+ ),
+ ),
+ ),
+
+ dict(
+ desc='Add a service to host %r' % fqdn1,
+ command=('service_add', [service1], {}),
+ expected=dict(
+ value=service1,
+ summary=u'Added service "%s"' % service1,
+ result=dict(
+ dn=service1dn,
+ krbprincipalname=[service1],
+ objectclass=objectclasses.service,
+ ipauniqueid=[fuzzy_uuid],
+ ),
+ ),
+ ),
+
+ dict(
+ desc='Delete using host name %r' % short1,
+ command=('host_del', [short1], {}),
+ expected=dict(
+ value=short1,
+ summary=u'Deleted host "%s"' % short1,
+ result=True,
+ ),
+ ),
+
+ dict(
+ desc='Search for services for %r' % fqdn1,
+ command=('service_find', [fqdn1], {}),
+ expected=dict(
+ count=0,
+ truncated=False,
+ summary=None,
+ result=[
+ ],
+ ),
+ ),
+
]