Exemplo n.º 1
0
 def test_distribution_three_replicas(self):
     hosts = ['foo', 'bar', 'baz']
     ring = hash_ring.HashRing(hosts, replicas=3)
     fake_1_hosts = ring.get_hosts('fake')
     fake_2_hosts = ring.get_hosts('fake-again')
     # We should have two hosts for each thing
     self.assertThat(fake_1_hosts, matchers.HasLength(3))
     self.assertThat(fake_2_hosts, matchers.HasLength(3))
     # And they must not be the same answers even on this simple data
     # because if they were we'd be making the active replica a hot spot.
     self.assertNotEqual(fake_1_hosts, fake_2_hosts)
     self.assertNotEqual(fake_1_hosts[0], fake_2_hosts[0])
Exemplo n.º 2
0
    def test__hash2int_returns_int(self, mock_md5):
        CONF.set_override('hash_partition_exponent', 0)
        r1 = 32 * 'a'
        r2 = 32 * 'b'
        mock_md5.return_value.hexdigest.side_effect = [r1, r2]

        hosts = ['foo', 'bar']
        replicas = 1
        ring = hash_ring.HashRing(hosts, replicas=replicas)

        self.assertIn(int(r1, 16), ring._host_hashes)
        self.assertIn(int(r2, 16), ring._host_hashes)
Exemplo n.º 3
0
 def test_ignore_hosts(self):
     hosts = ['foo', 'bar', 'baz']
     ring = hash_ring.HashRing(hosts, replicas=1)
     equals_bar_or_baz = matchers.MatchesAny(
         matchers.Equals(['bar']),
         matchers.Equals(['baz']))
     self.assertThat(
         ring.get_hosts('fake', ignore_hosts=['foo']),
         equals_bar_or_baz)
     self.assertThat(
         ring.get_hosts('fake', ignore_hosts=['foo', 'bar']),
         equals_bar_or_baz)
     self.assertEqual([], ring.get_hosts('fake', ignore_hosts=hosts))
Exemplo n.º 4
0
 def test_ignore_hosts_with_replicas(self):
     hosts = ['foo', 'bar', 'baz']
     ring = hash.HashRing(hosts, replicas=2)
     self.assertEqual(['bar', 'baz'],
                      ring.get_hosts('fake', ignore_hosts=['foo']))
     self.assertEqual(['baz'],
                      ring.get_hosts('fake', ignore_hosts=['foo', 'bar']))
     self.assertEqual(['baz', 'foo'],
                      ring.get_hosts('fake-again', ignore_hosts=['bar']))
     self.assertEqual(['foo'],
                      ring.get_hosts('fake-again',
                                     ignore_hosts=['bar', 'baz']))
     self.assertEqual([], ring.get_hosts('fake', ignore_hosts=hosts))
Exemplo n.º 5
0
    def __init__(self, topic=None):
        if topic is None:
            topic = manager.MANAGER_TOPIC

        # Initialize consistent hash ring
        self.hash_rings = {}
        d2c = dbapi.get_instance().get_active_driver_dict()
        for driver in d2c.keys():
            self.hash_rings[driver] = hash.HashRing(d2c[driver])

        super(ConductorAPI, self).__init__(
                topic=topic,
                serializer=objects_base.IronicObjectSerializer(),
                default_version=self.RPC_API_VERSION)
Exemplo n.º 6
0
 def test_create_ring(self):
     hosts = ['foo', 'bar']
     replicas = 2
     ring = hash_ring.HashRing(hosts, replicas=replicas)
     self.assertEqual(set(hosts), ring.hosts)
     self.assertEqual(replicas, ring.replicas)
Exemplo n.º 7
0
 def test_get_hosts_invalid_data(self):
     hosts = ['foo', 'bar']
     ring = hash_ring.HashRing(hosts)
     self.assertRaises(exception.Invalid, ring.get_hosts, None)
Exemplo n.º 8
0
 def test_ignore_non_existent_host(self):
     hosts = ['foo', 'bar']
     ring = hash_ring.HashRing(hosts, replicas=1)
     self.assertEqual(['foo'], ring.get_hosts('fake', ignore_hosts=['baz']))
Exemplo n.º 9
0
 def test_more_replicas_than_hosts(self):
     hosts = ['foo', 'bar']
     ring = hash_ring.HashRing(hosts, replicas=10)
     self.assertEqual(set(hosts), set(ring.get_hosts('fake')))
Exemplo n.º 10
0
 def test_distribution_three_replicas(self):
     hosts = ['foo', 'bar', 'baz']
     ring = hash.HashRing(hosts, replicas=3)
     self.assertEqual(['foo', 'bar', 'baz'], ring.get_hosts('fake'))
     self.assertEqual(['bar', 'baz', 'foo'], ring.get_hosts('fake-again'))