def test_decommission(self): n = 20 replicas = 3 self.cs_client.generate_services(n, locations=7) mapping = PrefixMapping(self.ns, replicas=replicas, conscience_client=self.cs_client) mapping.bootstrap() mapping.rebalance() self.assertTrue(mapping.check_replicas()) n_pfx_by_svc = mapping.count_pfx_by_svc() ideal = PrefixMapping.TOTAL_PREFIXES * replicas / n arange = range(int(ideal * 0.95), int(ideal * 1.05)) print "Ideal: ", ideal for svc1, count in n_pfx_by_svc.iteritems(): print svc1, count svc = mapping.services.values()[0] svc["score"] = 0 print "Decommissioning ", svc["addr"] mapping.decommission(svc) self.assertTrue(mapping.check_replicas()) ideal = PrefixMapping.TOTAL_PREFIXES * replicas / (n - 1) arange = range(int(ideal * 0.95), int(ideal * 1.05)) print "Ideal: ", ideal n_pfx_by_svc = mapping.count_pfx_by_svc() for svc1, count in n_pfx_by_svc.iteritems(): print svc1, count for svc1, count in n_pfx_by_svc.iteritems(): if svc1 == svc["addr"]: self.assertEqual(0, count) else: self.assertIn(count, arange)
def test_decommission(self): n = 20 replicas = 3 self.cs_client.generate_services(n, locations=7) mapping = PrefixMapping(self.m0_client, self.cs_client, replicas=replicas) mapping.bootstrap() mapping.rebalance() self.assertTrue(mapping.check_replicas()) n_pfx_by_svc = mapping.count_pfx_by_svc() ideal = PrefixMapping.TOTAL_PREFIXES * replicas / n arange = range(int(ideal * 0.95), int(ideal * 1.05)) print "Ideal: ", ideal for svc1, count in n_pfx_by_svc.iteritems(): print svc1, count svc = mapping.services.values()[0] svc["score"] = 0 print "Decommissioning ", svc["addr"] mapping.decommission(svc) self.assertTrue(mapping.check_replicas()) ideal = PrefixMapping.TOTAL_PREFIXES * replicas / (n-1) arange = range(int(ideal * 0.95), int(ideal * 1.05)) print "Ideal: ", ideal n_pfx_by_svc = mapping.count_pfx_by_svc() for svc1, count in n_pfx_by_svc.iteritems(): print svc1, count for svc1, count in n_pfx_by_svc.iteritems(): if svc1 == svc["addr"]: self.assertEqual(0, count) else: self.assertIn(count, arange)
def test_bootstrap_3_services_rebalanced(self): self.cs_client.generate_services(3) mapping = PrefixMapping(self.ns, conscience_client=self.cs_client) mapping.bootstrap() mapping.rebalance() n_pfx_by_svc = mapping.count_pfx_by_svc() for count in n_pfx_by_svc.itervalues(): self.assertEqual(PrefixMapping.TOTAL_PREFIXES, count)
def test_bootstrap_3_services_rebalanced(self): self.cs_client.generate_services(3) mapping = PrefixMapping(self.m0_client, self.cs_client) mapping.bootstrap() mapping.rebalance() n_pfx_by_svc = mapping.count_pfx_by_svc() for count in n_pfx_by_svc.itervalues(): self.assertEqual(PrefixMapping.TOTAL_PREFIXES, count)
def test_bootstrap_20_services_rebalanced(self): n = 20 replicas = 3 self.cs_client.generate_services(n, locations=7) mapping = PrefixMapping(self.m0_client, self.cs_client, replicas=replicas) mapping.bootstrap() mapping.rebalance() self.assertTrue(mapping.check_replicas()) n_pfx_by_svc = mapping.count_pfx_by_svc() ideal = PrefixMapping.TOTAL_PREFIXES * replicas / n arange = range(int(ideal * 0.95), int(ideal * 1.05)) print "Ideal: ", ideal for count in n_pfx_by_svc.itervalues(): self.assertIn(count, arange)
def test_bootstrap_20_services_rebalanced(self): n = 20 replicas = 3 self.cs_client.generate_services(n, locations=7) mapping = PrefixMapping(self.ns, replicas=replicas, conscience_client=self.cs_client) mapping.bootstrap() mapping.rebalance() self.assertTrue(mapping.check_replicas()) n_pfx_by_svc = mapping.count_pfx_by_svc() ideal = PrefixMapping.TOTAL_PREFIXES * replicas / n arange = range(int(ideal * 0.95), int(ideal * 1.05)) print "Ideal: ", ideal for count in n_pfx_by_svc.itervalues(): self.assertIn(count, arange)