Repository: HewlettPackard/oneview-python

Issue:
raise exception with proper error message when ip is not provided in config
Currently, while running i3s examples without providing i3s ip in config, oneview_client doesn't raise any exception and throws improper error messages which becomes quite difficult for user to understand the root cause of error.

Expected result: oneview_client throws below error.

![image](https://user-images.githubusercontent.com/39786905/85988305-78f64200-ba0c-11ea-8ba5-76e29c59a8ef.png)


Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2bf3ad10..2581312f 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ Added code to handle login acknowledgement.
 - #23 MISSING_JSON_TYPE error code is thrown when attempting to restore the appliance
 - #58 loginMsgAck is not handled in python code
 - #60 SPT type for api1600 should be ServerProfileTemplateV8
+- #67 raise exception with proper error message when ip is not provided in config
 
 # 5.2.0
 #### Notes
diff --git a/hpOneView/oneview_client.py b/hpOneView/oneview_client.py
index d3d3552e..56bb077f 100755
--- a/hpOneView/oneview_client.py
+++ b/hpOneView/oneview_client.py
@@ -112,15 +112,18 @@ from hpOneView.resources.security.certificates_server import CertificatesServer
 from hpOneView.resources.hypervisors.hypervisor_cluster_profiles import HypervisorClusterProfiles
 
 ONEVIEW_CLIENT_INVALID_PROXY = 'Invalid Proxy format'
+ONEVIEW_CLIENT_INVALID_I3S_IP = 'Image streamer ip address is missing'
+ONEVIEW_CLIENT_MISSING_IP = 'Oneview ip address is missing'
 
 
 class OneViewClient(object):
     DEFAULT_API_VERSION = 800
 
     def __init__(self, config):
-        self.__connection = connection(config["ip"], config.get('api_version', self.DEFAULT_API_VERSION), config.get('ssl_certificate', False),
+        self.__connection = connection(config.get('ip'), config.get('api_version', self.DEFAULT_API_VERSION), config.get('ssl_certificate', False),
                                        config.get('timeout'))
         self.__image_streamer_ip = config.get("image_streamer_ip")
+        self.__validate_host()
         self.__set_proxy(config)
         self.__connection.login(config["credentials"])
         self.__certificate_authority = None
@@ -268,6 +271,13 @@ class OneViewClient(object):
             proxy_port = int(splitted[1])
             self.__connection.set_proxy(proxy_host, proxy_port)
 
+    def __validate_host(self):
+        """
+        Fails if oneview ip is not provided
+        """
+        if not self.__connection._host:
+            raise ValueError(ONEVIEW_CLIENT_MISSING_IP)
+
     @property
     def api_version(self):
         """
@@ -295,6 +305,9 @@ class OneViewClient(object):
         Returns:
             ImageStreamerClient:
         """
+        if not self.__image_streamer_ip:
+            raise ValueError(ONEVIEW_CLIENT_INVALID_I3S_IP)
+
         image_streamer = ImageStreamerClient(self.__image_streamer_ip,
                                              self.__connection.get_session_id(),
                                              self.__connection._apiVersion,


Test patch:
diff --git a/tests/unit/test_oneview_client.py b/tests/unit/test_oneview_client.py
index 5818172b..7a39fddf 100755
--- a/tests/unit/test_oneview_client.py
+++ b/tests/unit/test_oneview_client.py
@@ -137,6 +137,17 @@ class OneViewClientTest(unittest.TestCase):
 
         self._oneview = OneViewClient(config)
 
+    def test_raise_error_missing_ip(self):
+        config = {"ip": "",
+                  "credentials": {
+                      "userName": "administrator",
+                      "password": ""}}
+
+        try:
+            OneViewClient(config)
+        except ValueError as e:
+            self.assertTrue("ip address is missing" in e.args[0])
+
     def test_raise_error_invalid_proxy(self):
         config = {"ip": "172.16.102.59",
                   "proxy": "3128",
@@ -357,12 +368,10 @@ class OneViewClientTest(unittest.TestCase):
         client = OneViewClient(config)
         client.connection.set_session_id('123')
 
-        i3s = client.create_image_streamer_client()
-
-        self.assertEqual(i3s.connection.get_session_id(), client.connection.get_session_id())
-        self.assertEqual(i3s.connection._apiVersion, client.api_version)
-        self.assertEqual(i3s.connection.get_host(), None)
-        self.assertEqual(client.connection.get_host(), "172.16.102.59")
+        try:
+            client.create_image_streamer_client()
+        except ValueError as e:
+            self.assertTrue("Image streamer ip" in e.args[0])
 
     @mock.patch.object(connection, 'login')
     def test_create_image_streamer_client_with_image_streamer_ip(self, mock_login):