Beispiel #1
0
    def test_goodness_weigher_passing_host(self):
        weigher = goodness.GoodnessWeigher()
        host_state = fakes.FakeHostState(
            'host1', {
                'host': 'host.example.com',
                'capabilities': {
                    'goodness_function': '100'
                }
            })
        host_state_2 = fakes.FakeHostState(
            'host2', {
                'host': 'host2.example.com',
                'capabilities': {
                    'goodness_function': '0'
                }
            })
        host_state_3 = fakes.FakeHostState(
            'host3', {
                'host': 'host3.example.com',
                'capabilities': {
                    'goodness_function': '100 / 2'
                }
            })

        weight_properties = {}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(100, weight)
        weight = weigher._weigh_object(host_state_2, weight_properties)
        self.assertEqual(0, weight)
        weight = weigher._weigh_object(host_state_3, weight_properties)
        self.assertEqual(50, weight)
Beispiel #2
0
    def test_goodness_weigher_with_no_goodness_function(self):
        weigher = goodness.GoodnessWeigher()
        host_state = fakes.FakeHostState('host1', {
            'host': 'host.example.com',
            'capabilities': {
                'foo': '50'
            }
        })

        weight_properties = {}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(0, weight)
Beispiel #3
0
    def test_goodness_weigher_extra_specs_substitution(self):
        weigher = goodness.GoodnessWeigher()
        host_state = fakes.FakeHostState(
            'host1', {
                'host': 'host.example.com',
                'capabilities': {
                    'goodness_function': '10 + extra.foo'
                }
            })

        weight_properties = {'share_type': {'extra_specs': {'foo': 50}}}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(60, weight)
Beispiel #4
0
    def test_goodness_weigher_invalid_substitution(self):
        weigher = goodness.GoodnessWeigher()
        host_state = fakes.FakeHostState(
            'host1', {
                'host': 'host.example.com',
                'capabilities': {
                    'goodness_function': '10 + stats.my_val'
                },
                'foo': 50
            })

        weight_properties = {}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(0, weight)
Beispiel #5
0
    def test_goodness_weigher_stats_substitution(self):
        weigher = goodness.GoodnessWeigher()
        host_state = fakes.FakeHostState(
            'host1', {
                'host': 'host.example.com',
                'capabilities': {
                    'goodness_function': 'stats.free_capacity_gb > 20'
                },
                'free_capacity_gb': 50
            })

        weight_properties = {}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(100, weight)
Beispiel #6
0
    def test_goodness_weigher_host_rating_out_of_bounds(self):
        weigher = goodness.GoodnessWeigher()
        host_state = fakes.FakeHostState(
            'host1', {
                'host': 'host.example.com',
                'capabilities': {
                    'goodness_function': '-10'
                }
            })
        host_state_2 = fakes.FakeHostState(
            'host2', {
                'host': 'host2.example.com',
                'capabilities': {
                    'goodness_function': '200'
                }
            })

        weight_properties = {}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(0, weight)
        weight = weigher._weigh_object(host_state_2, weight_properties)
        self.assertEqual(0, weight)