Merge "Cleanup code duplication in cinder.cmd.backup module"
This commit is contained in:
commit
0e9ead912e
@ -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()
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user