URL: https://github.com/SSSD/sssd/pull/672
Author: mrniranjan
 Title: #672: testlib/utils: use SSSDException and decode str to bytes.
Action: opened

PR body:
"""
Signed-off-by: Niranjan M.R <mrniran...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/672/head:pr672
git checkout pr672
From 77a9e24b78ad76488589337a9cae4a3d199d9dfe Mon Sep 17 00:00:00 2001
From: "Niranjan M.R" <mrniran...@redhat.com>
Date: Tue, 9 Oct 2018 17:33:10 +0530
Subject: [PATCH] testlib/utils: use SSSDException and decode str to bytes.

Signed-off-by: Niranjan M.R <mrniran...@redhat.com>
---
 src/tests/python/sssd/testlib/common/utils.py | 49 +++++++++----------
 1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/src/tests/python/sssd/testlib/common/utils.py b/src/tests/python/sssd/testlib/common/utils.py
index bdba012e9..38cf4eabf 100644
--- a/src/tests/python/sssd/testlib/common/utils.py
+++ b/src/tests/python/sssd/testlib/common/utils.py
@@ -26,6 +26,7 @@
 from .exceptions import PkiLibException
 from .exceptions import LdapException
 from .exceptions import OSException
+from .exceptions import SSSDException
 
 
 PARAMIKO_VERSION = (int(paramiko.__version__.split('.')[0]),
@@ -48,20 +49,20 @@ def update_resolv_conf(self, ip_addr):
 
             :param str ip_addr: IP Address to be added in resolv.conf
             :return: None
-            :Exception: Raises OSException of builtin type Exception
         """
         self.multihost.log.info("Taking backup of /etc/resolv.conf")
         bkup_cmd = 'cp -f /etc/resolv.conf /etc/resolv.conf.bkup'
-        output = self.multihost.run_command(bkup_cmd, raiseonerr=False)
+        self.multihost.run_command(bkup_cmd, raiseonerr=False)
         self.multihost.log.info("/etc/resolv.conf successfully backed up")
         self.multihost.log.info("Add ip addr %s in resolv.conf" % ip_addr)
         nameserver = 'nameserver %s\n' % ip_addr
-        contents = self.multihost.get_file_contents('/etc/resolv.conf')
-        if not contents.startswith(nameserver):
-            contents = nameserver + contents.replace(nameserver, '')
-            self.multihost.put_file_contents('/etc/resolv.conf', contents)
+        resolv_conf = self.multihost.get_file_contents('/etc/resolv.conf')
+        if isinstance(resolv_conf, bytes):
+            contents = resolv_conf.decode('utf-8')
         else:
-            raise OSException("modifying resolv.conf failed")
+            contents = resolv_conf
+        contents = nameserver + contents.replace(nameserver, '')
+        self.multihost.put_file_contents('/etc/resolv.conf', contents)
 
     def config_authconfig(self, hostname, domainname):
         """ Run authconfig to configure Kerberos and SSSD auth on remote host
@@ -121,9 +122,7 @@ def realm_join(self, domainname, admin_password,
             :param str client_software: client software to be used (sssd/samba)
             :param str server_software: server software (active-directory/ipa)
             :param str membership_software: membership software (samba/adcli)
-            :return bool: True if successfully joined to AD/IPA
-                          else raises Exception
-            :Exception: Raises exception(builtin)
+            :Exception: Raises SSSDException
         """
 
         cmd = self.multihost.run_command(['realm', 'join', domainname,
@@ -137,9 +136,7 @@ def realm_join(self, domainname, admin_password,
                                          raiseonerr=False)
 
         if cmd.returncode != 0:
-            raise Exception("Error: %s" % cmd.stderr_text)
-        else:
-            return True
+            raise SSSDException("Error: %s" % cmd.stderr_text)
 
     def realm_leave(self, domainname):
         """ Leave system from AD/IPA Domain
@@ -147,16 +144,14 @@ def realm_leave(self, domainname):
             :param str domainname: domain name of AD/IPA
             :return bool: True if successfully dis-joined to AD/IPA
              else raises Exception
-            :Exception: Raises exception(builtin)
+            :Exception: Raises SSSDException
         """
 
         cmd = self.multihost.run_command(['realm', 'leave',
                                           domainname, '-v'],
                                          raiseonerr=False)
         if cmd.returncode != 0:
-            raise Exception("Error: %s", cmd.stderr_text)
-        else:
-            return True
+            raise SSSDException("Error: %s", cmd.stderr_text)
 
     def export_nfs_fs(self, path_list, nfs_client):
         """ Add local file systems directories to /etc/exports
@@ -174,7 +169,7 @@ def export_nfs_fs(self, path_list, nfs_client):
             cmd = self.multihost.run_command(['mkdir', '-p', local_dir],
                                              raiseonerr=False)
             if cmd.returncode != 0:
-                raise Exception("Unable to create %s directory" % local_dir)
+                raise SSSDException("failed to create %s dir" % local_dir)
             exp_share = '{}{}{}{}'.format(local_dir, ' ', nfs_client,
                                           '(rw,sync,fsid=0)')
 
@@ -201,11 +196,11 @@ def remove_sss_cache(self, cache_path):
                                                       relative_path],
                                                      raiseonerr=False)
                 if rm_file.returncode != 0:
-                    raise Exception("Error: %s", cmd.stderr_text)
+                    raise SSSDException("Error: %s", cmd.stderr_text)
                 else:
                     print("Successfully deleted %s" % (relative_path))
         else:
-            raise Exception('%s path not found' % cache_path)
+            raise SSSDException('%s path not found' % cache_path)
         return True
 
     def domain_from_suffix(self, suffix):
@@ -237,7 +232,7 @@ def delete_sssd_domain_log(self, domainname):
         path = ("/var/log/sssd/sssd_%s.log" % domainname)
         cmd = self.multihost.run_command(['rm', '-rf', path], raiseonerr=False)
         if cmd.returncode != 0:
-            raise Exception("Error: %s", cmd.stderr_text)
+            raise SSSDException("Error: %s", cmd.stderr_text)
         else:
             return True
 
@@ -254,7 +249,7 @@ def get_ad_user_info(self, username, ad_host):
         cmd = self.multihost.run_command(['net', 'ads', 'dn', user_dn],
                                          raiseonerr=False)
         if cmd.returncode != 0:
-            raise Exception("Error: %s", cmd.stderr_text)
+            raise SSSDException("Error: %s", cmd.stderr_text)
         else:
             return(True, cmd.stdout_text)
 
@@ -307,7 +302,7 @@ def config_etckrb5(self, realm, krb5_server=None):
         if krb5_server is None:
             krb5_server = self.multihost.sys_hostname
         if realm is None:
-            raise Exception("Error: realm should be passed")
+            raise SSSDException("Error: realm should be passed")
         else:
             realm_def = ("{\n"
                          "kdc = %s\n"
@@ -380,23 +375,23 @@ def enable_kcm(self):
             self.multihost.run_command(['ls', '-l', symlink])
         except subprocess.CalledProcessError:
             self.multihost.log.info("kcm socket not enabled")
-            raise Exception("kcm socket not enabled")
+            raise SSSDException("kcm socket not enabled")
         start_ssd_kcm_socket = 'systemctl start sssd-kcm.socket'
         cmd = self.multihost.run_command(start_ssd_kcm_socket,
                                          raiseonerr=False)
         if cmd.returncode != 0:
-            raise Exception("sssd-kcm.socket service not started")
+            raise SSSDException("sssd-kcm.socket service not started")
         enable_kcm_service = 'systemctl enable sssd-kcm.service'
         cmd = self.multihost.run_command(enable_kcm_service,
                                          raiseonerr=False)
         symlink = '/etc/systemd/system/sockets.target.wants/sssd-kcm.socket'
         if cmd.returncode != 0:
-            raise Exception("sssd-kcm.service not enabled")
+            raise SSSDException("sssd-kcm.service not enabled")
         try:
             self.multihost.run_command(['ls', '-l', symlink])
         except subprocess.CalledProcessError:
             self.multihost.log.info("kcm socket not enabled")
-            raise Exception("kcm socket not enabled")
+            raise SSSDException("kcm socket not enabled")
 
 
 class LdapOperations(object):
_______________________________________________
sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org
To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/sssd-devel@lists.fedorahosted.org

Reply via email to