예제 #1
0
파일: autogen.py 프로젝트: rajamony/neutron
def _migration_script_ops(context, directive, phase):
    """Generate a new ops.MigrationScript() for a given phase.

    E.g. given an ops.MigrationScript() directive from a vanilla autogenerate
    and an expand/contract phase name, produce a new ops.MigrationScript()
    which contains only those sub-directives appropriate to "expand" or
    "contract".  Also ensure that the branch directory exists and that
    the correct branch labels/depends_on/head revision are set up.

    """
    version_path = cli._get_version_branch_path(context.config, phase)
    autogen_kwargs = {}
    cli._check_bootstrap_new_branch(phase, version_path, autogen_kwargs)

    op = ops.MigrationScript(new_rev_id(),
                             ops.UpgradeOps(ops=[
                                 d for d in _assign_directives(
                                     context, directive.upgrade_ops.ops, phase)
                             ]),
                             ops.DowngradeOps(ops=[]),
                             message=directive.message,
                             **autogen_kwargs)

    if not op.upgrade_ops.is_empty():
        return op
예제 #2
0
    def _test_database_sync_revision(self, separate_branches=True):
        with mock.patch.object(cli, 'update_heads_file') as update:
            fake_config = FakeConfig()
            if separate_branches:
                expected_kwargs = [
                    {'message': 'message', 'sql': False, 'autogenerate': True,
                     'version_path':
                         cli._get_version_branch_path(fake_config, branch),
                     'head': cli._get_branch_head(branch)}
                    for branch in cli.MIGRATION_BRANCHES]
            else:
                expected_kwargs = [{
                    'message': 'message', 'sql': False, 'autogenerate': True,
                }]
            self._main_test_helper(
                ['prog', 'revision', '--autogenerate', '-m', 'message'],
                'revision',
                (), expected_kwargs
            )
            update.assert_called_once_with(mock.ANY)
            update.reset_mock()

            for kwarg in expected_kwargs:
                kwarg['autogenerate'] = False
                kwarg['sql'] = True

            self._main_test_helper(
                ['prog', 'revision', '--sql', '-m', 'message'],
                'revision',
                (), expected_kwargs
            )
            update.assert_called_once_with(mock.ANY)
예제 #3
0
    def _test_database_sync_revision(self, separate_branches=True):
        with mock.patch.object(cli, 'update_heads_file') as update,\
                mock.patch.object(cli, '_use_separate_migration_branches',
                                  return_value=separate_branches):
            if separate_branches:
                mock.patch('os.path.exists').start()
                expected_kwargs = [
                    {'message': 'message', 'sql': False, 'autogenerate': True,
                     'version_path':
                         cli._get_version_branch_path(config, branch),
                     'head': cli._get_branch_head(branch)}
                    for config in self.configs
                    for branch in cli.MIGRATION_BRANCHES]
            else:
                expected_kwargs = [{
                    'message': 'message', 'sql': False, 'autogenerate': True,
                }]
            self._main_test_helper(
                ['prog', 'revision', '--autogenerate', '-m', 'message'],
                'revision',
                (), expected_kwargs
            )
            self.assertEqual(len(self.projects), update.call_count)
            update.reset_mock()

            for kwarg in expected_kwargs:
                kwarg['autogenerate'] = False
                kwarg['sql'] = True

            self._main_test_helper(
                ['prog', 'revision', '--sql', '-m', 'message'],
                'revision',
                (), expected_kwargs
            )
            self.assertEqual(len(self.projects), update.call_count)
예제 #4
0
def _migration_script_ops(context, directive, phase):
    """Generate a new ops.MigrationScript() for a given phase.

    E.g. given an ops.MigrationScript() directive from a vanilla autogenerate
    and an expand/contract phase name, produce a new ops.MigrationScript()
    which contains only those sub-directives appropriate to "expand" or
    "contract".  Also ensure that the branch directory exists and that
    the correct branch labels/depends_on/head revision are set up.

    """
    version_path = cli._get_version_branch_path(context.config, phase)
    autogen_kwargs = {}
    cli._check_bootstrap_new_branch(phase, version_path, autogen_kwargs)

    op = ops.MigrationScript(
        new_rev_id(),
        ops.UpgradeOps(ops=[
            d for d in _assign_directives(
                context, directive.upgrade_ops.ops, phase)
        ]),
        ops.DowngradeOps(ops=[]),
        message=directive.message,
        **autogen_kwargs
    )

    if not op.upgrade_ops.is_empty():
        return op
예제 #5
0
    def _test_database_sync_revision(self, separate_branches=True):
        with mock.patch.object(cli, 'update_heads_file') as update,\
                mock.patch.object(cli, '_use_separate_migration_branches',
                                  return_value=separate_branches):
            if separate_branches:
                mock.patch('os.path.exists').start()
                expected_kwargs = [
                    {'message': 'message', 'sql': False, 'autogenerate': True,
                     'version_path':
                         cli._get_version_branch_path(config, branch),
                     'head': cli._get_branch_head(branch)}
                    for config in self.configs
                    for branch in cli.MIGRATION_BRANCHES]
            else:
                expected_kwargs = [{
                    'message': 'message', 'sql': False, 'autogenerate': True,
                }]
            self._main_test_helper(
                ['prog', 'revision', '--autogenerate', '-m', 'message'],
                'revision',
                expected_kwargs
            )
            self.assertEqual(len(self.projects), update.call_count)
            update.reset_mock()

            for kwarg in expected_kwargs:
                kwarg['autogenerate'] = False
                kwarg['sql'] = True

            self._main_test_helper(
                ['prog', 'revision', '--sql', '-m', 'message'],
                'revision',
                expected_kwargs
            )
            self.assertEqual(len(self.projects), update.call_count)
예제 #6
0
    def _test_database_sync_revision(self, separate_branches=True):
        with mock.patch.object(cli, "update_heads_file") as update:

            class FakeConfig(object):
                service = ""

            fake_config = FakeConfig()
            if separate_branches:
                expected_kwargs = [
                    {
                        "message": "message",
                        "sql": False,
                        "autogenerate": True,
                        "version_path": cli._get_version_branch_path(fake_config, branch),
                        "head": cli._get_branch_head(branch),
                    }
                    for branch in cli.MIGRATION_BRANCHES
                ]
            else:
                expected_kwargs = [{"message": "message", "sql": False, "autogenerate": True}]
            self._main_test_helper(
                ["prog", "revision", "--autogenerate", "-m", "message"], "revision", (), expected_kwargs
            )
            update.assert_called_once_with(mock.ANY)
            update.reset_mock()

            for kwarg in expected_kwargs:
                kwarg["autogenerate"] = False
                kwarg["sql"] = True

            self._main_test_helper(["prog", "revision", "--sql", "-m", "message"], "revision", (), expected_kwargs)
            update.assert_called_once_with(mock.ANY)
예제 #7
0
    def _test_database_sync_revision(self, separate_branches=True):
        with mock.patch.object(cli, 'update_heads_file') as update:
            class FakeConfig(object):
                service = ''

            fake_config = FakeConfig()
            if separate_branches:
                expected_kwargs = [
                    {'message': 'message', 'sql': False, 'autogenerate': True,
                     'version_path':
                         cli._get_version_branch_path(fake_config, branch),
                     'head': cli._get_branch_head(branch)}
                    for branch in cli.MIGRATION_BRANCHES]
            else:
                expected_kwargs = [{
                    'message': 'message', 'sql': False, 'autogenerate': True,
                }]
            self._main_test_helper(
                ['prog', 'revision', '--autogenerate', '-m', 'message'],
                'revision',
                (), expected_kwargs
            )
            update.assert_called_once_with(mock.ANY)
            update.reset_mock()

            for kwarg in expected_kwargs:
                kwarg['autogenerate'] = False
                kwarg['sql'] = True

            self._main_test_helper(
                ['prog', 'revision', '--sql', '-m', 'message'],
                'revision',
                (), expected_kwargs
            )
            update.assert_called_once_with(mock.ANY)