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

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 29c421a794f80f1a25e8946ef74b28a5e3395c47 Mon Sep 17 00:00:00 2001
From: "Niranjan M.R" <mrniran...@redhat.com>
Date: Tue, 16 Oct 2018 19:57:43 +0530
Subject: [PATCH 1/2] testlib: Update update_resolv_conf() to decode str to
 bytes

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

diff --git a/src/tests/python/sssd/testlib/common/utils.py b/src/tests/python/sssd/testlib/common/utils.py
index bdba012e93..561e59ead9 100644
--- a/src/tests/python/sssd/testlib/common/utils.py
+++ b/src/tests/python/sssd/testlib/common/utils.py
@@ -48,20 +48,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

From 374f465fe7ecc9767808d7aafabe0b69b1882305 Mon Sep 17 00:00:00 2001
From: "Niranjan M.R" <mrniran...@redhat.com>
Date: Tue, 16 Oct 2018 20:32:16 +0530
Subject: [PATCH 2/2] testlib: Use SSSDException instead of Exception

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

diff --git a/src/tests/python/sssd/testlib/common/utils.py b/src/tests/python/sssd/testlib/common/utils.py
index 561e59ead9..9947c49ca5 100644
--- a/src/tests/python/sssd/testlib/common/utils.py
+++ b/src/tests/python/sssd/testlib/common/utils.py
@@ -25,7 +25,7 @@
 from .authconfig import RedHatAuthConfig
 from .exceptions import PkiLibException
 from .exceptions import LdapException
-from .exceptions import OSException
+from .exceptions import SSSDException
 
 
 PARAMIKO_VERSION = (int(paramiko.__version__.split('.')[0]),
@@ -121,9 +121,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 +135,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 +143,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 +168,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("fail to create %s directory" % local_dir)
             exp_share = '{}{}{}{}'.format(local_dir, ' ', nfs_client,
                                           '(rw,sync,fsid=0)')
 
@@ -201,11 +195,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 +231,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 +248,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 +301,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"
@@ -355,7 +349,7 @@ def enable_kcm(self):
         """ Enable kcm
             :param: None
             :Return: None
-            :Exception: Raise Exception("message")
+            :Exception: Raise SSSDException
         """
         self.multihost.transport.get_file('/etc/krb5.conf', '/tmp/krb5.conf')
         str1 = 'includedir /var/lib/sss/pubconf/krb5.include.d/'
@@ -380,23 +374,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):
@@ -506,7 +500,7 @@ def posix_user(self, org_unit, basedn, user_attr):
             :param str basedn: Base dn ('dc=example,dc=test')
             :param dict user_attr: Entry attributes
             :Return bool: Return True
-            :Exception: Raise Exception if unable to add user
+            :Exception: Raise SSSDException if unable to add user
         """
         common_name = user_attr['cn']
         uid = user_attr['uid']
@@ -557,7 +551,7 @@ def posix_user(self, org_unit, basedn, user_attr):
         if ret == 'Success':
             return True
         else:
-            raise Exception('Unable to add User to ldap')
+            raise SSSDException('Unable to add User to ldap')
 
     def posix_group(self, org_unit, basedn, group_attr, memberUid=False):
         """ Add POSIX group
@@ -739,7 +733,7 @@ def execute(self,
         :param str cwd: Current working Directory
 
         :return stdout, stderr and returncode: if command return code is 0
-        :Exception: raises exception if raiseonerr is True
+        :Exception: raises subprocess.CalledProcessError Exception
         """
 
         p_in = None
@@ -925,7 +919,7 @@ def create_ad_unix_group(self, groupname):
 
         :param str groupname: Windows AD Group name
         :Return bool : True if AD group was created with Unix Attributes
-        :Exceptions: None
+        :Exception: None
         """
 
         gid = random.randint(9999, 999999)
_______________________________________________
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