瀏覽代碼

Add the option to run the test suite on a specific cloud only (set via env vars)

Enis Afgan 10 年之前
父節點
當前提交
e655553d97
共有 3 個文件被更改,包括 35 次插入19 次删除
  1. 13 0
      cloudbridge/providers/factory.py
  2. 20 17
      test/__init__.py
  3. 2 2
      tox.ini

+ 13 - 0
cloudbridge/providers/factory.py

@@ -96,6 +96,19 @@ class CloudProviderFactory(object):
                                  class_name)
                                  class_name)
         return provider_class
         return provider_class
 
 
+    def get_provider_class(self, name, version=None):
+        """
+        Return a class for the requested provider.
+
+        :rtype: provider class or ``None``
+        :return: A class corresponding to the requested provider or ``None``
+                 if the provider was not found.
+        """
+        provider_class = self.find_provider_impl(name, version)
+        if provider_class:
+            return self._get_provider_class(provider_class)
+        return None
+
     def get_all_provider_classes(self):
     def get_all_provider_classes(self):
         """
         """
         Returns a list of classes for all available provider implementations
         Returns a list of classes for all available provider implementations

+ 20 - 17
test/__init__.py

@@ -1,25 +1,28 @@
 """
 """
 Tests the functionality of each provider implementation against registered test cases.
 Tests the functionality of each provider implementation against registered test cases.
-These tests require that provider credentials are set as environment variables, as required for
-each provider.
-
-Since the tests exercise the cloudbridge interfaces, and there are multiple implementations of these
-interfaces, for m interfaces and n implementation, exercising all interfaces means that m*n test case
-classes are needed. Otherwise, the standard test runners such as unittest and nose2 do not correctly
-pick up the tests.
-
-To avoid an explosion of repetitive test cases, the ProviderTestCaseGenerator class will
-automatically generate a new Python class for each combination of test and provider. The
-load_tests protocol (https://docs.python.org/2/library/unittest.html#load-tests-protocol)
+These tests require that provider credentials are set as environment variables,
+as required for each provider (see `tox.ini` for a list of env variables).
+
+Since the tests exercise the ``cloudbridge`` interfaces, and there are multiple
+implementations of these interfaces, for m interfaces and n implementation,
+exercising all interfaces means that m*n test case classes are needed. Otherwise,
+the standard test runners such as unittest and nose2 do not correctly pick up
+the tests.
+
+To avoid an explosion of repetitive test cases, the ``ProviderTestCaseGenerator``
+class will automatically generate a new Python class for each combination of
+test and provider. The ``load_tests`` protocol
+(https://docs.python.org/2/library/unittest.html#load-tests-protocol)
 is used to aid test discovery.
 is used to aid test discovery.
 
 
-Use ``python setup.py test`` to run these unit tests. (alternatively,use
-``python -m unittest test``)
+Use ``python setup.py test`` to run these unit tests (alternatively, use
+``python -m unittest test``).
 
 
-All test cases need to be registered below, and available providers will be discovered through
-the ProviderFactory. Test Cases must not inherit from unittest.TestCase, to avoid confusing
-unittest and nose2's automatic discovery.
-(The test generator will automatically add unittest.TestCase as a base class to each combination)
+All test cases need to be registered below, and available providers will be
+discovered through the ``ProviderFactory``. Test Cases must not inherit from
+``unittest.TestCase``, to avoid confusing unittest and nose2's automatic discovery.
+(The test generator will automatically add ``unittest.TestCase`` as a base class
+to each combination).
 """
 """
 
 
 from test.helpers import ProviderTestCaseGenerator
 from test.helpers import ProviderTestCaseGenerator

+ 2 - 2
tox.ini

@@ -8,11 +8,11 @@ envlist = py27, py33, py34, pypy
 
 
 [testenv]
 [testenv]
 commands = {envpython} setup.py test
 commands = {envpython} setup.py test
-passenv = EC2_ACCESS_KEY EC2_SECRET_KEY OS_AUTH_URL OS_PASSWORD OS_TENANT_NAME OS_USERNAME CB_AMI CB_INSTANCE_TYPE CB_IMAGE CB_FLAVOR
+passenv = EC2_ACCESS_KEY EC2_SECRET_KEY OS_AUTH_URL OS_PASSWORD OS_TENANT_NAME OS_USERNAME CB_AMI CB_INSTANCE_TYPE CB_IMAGE CB_FLAVOR CB_TEST_PROVIDER
 
 
 # Run coverage for python27 - omit interfaces.py since it's a behaviour spec only.
 # Run coverage for python27 - omit interfaces.py since it's a behaviour spec only.
 [testenv:py27]
 [testenv:py27]
 commands = {envpython} -m coverage run --branch --source=cloudbridge --omit=cloudbridge/providers/interfaces.py setup.py test
 commands = {envpython} -m coverage run --branch --source=cloudbridge --omit=cloudbridge/providers/interfaces.py setup.py test
-passenv = EC2_ACCESS_KEY EC2_SECRET_KEY OS_AUTH_URL OS_PASSWORD OS_TENANT_NAME OS_USERNAME CB_AMI CB_INSTANCE_TYPE CB_IMAGE CB_FLAVOR
+passenv = EC2_ACCESS_KEY EC2_SECRET_KEY OS_AUTH_URL OS_PASSWORD OS_TENANT_NAME OS_USERNAME CB_AMI CB_INSTANCE_TYPE CB_IMAGE CB_FLAVOR CB_TEST_PROVIDER
 deps =
 deps =
     coverage
     coverage