Skip to content

Instantly share code, notes, and snippets.

@alistairncoles
Created August 13, 2014 14:52
Show Gist options
  • Save alistairncoles/d50c8c3bf981cacbf583 to your computer and use it in GitHub Desktop.
Save alistairncoles/d50c8c3bf981cacbf583 to your computer and use it in GitHub Desktop.
unit tests for swift data migration
diff --git a/test/unit/common/middleware/test_data_migration.py b/test/unit/common/middleware/test_data_migration.py
index afe986e..40d3e83 100755
--- a/test/unit/common/middleware/test_data_migration.py
+++ b/test/unit/common/middleware/test_data_migration.py
@@ -14,6 +14,9 @@
# limitations under the License.
import unittest
+from swift.common.middleware.data_migration import DataMigrationError
+from swift.common.data_migrator_drivers import SwiftAccessDriver, \
+ FileSystemAccessDriver
from swift.common.utils import split_path
from swift.common.swob import Request, Response
from swift.common.middleware import data_migration
@@ -256,5 +259,61 @@ class TestDataMigrationSwiftClient(unittest.TestCase):
else:
self.assertEquals(res.status_int, 503)
+
+class TestDataMigration(unittest.TestCase):
+ def setUp(self):
+ self.app = data_migration.filter_factory(global_conf,
+ **local_conf)(FakeApp())
+ def test_remote_driver_resolver_swift(self):
+ keys = ['auth-type', 'token-url', 'user', 'key']
+ migration_conf = {'swift': {'the_class': SwiftAccessDriver,
+ 'driver_loaded': True,
+ 'keys': keys}}
+ container_md = {'migration-provider': 'swift',
+ 'migration-source': 'a_source',
+ 'migration-auth-type': 'auth1',
+ 'migration-token-url': 'http://example.com',
+ 'migration-user': 'username',
+ 'migration-key': 'secret'}
+ driver = self.app.remote_driver_resolver(container_md, migration_conf)
+ self.assertTrue(isinstance(driver, SwiftAccessDriver))
+ self.assertEqual(driver.data_source, 'a_source')
+ self.assertEqual(driver.auth_type, 'auth1')
+ self.assertEqual(driver.user, 'username')
+ self.assertEqual(driver.key, 'secret')
+ self.assertEqual(driver.token_url, 'http://example.com')
+
+ def test_remote_driver_resolver_file_system(self):
+ keys = ['path']
+ migration_conf = {'fsystem': {'the_class': FileSystemAccessDriver,
+ 'driver_loaded': True,
+ 'keys': keys}}
+ container_md = {'migration-provider': 'fsystem',
+ 'migration-source': 'a_source',
+ 'migration-path': '/a/b/c'}
+ driver = self.app.remote_driver_resolver(container_md, migration_conf)
+ self.assertTrue(isinstance(driver, FileSystemAccessDriver))
+ self.assertEqual(driver.data_source, 'a_source')
+ self.assertEqual(driver.data_path, '/a/b/c')
+
+ def test_remote_driver_resolver_not_loaded(self):
+ keys = ['path']
+ migration_conf = {'fsystem': {'the_class': FileSystemAccessDriver,
+ 'driver_loaded': False,
+ 'keys': keys}}
+ container_md = {'migration-provider': 'fsystem'}
+ self.assertRaises(DataMigrationError, self.app.remote_driver_resolver,
+ container_md, migration_conf)
+
+ def test_remote_driver_resolver_not_found(self):
+ keys = ['path']
+ migration_conf = {'fsystem': {'the_class': FileSystemAccessDriver,
+ 'driver_loaded': True,
+ 'keys': keys}}
+ container_md = {'migration-provider': 'bad'}
+ self.assertRaises(DataMigrationError, self.app.remote_driver_resolver,
+ container_md, migration_conf)
+
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment