Created new class KeypairSettingsError. 75/37875/1
authorspisarski <s.pisarski@cablelabs.com>
Thu, 20 Jul 2017 17:20:13 +0000 (11:20 -0600)
committerspisarski <s.pisarski@cablelabs.com>
Thu, 20 Jul 2017 17:20:13 +0000 (11:20 -0600)
Raising KeypairSettingsError in KeypairSettings instead of Exception.

JIRA: SNAPS-133

Change-Id: Ie67f1da429f7d7a5e1c71c4f2f30bf9d11bbe209
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
snaps/openstack/create_keypairs.py
snaps/openstack/tests/create_keypairs_tests.py

index 83cfbbc..03ff7ec 100644 (file)
@@ -130,4 +130,10 @@ class KeypairSettings:
         self.private_filepath = kwargs.get('private_filepath')
 
         if not self.name:
-            raise Exception('Name is a required attribute')
+            raise KeypairSettingsError('Name is a required attribute')
+
+
+class KeypairSettingsError(Exception):
+    """
+    Exception to be thrown when keypair settings are incorrect
+    """
index 29fe843..aeeefaf 100644 (file)
@@ -16,7 +16,8 @@ import unittest
 import uuid
 
 import os
-from snaps.openstack.create_keypairs import KeypairSettings, OpenStackKeypair
+from snaps.openstack.create_keypairs import (
+    KeypairSettings, OpenStackKeypair, KeypairSettingsError)
 from snaps.openstack.tests.os_source_file_test import OSIntegrationTestCase
 from snaps.openstack.utils import nova_utils
 
@@ -29,11 +30,11 @@ class KeypairSettingsUnitTests(unittest.TestCase):
     """
 
     def test_no_params(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(KeypairSettingsError):
             KeypairSettings()
 
     def test_empty_config(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(KeypairSettingsError):
             KeypairSettings(**dict())
 
     def test_name_only(self):
@@ -84,7 +85,7 @@ class KeypairSettingsUnitTests(unittest.TestCase):
     def test_config_all(self):
         settings = KeypairSettings(
             **{'name': 'foo', 'public_filepath': '/foo/bar.pub',
-                    'private_filepath': '/foo/bar'})
+               'private_filepath': '/foo/bar'})
         self.assertEqual('foo', settings.name)
         self.assertEqual('/foo/bar.pub', settings.public_filepath)
         self.assertEqual('/foo/bar', settings.private_filepath)