Exemple #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)
Exemple #2
0
    def test_not_implemented(self):
        filt_cls = self.class_map['DriverFilter']()
        host1 = fakes.FakeHostState('host1', {'capabilities': {}})

        filter_properties = {'volume_type': {}}

        self.assertTrue(filt_cls.host_passes(host1, filter_properties))
Exemple #3
0
    def test_handles_none(self):
        filt_cls = self.class_map['InstanceLocalityFilter']()
        host = fakes.FakeHostState('host1', {})

        filter_properties = {'context': self.context,
                             'scheduler_hints': None}
        self.assertTrue(filt_cls.host_passes(host, filter_properties))
Exemple #4
0
    def test_same_filter_handles_none(self):
        filt_cls = self.class_map['SameBackendFilter']()
        host = fakes.FakeHostState('host1', {})

        filter_properties = {'context': self.context.elevated(),
                             'scheduler_hints': None}

        self.assertTrue(filt_cls.host_passes(host, filter_properties))
Exemple #5
0
    def test_different_host(self, _mock_novaclient):
        _mock_novaclient.return_value = fakes.FakeNovaClient()
        filt_cls = self.class_map['InstanceLocalityFilter']()
        host = fakes.FakeHostState('host1', {})
        uuid = nova.novaclient().servers.create('host2')

        filter_properties = {'context': self.context,
                             'scheduler_hints': {'local_to_instance': uuid}}
        self.assertFalse(filt_cls.host_passes(host, filter_properties))
Exemple #6
0
    def test_same_filter_fail_nonuuid_hint(self):
        filt_cls = self.class_map['SameBackendFilter']()
        host = fakes.FakeHostState('host1', {})

        filter_properties = {'context': self.context.elevated(),
                             'scheduler_hints': {
            'same_host': "NOT-a-valid-UUID", }}

        self.assertFalse(filt_cls.host_passes(host, filter_properties))
Exemple #7
0
    def test_invalid_uuid(self):
        filt_cls = self.class_map['InstanceLocalityFilter']()
        host = fakes.FakeHostState('host1', {})

        filter_properties = {'context': self.context,
                             'scheduler_hints':
                             {'local_to_instance': 'e29b11d4-not-valid-a716'}}
        self.assertRaises(exception.InvalidUUID,
                          filt_cls.host_passes, host, filter_properties)
Exemple #8
0
    def test_nova_down_does_not_alter_other_filters(self, _mock_novaclient):
        # Simulate Nova API is not available
        _mock_novaclient.side_effect = Exception

        filt_cls = self.class_map['InstanceLocalityFilter']()
        host = fakes.FakeHostState('host1', {})

        filter_properties = {'context': self.context, 'size': 100}
        self.assertTrue(filt_cls.host_passes(host, filter_properties))
Exemple #9
0
    def test_no_volume_extra_specs(self):
        filt_cls = self.class_map['DriverFilter']()
        host1 = fakes.FakeHostState(
            'host1', {'capabilities': {
                'filter_function': '1 == 1',
            }})

        filter_properties = {'volume_type': {}}

        self.assertTrue(filt_cls.host_passes(host1, filter_properties))
Exemple #10
0
    def test_function_qos_spec_replacement(self):
        filt_cls = self.class_map['DriverFilter']()
        host1 = fakes.FakeHostState(
            'host1', {'capabilities': {
                'filter_function': 'qos.var == 1',
            }})

        filter_properties = {'qos_specs': {'var': 1}}

        self.assertTrue(filt_cls.host_passes(host1, filter_properties))
Exemple #11
0
    def test_function_exception_caught(self):
        filt_cls = self.class_map['DriverFilter']()
        host1 = fakes.FakeHostState(
            'host1', {'capabilities': {
                'filter_function': '1 / 0 == 0',
            }})

        filter_properties = {}

        self.assertFalse(filt_cls.host_passes(host1, filter_properties))
Exemple #12
0
 def test_filter_passes_infinite(self, _mock_serv_is_up):
     _mock_serv_is_up.return_value = True
     filt_cls = self.class_map['CapacityFilter']()
     filter_properties = {'size': 100}
     service = {'disabled': False}
     host = fakes.FakeHostState('host1',
                                {'free_capacity_gb': 'infinite',
                                 'updated_at': None,
                                 'service': service})
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
Exemple #13
0
    def test_failing_function(self):
        filt_cls = self.class_map['DriverFilter']()
        host1 = fakes.FakeHostState(
            'host1', {'capabilities': {
                'filter_function': '1 == 2',
            }})

        filter_properties = {'volume_type': {}}

        self.assertFalse(filt_cls.host_passes(host1, filter_properties))
Exemple #14
0
 def test_filter_current_host_passes(self, _mock_serv_is_up):
     _mock_serv_is_up.return_value = True
     filt_cls = self.class_map['CapacityFilter']()
     filter_properties = {'size': 100, 'vol_exists_on': 'host1'}
     service = {'disabled': False}
     host = fakes.FakeHostState('host1',
                                {'total_capacity_gb': 100,
                                 'free_capacity_gb': 10,
                                 'updated_at': None,
                                 'service': service})
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
Exemple #15
0
    def test_nova_no_extended_server_attributes(self, _mock_novaclient):
        _mock_novaclient.return_value = fakes.FakeNovaClient(
            ext_srv_attr=False)
        filt_cls = self.class_map['InstanceLocalityFilter']()
        host = fakes.FakeHostState('host1', {})
        uuid = nova.novaclient().servers.create('host1')

        filter_properties = {'context': self.context,
                             'scheduler_hints': {'local_to_instance': uuid}}
        self.assertRaises(exception.CinderException,
                          filt_cls.host_passes, host, filter_properties)
Exemple #16
0
    def test_different_filter_handles_invalid_uuids(self):
        filt_cls = self.class_map['DifferentBackendFilter']()
        host = fakes.FakeHostState('host1', {})
        volume = utils.create_volume(self.context, host='host2')
        vol_id = volume.id

        filter_properties = {'context': self.context.elevated(),
                             'scheduler_hints': {
            'different_host': [vol_id, "NOT-a-valid-UUID"], }}

        self.assertFalse(filt_cls.host_passes(host, filter_properties))
Exemple #17
0
    def test_same_filter_fails(self):
        filt_cls = self.class_map['SameBackendFilter']()
        host = fakes.FakeHostState('host1#pool0', {})
        volume = utils.create_volume(self.context, host='host1#pool1')
        vol_id = volume.id

        filter_properties = {'context': self.context.elevated(),
                             'scheduler_hints': {
            'same_host': [vol_id], }}

        self.assertFalse(filt_cls.host_passes(host, filter_properties))
Exemple #18
0
    def test_different_filter_non_list_fails(self):
        filt_cls = self.class_map['DifferentBackendFilter']()
        host = fakes.FakeHostState('host2', {})
        volume = utils.create_volume(self.context, host='host2')
        vol_id = volume.id

        filter_properties = {'context': self.context.elevated(),
                             'scheduler_hints': {
            'different_host': vol_id}}

        self.assertFalse(filt_cls.host_passes(host, filter_properties))
Exemple #19
0
    def test_function_empty_qos(self):
        filt_cls = self.class_map['DriverFilter']()
        host1 = fakes.FakeHostState(
            'host1',
            {'capabilities': {
                'filter_function': 'qos.maxiops == 1',
            }})

        filter_properties = {'qos_specs': None}

        self.assertFalse(filt_cls.host_passes(host1, filter_properties))
Exemple #20
0
    def test_nova_timeout(self, _mock_request):
        # Simulate a HTTP timeout
        _mock_request.side_effect = request_exceptions.Timeout

        filt_cls = self.class_map['InstanceLocalityFilter']()
        host = fakes.FakeHostState('host1', {})

        filter_properties = \
            {'context': self.context, 'scheduler_hints':
                {'local_to_instance': 'e29b11d4-15ef-34a9-a716-598a6f0b5467'}}
        self.assertRaises(exception.APITimeout,
                          filt_cls.host_passes, host, filter_properties)
Exemple #21
0
    def test_same_filter_handles_deleted_instance(self):
        filt_cls = self.class_map['SameBackendFilter']()
        host = fakes.FakeHostState('host1', {})
        volume = utils.create_volume(self.context, host='host2')
        vol_id = volume.id
        db.volume_destroy(utils.get_test_admin_context(), vol_id)

        filter_properties = {'context': self.context.elevated(),
                             'scheduler_hints': {
            'same_host': [vol_id], }}

        self.assertFalse(filt_cls.host_passes(host, filter_properties))
Exemple #22
0
 def test_filter_fails(self, _mock_serv_is_up):
     _mock_serv_is_up.return_value = True
     filt_cls = self.class_map['CapacityFilter']()
     filter_properties = {'size': 100}
     service = {'disabled': False}
     host = fakes.FakeHostState('host1',
                                {'total_capacity_gb': 200,
                                 'free_capacity_gb': 120,
                                 'reserved_percentage': 20,
                                 'updated_at': None,
                                 'service': service})
     self.assertFalse(filt_cls.host_passes(host, filter_properties))
Exemple #23
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)
Exemple #24
0
    def test_wrong_capabilities(self):
        filt_cls = self.class_map['DriverFilter']()
        host1 = fakes.FakeHostState(
            'host1', {
                'capabilities': {
                    'bar': 10,
                    'filter_function': 'capabilities.foo == 10',
                },
            })

        filter_properties = {}

        self.assertFalse(filt_cls.host_passes(host1, filter_properties))
Exemple #25
0
    def test_same_filter_vol_list_pass(self):
        filt_cls = self.class_map['SameBackendFilter']()
        host = fakes.FakeHostState('host1', {})
        volume1 = utils.create_volume(self.context, host='host1')
        vol_id1 = volume1.id
        volume2 = utils.create_volume(self.context, host='host2')
        vol_id2 = volume2.id

        filter_properties = {'context': self.context.elevated(),
                             'scheduler_hints': {
            'same_host': [vol_id1, vol_id2], }}

        self.assertTrue(filt_cls.host_passes(host, filter_properties))
Exemple #26
0
    def test_function_stats_replacement(self):
        filt_cls = self.class_map['DriverFilter']()
        host1 = fakes.FakeHostState(
            'host1', {
                'total_capacity_gb': 100,
                'capabilities': {
                    'filter_function': 'stats.total_capacity_gb < 200',
                }
            })

        filter_properties = {'volume_type': {}}

        self.assertTrue(filt_cls.host_passes(host1, filter_properties))
Exemple #27
0
    def test_different_filter_handles_multiple_uuids(self):
        filt_cls = self.class_map['DifferentBackendFilter']()
        host = fakes.FakeHostState('host1#pool0', {})
        volume1 = utils.create_volume(self.context, host='host1:pool1')
        vol_id1 = volume1.id
        volume2 = utils.create_volume(self.context, host='host1:pool3')
        vol_id2 = volume2.id

        filter_properties = {'context': self.context.elevated(),
                             'scheduler_hints': {
            'different_host': [vol_id1, vol_id2], }}

        self.assertTrue(filt_cls.host_passes(host, filter_properties))
Exemple #28
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 = {'volume_type': {'extra_specs': {'foo': 50}}}
        weight = weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(60, weight)
Exemple #29
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)
Exemple #30
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)