当前位置: 首页>>代码示例>>Python>>正文


Python MigrationTracker.get_collection方法代码示例

本文整理汇总了Python中pulp.server.db.model.migration_tracker.MigrationTracker.get_collection方法的典型用法代码示例。如果您正苦于以下问题:Python MigrationTracker.get_collection方法的具体用法?Python MigrationTracker.get_collection怎么用?Python MigrationTracker.get_collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pulp.server.db.model.migration_tracker.MigrationTracker的用法示例。


在下文中一共展示了MigrationTracker.get_collection方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_current_version_too_high

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
    def test_current_version_too_high(self, mocked_file_config, getLogger):
        """
        Set the current package version higher than latest available version, then sit back and eat
        popcorn.
        """
        logger = MagicMock()
        getLogger.return_value = logger

        # Make sure we start out with a clean slate
        self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
        # Make sure that our mock works. There are four valid packages.
        self.assertEquals(len(models.get_migration_packages()), 4)
        # Set all versions to ridiculously high values
        for package in models.get_migration_packages():
            package._migration_tracker.version = 9999999
            package._migration_tracker.save()
        error_code = manage.main()
        self.assertEqual(error_code, os.EX_DATAERR)

        # There should have been a critical log about the Exception
        expected_messages = ('The database for migration package unit.server.db.migration_packages.'
                             'platform is at version 9999999, which is larger than the latest '
                             'version available, 1.')
        critical_messages = ''.join([mock_call[1][0] for mock_call in logger.critical.mock_calls])
        for msg in expected_messages:
            self.assertTrue(msg in critical_messages)
开发者ID:hgschmie,项目名称:pulp,代码行数:28,代码来源:test_manage.py

示例2: test__initialize_pulp

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
 def test__initialize_pulp(self):
     """
     _initialize_pulp() should raise an Exception if any of the packages aren't at their latest
     version.
     """
     # It is unusual to put an import in the middle of a test, but unfortunately this import will
     # call start_logging() before our test super class can override the logging settings, and
     # thus all the logging will be done to /var/log instead of to /tmp. Moving the import here
     # from the top of the file solves the problem, though not elegantly.
     from pulp.server.webservices.application import _initialize_pulp
     # Make sure we start out with a clean slate
     self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
     # Make sure that our mock works. There are three valid packages.
     self.assertEquals(len(models.get_migration_packages()), 4)
     # Set all versions back to 0
     for package in models.get_migration_packages():
         package._migration_tracker.version = 0
         package._migration_tracker.save()
     # Let's make sure we raise the exception
     try:
         _initialize_pulp()
         self.fail('_initialize_pulp() should have raised an Exception, but did not.')
     except Exception, e:
         self.assertEqual(str(e), ('There are unapplied migrations. Please '
                                   'run the database management utility to apply them.'))
开发者ID:ryanschneider,项目名称:pulp,代码行数:27,代码来源:test_pulp_manage_db.py

示例3: test_migrate

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
    def test_migrate(self, mock_file_config, mocked_apply_migration, getLogger):
        """
        Let's set all the packages to be at version 0, and then check that the migrations get
        called in the correct order.
        """

        logger = MagicMock()
        getLogger.return_value = logger

        # Make sure we start out with a clean slate
        self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
        # Make sure that our mock works. There are three valid packages.
        self.assertEquals(len(models.get_migration_packages()), 4)
        # Set all versions back to 0
        for package in models.get_migration_packages():
            package._migration_tracker.version = 0
            package._migration_tracker.save()
        manage.main()

        # There should have been a critical log about the Exception
        expected_messages = (
            'Applying migration unit.server.db.migration_packages.raise_exception.0002_oh_no '
            'failed.\n\nHalting migrations due to a migration failure.',
            "Bet you didn\'t see this coming."
        )
        critical_messages = ''.join([mock_call[1][0] for mock_call in logger.critical.mock_calls])
        for msg in expected_messages:
            self.assertTrue(msg in critical_messages)

        migration_modules_called = [
            mock_call[1][1].name for mock_call in mocked_apply_migration.mock_calls]
        # Note that none of the migrations that don't meet our criteria show up in this list. Also,
        # Note that migration_packages.raise_exception.0003_shouldnt_run doesn't appear
        # since migration_packages.raise_exception.0002_oh_no raised an Exception. Note
        # also that even though the raise_exception package raised an Exception, we still run all
        # the z migrations because we don't want one package to break another.
        expected_migration_modules_called = [
            'unit.server.db.migration_packages.platform.0001_stuff_and_junk',
            'unit.server.db.migration_packages.raise_exception.0001_works_fine',
            'unit.server.db.migration_packages.raise_exception.0002_oh_no']
        self.assertEquals(migration_modules_called, expected_migration_modules_called)
        # Assert that our precious versions have been updated correctly
        for package in models.get_migration_packages():
            if package.name == 'unit.server.db.migration_packages.platform':
                self.assertEqual(package.current_version, package.latest_available_version)
            elif package.name == 'unit.server.db.migration_packages.raise_exception':
                # The raised Exception should have prevented us from getting past version 1
                self.assertEquals(package.current_version, 1)
            else:
                # raise_exception should cause the migrations to stop
                self.assertEqual(package.current_version, 0)
开发者ID:hgschmie,项目名称:pulp,代码行数:53,代码来源:test_manage.py

示例4: test_migrate

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
    def test_migrate(self, file_config_mock, logger_mock, mocked_apply_migration, mocked_stdout,
                     mocked_stderr):
        """
        Let's set all the packages to be at version 0, and then check that the migrations get
        called in the correct order.
        """
        # Make sure we start out with a clean slate
        self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
        # Make sure that our mock works. There are three valid packages.
        self.assertEquals(len(models.get_migration_packages()), 4)
        # Set all versions back to 0
        for package in models.get_migration_packages():
            package._migration_tracker.version = 0
            package._migration_tracker.save()
        manage.main()

        # There should have been a print to stderr about the Exception
        expected_stderr_calls = [
            ('Applying migration unit.server.db.migration_packages.raise_exception.0002_oh_no '
             'failed.'), ' ', ' See log for details.', '\n']
        stderr_calls = [mock_call[1][0] for mock_call in mocked_stderr.mock_calls]
        self.assertEquals(stderr_calls, expected_stderr_calls)

        migration_modules_called = [
            mock_call[1][1].name for mock_call in mocked_apply_migration.mock_calls]
        # Note that none of the migrations that don't meet our criteria show up in this list. Also,
        # Note that migration_packages.raise_exception.0003_shouldnt_run doesn't appear
        # since migration_packages.raise_exception.0002_oh_no raised an Exception. Note
        # also that even though the raise_exception package raised an Exception, we still run all
        # the z migrations because we don't want one package to break another.
        expected_migration_modules_called = [
            'unit.server.db.migration_packages.platform.0001_stuff_and_junk',
            'unit.server.db.migration_packages.raise_exception.0001_works_fine',
            'unit.server.db.migration_packages.raise_exception.0002_oh_no',
            'unit.server.db.migration_packages.z.0001_test',
            'unit.server.db.migration_packages.z.0002_test',
            'unit.server.db.migration_packages.z.0003_test']
        self.assertEquals(migration_modules_called, expected_migration_modules_called)
        # Assert that our precious versions have been updated correctly
        for package in models.get_migration_packages():
            if package.name != 'unit.server.db.migration_packages.raise_exception':
                self.assertEqual(package.current_version, package.latest_available_version)
            else:
                # The raised Exception should have prevented us from getting past version 1
                self.assertEqual(package.current_version, 1)
开发者ID:aweiteka,项目名称:pulp,代码行数:47,代码来源:test_manage.py

示例5: test_migrate_with_new_packages

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
    def test_migrate_with_new_packages(self, start_logging_mock, logger_mock, mocked_stderr):
        """
        Adding new packages to a system that doesn't have any trackers should advance
        each package to the latest available version, applying all migrate() functions along the way.
        """
        # Make sure we start out with a clean slate
        self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
        # Make sure that our mock works. There are four valid packages.
        self.assertEquals(len(models.get_migration_packages()), 4)
        manage.main()

        for package in models.get_migration_packages():
            if 'raise_exception' in str(package):
                # The Exception raising package should get to version 1, because version 2 raises
                self.assertEqual(package.current_version, 1)
            else:
                # All other packages should reach their top versions
                self.assertEqual(package.current_version, package.latest_available_version)
开发者ID:bartwo,项目名称:pulp,代码行数:20,代码来源:test_pulp_manage_db.py

示例6: test_save

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
 def test_save(self):
     # Make sure we are starting off clean
     self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
     # Instantiate a MigrationTracker
     mt = MigrationTracker('meaning_of_life', 41)
     # At this point there should not be a MigrationTracker in the database
     self.assertEquals(mt._collection.find({}).count(), 0)
     # saving the mt should add it to the DB
     mt.save()
     self.assertEquals(mt._collection.find({}).count(), 1)
     mt_bson = mt._collection.find_one({'name': 'meaning_of_life'})
     self.assertEquals(mt_bson['name'], 'meaning_of_life')
     self.assertEquals(mt_bson['version'], 41)
     # now let's update the version to 42, the correct meaning of life
     mt.version = 42
     mt.save()
     # see if the updated meaning of life made it to the DB
     self.assertEquals(mt._collection.find({}).count(), 1)
     mt_bson = mt._collection.find_one({'name': 'meaning_of_life'})
     self.assertEquals(mt_bson['name'], 'meaning_of_life')
     self.assertEquals(mt_bson['version'], 42)
开发者ID:bartwo,项目名称:pulp,代码行数:23,代码来源:test_pulp_manage_db.py

示例7: test_current_version_too_high

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
 def test_current_version_too_high(self, mocked_file_config, mocked_logger, mocked_stderr):
     """
     Set the current package version higher than latest available version, then sit back and eat
     popcorn.
     """
     # Make sure we start out with a clean slate
     self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
     # Make sure that our mock works. There are four valid packages.
     self.assertEquals(len(models.get_migration_packages()), 4)
     # Set all versions to ridiculously high values
     for package in models.get_migration_packages():
         package._migration_tracker.version = 9999999
         package._migration_tracker.save()
     error_code = manage.main()
     self.assertEqual(error_code, os.EX_DATAERR)
     # There should have been a print to stderr about the Exception
     expected_stderr_calls = [
         'The database for migration package data.test_migration_packages.platform is at ' +\
         'version 9999999, which is larger than the latest version available, 1.', '\n']
     stderr_calls = [call[1][0] for call in mocked_stderr.mock_calls]
     self.assertEquals(stderr_calls, expected_stderr_calls)
开发者ID:bartwo,项目名称:pulp,代码行数:23,代码来源:test_pulp_manage_db.py

示例8: test_migrate_with_new_packages

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
    def test_migrate_with_new_packages(self, mocked_apply_migration):
        """
        Adding new packages to a system that doesn't have any trackers should automatically advance
        each package to the latest available version without calling any migrate() functions.
        """
        # Make sure we start out with a clean slate
        self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
        # Make sure that our mock works. There are three valid packages.
        self.assertEquals(len(models.get_migration_packages()), 4)
        manage.main()
        # No calls to apply_migration should have been made, and we should be at the latest package
        # versions for each of the packages that have valid migrations.
        self.assertFalse(mocked_apply_migration.called)
        for package in models.get_migration_packages():
            self.assertEqual(package.current_version, package.latest_available_version)

        # Calling main() again should still not call apply_migration() or change the versions
        manage.main()
        self.assertFalse(mocked_apply_migration.called)
        for package in models.get_migration_packages():
            self.assertEqual(package.current_version, package.latest_available_version)
开发者ID:ryanschneider,项目名称:pulp,代码行数:23,代码来源:test_pulp_manage_db.py

示例9: test_migrate_with_test_flag

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
 def test_migrate_with_test_flag(self, start_logging_mock, mocked_apply_migration, mocked_stdout,
                                 mocked_stderr):
     """
     Let's set all the packages to be at version 0, and then check that the migrations get called
     in the correct order. We will also set the --test flag and ensure that the migration
     versions do not get updated.
     """
     # Make sure we start out with a clean slate
     self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
     # Make sure that our mock works. There are three valid packages.
     self.assertEquals(len(models.get_migration_packages()), 4)
     # Set all versions back to 0
     for package in models.get_migration_packages():
         package._migration_tracker.version = 0
         package._migration_tracker.save()
     manage.main()
     # There should have been a print to stderr about the Exception
     expected_stderr_calls = [
         ('Applying migration unit.server.db.migration_packages.raise_exception.0002_oh_no '
          'failed.\n\nHalting migrations due to a migration failure.'), ' ', ' See log for details.', '\n',
         'Bet you didn\'t see this coming.', '\n']
     stderr_calls = [mock_call[1][0] for mock_call in mocked_stderr.mock_calls]
     self.assertEquals(stderr_calls, expected_stderr_calls)
     migration_modules_called = [
         mock_call[1][1].name for mock_call in mocked_apply_migration.mock_calls]
     # Note that none of the migrations that don't meet our criteria show up in this list. Also,
     # Note that migration_packages.raise_exception.0003_shouldnt_run doesn't appear
     # since migration_packages.raise_exception.0002_oh_no raised an Exception. Note
     # also that even though the raise_exception package raised an Exception, we still run all
     # the z migrations because we don't want one package to break another.
     expected_migration_modules_called = [
         'unit.server.db.migration_packages.platform.0001_stuff_and_junk',
         'unit.server.db.migration_packages.raise_exception.0001_works_fine',
         'unit.server.db.migration_packages.raise_exception.0002_oh_no']
     self.assertEquals(migration_modules_called, expected_migration_modules_called)
     # Assert that our precious versions have not been updated, since we have the --test flag
     for package in models.get_migration_packages():
         self.assertEqual(package.current_version, 0)
开发者ID:unixbhaskar,项目名称:pulp,代码行数:40,代码来源:test_manage.py

示例10: test_migrate_with_dry_run_flag

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
    def test_migrate_with_dry_run_flag(self, mock_file_config, mocked_apply_migration, getLogger):
        """
        Test that when a dry run is performed, no migrations actually occur.
        """
        logger = MagicMock()
        getLogger.return_value = logger

        # Make sure we start out with a clean slate
        self.assertEquals(MigrationTracker.get_collection().find({}).count(), 0)
        # Make sure that our mock works. There are three valid packages.
        self.assertEquals(len(models.get_migration_packages()), 4)
        # Set all versions back to 0
        for package in models.get_migration_packages():
            package._migration_tracker.version = 0
            package._migration_tracker.save()
        result = manage.main()

        # Test that none of the mock objects were actually called
        migration_modules_called = [
            mock_call[1][1].name for mock_call in mocked_apply_migration.mock_calls]
        self.assertEquals(0, len(migration_modules_called))
        self.assertEquals(1, result)
        for package in models.get_migration_packages():
            self.assertEqual(package.current_version, 0)
开发者ID:hgschmie,项目名称:pulp,代码行数:26,代码来源:test_manage.py

示例11: clean

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
 def clean(self):
     super(MigrationTest, self).clean()
     # Make sure each test doesn't have any lingering MigrationTrackers
     MigrationTracker.get_collection().remove({})
开发者ID:hgschmie,项目名称:pulp,代码行数:6,代码来源:test_manage.py

示例12: test___init__

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
 def test___init__(self):
     self.assertEquals(self.mtm._collection, MigrationTracker.get_collection())
开发者ID:hgschmie,项目名称:pulp,代码行数:4,代码来源:test_manage.py

示例13: test___init__

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
 def test___init__(self):
     mt = MigrationTracker('meaning_of_life', 42)
     self.assertEquals(mt.name, 'meaning_of_life')
     self.assertEquals(mt.version, 42)
     self.assertEquals(mt._collection, MigrationTracker.get_collection())
开发者ID:bartwo,项目名称:pulp,代码行数:7,代码来源:test_pulp_manage_db.py

示例14: __init__

# 需要导入模块: from pulp.server.db.model.migration_tracker import MigrationTracker [as 别名]
# 或者: from pulp.server.db.model.migration_tracker.MigrationTracker import get_collection [as 别名]
 def __init__(self):
     self._collection = MigrationTracker.get_collection()
开发者ID:domcleal,项目名称:pulp,代码行数:4,代码来源:migration_tracker.py


注:本文中的pulp.server.db.model.migration_tracker.MigrationTracker.get_collection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。