Hi All,

Please review attached patch

Fixes : https://fedorahosted.org/python-pytest-multihost/ticket/3

Thanks,
Abhijeet Kasurde
From 0fc2238dd0bd26a789232ffaec058ac59f304e43 Mon Sep 17 00:00:00 2001
From: Abhijeet Kasurde <akasu...@redhat.com>
Date: Wed, 6 Jan 2016 11:38:24 +0530
Subject: [PATCH] Added error handling in config file handling.

The fix provides error handling in multihost configuration file handling,
by notifying user about exact error message about missing or wrong
configuration file.

https://fedorahosted.org/python-pytest-multihost/ticket/3

Signed-off-by: Abhijeet Kasurde <akasu...@redhat.com>
---
 pytest_multihost/plugin.py | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/pytest_multihost/plugin.py b/pytest_multihost/plugin.py
index af1441fc9fa7d701dfd4a12336277960ff708858..dc6ffac1ba5ad2f896977d812db7962db6178396 100644
--- a/pytest_multihost/plugin.py
+++ b/pytest_multihost/plugin.py
@@ -26,17 +26,22 @@ def pytest_addoption(parser):
 def pytest_load_initial_conftests(args, early_config, parser):
     ns = early_config.known_args_namespace
     if ns.multihost_config:
-        with open(ns.multihost_config) as conffile:
-            if yaml:
-                confdict = yaml.safe_load(conffile)
-            else:
-                try:
-                    confdict = json.load(conffile)
-                except Exception:
-                    traceback.print_exc()
-                    raise exit(
-                        'Could not load %s. If it is a YAML file, you need '
-                        'PyYAML installed.' % ns.multihost_config)
+        try:
+            with open(ns.multihost_config) as conffile:
+                if yaml:
+                    confdict = yaml.safe_load(conffile)
+                else:
+                    try:
+                        confdict = json.load(conffile)
+                    except Exception:
+                        traceback.print_exc()
+                        raise exit(
+                            'Could not load %s. If it is a YAML file, you need '
+                            'PyYAML installed.' % ns.multihost_config)
+        except IOError as e:
+            raise exit('Unable to find multihost configuration file (%s),\n'
+                       'Please check path of configuration file and retry.'
+                       % (ns.multihost_config))
         plugin = MultihostPlugin(confdict)
         pluginmanager = early_config.pluginmanager.register(
             plugin, 'MultihostPlugin')
-- 
2.4.3

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to