Add a basic filter for Nova

Change-Id: I2c54418e15c4783f6f062209a7038282bcb66cd8
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-04-30 16:15:47 +02:00
parent f7504de458
commit ceae8641a1
6 changed files with 79 additions and 1 deletions

0
climate/nova/__init__.py Normal file
View File

View File

@ -0,0 +1,27 @@
# Copyright 2013 Julien Danjou <julien@danjou.info>
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova.scheduler import filters
class ClimateFilter(filters.BaseHostFilter):
"""Climate Filter for nova-scheduler."""
def host_passes(self, host_state, filter_properties):
"""Filter based on Climate."""
scheduler_hints = filter_properties.get('scheduler_hints') or {}
# XXX send host_state + to Climate API
return True

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Copyright © 2013 Julien Danjou <julien@danjou.info>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import gettext
gettext.install('nova', unicode=True)

View File

@ -0,0 +1,29 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Copyright © 2013 Julien Danjou <julien@danjou.info>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import unittest
from nova.tests.scheduler import fakes
from climate.nova import climate_filter
class ClimateSchedulerTestCase(unittest.TestCase):
def test_climate_scheduler(self):
f = climate_filter.ClimateFilter()
host = fakes.FakeHostState('host1', 'node1', {})
filter_properties = {"scheduler_hints": {"foo": "bar"}}
self.assertTrue(f.host_passes(host, filter_properties))

View File

@ -1,3 +1,4 @@
nose nose
mock mock
mox mox
http://tarballs.openstack.org/nova/nova-master.tar.gz

View File

@ -10,7 +10,8 @@ setenv = VIRTUAL_ENV={envdir}
NOSE_OPENSTACK_RED=0.05 NOSE_OPENSTACK_RED=0.05
NOSE_OPENSTACK_YELLOW=0.025 NOSE_OPENSTACK_YELLOW=0.025
NOSE_OPENSTACK_SHOW_ELAPSED=1 NOSE_OPENSTACK_SHOW_ELAPSED=1
commands = nosetests --no-path-adjustment commands = nosetests --no-path-adjustment --where=tests_nova_scheduler
nosetests --no-path-adjustment --where=tests {posargs}
sitepackages = False sitepackages = False
[testenv:cover] [testenv:cover]