From ece17cef17f1a84e92846ae288bee581533d753e Mon Sep 17 00:00:00 2001 From: Felipe Barreto Date: Mon, 15 Jan 2018 17:12:15 -0200 Subject: [PATCH] Check if replication agreement exist before enable/disable it If the replication agreement does not exist, a custom exception is raised explaining the problem. https://pagure.io/freeipa/issue/7201 Reviewed-By: Rob Crittenden --- install/tools/ipa-replica-manage | 7 +++++-- ipaserver/install/replication.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/install/tools/ipa-replica-manage b/install/tools/ipa-replica-manage index 4ae8818e7..75b02c929 100755 --- a/install/tools/ipa-replica-manage +++ b/install/tools/ipa-replica-manage @@ -1206,8 +1206,11 @@ def re_initialize(realm, thishost, fromhost, dirman_passwd, nolookup=False): repl = replication.ReplicationManager(realm, fromhost, dirman_passwd) agreement = repl.get_replication_agreement(thishost) - thisrepl.enable_agreement(fromhost) - repl.enable_agreement(thishost) + try: + thisrepl.enable_agreement(fromhost) + repl.enable_agreement(thishost) + except errors.NotFound as e: + sys.exit(e) repl.force_sync(repl.conn, thishost) diff --git a/ipaserver/install/replication.py b/ipaserver/install/replication.py index 8aae90c0a..43f00a730 100644 --- a/ipaserver/install/replication.py +++ b/ipaserver/install/replication.py @@ -32,6 +32,7 @@ import ldap from ipalib import api, errors from ipalib.cli import textui +from ipalib.text import _ from ipapython import ipautil, ipaldap, kerberos from ipapython.admintool import ScriptError from ipapython.dn import DN @@ -1547,6 +1548,11 @@ class ReplicationManager(object): Disable the replication agreement to hostname. """ entry = self.get_replication_agreement(hostname) + if not entry: + raise errors.NotFound(reason=_( + "Replication agreement for %(hostname)s not found") % { + 'hostname': hostname + }) entry['nsds5ReplicaEnabled'] = 'off' try: @@ -1561,6 +1567,11 @@ class ReplicationManager(object): Note: for replication to work it needs to be enabled both ways. """ entry = self.get_replication_agreement(hostname) + if not entry: + raise errors.NotFound(reason=_( + "Replication agreement for %(hostname)s not found") % { + 'hostname': hostname + }) entry['nsds5ReplicaEnabled'] = 'on' try: