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_retry_filter_pass(self):
     # Node not previously tried.
     filt_cls = self.class_map['RetryFilter']()
     host = fakes.FakeHostState('host1', {})
     retry = dict(num_attempts=2, hosts=['host2'])
     filter_properties = dict(retry=retry)
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
Beispiel #3
0
 def test_retry_filter_fail(self):
     # Node was already tried.
     filt_cls = self.class_map['RetryFilter']()
     host = fakes.FakeHostState('host1', {})
     retry = dict(num_attempts=1, hosts=['host1'])
     filter_properties = dict(retry=retry)
     self.assertFalse(filt_cls.host_passes(host, filter_properties))
Beispiel #4
0
    def test___format_filter_properties_active_replica_host_is_provided(self):
        sched = fakes.FakeFilterScheduler()
        fake_context = context.RequestContext('user', 'project')
        request_spec = {
            'share_properties': {
                'project_id': 1,
                'size': 1
            },
            'share_instance_properties': {},
            'share_type': {
                'name': 'NFS'
            },
            'share_id': ['fake-id1'],
            'active_replica_host': 'fake_ar_host',
        }
        hosts = [
            fakes.FakeHostState(host, {'replication_domain': 'xyzzy'})
            for host in ('fake_ar_host', 'fake_host_2')
        ]
        self.mock_object(sched.host_manager, 'get_all_host_states_share',
                         mock.Mock(return_value=hosts))
        self.mock_object(sched, 'populate_filter_properties_share')

        retval = sched._format_filter_properties(fake_context, {},
                                                 request_spec)

        self.assertIn('replication_domain', retval[0])
Beispiel #5
0
 def test_filter_thin_passes(self, size, cap_thin, total, free, provisioned,
                             max_ratio, reserved, thin_prov, cap_thin_key):
     self._stub_service_is_up(True)
     filter_properties = {
         'size': size,
         'snapshot_id': None,
         'share_type': {
             'extra_specs': {
                 cap_thin_key: cap_thin,
             }
         }
     }
     service = {'disabled': False}
     host = fakes.FakeHostState(
         'host1', {
             'total_capacity_gb': total,
             'free_capacity_gb': free,
             'provisioned_capacity_gb': provisioned,
             'max_over_subscription_ratio': max_ratio,
             'reserved_percentage': reserved,
             'thin_provisioning': thin_prov,
             'updated_at': None,
             'service': service
         })
     self.assertTrue(self.filter.host_passes(host, filter_properties))
Beispiel #6
0
    def test_share_replication_filter_passes_no_active_replica_host(self):
        request = self._create_replica_request(active_replica_host=None)

        host = fakes.FakeHostState('host1', {
            'replication_domain': 'tatooine',
        })

        self.assertTrue(self.filter.host_passes(host, request))
Beispiel #7
0
    def test_share_replication_filter_empty(self):
        request = {}

        host = fakes.FakeHostState('host1', {
            'replication_domain': 'naboo',
        })

        self.assertTrue(self.filter.host_passes(host, request))
Beispiel #8
0
    def test_share_replication_filter_fails_no_replication_domain(self):
        request = self._create_replica_request()

        host = fakes.FakeHostState('host1', {
            'replication_domain': None,
        })

        self.assertFalse(self.filter.host_passes(host, request))
        self.assertTrue(self.debug_log.called)
Beispiel #9
0
    def test_function_exception_caught(self):
        host1 = fakes.FakeHostState(
            'host1', {'capabilities': {
                'filter_function': '1 / 0 == 0',
            }})

        filter_properties = {}

        self.assertFalse(self.filter.host_passes(host1, filter_properties))
Beispiel #10
0
    def test_not_implemented(self):
        host1 = fakes.FakeHostState(
            'host1', {
                'capabilities': {}
            })

        filter_properties = {'share_type': {}}

        self.assertTrue(self.filter.host_passes(host1, filter_properties))
Beispiel #11
0
    def test_failing_function(self):
        host1 = fakes.FakeHostState(
            'host1', {'capabilities': {
                'filter_function': '1 == 2',
            }})

        filter_properties = {'share_type': {}}

        self.assertFalse(self.filter.host_passes(host1, filter_properties))
Beispiel #12
0
    def test_no_share_extra_specs(self):
        host1 = fakes.FakeHostState(
            'host1', {'capabilities': {
                'filter_function': '1 == 1',
            }})

        filter_properties = {'share_type': {}}

        self.assertTrue(self.filter.host_passes(host1, filter_properties))
Beispiel #13
0
    def test_without_snapshot_host(self):
        host_state = fakes.FakeHostState('host1', {
            'host': 'host1@AAA#pool2',
        })
        weight_properties = self._create_weight_properties(
            snapshot_id='fake_snapshot_id')

        weight = self.weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(0, weight)
Beispiel #14
0
    def test_share_replication_filter_fails_host_has_replicas(self):
        all_replica_hosts = ','.join(['host1', fakes.FAKE_HOST_STRING_1])
        request = self._create_replica_request(
            all_replica_hosts=all_replica_hosts)

        host = fakes.FakeHostState('host1', {
            'replication_domain': 'kashyyyk',
        })
        self.assertFalse(self.filter.host_passes(host, request))
        self.assertTrue(self.debug_log.called)
Beispiel #15
0
 def test_capacity_filter_passes_unknown(self):
     free = 'unknown'
     self._stub_service_is_up(True)
     filter_properties = {'size': 100}
     service = {'disabled': False}
     host = fakes.FakeHostState('host1',
                                {'free_capacity_gb': free,
                                 'updated_at': None,
                                 'service': service})
     self.assertTrue(self.filter.host_passes(host, filter_properties))
Beispiel #16
0
    def test_share_replication_filter_passes_happy_day(self):
        all_replica_hosts = ','.join(['host1', fakes.FAKE_HOST_STRING_1])
        request = self._create_replica_request(
            all_replica_hosts=all_replica_hosts)

        host = fakes.FakeHostState('host2', {
            'replication_domain': 'kashyyyk',
        })

        self.assertTrue(self.filter.host_passes(host, request))
Beispiel #17
0
 def test_json_filter_passes_with_no_query(self):
     filter_properties = {'resource_type': {'memory_mb': 1024,
                                            'root_gb': 200,
                                            'ephemeral_gb': 0}}
     capabilities = {'enabled': True}
     host = fakes.FakeHostState('host1',
                                {'free_ram_mb': 0,
                                 'free_disk_mb': 0,
                                 'capabilities': capabilities})
     self.assertTrue(self.filter.host_passes(host, filter_properties))
Beispiel #18
0
 def test_capacity_filter_passes(self, size, share_on, host):
     self._stub_service_is_up(True)
     filter_properties = {'size': size,
                          'share_exists_on': share_on}
     service = {'disabled': False}
     host = fakes.FakeHostState(host,
                                {'total_capacity_gb': 500,
                                 'free_capacity_gb': 200,
                                 'updated_at': None,
                                 'service': service})
     self.assertTrue(self.filter.host_passes(host, filter_properties))
Beispiel #19
0
 def test_capacity_filter_fails_total(self, free, total, reserved):
     self._stub_service_is_up(True)
     filter_properties = {'size': 100}
     service = {'disabled': False}
     host = fakes.FakeHostState('host1',
                                {'free_capacity_gb': free,
                                 'total_capacity_gb': total,
                                 'reserved_percentage': reserved,
                                 'updated_at': None,
                                 'service': service})
     self.assertFalse(self.filter.host_passes(host, filter_properties))
Beispiel #20
0
 def test_capacity_filter_passes_infinite(self):
     self._stub_service_is_up(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))
Beispiel #21
0
 def test_json_filter_unknown_operator_raises(self):
     raw = ['!=', 1, 2]
     filter_properties = {
         'scheduler_hints': {
             'query': jsonutils.dumps(raw),
         },
     }
     host = fakes.FakeHostState('host1',
                                {'capabilities': {'enabled': True}})
     self.assertRaises(KeyError,
                       self.filter.host_passes, host, filter_properties)
Beispiel #22
0
 def test_capacity_filter_current_host_passes(self):
     self._stub_service_is_up(True)
     filt_cls = self.class_map['CapacityFilter']()
     filter_properties = {'size': 100, 'share_exists_on': 'host1#pool1'}
     service = {'disabled': False}
     host = fakes.FakeHostState('host1#pools1', {
         'free_capacity_gb': 200,
         'updated_at': None,
         'service': service
     })
     self.assertTrue(filt_cls.host_passes(host, filter_properties))
Beispiel #23
0
 def test_json_filter_fails_on_disk(self):
     filter_properties = {'resource_type': {'memory_mb': 1024,
                                            'root_gb': 200,
                                            'ephemeral_gb': 0},
                          'scheduler_hints': {'query': self.json_query}}
     capabilities = {'enabled': True}
     host = fakes.FakeHostState('host1',
                                {'free_ram_mb': 1024,
                                 'free_disk_mb': (200 * 1024) - 1,
                                 'capabilities': capabilities})
     self.assertFalse(self.filter.host_passes(host, filter_properties))
Beispiel #24
0
    def test_function_stats_replacement(self):
        host1 = fakes.FakeHostState(
            'host1', {
                'total_capacity_gb': 100,
                'capabilities': {
                    'filter_function': 'stats.total_capacity_gb < 200',
                }
            })

        filter_properties = {'share_type': {}}

        self.assertTrue(self.filter.host_passes(host1, filter_properties))
Beispiel #25
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 #26
0
    def test_wrong_capabilities(self):
        host1 = fakes.FakeHostState(
            'host1', {
                'capabilities': {
                    'bar': 10,
                    'filter_function': 'capabilities.foo == 10',
                },
            })

        filter_properties = {}

        self.assertFalse(self.filter.host_passes(host1, filter_properties))
Beispiel #27
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)
Beispiel #28
0
    def test_same_backend_different_pool(self):
        share = db_utils.create_share(host="host1@AAA#pool1",
                                      status=constants.STATUS_AVAILABLE)
        snapshot = db_utils.create_snapshot(share_id=share['id'])
        self.mock_object(db_api, 'share_snapshot_get',
                         mock.Mock(return_value=snapshot))

        host_state = fakes.FakeHostState('host1@AAA#pool2', {})
        weight_properties = self._create_weight_properties(
            snapshot_id=snapshot['id'], snapshot_host=share['host'])

        weight = self.weigher._weigh_object(host_state, weight_properties)
        self.assertEqual(75, weight)
Beispiel #29
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)
    def test_availability_zone_filter_only_share_type_AZs(
            self, supported_azs, request_az, host_passes):
        service = {
            'availability_zone': {
                'name': request_az,
                'id': '9382098d-d40f-42a2-8f31-8eb78ee18c02',
            },
            'availability_zone_id': '9382098d-d40f-42a2-8f31-8eb78ee18c02',
        }
        request = self._make_zone_request(None)
        request['request_spec']['availability_zones'] = supported_azs
        host = fakes.FakeHostState('host1', {'service': service})

        self.assertEqual(host_passes, self.filter.host_passes(host, request))