コード例 #1
0
    def test_on_success(self, glob_mock, utils_mock):
        upgrader = UpgradeManager(**self.default_args())
        upgrader._on_success()

        glob_mock.assert_called_once_with(self.fake_config.version_files_mask)
        self.assertEqual(
            utils_mock.remove.call_args_list,
            [mock.call('file1'), mock.call('file2')])

        templates_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '../templates'))
        utils_mock.render_template_to_file.assert_has_calls([
            mock.call(
                '{0}/nailgun.repo'.format(templates_path),
                '/etc/yum.repos.d/mos9999-updates.repo', {
                    'name': 'mos9999-updates',
                    'baseurl': 'http://mirror.fuel-infra.org/mos-repos/'
                    'centos/mos9999-centos6-fuel/updates/x86_64/',
                    'gpgcheck': 0,
                    'skip_if_unavailable': 1,
                }),
            mock.call(
                '{0}/nailgun.repo'.format(templates_path),
                '/etc/yum.repos.d/mos9999-security.repo', {
                    'name': 'mos9999-security',
                    'baseurl': 'http://mirror.fuel-infra.org/mos-repos/'
                    'centos/mos9999-centos6-fuel/security/x86_64/',
                    'gpgcheck': 0,
                    'skip_if_unavailable': 1,
                }),
        ])
コード例 #2
0
ファイル: test_upgrade_manager.py プロジェクト: Axam/fuel-web
    def test_upgrade_run_on_success_methods(self):
        engines = [mock.Mock(), mock.Mock(), mock.Mock()]
        upgrader = UpgradeManager(**self.default_args(upgraders=engines))
        upgrader.run()

        for engine in engines:
            self.called_once(engine.on_success)
コード例 #3
0
def run_upgrade(args):
    """Run upgrade on master node

    :param args: argparse object
    """
    # Get admin password
    if not args.password:
        args.password = getpass.getpass('Admin Password: '******'Configuration data: %s', config)

    # Initialize upgrade engines
    upgraders_to_use = [
        SUPPORTED_SYSTEMS[system](config) for system in args.systems
    ]

    # Initialize checkers
    if not args.no_checker:
        checker_manager = CheckerManager(upgraders_to_use, config)
        checker_manager.check()

    # Initialize pre upgrade hook manager
    hook_manager = PreUpgradeHookManager(upgraders_to_use, config)
    hook_manager.run()

    # Initialize upgrade manager with engines and checkers
    upgrade_manager = UpgradeManager(upgraders_to_use, args.no_rollback)
    upgrade_manager.run()
コード例 #4
0
    def test_run_backup_for_all_engines(self):
        upgrader = UpgradeManager(**self.default_args(
            upgraders=[mock.Mock(), mock.Mock()], ))
        upgrader.run()

        self.called_once(upgrader._upgraders[0].backup)
        self.called_once(upgrader._upgraders[1].backup)
コード例 #5
0
    def test_upgrade_succed(self):
        upgrader = UpgradeManager(**self.default_args())
        engine_mock = upgrader._upgraders[0]
        upgrader.run()

        engine_mock.upgrade.assert_called_once_with()
        self.method_was_not_called(engine_mock.rollback)
コード例 #6
0
    def test_upgrade_run_on_success_methods(self):
        engines = [mock.Mock(), mock.Mock(), mock.Mock()]
        upgrader = UpgradeManager(**self.default_args(upgraders=engines))
        upgrader.run()

        for engine in engines:
            self.called_once(engine.on_success)
コード例 #7
0
    def test_upgrade_succed(self):
        upgrader = UpgradeManager(**self.default_args())
        engine_mock = upgrader._upgraders[0]
        upgrader.run()

        engine_mock.upgrade.assert_called_once_with()
        self.method_was_not_called(engine_mock.rollback)
コード例 #8
0
def run_upgrade(args):
    """Run upgrade on master node

    :param args: argparse object
    """
    # Get admin password
    if not args.password:
        args.password = getpass.getpass('Admin Password: '******'Configuration data: %s', config)

    # Initialize upgrade engines
    upgraders_to_use = [
        SUPPORTED_SYSTEMS[system](config)
        for system in args.systems]

    # Initialize checkers
    if not args.no_checker:
        checker_manager = CheckerManager(upgraders_to_use, config)
        checker_manager.check()

    # Initialize pre upgrade hook manager
    hook_manager = PreUpgradeHookManager(upgraders_to_use, config)
    hook_manager.run()

    # Initialize upgrade manager with engines and checkers
    upgrade_manager = UpgradeManager(
        upgraders_to_use, config, args.no_rollback)
    upgrade_manager.run()
コード例 #9
0
ファイル: cli.py プロジェクト: romcheg/fuel-web
def run_upgrade(args):
    """Run upgrade on master node

    :param args: argparse object
    """
    # Initialize config
    config = build_config(args.src)
    logger.debug('Configuration data: {0}'.format(config))

    # Initialize upgrade engines
    upgraders_to_use = [
        SUPPORTED_SYSTEMS[system](config) for system in args.systems
    ]

    # Initialize checkers
    if not args.no_checker:
        checker_manager = CheckerManager(upgraders_to_use, config)
        checker_manager.check()

    # Initialize pre upgrade hook manager
    hook_manager = PreUpgradeHookManager(upgraders_to_use, config)
    hook_manager.run()

    # Initialize upgrade manager with engines and checkers
    upgrade_manager = UpgradeManager(upgraders_to_use, args.no_rollback)
    upgrade_manager.run()
コード例 #10
0
    def test_checkers_are_called(self):
        upgrader = UpgradeManager(**self.default_args())
        checkers_mock = upgrader._checkers
        upgrader.before_upgrade()

        for checker_mock in checkers_mock:
            self.called_once(checker_mock.check)
コード例 #11
0
    def test_on_success(self, glob_mock, utils_mock):
        upgrader = UpgradeManager(**self.default_args())
        upgrader._on_success()

        glob_mock.assert_called_once_with(self.fake_config.version_files_mask)
        self.assertEqual(
            utils_mock.remove.call_args_list,
            [mock.call('file1'), mock.call('file2')])

        templates_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '../templates'))
        utils_mock.render_template_to_file.assert_has_calls([
            mock.call(
                '{0}/nailgun.repo'.format(templates_path),
                '/etc/yum.repos.d/mos9999-updates.repo',
                {
                    'name': 'mos9999-updates',
                    'baseurl': 'http://mirror.fuel-infra.org/mos-repos/'
                               'centos/mos9999-centos6-fuel/updates/x86_64/',
                    'gpgcheck': 0,
                    'skip_if_unavailable': 1,
                }),
            mock.call(
                '{0}/nailgun.repo'.format(templates_path),
                '/etc/yum.repos.d/mos9999-security.repo',
                {
                    'name': 'mos9999-security',
                    'baseurl': 'http://mirror.fuel-infra.org/mos-repos/'
                               'centos/mos9999-centos6-fuel/security/x86_64/',
                    'gpgcheck': 0,
                    'skip_if_unavailable': 1,
                }),
        ])
コード例 #12
0
ファイル: cli.py プロジェクト: Axam/nsx-web
def run_upgrade(args):
    """Run upgrade on master node

    :param args: argparse object
    """
    # Initialize config
    config = build_config(args.src)
    logger.debug('Configuration data: {0}'.format(config))

    # Initialize upgrade engines
    upgraders_to_use = [
        SUPPORTED_SYSTEMS[system](config)
        for system in args.systems]

    # Initialize checkers
    if not args.no_checker:
        checker_manager = CheckerManager(upgraders_to_use, config)
        checker_manager.check()

    # Initialize pre upgrade hook manager
    hook_manager = PreUpgradeHookManager(upgraders_to_use, config)
    hook_manager.run()

    # Initialize upgrade manager with engines and checkers
    upgrade_manager = UpgradeManager(upgraders_to_use, args.no_rollback)
    upgrade_manager.run()
コード例 #13
0
    def test_on_success(self, glob_mock, utils_mock):
        upgrader = UpgradeManager(**self.default_args())
        upgrader._on_success()

        glob_mock.assert_called_once_with(self.fake_config.version_files_mask)
        self.assertEqual(
            utils_mock.remove.call_args_list,
            [mock.call('file1'), mock.call('file2')])
コード例 #14
0
    def test_run_backup_for_all_engines(self):
        upgrader = UpgradeManager(**self.default_args(
            upgraders=[mock.Mock(), mock.Mock()],
        ))
        upgrader.run()

        self.called_once(upgrader._upgraders[0].backup)
        self.called_once(upgrader._upgraders[1].backup)
コード例 #15
0
    def test_upgrade_does_not_fail_if_on_success_method_raise_error(self):
        error_engine = mock.Mock()
        error_engine.on_success.side_effect = Exception('error')
        engines = [mock.Mock(), error_engine, mock.Mock()]
        upgrader = UpgradeManager(**self.default_args(upgraders=engines))
        upgrader.run()

        for engine in engines:
            self.called_once(engine.on_success)
コード例 #16
0
ファイル: test_upgrade_manager.py プロジェクト: Axam/fuel-web
    def test_upgrade_does_not_fail_if_on_success_method_raise_error(self):
        error_engine = mock.Mock()
        error_engine.on_success.side_effect = Exception('error')
        engines = [mock.Mock(), error_engine, mock.Mock()]
        upgrader = UpgradeManager(**self.default_args(upgraders=engines))
        upgrader.run()

        for engine in engines:
            self.called_once(engine.on_success)
コード例 #17
0
    def test_run_upgrade_for_all_engines(self):
        upgrader = UpgradeManager(**self.default_args(
            upgraders=[mock.Mock(), mock.Mock()], ))
        upgrader.run()

        self.called_once(upgrader._upgraders[0].upgrade)
        self.method_was_not_called(upgrader._upgraders[0].rollback)

        self.called_once(upgrader._upgraders[1].upgrade)
        self.method_was_not_called(upgrader._upgraders[1].rollback)
コード例 #18
0
    def test_upgrade_succed(self):
        upgrader = UpgradeManager(**self.default_args())
        engine_mock = upgrader._upgraders[0]
        upgrader.run()

        engine_mock.upgrade.assert_called_once_with()
        self.method_was_not_called(engine_mock.rollback)

        self.called_once(self.version_mock.save_current)
        self.called_once(self.version_mock.switch_to_new)
        self.method_was_not_called(self.version_mock.switch_to_previous)
コード例 #19
0
    def test_upgrade_succed(self):
        upgrader = UpgradeManager(**self.default_args())
        engine_mock = upgrader._upgraders[0]
        upgrader.run()

        engine_mock.upgrade.assert_called_once_with()
        self.method_was_not_called(engine_mock.rollback)

        self.called_once(self.version_mock.save_current)
        self.called_once(self.version_mock.switch_to_new)
        self.method_was_not_called(self.version_mock.switch_to_previous)
コード例 #20
0
    def test_run_upgrade_for_all_engines(self):
        upgrader = UpgradeManager(**self.default_args(
            upgraders=[mock.Mock(), mock.Mock()],
        ))
        upgrader.run()

        self.called_once(upgrader._upgraders[0].upgrade)
        self.method_was_not_called(upgrader._upgraders[0].rollback)

        self.called_once(upgrader._upgraders[1].upgrade)
        self.method_was_not_called(upgrader._upgraders[1].rollback)
コード例 #21
0
    def test_does_not_run_rollback_if_disabled(self):
        upgrader = UpgradeManager(**self.default_args(no_rollback=True))
        engine_mock = upgrader._upgraders[0]
        engine_mock.upgrade.side_effect = Exception('Upgrade failed')
        self.assertRaisesRegexp(Exception, 'Upgrade failed', upgrader.run)

        engine_mock.upgrade.assert_called_once_with()
        self.method_was_not_called(engine_mock.rollback)
コード例 #22
0
    def test_run_rollback_in_case_of_errors(self):
        upgrader = UpgradeManager(**self.default_args())
        engine_mock = upgrader._upgraders[0]
        engine_mock.upgrade.side_effect = Exception('Upgrade failed')
        self.assertRaisesRegexp(Exception, 'Upgrade failed', upgrader.run)

        engine_mock.upgrade.assert_called_once_with()
        engine_mock.rollback.assert_called_once_with()
コード例 #23
0
    def test_run_backup_fails(self):
        upgrader = UpgradeManager(**self.default_args(
            upgraders=[mock.Mock(), mock.Mock()], ))
        upgrader._upgraders[1].backup.side_effect = Exception('Backup fails')
        self.assertRaisesRegexp(Exception, 'Backup fails', upgrader.run)

        self.called_once(upgrader._upgraders[0].backup)
        self.called_once(upgrader._upgraders[1].backup)

        self.method_was_not_called(upgrader._upgraders[0].rollback)
        self.method_was_not_called(upgrader._upgraders[1].rollback)
コード例 #24
0
    def test_hostsystem_rollback_is_first(self, _):
        args = self.default_args()

        hostsystem = HostSystemUpgrader(args['config'])
        hostsystem.upgrade = mock.Mock()
        hostsystem.rollback = mock.Mock()

        def check_call():
            hostsystem.rollback.assert_called_once_with()

        # there's no way to check call order of different mocks, so
        # let's use this trick - check that all mock calls were
        # after hostsystem rollback call.
        args['upgraders'] = [
            hostsystem,
            mock.Mock(rollback=mock.Mock(side_effect=check_call)),
            mock.Mock(rollback=mock.Mock(side_effect=check_call))]

        upgrader = UpgradeManager(**args)
        upgrader._used_upgraders = args['upgraders']
        upgrader.rollback()
コード例 #25
0
    def test_run_rollback_in_case_of_errors(self):
        upgrader = UpgradeManager(**self.default_args())
        engine_mock = upgrader._upgraders[0]
        engine_mock.upgrade.side_effect = Exception('Upgrade failed')
        self.assertRaisesRegexp(Exception, 'Upgrade failed', upgrader.run)

        self.called_once(self.version_mock.save_current)
        self.called_once(self.version_mock.switch_to_new)

        engine_mock.upgrade.assert_called_once_with()
        engine_mock.rollback.assert_called_once_with()

        self.called_once(self.version_mock.switch_to_previous)
コード例 #26
0
    def test_hostsystem_rollback_is_first(self, _):
        args = self.default_args()

        hostsystem = HostSystemUpgrader(args['config'])
        hostsystem.upgrade = mock.Mock()
        hostsystem.rollback = mock.Mock()

        def check_call():
            hostsystem.rollback.assert_called_once_with()

        # there's no way to check call order of different mocks, so
        # let's use this trick - check that all mock calls were
        # after hostsystem rollback call.
        args['upgraders'] = [
            hostsystem,
            mock.Mock(rollback=mock.Mock(side_effect=check_call)),
            mock.Mock(rollback=mock.Mock(side_effect=check_call))
        ]

        upgrader = UpgradeManager(**args)
        upgrader._used_upgraders = args['upgraders']
        upgrader.rollback()
コード例 #27
0
    def test_run_rollback_for_used_engines(self):
        upgrader = UpgradeManager(**self.default_args(upgraders=[
            mock.Mock(), mock.Mock(), mock.Mock()
        ], ))
        upgrader._upgraders[1].upgrade.side_effect = Exception('Failed')

        self.assertRaisesRegexp(Exception, 'Failed', upgrader.run)

        self.called_once(upgrader._upgraders[0].upgrade)
        self.called_once(upgrader._upgraders[0].rollback)

        self.called_once(upgrader._upgraders[1].upgrade)
        self.called_once(upgrader._upgraders[1].rollback)

        self.method_was_not_called(upgrader._upgraders[2].upgrade)
        self.method_was_not_called(upgrader._upgraders[2].rollback)
コード例 #28
0
    def test_before_upgrade_is_called(self):
        upgrader = UpgradeManager(**self.default_args())
        upgrader.before_upgrade = mock.Mock()
        upgrader.run()

        self.called_once(upgrader.before_upgrade)
コード例 #29
0
    def test_upgrade_run_on_success_methods(self):
        upgrader = UpgradeManager(**self.default_args())
        upgrader._on_success = mock.Mock()
        upgrader.run()

        self.called_once(upgrader._on_success)
コード例 #30
0
    def test_upgrade_run_on_success_methods(self):
        upgrader = UpgradeManager(**self.default_args())
        upgrader._on_success = mock.Mock()
        upgrader.run()

        self.called_once(upgrader._on_success)
コード例 #31
0
 def test_upgrade_does_not_fail_if_on_success_method_raise_error(self):
     upgrader = UpgradeManager(**self.default_args())
     upgrader._on_success = mock.Mock()
     upgrader._on_success.side_effect = Exception('error')
     upgrader.run()
コード例 #32
0
 def test_upgrade_does_not_fail_if_on_success_method_raise_error(self):
     upgrader = UpgradeManager(**self.default_args())
     upgrader._on_success = mock.Mock()
     upgrader._on_success.side_effect = Exception('error')
     upgrader.run()