本文整理汇总了Python中pulp.server.db.migrate.models._import_all_the_way函数的典型用法代码示例。如果您正苦于以下问题:Python _import_all_the_way函数的具体用法?Python _import_all_the_way怎么用?Python _import_all_the_way使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_import_all_the_way函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_migrate
def test_migrate(self):
migration = _import_all_the_way('pulp_rpm.migrations.0009_iso_importer_config_keys')
# Run the migration
migration.migrate()
# Verify the proxy repo
proxy = self.repo_importers.find_one({'repo_id': 'proxy'})
self.assertEqual(proxy['importer_type_id'], 'iso_importer')
self.assertEqual(proxy['last_sync'], '2013-04-09T16:57:06-04:00')
self.assertEqual(proxy['scheduled_syncs'], [])
self.assertEqual(proxy['scratchpad'], None)
self.assertEqual(dict(proxy['config']), {
u'proxy_username': u'rbarlow',
u'feed': u'http://pkilambi.fedorapeople.org/test_file_repo/',
u'proxy_host': u'localhost', u'proxy_password': u'password',
u'proxy_port': 3128, u'id': u'proxy'})
self.assertEqual(proxy['id'], 'iso_importer')
# Verify the test repo
test = self.repo_importers.find_one({'repo_id': 'test'})
self.assertEqual(test['importer_type_id'], 'iso_importer')
self.assertEqual(dict(test['config']), {
u'max_downloads': 42,
u'feed': u'http://feed.com/isos',
u'proxy_host': u'proxy.com', u'proxy_username': u'jeeves',
u'remove_missing': False, u'validate': True})
self.assertEqual(test['id'], 'iso_importer')
# verify that the yum repo wasn't touched
a_yum_repo = self.repo_importers.find_one({'repo_id': 'a_yum_repo'})
self.assertEqual(a_yum_repo['importer_type_id'], 'yum_importer')
self.assertEqual(dict(a_yum_repo['config']),
{u'feed_url': u'This should not change.'})
示例2: test_move_directory_contents
def test_move_directory_contents(self):
test_old_publish_dir = tempfile.mkdtemp(prefix='test_0002_migration_old')
old_http_publish_dir = os.path.join(test_old_publish_dir, 'http', 'repos')
old_https_publish_dir = os.path.join(test_old_publish_dir, 'https', 'repos')
os.makedirs(old_http_publish_dir)
os.makedirs(old_https_publish_dir)
test_new_publish_dir = tempfile.mkdtemp(prefix='test_0002_migration_new')
test_new_publish_puppet_dir = os.path.join(test_new_publish_dir, 'puppet')
# on a real system, this dir is created by the rpm
os.mkdir(test_new_publish_puppet_dir)
new_http_publish_dir = os.path.join(test_new_publish_puppet_dir, 'http', 'repos')
new_https_publish_dir = os.path.join(test_new_publish_puppet_dir, 'https', 'repos')
# put a file in the top-level dir to ensure it gets copied over too.
# It is not typical to have a file there but we should move it over
# just in case.
open(os.path.join(test_old_publish_dir, 'some_file'), 'w').close()
migration = _import_all_the_way('pulp_puppet.plugins.migrations.0002_puppet_'
'publishing_directory_change')
migration.move_directory_contents(test_old_publish_dir, test_new_publish_puppet_dir)
self.assertTrue(os.path.exists(new_http_publish_dir))
self.assertTrue(os.path.exists(new_https_publish_dir))
self.assertTrue(os.path.exists(os.path.join(test_new_publish_puppet_dir, 'some_file')))
# bz 1153072 - user needs to clear this dir manually
self.assertTrue(os.path.exists(test_old_publish_dir))
for (root, files, dirs) in os.walk(test_old_publish_dir):
self.assertTrue(files == [])
self.assertTrue(dirs == [])
示例3: setUp
def setUp(self):
super(Migration0004Tests, self).setUp()
# Special way to import modules that start with a number
self.migration = _import_all_the_way(
'pulp_rpm.plugins.migrations.0004_pkg_group_category_repoid')
factory.initialize()
api.initialize(False)
types_db.update_database([TYPE_DEF_GROUP, TYPE_DEF_CATEGORY])
# Create the repositories necessary for the tests
self.source_repo_id = 'source-repo' # where units were copied from with the bad code
self.dest_repo_id = 'dest-repo' # where bad units were copied to
source_repo = model.Repository(repo_id=self.source_repo_id)
source_repo.save()
dest_repo = model.Repository(repo_id=self.dest_repo_id)
dest_repo.save()
source_importer = model.Importer(self.source_repo_id, 'yum_importer', {})
source_importer.save()
dest_importer = model.Importer(self.dest_repo_id, 'yum_importer', {})
dest_importer.save()
示例4: test_migrate
def test_migrate(self):
# Let's set up some package groups, some with the new way, and some with the old way
# We'll only put the name and conditional_package_names attributes since the
# migration only touches those fields
package_groups = [
{"name": "v1_style_1", "conditional_package_names" : {'a': 1, 'b': 2}},
{"name": "v1_style_2", "conditional_package_names" : {'b': 1, 'c': 3}},
{"name": "v2_style", "conditional_package_names" : [['d', 4], ['e', 5]]}]
for package_group in package_groups:
self.package_group_collection.insert(package_group)
migration = _import_all_the_way(
'pulp_rpm.migrations.0012_conditional_package_names_v1_v2_upgrade')
# Run the migration
migration.migrate()
# Inspect the package groups
expected_package_groups = [
{"name": "v1_style_1", "conditional_package_names" : [['a', 1], ['b', 2]]},
{"name": "v1_style_2", "conditional_package_names" : [['b', 1], ['c', 3]]},
{"name": "v2_style", "conditional_package_names" : [['d', 4], ['e', 5]]}]
for expected_package_group in expected_package_groups:
package_group = self.package_group_collection.find_one(
{'name': expected_package_group['name']})
self.assertTrue(isinstance(package_group['conditional_package_names'], list))
self.assertEqual(len(package_group['conditional_package_names']),
len(expected_package_group['conditional_package_names']))
# Since dictionaries don't have ordering, we cannot assert that the expected
# list is the same as the actual list. Instead, we assert that the lengths are
# the same, and that all the expected items appear in the actual
for pair in expected_package_group['conditional_package_names']:
self.assertTrue(pair in package_group['conditional_package_names'])
示例5: setUp
def setUp(self):
super(Migration0004Tests, self).setUp()
# Special way to import modules that start with a number
self.migration = _import_all_the_way(
'pulp_rpm.plugins.migrations.0004_pkg_group_category_repoid')
factory.initialize()
types_db.update_database([TYPE_DEF_GROUP, TYPE_DEF_CATEGORY])
# Create the repositories necessary for the tests
self.source_repo_id = 'source-repo' # where units were copied from with the bad code
self.dest_repo_id = 'dest-repo' # where bad units were copied to
source_repo = Repo(self.source_repo_id, '')
Repo.get_collection().insert(source_repo, safe=True)
dest_repo = Repo(self.dest_repo_id, '')
Repo.get_collection().insert(dest_repo, safe=True)
source_importer = RepoImporter(self.source_repo_id, 'yum_importer', 'yum_importer', {})
RepoImporter.get_collection().insert(source_importer, safe=True)
dest_importer = RepoImporter(self.dest_repo_id, 'yum_importer', 'yum_importer', {})
RepoImporter.get_collection().insert(dest_importer, safe=True)
示例6: test_fix_distribution_units
def test_fix_distribution_units(self):
migration = _import_all_the_way('pulp_rpm.plugins.migrations.0015_fix_distributor_units')
mock_collection = mock.MagicMock()
mock_collection.find.return_value = FAKE_DIST_UNITS
migration._fix_distribution_units(mock_collection)
mock_collection.find.assert_called_once_with({'files': {'$exists': True}})
mock_collection.update.assert_called_once_with({'_id': u'6ec94809-6d4f-48cf-9077-88d003eb284e'},
{'$set': {'files': []}}, safe=True)
示例7: setUp
def setUp(self):
super(BaseMigrationTests, self).setUp()
self.distributors_collection = RepoDistributor.get_collection()
self.root_test_dir = tempfile.mkdtemp(prefix='test_0016_migration_')
self.http_publish_dir = os.path.join(self.root_test_dir, 'http', 'repos')
self.https_publish_dir = os.path.join(self.root_test_dir, 'https', 'repos')
self.migration_module = _import_all_the_way(MIGRATION_MODULE)
示例8: test_migrate
def test_migrate(self):
migration = _import_all_the_way('pulp_rpm.migrations.0013_errata_from_str')
# Run the migration
migration.migrate()
# Verify that this one's "from_str" got changed to "from"
old = self.collection.find_one({'id': 'RHEA-2012:0003'})
self.assertEqual(old.get('from', None), '[email protected]')
self.assertFalse('from_str' in old)
# Verify that this one's "from" is still "from"
new = self.collection.find_one({'id': 'RHEA-2012:0004'})
self.assertEqual(new.get('from', None), '[email protected]')
self.assertFalse('from_str' in new)
示例9: test_migration
def test_migration(self, mock_query_manager, mock_calc_checksum):
migration = _import_all_the_way('pulp_puppet.plugins.migrations.0001_puppet_'
'module_unit_checksum')
storage_path = '/foo/storage'
mock_calc_checksum.return_value = "foo_checksum"
unit = {'_storage_path': storage_path}
mock_query_manager.return_value.get_content_unit_collection.return_value.find.return_value \
= MockCursor([unit])
migration.migrate()
mock_calc_checksum.assert_called_once_with(storage_path)
mock_query_manager.return_value.get_content_unit_collection.return_value.\
save.assert_called_once()
target_unit = mock_query_manager.return_value.get_content_unit_collection.return_value. \
save.call_args[0][0]
self.assertEquals(target_unit['checksum'], 'foo_checksum')
self.assertEquals(target_unit['checksum_type'], constants.DEFAULT_HASHLIB)
示例10: test_fix_distribution_units_multifile
def test_fix_distribution_units_multifile(self):
"""
verify that we don't remove files that are OK
"""
migration = _import_all_the_way('pulp_rpm.plugins.migrations.0015_fix_distributor_units')
mock_collection = mock.MagicMock()
mock_collection.find.return_value = FAKE_DIST_UNITS_MULTIFILE
migration._fix_distribution_units(mock_collection)
mock_collection.find.assert_called_once_with({'files': {'$exists': True}})
mock_collection.update.assert_called_once_with({'_id': u'6ec94809-6d4f-48cf-9077-88d003eb284e'},
{'$set':
{'files': [{'downloadurl': 'http ://fake-url/os/another_file',
'item_type': 'distribution',
'fileName': 'another_file'}]}},
safe=True)
示例11: test_migrate
def test_migrate(self):
migration = _import_all_the_way("pulp_rpm.plugins.migrations.0009_iso_importer_config_keys")
# Run the migration
migration.migrate()
# Verify the proxy repo
proxy = self.repo_importers.find_one({"repo_id": "proxy"})
self.assertEqual(proxy["importer_type_id"], "iso_importer")
self.assertEqual(proxy["last_sync"], "2013-04-09T16:57:06-04:00")
self.assertEqual(proxy["scheduled_syncs"], [])
self.assertEqual(proxy["scratchpad"], None)
self.assertEqual(
dict(proxy["config"]),
{
u"proxy_username": u"rbarlow",
u"feed": u"http://pkilambi.fedorapeople.org/test_file_repo/",
u"proxy_host": u"localhost",
u"proxy_password": u"password",
u"proxy_port": 3128,
u"id": u"proxy",
},
)
self.assertEqual(proxy["id"], "iso_importer")
# Verify the test repo
test = self.repo_importers.find_one({"repo_id": "test"})
self.assertEqual(test["importer_type_id"], "iso_importer")
self.assertEqual(
dict(test["config"]),
{
u"max_downloads": 42,
u"feed": u"http://feed.com/isos",
u"proxy_host": u"proxy.com",
u"proxy_username": u"jeeves",
u"remove_missing": False,
u"validate": True,
},
)
self.assertEqual(test["id"], "iso_importer")
# verify that the yum repo wasn't touched
a_yum_repo = self.repo_importers.find_one({"repo_id": "a_yum_repo"})
self.assertEqual(a_yum_repo["importer_type_id"], "yum_importer")
self.assertEqual(dict(a_yum_repo["config"]), {u"feed_url": u"This should not change."})
示例12: test_migrate
def test_migrate(self):
# Test
migration = _import_all_the_way('pulp_rpm.plugins.migrations.0010_yum_importer_config_keys')
migration.migrate()
# Verify
proxy = self.repo_importers.find_one({'repo_id': 'proxy'})
self.assertTrue('proxy_url' not in proxy['config'])
self.assertTrue('proxy_user' not in proxy['config'])
self.assertTrue('proxy_pass' not in proxy['config'])
self.assertEqual(proxy['config']['proxy_host'], 'localhost')
self.assertEqual(proxy['config']['proxy_username'], 'user-1')
self.assertEqual(proxy['config']['proxy_password'], 'pass-1')
mixed = self.repo_importers.find_one({'repo_id': 'mixed'})
self.assertTrue('feed_url' not in mixed['config'])
self.assertTrue('ssl_verify' not in mixed['config'])
self.assertTrue('num_threads' not in mixed['config'])
self.assertTrue('verify_checksum' not in mixed['config'])
self.assertTrue('remove_old' not in mixed['config'])
self.assertTrue('num_old_packages' not in mixed['config'])
self.assertEqual(mixed['config']['feed'], 'http://localhost/repo')
self.assertEqual(mixed['config']['ssl_validation'], True)
self.assertEqual(mixed['config']['max_downloads'], 42)
self.assertEqual(mixed['config']['validate'], True)
self.assertEqual(mixed['config']['remove_missing'], False)
self.assertEqual(mixed['config']['retain_old_count'], 3)
self.assertEqual(mixed['config']['skip'], ['rpm'])
self.assertEqual(mixed['config']['max_speed'], 1024)
remove = self.repo_importers.find_one({'repo_id': 'remove'})
self.assertTrue('newest' not in remove['config'])
self.assertTrue('verify_size' not in remove['config'])
self.assertTrue('purge_orphaned' not in remove['config'])
self.assertEqual(remove['config']['feed'], 'localhost')
no_touch = self.repo_importers.find_one({'repo_id': 'no-touch'})
self.assertEqual(no_touch['config']['feed'], 'localhost')
self.assertEqual(no_touch['config']['newest'], True)
self.assertEqual(no_touch['config']['verify_size'], True)
self.assertEqual(no_touch['config']['purge_orphaned'], True)
示例13: test_move_directory_contents_and_rename
def test_move_directory_contents_and_rename(self):
test_old_publish_dir = tempfile.mkdtemp(prefix='test_0002_migration_old')
old_http_publish_dir = os.path.join(test_old_publish_dir, 'http', 'repos')
old_https_publish_dir = os.path.join(test_old_publish_dir, 'https', 'repos')
os.makedirs(old_http_publish_dir)
os.makedirs(old_https_publish_dir)
test_new_publish_dir = tempfile.mkdtemp(prefix='test_0002_migration_new')
new_http_publish_dir = os.path.join(test_new_publish_dir, 'puppet', 'http', 'repos')
new_https_publish_dir = os.path.join(test_new_publish_dir, 'puppet', 'https', 'repos')
migration = _import_all_the_way('pulp_puppet.plugins.migrations.0002_puppet_'
'publishing_directory_change')
migration.move_directory_contents_and_rename(test_old_publish_dir,
test_new_publish_dir,
os.path.basename(test_old_publish_dir),
'puppet')
self.assertTrue(os.path.exists(new_http_publish_dir))
self.assertTrue(os.path.exists(new_https_publish_dir))
self.assertFalse(os.path.exists(test_old_publish_dir))
示例14: test_migrate
def test_migrate(self):
# Setup
for type_id in (TYPE_ID_RPM, TYPE_ID_SRPM, TYPE_ID_DRPM):
self.add_sample_data(type_id)
# Test
migration = _import_all_the_way('pulp_rpm.plugins.migrations.0008_version_sort_index')
migration.migrate()
# Verify
# The migration should cover these three types, so make sure they were all included
for type_id in (TYPE_ID_RPM, TYPE_ID_SRPM, TYPE_ID_DRPM):
collection = types_db.type_units_collection(type_id)
test_me = collection.find_one({'version': '1.1'})
self.assertEqual(test_me['version_sort_index'], version_utils.encode('1.1'))
self.assertEqual(test_me['release_sort_index'], version_utils.encode('1.1'))
# Make sure the script didn't run on units that already have the indexes
test_me = collection.find_one({'version': '3.1'})
self.assertEqual(test_me['version_sort_index'], 'fake')
self.assertEqual(test_me['release_sort_index'], 'fake')
示例15: _import_all_the_way
"""
This module contains tests for pulp.server.db.migrations.0015_load_content_types.
"""
import unittest
from mock import Mock, call, patch
from pulp.server.db.migrate.models import _import_all_the_way
migration = _import_all_the_way('pulp.server.db.migrations.'
'0016_remove_repo_content_unit_owner_type_and_id')
class TestMigrate(unittest.TestCase):
@patch.object(migration.connection, 'get_database')
def test_migrate_no_collection_in_db(self, mock_get_database):
"""
Test doing nothing, no actual tests since if it tries to do any work it will raise
"""
mock_get_database.return_value.collection_names.return_value = []
migration.migrate()
@patch.object(migration.connection, 'get_database')
@patch.object(migration, 'remove_duplicates')
def test_migrate_removes_duplicates(self, mock_remove_duplicates, mock_get_database):
"""
Test that the migration calls the remove_duplicates method & drops the
owner_type and owner_id fields from the repo_content_units collection
"""
mock_get_database.return_value.collection_names.return_value = ['repo_content_units']
collection = mock_get_database.return_value['repo_content_units']