示例#1
0
 def setUp(self):
     super(HostManagerTestCase, self).setUp()
     self.host_manager = host_manager.HostManager()
     self.fake_hosts = [host_manager.HostState('fake_host%s' % x)
                        for x in range(1, 5)]
     # For a second scheduler service.
     self.host_manager_1 = host_manager.HostManager()
示例#2
0
 def test_host_manager_choosing_chance_weigher(self):
     # ensure HostManager can load the ChanceWeigher
     # via the entry points mechanism
     hm = host_manager.HostManager()
     weighers = hm._choose_host_weighers('ChanceWeigher')
     self.assertEqual(1, len(weighers))
     self.assertEqual(weighers[0], chance.ChanceWeigher)
示例#3
0
    def test_has_all_capabilities(self, _mock_service_get_all,
                                  _mock_service_is_up):
        _mock_service_is_up.return_value = True
        services = [
            dict(id=1, host='host1', topic='volume', disabled=False,
                 availability_zone='zone1', updated_at=timeutils.utcnow()),
            dict(id=2, host='host2', topic='volume', disabled=False,
                 availability_zone='zone1', updated_at=timeutils.utcnow()),
            dict(id=3, host='host3', topic='volume', disabled=False,
                 availability_zone='zone1', updated_at=timeutils.utcnow()),
        ]
        _mock_service_get_all.return_value = services
        # Create host_manager again to let db.service_get_all mock run
        self.host_manager = host_manager.HostManager()
        self.assertFalse(self.host_manager.has_all_capabilities())

        host1_volume_capabs = dict(free_capacity_gb=4321, timestamp=1)
        host2_volume_capabs = dict(free_capacity_gb=5432, timestamp=1)
        host3_volume_capabs = dict(free_capacity_gb=6543, timestamp=1)

        service_name = 'volume'
        self.host_manager.update_service_capabilities(service_name, 'host1',
                                                      host1_volume_capabs)
        self.assertFalse(self.host_manager.has_all_capabilities())
        self.host_manager.update_service_capabilities(service_name, 'host2',
                                                      host2_volume_capabs)
        self.assertFalse(self.host_manager.has_all_capabilities())
        self.host_manager.update_service_capabilities(service_name, 'host3',
                                                      host3_volume_capabs)
        self.assertTrue(self.host_manager.has_all_capabilities())
示例#4
0
 def test_use_of_chance_weigher_via_host_manager(self):
     # ensure we don't lose any hosts when weighing with
     # the ChanceWeigher
     hm = host_manager.HostManager()
     fake_hosts = [host_manager.HostState('fake_host%s' % x)
                   for x in range(1, 5)]
     weighed_hosts = hm.get_weighed_hosts(fake_hosts, {}, 'ChanceWeigher')
     self.assertEqual(4, len(weighed_hosts))
示例#5
0
 def setUp(self):
     super(HostManagerTestCase, self).setUp()
     self.host_manager = host_manager.HostManager()
     self.fake_hosts = [
         host_manager.HostState('fake_host%s' % x) for x in range(1, 5)
     ]
示例#6
0
 def __init__(self, *args, **kwargs):
     super(FakeFilterScheduler, self).__init__(*args, **kwargs)
     self.host_manager = host_manager.HostManager()