Exemple #1
0
 def periodic_balance_all(self, engine_id):
     LOG.info(_LI("periodically balance quota for all keystone tenants"))
     lock = kingbird_lock.sync_lock_acquire(self.context, engine_id,
                                            TASK_TYPE)
     if not lock:
         LOG.error(_LE("Not able to acquire lock for %(task_type)s, may"
                       " be Previous sync job has not finished yet, "
                       "Aborting this run at: %(time)s "),
                   {'task_type': TASK_TYPE,
                    'time': time.strftime("%c")}
                   )
         return
     LOG.info(_LI("Successfully acquired lock"))
     projects_thread_list = []
     # Iterate through project list and call sync project for each project
     # using threads
     project_list = sdk.OpenStackDriver().get_enabled_projects()
     # Divide list of projects into batches and perfrom quota sync
     # for one batch at a time.
     for current_batch_projects in utils.get_batch_projects(
             cfg.CONF.batch.batch_size, project_list):
         LOG.info(_LI("Syncing quota for current batch with projects: %s"),
                  current_batch_projects)
         for current_project in current_batch_projects:
             if current_project:
                 thread = threading.Thread(
                     target=self.quota_sync_for_project,
                     args=(current_project,))
                 projects_thread_list.append(thread)
                 thread.start()
             # Wait for all the threads to complete
             # the job(sync all projects quota)
             for current_thread in projects_thread_list:
                 current_thread.join()
     kingbird_lock.sync_lock_release(self.context, engine_id, TASK_TYPE)
 def test_sync_lock_acquire_fail(self, mock_db_api):
     mock_db_api.sync_lock_acquire.return_value = False
     expected_value = kingbird_lock.sync_lock_acquire(
         self.context, FAKE_ENGINE_ID, FAKE_TASK_TYPE)
     self.assertEqual(expected_value, False)
 def test_sync_lock_acquire_force_yes(self, mock_db_api):
     mock_db_api.sync_lock_acquire.return_value = False
     mock_db_api.db_api.sync_lock_steal.return_value = True
     expected_value = kingbird_lock.sync_lock_acquire(
         self.context, FAKE_ENGINE_ID, FAKE_TASK_TYPE, True)
     self.assertEqual(expected_value, True)
 def test_sync_lock_acquire(self, mock_db_api):
     mock_db_api.sync_lock_acquire.return_value = "Fake Record"
     expected_value = kingbird_lock.sync_lock_acquire(
         self.context, FAKE_ENGINE_ID, FAKE_TASK_TYPE)
     self.assertEqual(expected_value, True)
 def test_sync_lock_acquire_fail(self, mock_db_api):
     mock_db_api.sync_lock_acquire.return_value = False
     expected_value = kingbird_lock.sync_lock_acquire(
         self.context, FAKE_ENGINE_ID, FAKE_TASK_TYPE)
     self.assertEqual(expected_value, False)
 def test_sync_lock_acquire_force_yes(self, mock_db_api):
     mock_db_api.sync_lock_acquire.return_value = False
     mock_db_api.db_api.sync_lock_steal.return_value = True
     expected_value = kingbird_lock.sync_lock_acquire(
         self.context, FAKE_ENGINE_ID, FAKE_TASK_TYPE, True)
     self.assertEqual(expected_value, True)
 def test_sync_lock_acquire(self, mock_db_api):
     mock_db_api.sync_lock_acquire.return_value = "Fake Record"
     expected_value = kingbird_lock.sync_lock_acquire(
         self.context, FAKE_ENGINE_ID, FAKE_TASK_TYPE)
     self.assertEqual(expected_value, True)