Add the function of getting endpoint
[snaps.git] / snaps / openstack / tests / os_source_file_test.py
index 0c9f1b1..3a632e5 100644 (file)
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-import unittest
+import logging
 import uuid
+import unittest
 
 from snaps import file_utils
-import openstack_tests
-import logging
-
 from snaps.openstack.create_project import ProjectSettings
 from snaps.openstack.create_user import UserSettings
+from snaps.openstack.tests import openstack_tests
 from snaps.openstack.utils import deploy_utils, keystone_utils
 
 dev_os_env_file = 'openstack/tests/conf/os_env.yaml'
@@ -32,12 +31,14 @@ dev_os_env_file = 'openstack/tests/conf/os_env.yaml'
 
 class OSComponentTestCase(unittest.TestCase):
 
-    def __init__(self, method_name='runTest', os_creds=None, ext_net_name=None, log_level=logging.DEBUG):
+    def __init__(self, method_name='runTest', os_creds=None, ext_net_name=None, image_metadata=None,
+                 log_level=logging.DEBUG):
         """
         Super for test classes requiring a connection to OpenStack
         :param method_name: default 'runTest'
         :param os_creds: the OSCreds object, when null it searches for the file {cwd}/openstack/tests/conf/os_env.yaml
         :param ext_net_name: the name of the external network that is used for creating routers for floating IPs
+        :param image_metadata: ability to override images being used in the tests (see examples/image-metadata)
         :param log_level: the logging level of your test run (default DEBUG)
         """
         super(OSComponentTestCase, self).__init__(method_name)
@@ -55,8 +56,10 @@ class OSComponentTestCase(unittest.TestCase):
             test_conf = file_utils.read_yaml(dev_os_env_file)
             self.ext_net_name = test_conf.get('ext_net')
 
+        self.image_metadata = image_metadata
+
     @staticmethod
-    def parameterize(testcase_klass, os_creds, ext_net_name, log_level=logging.DEBUG):
+    def parameterize(testcase_klass, os_creds, ext_net_name, image_metadata=None, log_level=logging.DEBUG):
         """ Create a suite containing all tests taken from the given
             subclass, passing them the parameter 'param'.
         """
@@ -64,7 +67,7 @@ class OSComponentTestCase(unittest.TestCase):
         test_names = test_loader.getTestCaseNames(testcase_klass)
         suite = unittest.TestSuite()
         for name in test_names:
-            suite.addTest(testcase_klass(name, os_creds, ext_net_name, log_level))
+            suite.addTest(testcase_klass(name, os_creds, ext_net_name, image_metadata, log_level))
         return suite
 
 
@@ -78,16 +81,20 @@ class OSIntegrationTestCase(OSComponentTestCase):
         :param os_creds: the OSCreds object, when null it searches for the file {cwd}/openstack/tests/conf/os_env.yaml
         :param ext_net_name: the name of the external network that is used for creating routers for floating IPs
         :param use_keystone: when true, these tests will create a new user/project under which to run the test
+        :param image_metadata: dict() containing the URLs for the disk, kernel, and ramdisk images when multi-part
+                               images are required.
+            image_metadata={'disk_url': 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img',
+                            'kernel_url': 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-kernel',
+                            'ramdisk_url': 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-initramfs'})
         :param flavor_metadata: dict() to be sent directly into the Nova client generally used for page sizes
-        :param image_metadata: dict() to be sent directly into the Nova client generally used for multi-part images
         :param log_level: the logging level of your test run (default DEBUG)
         """
         super(OSIntegrationTestCase, self).__init__(method_name=method_name, os_creds=os_creds,
-                                                    ext_net_name=ext_net_name, log_level=log_level)
+                                                    ext_net_name=ext_net_name, image_metadata=image_metadata,
+                                                    log_level=log_level)
         self.use_keystone = use_keystone
         self.keystone = None
         self.flavor_metadata = flavor_metadata
-        self.image_metadata = image_metadata
 
     @staticmethod
     def parameterize(testcase_klass, os_creds, ext_net_name, use_keystone=False, flavor_metadata=None,