2ff659
From 3cf7fb1014ae40fd5a5278f27577a8196a4af051 Mon Sep 17 00:00:00 2001
2ff659
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fcami@redhat.com>
2ff659
Date: Fri, 7 Aug 2020 07:51:53 +0200
2ff659
Subject: [PATCH] ipatests: test_epn: add test_EPN_connection_refused
2ff659
MIME-Version: 1.0
2ff659
Content-Type: text/plain; charset=UTF-8
2ff659
Content-Transfer-Encoding: 8bit
2ff659
2ff659
Add a test for EPN behavior when the configured SMTP does not
2ff659
accept connections.
2ff659
2ff659
Fixes: https://pagure.io/freeipa/issue/8445
2ff659
Signed-off-by: François Cami <fcami@redhat.com>
2ff659
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
2ff659
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
2ff659
---
2ff659
 ipatests/test_integration/test_epn.py | 27 ++++++++++++++++++++++++---
2ff659
 1 file changed, 24 insertions(+), 3 deletions(-)
2ff659
2ff659
diff --git a/ipatests/test_integration/test_epn.py b/ipatests/test_integration/test_epn.py
2ff659
index c5c73835a..1a25d3710 100644
2ff659
--- a/ipatests/test_integration/test_epn.py
2ff659
+++ b/ipatests/test_integration/test_epn.py
2ff659
@@ -182,14 +182,20 @@ class TestEPN(IntegrationTest):
2ff659
         self,
2ff659
         host,
2ff659
         dry_run=False,
2ff659
+        mailtest=False,
2ff659
         from_nbdays=None,
2ff659
         to_nbdays=None,
2ff659
         raiseonerr=True,
2ff659
         validatejson=True
2ff659
     ):
2ff659
-        result = tasks.ipa_epn(host, raiseonerr=raiseonerr, dry_run=dry_run,
2ff659
-                               from_nbdays=from_nbdays,
2ff659
-                               to_nbdays=to_nbdays)
2ff659
+        result = tasks.ipa_epn(
2ff659
+            host,
2ff659
+            from_nbdays=from_nbdays,
2ff659
+            to_nbdays=to_nbdays,
2ff659
+            mailtest=mailtest,
2ff659
+            dry_run=dry_run,
2ff659
+            raiseonerr=raiseonerr
2ff659
+        )
2ff659
         if validatejson:
2ff659
             json.dumps(json.loads(result.stdout_text), ensure_ascii=False)
2ff659
         return (result.stdout_text, result.stderr_text, result.returncode)
2ff659
@@ -243,6 +249,21 @@ class TestEPN(IntegrationTest):
2ff659
         ck = "192481b52fb591112afd7b55b12a44c6618fdbc7e05a3b1866fd67ec579c51df"
2ff659
         assert cmd2.stdout_text.find(ck) == 0
2ff659
 
2ff659
+    @pytest.mark.xfail(reason='freeipa ticket 8445', strict=True)
2ff659
+    def test_EPN_connection_refused(self):
2ff659
+        """Test EPN behavior when the configured SMTP is down
2ff659
+        """
2ff659
+
2ff659
+        self.master.run_command(["systemctl", "stop", "postfix"])
2ff659
+        (unused, stderr_text, rc) = self._check_epn_output(
2ff659
+            self.master, mailtest=True,
2ff659
+            raiseonerr=False, validatejson=False
2ff659
+        )
2ff659
+        self.master.run_command(["systemctl", "start", "postfix"])
2ff659
+        assert "IPA-EPN: Could not connect to the configured SMTP server" in \
2ff659
+            stderr_text
2ff659
+        assert rc > 0
2ff659
+
2ff659
     def test_EPN_smoketest_1(self):
2ff659
         """No users except admin. Check --dry-run output.
2ff659
            With the default configuration, the result should be an empty list.
2ff659
-- 
2ff659
2.26.2
2ff659
2ff659
From 53f330b053740b169d211aa16b3b36fb61157bbd Mon Sep 17 00:00:00 2001
2ff659
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fcami@redhat.com>
2ff659
Date: Fri, 7 Aug 2020 06:19:31 +0200
2ff659
Subject: [PATCH] IPA-EPN: Fix SMTP connection error handling
2ff659
MIME-Version: 1.0
2ff659
Content-Type: text/plain; charset=UTF-8
2ff659
Content-Transfer-Encoding: 8bit
2ff659
2ff659
Enhance error message when SMTP is down.
2ff659
2ff659
Fixes: https://pagure.io/freeipa/issue/8445
2ff659
Signed-off-by: François Cami <fcami@redhat.com>
2ff659
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
2ff659
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
2ff659
---
2ff659
 ipaclient/install/ipa_epn.py          | 17 ++++++++++-------
2ff659
 ipatests/test_integration/test_epn.py |  1 -
2ff659
 2 files changed, 10 insertions(+), 8 deletions(-)
2ff659
2ff659
diff --git a/ipaclient/install/ipa_epn.py b/ipaclient/install/ipa_epn.py
2ff659
index 0d1ae2add..82d7b3f57 100644
2ff659
--- a/ipaclient/install/ipa_epn.py
2ff659
+++ b/ipaclient/install/ipa_epn.py
2ff659
@@ -38,6 +38,7 @@ from email.mime.multipart import MIMEMultipart
2ff659
 from email.mime.text import MIMEText
2ff659
 from email.header import Header
2ff659
 from email.utils import make_msgid
2ff659
+from socket import error as socketerror
2ff659
 
2ff659
 from ipaplatform.paths import paths
2ff659
 from ipalib import api, errors
2ff659
@@ -640,13 +641,15 @@ class MTAClient:
2ff659
                     port=self._smtp_port,
2ff659
                     timeout=self._smtp_timeout,
2ff659
                 )
2ff659
-        except smtplib.SMTPException as e:
2ff659
-            logger.error(
2ff659
-                "IPA-EPN: Unable to connect to %s:%s: %s",
2ff659
-                self._smtp_hostname,
2ff659
-                self._smtp_port,
2ff659
-                e,
2ff659
-            )
2ff659
+        except (socketerror, smtplib.SMTPException) as e:
2ff659
+            msg = \
2ff659
+                "IPA-EPN: Could not connect to the configured SMTP server: " \
2ff659
+                "{host}:{port}: {error}".format(
2ff659
+                    host=self._smtp_hostname,
2ff659
+                    port=self._smtp_port,
2ff659
+                    error=e
2ff659
+                )
2ff659
+            raise admintool.ScriptError(msg)
2ff659
 
2ff659
         try:
2ff659
             self._conn.ehlo()
2ff659
diff --git a/ipatests/test_integration/test_epn.py b/ipatests/test_integration/test_epn.py
2ff659
index 1a25d3710..e03521193 100644
2ff659
--- a/ipatests/test_integration/test_epn.py
2ff659
+++ b/ipatests/test_integration/test_epn.py
2ff659
@@ -249,7 +249,6 @@ class TestEPN(IntegrationTest):
2ff659
         ck = "192481b52fb591112afd7b55b12a44c6618fdbc7e05a3b1866fd67ec579c51df"
2ff659
         assert cmd2.stdout_text.find(ck) == 0
2ff659
 
2ff659
-    @pytest.mark.xfail(reason='freeipa ticket 8445', strict=True)
2ff659
     def test_EPN_connection_refused(self):
2ff659
         """Test EPN behavior when the configured SMTP is down
2ff659
         """
2ff659
-- 
2ff659
2.26.2
2ff659