Made Decision Engine extensible via stevedore
The objective for this is to give the ability to extend the default set of placement algorithms (i.e. strategies) currently available in Watcher using Stevedore. Now, you can add your new strategy as an entry point under the '[watcher_strategies]' section. Change-Id: I4aecf629015e41b0389d07e47220333e50bbbe1a
This commit is contained in:
@@ -24,7 +24,7 @@ class FakeStrategy(object):
|
||||
self.name = "BALANCE_LOAD"
|
||||
|
||||
|
||||
class TestStrategyContextImpl(base.BaseTestCase):
|
||||
class TestStrategyContext(base.BaseTestCase):
|
||||
def test_add_remove_strategy(self):
|
||||
strategy = FakeStrategy()
|
||||
strategy_context = StrategyContext()
|
||||
@@ -13,6 +13,7 @@
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from watcher.decision_engine.api.strategy.strategy import BaseStrategy
|
||||
from watcher.decision_engine.framework.strategy.strategy_loader import \
|
||||
StrategyLoader
|
||||
from watcher.tests import base
|
||||
@@ -26,6 +27,7 @@ class TestStrategySelector(base.BaseTestCase):
|
||||
selected_strategy = self.strategy_loader.load(None)
|
||||
self.assertIsNotNone(selected_strategy,
|
||||
'The default strategy be must not none')
|
||||
self.assertIsInstance(selected_strategy, BaseStrategy)
|
||||
|
||||
def test_load_strategy_is_basic(self):
|
||||
exptected_strategy = 'basic'
|
||||
@@ -34,7 +36,3 @@ class TestStrategySelector(base.BaseTestCase):
|
||||
selected_strategy.name,
|
||||
exptected_strategy,
|
||||
'The default strategy should be basic')
|
||||
|
||||
def test_load_driver(self):
|
||||
algo = self.strategy_loader.load_driver("basic")
|
||||
self.assertEqual(algo._names[0], "basic")
|
||||
|
||||
49
watcher/tests/decision_engine/test_strategy_loader.py
Normal file
49
watcher/tests/decision_engine/test_strategy_loader.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# 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 __future__ import unicode_literals
|
||||
|
||||
from mock import patch
|
||||
from stevedore.extension import Extension
|
||||
from stevedore.extension import ExtensionManager
|
||||
from watcher.decision_engine.framework.strategy.strategy_loader import \
|
||||
StrategyLoader
|
||||
from watcher.decision_engine.strategies.dummy_strategy import DummyStrategy
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestLoader(base.BaseTestCase):
|
||||
|
||||
@patch("watcher.decision_engine.framework.strategy."
|
||||
"strategy_loader.ExtensionManager")
|
||||
def test_strategy_loader(self, m_extension_manager):
|
||||
dummy_strategy_name = "dummy"
|
||||
m_extension_manager.return_value = ExtensionManager.make_test_instance(
|
||||
extensions=[Extension(
|
||||
name=dummy_strategy_name,
|
||||
entry_point="%s:%s" % (DummyStrategy.__module__,
|
||||
DummyStrategy.__name__),
|
||||
plugin=DummyStrategy,
|
||||
obj=None,
|
||||
)],
|
||||
namespace="watcher_strategies",
|
||||
)
|
||||
# Set up the fake Stevedore extensions
|
||||
strategy_loader = StrategyLoader()
|
||||
loaded_strategy = strategy_loader.load("dummy")
|
||||
|
||||
self.assertEqual("dummy", loaded_strategy.name)
|
||||
self.assertEqual("Dummy Strategy", loaded_strategy.description)
|
||||
Reference in New Issue
Block a user