The Samba-Bugzilla – Attachment 14781 Details for
Bug 13747
Untidy error handling in samba-tool domain join
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Backport of fix for v4.9
v4.9-patch.txt (text/plain), 4.69 KB, created by
Tim Beale
on 2019-01-17 02:53:20 UTC
(
hide
)
Description:
Backport of fix for v4.9
Filename:
MIME Type:
Creator:
Tim Beale
Created:
2019-01-17 02:53:20 UTC
Size:
4.69 KB
patch
obsolete
>From 87640224b0c151c86ed34f7e78054cd398d334ae Mon Sep 17 00:00:00 2001 >From: Tim Beale <timbeale@catalyst.net.nz> >Date: Wed, 16 Jan 2019 15:17:38 +1300 >Subject: [PATCH 1/2] join: Fix TypeError when handling exception > >When we can't resolve a domain name, we were inadvertently throwing a >TypeError whilst trying to output a helpful message. E.g. > >ERROR(<class 'TypeError'>): uncaught exception - 'NTSTATUSError' object >does not support indexing > >Instead of indexing the object, we want to index the Exception.args so >that we just display the string portion of the exception error. > >The same problem is also present for the domain trust commands. > >BUG: https://bugzilla.samba.org/show_bug.cgi?id=13747 > >Signed-off-by: Tim Beale <timbeale@catalyst.net.nz> >Reviewed-by: Rowland Penny <rpenny@samba.org> >Reviewed-by: Jeremy Allison <rpenny@samba.org> >(cherry picked from commit 3bb7808984c163a7bba66fb983411d1281589722) >--- > python/samba/join.py | 2 +- > python/samba/netcmd/domain.py | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > >diff --git a/python/samba/join.py b/python/samba/join.py >index 3b648f5..3eaac75 100644 >--- a/python/samba/join.py >+++ b/python/samba/join.py >@@ -338,7 +338,7 @@ class DCJoinContext(object): > ctx.cldap_ret = ctx.net.finddc(domain=domain, flags=nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE) > except NTSTATUSError as error: > raise Exception("Failed to find a writeable DC for domain '%s': %s" % >- (domain, error[1])) >+ (domain, error.args[1])) > except Exception: > raise Exception("Failed to find a writeable DC for domain '%s'" % domain) > if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "": >diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py >index 1d34d06..f9dc08f 100644 >--- a/python/samba/netcmd/domain.py >+++ b/python/samba/netcmd/domain.py >@@ -1818,7 +1818,7 @@ class DomainTrustCommand(Command): > remote_info = remote_net.finddc(flags=remote_flags, domain=domain, address=remote_server) > except NTSTATUSError as error: > raise CommandError("Failed to find a writeable DC for domain '%s': %s" % >- (domain, error[1])) >+ (domain, error.args[1])) > except Exception: > raise CommandError("Failed to find a writeable DC for domain '%s'" % domain) > flag_map = { >-- >2.7.4 > > >From 518852957426217c76e8ae61925ef0d18e1af974 Mon Sep 17 00:00:00 2001 >From: Tim Beale <timbeale@catalyst.net.nz> >Date: Wed, 16 Jan 2019 15:37:00 +1300 >Subject: [PATCH 2/2] join: Throw CommandError instead of Exception for simple > errors > >Throwing an exception here still dumps out the Python stack trace, which >can be a little disconcerting for users. > >In this case, the stack trace isn't going to really help at all (the >problem is pretty obvious), and it obscures the useful message >explaining what went wrong. > >Throw a CommandError instead, which samba-tool will catch and display >more nicely. > >BUG: https://bugzilla.samba.org/show_bug.cgi?id=13747 > >Signed-off-by: Tim Beale <timbeale@catalyst.net.nz> >Reviewed-by: Rowland Penny <rpenny@samba.org> >Reviewed-by: Jeremy Allison <rpenny@samba.org> > >Autobuild-User(master): Jeremy Allison <jra@samba.org> >Autobuild-Date(master): Wed Jan 16 22:11:04 CET 2019 on sn-devel-144 > >(cherry picked from commit 9e4b08f4c384b8cae5ad853a7be7cf03e2749be5) >--- > python/samba/join.py | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > >diff --git a/python/samba/join.py b/python/samba/join.py >index 3eaac75..36a8547 100644 >--- a/python/samba/join.py >+++ b/python/samba/join.py >@@ -46,6 +46,7 @@ import time > import re > import os > import tempfile >+from samba.netcmd import CommandError > > class DCJoinException(Exception): > >@@ -337,10 +338,10 @@ class DCJoinContext(object): > try: > ctx.cldap_ret = ctx.net.finddc(domain=domain, flags=nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE) > except NTSTATUSError as error: >- raise Exception("Failed to find a writeable DC for domain '%s': %s" % >- (domain, error.args[1])) >+ raise CommandError("Failed to find a writeable DC for domain '%s': %s" % >+ (domain, error.args[1])) > except Exception: >- raise Exception("Failed to find a writeable DC for domain '%s'" % domain) >+ raise CommandError("Failed to find a writeable DC for domain '%s'" % domain) > if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "": > ctx.site = ctx.cldap_ret.client_site > return ctx.cldap_ret.pdc_dns_name >-- >2.7.4 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Flags:
dbagnall
:
review+
Actions:
View
Attachments on
bug 13747
:
14780
| 14781 |
14782