From f6c60d1d9c79a8048df7cc63fddb2b081eac430f Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Thu, 29 Nov 2018 12:18:24 +0200 Subject: [PATCH] Cleanup code duplication in cinder.cmd.backup module Change-Id: I758d0cf04e434a82beca8637cbe7e18bfdc02fb2 --- cinder/cmd/backup.py | 20 ++++++-------------- cinder/tests/unit/test_cmd.py | 23 ----------------------- 2 files changed, 6 insertions(+), 37 deletions(-) diff --git a/cinder/cmd/backup.py b/cinder/cmd/backup.py index ffe7cb9460a..d0fdc4c30d3 100644 --- a/cinder/cmd/backup.py +++ b/cinder/cmd/backup.py @@ -69,7 +69,7 @@ def _launch_backup_process(launcher, num_process): try: server = service.Service.create(binary='cinder-backup', coordination=True, - process_number=num_process + 1) + process_number=num_process) except Exception: LOG.exception('Backup service %s failed to start.', CONF.host) sys.exit(1) @@ -97,18 +97,10 @@ def main(): global LOG LOG = logging.getLogger(__name__) - if CONF.backup_workers > 1: - LOG.info('Backup running with %s processes.', CONF.backup_workers) - launcher = service.get_launcher() + LOG.info('Backup running with %s processes.', CONF.backup_workers) + launcher = service.get_launcher() - for i in range(CONF.backup_workers): - _launch_backup_process(launcher, i) + for i in range(1, CONF.backup_workers + 1): + _launch_backup_process(launcher, i) - launcher.wait() - else: - LOG.info('Backup running in single process mode.') - server = service.Service.create(binary='cinder-backup', - coordination=True, - process_number=1) - service.serve(server) - service.wait() + launcher.wait() diff --git a/cinder/tests/unit/test_cmd.py b/cinder/tests/unit/test_cmd.py index 6b748b1822b..db8670d0b1d 100644 --- a/cinder/tests/unit/test_cmd.py +++ b/cinder/tests/unit/test_cmd.py @@ -97,29 +97,6 @@ class TestCinderBackupCmd(test.TestCase): super(TestCinderBackupCmd, self).setUp() sys.argv = ['cinder-backup'] - @mock.patch('cinder.cmd.backup._launch_backup_process') - @mock.patch('cinder.service.wait') - @mock.patch('cinder.service.serve') - @mock.patch('cinder.service.Service.create') - @mock.patch('cinder.utils.monkey_patch') - @mock.patch('oslo_log.log.setup') - def test_main(self, log_setup, monkey_patch, service_create, service_serve, - service_wait, launch_mock): - server = service_create.return_value - - cinder_backup.main() - - self.assertEqual('cinder', CONF.project) - self.assertEqual(CONF.version, version.version_string()) - log_setup.assert_called_once_with(CONF, "cinder") - monkey_patch.assert_called_once_with() - service_create.assert_called_once_with(binary='cinder-backup', - coordination=True, - process_number=1) - service_serve.assert_called_once_with(server) - service_wait.assert_called_once_with() - launch_mock.assert_not_called() - @mock.patch('cinder.service.get_launcher') @mock.patch('cinder.service.Service.create') @mock.patch('cinder.utils.monkey_patch')