Beispiel #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)
Beispiel #2
0
 def test_get_batch_projects(self):
     fake_project_list = ['proj1', 'proj2', 'proj3', 'proj4',
                          'proj5', 'proj6', 'proj7']
     actual_project_list = utils.get_batch_projects(3, fake_project_list)
     self.assertEqual((fake_project_list[0], fake_project_list[1],
                       fake_project_list[2]), actual_project_list.next())
     self.assertEqual((fake_project_list[3], fake_project_list[4],
                       fake_project_list[5]), actual_project_list.next())
     self.assertEqual((fake_project_list[6], None, None),
                      actual_project_list.next())