Example #1
0
    def test_goodness_weigher_passing_host(self):
        weigher = 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)
Example #2
0
    def test_goodness_weigher_passing_host(self):
        weigher = 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)
Example #3
0
    def test_goodness_weigher_invalid_goodness_function(self):
        weigher = GoodnessWeigher()
        host_state = fakes.FakeHostState('host1', {
            'host': 'host.example.com',
            'capabilities': {
                'goodness_function': '50 / 0'
            }
        })

        weight_properties = {}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(0, weight)
Example #4
0
    def test_goodness_weigher_capabilities_substitution(self):
        weigher = GoodnessWeigher()
        host_state = fakes.FakeHostState('host1', {
            'host': 'host.example.com',
            'capabilities': {
                'foo': 50,
                'goodness_function': '10 + capabilities.foo'
            }
        })

        weight_properties = {}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(60, weight)
Example #5
0
    def test_goodness_weigher_stats_substitution(self):
        weigher = 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)
Example #6
0
    def test_goodness_weigher_extra_specs_substitution(self):
        weigher = GoodnessWeigher()
        host_state = fakes.FakeHostState(
            'host1', {
                'host': 'host.example.com',
                'capabilities': {
                    'goodness_function': '10 + extra.foo'
                }
            })

        weight_properties = {'volume_type': {'extra_specs': {'foo': 50}}}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(60, weight)
Example #7
0
    def test_goodness_weigher_invalid_goodness_function(self):
        weigher = GoodnessWeigher()
        host_state = fakes.FakeHostState(
            'host1', {
                'host': 'host.example.com',
                'capabilities': {
                    'goodness_function': '50 / 0'
                }
            })

        weight_properties = {}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(0, weight)
Example #8
0
    def test_goodness_weigher_stats_substitution(self):
        weigher = 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)
Example #9
0
    def test_goodness_weigher_host_rating_out_of_bounds(self):
        weigher = 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)
Example #10
0
    def test_goodness_weigher_host_rating_out_of_bounds(self):
        weigher = 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)