Cleanup code duplication in cinder.cmd.backup module
Change-Id: I758d0cf04e434a82beca8637cbe7e18bfdc02fb2
This commit is contained in:
		@@ -69,7 +69,7 @@ def _launch_backup_process(launcher, num_process):
 | 
				
			|||||||
    try:
 | 
					    try:
 | 
				
			||||||
        server = service.Service.create(binary='cinder-backup',
 | 
					        server = service.Service.create(binary='cinder-backup',
 | 
				
			||||||
                                        coordination=True,
 | 
					                                        coordination=True,
 | 
				
			||||||
                                        process_number=num_process + 1)
 | 
					                                        process_number=num_process)
 | 
				
			||||||
    except Exception:
 | 
					    except Exception:
 | 
				
			||||||
        LOG.exception('Backup service %s failed to start.', CONF.host)
 | 
					        LOG.exception('Backup service %s failed to start.', CONF.host)
 | 
				
			||||||
        sys.exit(1)
 | 
					        sys.exit(1)
 | 
				
			||||||
@@ -97,18 +97,10 @@ def main():
 | 
				
			|||||||
    global LOG
 | 
					    global LOG
 | 
				
			||||||
    LOG = logging.getLogger(__name__)
 | 
					    LOG = logging.getLogger(__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if CONF.backup_workers > 1:
 | 
					    LOG.info('Backup running with %s processes.', CONF.backup_workers)
 | 
				
			||||||
        LOG.info('Backup running with %s processes.', CONF.backup_workers)
 | 
					    launcher = service.get_launcher()
 | 
				
			||||||
        launcher = service.get_launcher()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for i in range(CONF.backup_workers):
 | 
					    for i in range(1, CONF.backup_workers + 1):
 | 
				
			||||||
            _launch_backup_process(launcher, i)
 | 
					        _launch_backup_process(launcher, i)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        launcher.wait()
 | 
					    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()
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -97,29 +97,6 @@ class TestCinderBackupCmd(test.TestCase):
 | 
				
			|||||||
        super(TestCinderBackupCmd, self).setUp()
 | 
					        super(TestCinderBackupCmd, self).setUp()
 | 
				
			||||||
        sys.argv = ['cinder-backup']
 | 
					        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.get_launcher')
 | 
				
			||||||
    @mock.patch('cinder.service.Service.create')
 | 
					    @mock.patch('cinder.service.Service.create')
 | 
				
			||||||
    @mock.patch('cinder.utils.monkey_patch')
 | 
					    @mock.patch('cinder.utils.monkey_patch')
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user