def _take_action(self, parsed_args): from oio.rdir.client import RdirDispatcher self.logger.debug("Checking rdir services.") # Load the assigned rdir services client = RdirDispatcher({"namespace": self.app.options.ns}) # rawx all_rawx, all_rdir = client.get_assignments('rawx') assert not any(r['rdir'] is None for r in all_rawx) self.logger.info("All rawx services have an rdir service assigned.") # meta2 all_meta2, all_rdir = client.get_assignments('meta2') assert not any(r['rdir'] is None for r in all_meta2) self.logger.info("All meta2 services have an rdir service assigned.") # Compare with the number of expected services l0 = list(self.filter_services(self.live, 'rdir')) c0 = list(self.filter_services(self.catalog, 'rdir')) assert len(l0) == len(c0) assert len(l0) == len(all_rdir) self.logger.info("All rdir services are alive.") yield ('OK', None)
def test_rdir_repartition(self): client = RdirDispatcher({'namespace': self.ns}) all_rawx = client.assign_all_rawx() by_rdir = dict() total = 0 for rawx in all_rawx: count = by_rdir.get(rawx['rdir']['addr'], 0) total += 1 by_rdir[rawx['rdir']['addr']] = count + 1 avg = total / float(len(by_rdir)) print "Ideal number of bases per rdir: ", avg print "Current repartition: ", by_rdir for count in by_rdir.itervalues(): self.assertLessEqual(count, avg + 1)
def rdir_dispatcher(self): if self._rdir_dispatcher is None: from oio.rdir.client import RdirDispatcher self._rdir_dispatcher = RdirDispatcher( self.client_conf, rdir_client=self.rdir, pool_manager=self.pool_manager) return self._rdir_dispatcher
def test_link_rdir_unachievable_min_dist(self): disp = RdirDispatcher({'namespace': self.ns}, pool_manager=self.http_pool) # Register a service, with score locked to zero new_rawx = self._srv('rawx', {'tag.loc': _fake_location}) new_rawx['score'] = 90 self._register_srv(new_rawx) self._reload_proxy() self.assertRaises(exc.OioException, disp.assign_all_rawx, min_dist=4) all_rawx, _ = disp.get_assignments('rawx') all_rawx_keys = [x['addr'] for x in all_rawx] self.assertIn(new_rawx['addr'], all_rawx_keys) self.assertRaises(exc.VolumeException, disp.rdir._get_rdir_addr, new_rawx['addr'])
def test_rdir_repartition(self): # FIXME(FVE): this test will fail if run after self._flush_cs('rawx') client = RdirDispatcher({'namespace': self.ns}) self._reload_proxy() all_rawx = client.assign_all_rawx() self.assertGreater(len(all_rawx), 0) by_rdir = dict() total = 0 for rawx in all_rawx: count = by_rdir.get(rawx['rdir']['addr'], 0) total += 1 by_rdir[rawx['rdir']['addr']] = count + 1 avg = total / float(len(by_rdir)) print("Ideal number of bases per rdir: ", avg) print("Current repartition: ", by_rdir) for count in by_rdir.values(): self.assertLessEqual(count, avg + 1)
def _test_link_rdir_fail_to_force(self, side_effects, expected_exc): disp = RdirDispatcher({'namespace': self.ns}) # Mock rdir and rawx services so we do not pollute following tests all_srvs = self._generate_services({'rdir': 3, 'rawx': 3}) def _all_services(type_, *args, **kwargs): """Return all mocked services of specified type""" return all_srvs[type_] def _poll(*args, **kwargs): """Pick one mocked random service""" return [random.choice(all_srvs['rdir'])] disp.cs.all_services = Mock(side_effect=_all_services) disp.cs.poll = Mock(side_effect=_poll) # Mock the check method to avoid calling the proxy disp.directory.list = Mock(side_effect=exc.NotFound) # Mock the assignation methods so we can check the calls disp._smart_link_rdir = \ Mock(wraps=disp._smart_link_rdir) disp.directory.force = \ Mock(wraps=disp.directory.force, side_effect=side_effects) # Expect an exception since some assignations will fail self.assertRaises(expected_exc, disp.assign_all_rawx, max_attempts=1) # But ensure all calls have been made link_calls = [ call(rawx['addr'], ANY, max_per_rdir=ANY, max_attempts=1, min_dist=ANY, service_type='rawx', reassign=False) for rawx in all_srvs['rawx'] ] disp._smart_link_rdir.assert_has_calls(link_calls) force_calls = \ [call(RDIR_ACCT, rawx['addr'], 'rdir', ANY, autocreate=True, replace=ANY) for rawx in all_srvs['rawx']] disp.directory.force.assert_has_calls(force_calls)
def test_link_rdir_to_zero_scored_rawx(self): client = RdirClient({'namespace': self.ns}) disp = RdirDispatcher({'namespace': self.ns}) # Register a service, with score locked to zero new_rawx = self._srv('rawx', {'tag.loc': 'whatever'}) new_rawx['score'] = 0 self._register_srv(new_rawx) self._reload_proxy() all_rawx = disp.assign_all_rawx() all_rawx_keys = [x['addr'] for x in all_rawx] self.assertIn(new_rawx['addr'], all_rawx_keys) rdir_addr = client._get_rdir_addr(new_rawx['addr']) self.assertIsNotNone(rdir_addr) try: self.api.unlink('_RDIR', new_rawx['addr'], 'rdir') self.api.delete('_RDIR', new_rawx['addr']) # self._flush_cs('rawx') except Exception: pass
def test_link_rdir_to_zero_scored_rawx(self): disp = RdirDispatcher({'namespace': self.ns}, pool_manager=self.http_pool) # Register a service, with score locked to zero new_rawx = self._srv('rawx', {'tag.loc': _fake_location}) new_rawx['score'] = 0 self._register_srv(new_rawx) self._reload_proxy() all_rawx = disp.assign_all_rawx() all_rawx_keys = [x['addr'] for x in all_rawx] self.assertIn(new_rawx['addr'], all_rawx_keys) rdir_addr = disp.rdir._get_rdir_addr(new_rawx['addr']) self.assertIsNotNone(rdir_addr) try: self.api.unlink(RDIR_ACCT, new_rawx['addr'], 'rdir') self.api.delete(RDIR_ACCT, new_rawx['addr']) # self._flush_cs('rawx') except Exception: pass
def rdir_lb(self): if not self._rdir_lb: from oio.rdir.client import RdirDispatcher self._rdir_lb = RdirDispatcher(self.conf) return self._rdir_lb
def rdir_lb(self): if not self._rdir_lb: from oio.rdir.client import RdirDispatcher self._rdir_lb = RdirDispatcher(self.conf, pool_manager=self.pool_manager) return self._rdir_lb
def rdir_lb(self): if not self._rdir_lb: self._rdir_lb = RdirDispatcher(self.conf, session=self.session) return self._rdir_lb