Added 'dummy' entrypoint within watcher_strategies

This should make our 'dummy' strategy available for use.
I also removed all previously defined default goals, which means
that they will have to define it themselves from now on.
This can also be useful for future integration tests.

Change-Id: I6c43eba941022a88851a199b56a6c20f017b9e71
DocImpact
Closes-Bug: #1520178
This commit is contained in:
Vincent Françoise
2015-11-26 14:16:18 +01:00
committed by David TARDIVEL
parent a809b8d52c
commit 9078e1e138
10 changed files with 73 additions and 61 deletions

View File

@@ -36,12 +36,9 @@ class TestTriggerAuditCommand(DbTestCase):
audit_template_id=self.audit_template.id)
def test_trigger_audit_without_errors(self):
try:
model_collector = FakerModelCollector()
command = TriggerAuditCommand(MagicMock(), model_collector)
command.execute(self.audit.uuid, self.context)
except Exception:
self.fail("The audit should be trigged without error")
model_collector = FakerModelCollector()
command = TriggerAuditCommand(MagicMock(), model_collector)
command.execute(self.audit.uuid, self.context)
def test_trigger_audit_state_success(self):
model_collector = FakerModelCollector()

View File

@@ -13,33 +13,37 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from mock import patch
from oslo_config import cfg
from watcher.common.exception import WatcherException
from watcher.decision_engine.strategy.loader import StrategyLoader
from watcher.decision_engine.strategy.selector.default import StrategySelector
from watcher.objects.audit_template import Goal
from watcher.tests import base
from watcher.tests.base import TestCase
CONF = cfg.CONF
class TestStrategySelector(base.BaseTestCase):
class TestStrategySelector(TestCase):
strategy_selector = StrategySelector()
def test_define_from_with_empty(self):
expected_goal = None
expected_strategy = \
CONF.watcher_goals.goals[Goal.SERVERS_CONSOLIDATION]
with mock.patch.object(StrategyLoader, 'load') as \
mock_call:
self.strategy_selector.define_from_goal(expected_goal)
mock_call.assert_called_once_with(expected_strategy)
def test_define_from_goal(self):
expected_goal = Goal.BALANCE_LOAD
@patch.object(StrategyLoader, 'load')
def test_define_from_goal(self, mock_call):
cfg.CONF.set_override(
'goals', {"DUMMY": "fake"}, group='watcher_goals'
)
expected_goal = 'DUMMY'
expected_strategy = CONF.watcher_goals.goals[expected_goal]
with mock.patch.object(StrategyLoader, 'load') as \
mock_call:
self.strategy_selector.define_from_goal(expected_goal)
mock_call.assert_called_once_with(expected_strategy)
self.strategy_selector.define_from_goal(expected_goal)
mock_call.assert_called_once_with(expected_strategy)
@patch.object(StrategyLoader, 'load')
def test_define_from_goal_with_incorrect_mapping(self, mock_call):
cfg.CONF.set_override(
'goals', {}, group='watcher_goals'
)
self.assertRaises(
WatcherException,
self.strategy_selector.define_from_goal,
"DUMMY"
)
self.assertEqual(mock_call.call_count, 0)

View File

@@ -21,14 +21,15 @@ from stevedore.extension import Extension
from stevedore.extension import ExtensionManager
from watcher.decision_engine.strategy.dummy_strategy import DummyStrategy
from watcher.decision_engine.strategy.loader import StrategyLoader
from watcher.tests import base
from watcher.tests.base import TestCase
class TestLoader(base.BaseTestCase):
class TestStrategyLoader(TestCase):
@patch("watcher.decision_engine.strategy.loader.ExtensionManager")
def test_strategy_loader(self, m_extension_manager):
dummy_strategy_name = "dummy"
# Set up the fake Stevedore extensions
m_extension_manager.return_value = ExtensionManager.make_test_instance(
extensions=[Extension(
name=dummy_strategy_name,
@@ -39,7 +40,13 @@ class TestLoader(base.BaseTestCase):
)],
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)
def test_load_dummy_strategy(self):
strategy_loader = StrategyLoader()
loaded_strategy = strategy_loader.load("dummy")