summaryrefslogtreecommitdiffstats
path: root/install/tools/ipa-replica-manage
diff options
context:
space:
mode:
authorStanislav Laznicka <slaznick@redhat.com>2016-04-15 13:34:34 +0200
committerMartin Basti <mbasti@redhat.com>2016-04-28 17:32:14 +0200
commitd2bb8b7bb1032bf501c984f26f47ef6778c6796a (patch)
tree58aa41c7035a7277dfadf250a6b635486f8a7f28 /install/tools/ipa-replica-manage
parent37865aa1d7d388042a3b8a66975b466ec27a3d38 (diff)
downloadfreeipa-d2bb8b7bb1032bf501c984f26f47ef6778c6796a.tar.gz
freeipa-d2bb8b7bb1032bf501c984f26f47ef6778c6796a.tar.xz
freeipa-d2bb8b7bb1032bf501c984f26f47ef6778c6796a.zip
ipa-replica-manage refactoring
get_ruv does not call sys.exit anymore, instead it raises RuntimeError for better error handling Also removed duplicit code from abort_clean_ruv https://fedorahosted.org/freeipa/ticket/4987 Reviewed-By: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'install/tools/ipa-replica-manage')
-rwxr-xr-xinstall/tools/ipa-replica-manage66
1 files changed, 38 insertions, 28 deletions
diff --git a/install/tools/ipa-replica-manage b/install/tools/ipa-replica-manage
index 0bb9d158e..6e82085db 100755
--- a/install/tools/ipa-replica-manage
+++ b/install/tools/ipa-replica-manage
@@ -72,6 +72,10 @@ commands = {
dirman_passwd_req_commands = ("list-ruv", "clean-ruv", "abort-clean-ruv")
+class NoRUVsFound(Exception):
+ pass
+
+
def parse_options():
parser = IPAOptionParser(version=version.VERSION)
parser.add_option("-H", "--host", dest="host", help="starting host")
@@ -364,8 +368,9 @@ def get_ruv(realm, host, dirman_passwd, nolookup=False, ca=False):
else:
thisrepl = replication.ReplicationManager(realm, host, dirman_passwd)
except Exception as e:
- print("Failed to connect to server %s: %s" % (host, e))
- sys.exit(1)
+ root_logger.debug(traceback.format_exc())
+ raise RuntimeError("Failed to connect to server {host}: {err}"
+ .format(host=host, err=e))
search_filter = '(&(nsuniqueid=ffffffff-ffffffff-ffffffff-ffffffff)(objectclass=nstombstone))'
try:
@@ -373,8 +378,8 @@ def get_ruv(realm, host, dirman_passwd, nolookup=False, ca=False):
thisrepl.db_suffix, thisrepl.conn.SCOPE_SUBTREE, search_filter,
['nsds50ruv'])
except errors.NotFound:
- print("No RUV records found.")
- sys.exit(0)
+ root_logger.debug(traceback.format_exc())
+ raise NoRUVsFound("No RUV records found.")
servers = []
for e in entries:
@@ -396,8 +401,11 @@ def list_ruv(realm, host, dirman_passwd, verbose, nolookup=False):
List the Replica Update Vectors on this host to get the available
replica IDs.
"""
-
- servers = get_ruv(realm, host, dirman_passwd, nolookup)
+ try:
+ servers = get_ruv(realm, host, dirman_passwd, nolookup)
+ except (NoRUVsFound, RuntimeError) as e:
+ print(e)
+ sys.exit(0 if isinstance(e, NoRUVsFound) else 1)
for (netloc, rid) in servers:
print("%s: %s" % (netloc, rid))
@@ -405,7 +413,11 @@ def get_rid_by_host(realm, sourcehost, host, dirman_passwd, nolookup=False):
"""
Try to determine the RID by host name.
"""
- servers = get_ruv(realm, sourcehost, dirman_passwd, nolookup)
+ try:
+ servers = get_ruv(realm, sourcehost, dirman_passwd, nolookup)
+ except (NoRUVsFound, RuntimeError) as e:
+ print(e)
+ sys.exit(0 if isinstance(e, NoRUVsFound) else 1)
for (netloc, rid) in servers:
if '%s:389' % host == netloc:
return int(rid)
@@ -419,14 +431,19 @@ def clean_ruv(realm, ruv, options, ca=False):
except ValueError:
sys.exit("Replica ID must be an integer: %s" % ruv)
- servers = get_ruv(realm, options.host, options.dirman_passwd,
- options.nolookup, ca=ca)
+ try:
+ servers = get_ruv(realm, options.host, options.dirman_passwd,
+ options.nolookup, ca=ca)
+ except (NoRUVsFound, RuntimeError) as e:
+ print(e)
+ sys.exit(0 if isinstance(e, NoRUVsFound) else 1)
+
found = False
for (netloc, rid) in servers:
if ruv == int(rid):
- found = True
- hostname = netloc
- break
+ found = True
+ hostname = netloc
+ break
if not found:
sys.exit("Replica ID %s not found" % ruv)
@@ -464,26 +481,19 @@ def abort_clean_ruv(realm, ruv, options):
except ValueError:
sys.exit("Replica ID must be an integer: %s" % ruv)
- servers = get_ruv(realm, options.host, options.dirman_passwd,
- options.nolookup)
- found = False
- for (netloc, rid) in servers:
- if ruv == int(rid):
- found = True
- hostname = netloc
- break
-
- if not found:
- sys.exit("Replica ID %s not found" % ruv)
+ try:
+ servers = get_ruv(realm, options.host, options.dirman_passwd,
+ options.nolookup)
+ except (NoRUVsFound, RuntimeError) as e:
+ print(e)
+ sys.exit(0 if isinstance(e, NoRUVsFound) else 1)
- servers = get_ruv(realm, options.host, options.dirman_passwd,
- options.nolookup)
found = False
for (netloc, rid) in servers:
if ruv == int(rid):
- found = True
- hostname = netloc
- break
+ found = True
+ hostname = netloc
+ break
if not found:
sys.exit("Replica ID %s not found" % ruv)