def sync(self, force_sync=False): """Synchronize members, config, and mapping between NIOS and neutron. First sync members, then config, and lastly mapping because config sync needs GM info and mapping needs grid config. """ session = self.grid_config.context.session allow_sync = False if self.grid_config.grid_sync_support: interval = self.grid_config.grid_sync_minimum_wait_time if force_sync or self.is_sync_needed(interval): allow_sync = True if allow_sync: self.member.sync() self.grid_config.sync() self.mapping.sync() self.last_sync_time = datetime.utcnow().replace(microsecond=0) dbi.record_last_sync_time(session, self.last_sync_time) self._report_sync_time() LOG.info("Infoblox grid has been synced up.")
def test_grid_operations(self): # 'last_sync_time' operation type does not exist so it will add it last_sync_time = infoblox_db.get_last_sync_time(self.ctx.session) self.assertIsNone(last_sync_time) # 'last_sync_time' should exist now but its value should be None last_sync_time = infoblox_db.get_last_sync_time(self.ctx.session) self.assertIsNone(last_sync_time) # attempt to add 'last_sync_time' operation type should fail with # DBDuplicateEntry exception try: infoblox_db.add_operation_type(self.ctx.session, 'last_sync_time', '') self.ctx.session.flush() except db_exc.DBDuplicateEntry as db_err: self.assertIsInstance(db_err, db_exc.DBDuplicateEntry) # test record_last_sync_time current_time = datetime.utcnow().replace(microsecond=0) infoblox_db.record_last_sync_time(self.ctx.session, current_time) last_sync_time = infoblox_db.get_last_sync_time(self.ctx.session) self.assertEqual(current_time, last_sync_time)