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

@@ -379,7 +379,7 @@ class TestPost(api_base.FunctionalTest):
wraps=self.dbapi.create_audit_template
) as cn_mock:
audit_template_dict = api_utils.audit_template_post_data(
goal='SERVERS_CONSOLIDATION')
goal='DUMMY')
response = self.post_json('/audit_templates', audit_template_dict)
self.assertEqual(audit_template_dict['goal'],
response.json['goal'])

View File

@@ -20,6 +20,13 @@ class TestListGoal(api_base.FunctionalTest):
def setUp(self):
super(TestListGoal, self).setUp()
# Override the default to get enough goals to test limit on query
cfg.CONF.set_override(
"goals", {
"DUMMY_1": "dummy", "DUMMY_2": "dummy",
"DUMMY_3": "dummy", "DUMMY_4": "dummy",
},
group='watcher_goals')
def _assert_goal_fields(self, goal):
goal_fields = ['name', 'strategy']
@@ -53,11 +60,11 @@ class TestListGoal(api_base.FunctionalTest):
self.assertEqual(len(CONF.watcher_goals.goals),
len(response['goals']))
def test_collection_links(self):
def test_goals_collection_links(self):
response = self.get_json('/goals/?limit=2')
self.assertEqual(2, len(response['goals']))
def test_collection_links_default_limit(self):
def test_goals_collection_links_default_limit(self):
cfg.CONF.set_override('max_limit', 3, 'api')
response = self.get_json('/goals')
self.assertEqual(3, len(response['goals']))

View File

@@ -21,7 +21,7 @@ def get_test_audit_template(**kwargs):
return {
'id': kwargs.get('id', 1),
'uuid': kwargs.get('uuid', 'e74c40e0-d825-11e2-a28f-0800200c9a66'),
'goal': kwargs.get('goal', 'SERVERS_CONSOLIDATION'),
'goal': kwargs.get('goal', 'DUMMY'),
'name': kwargs.get('name', 'My Audit Template'),
'description': kwargs.get('description', 'Desc. Of My Audit Template'),
'extra': kwargs.get('extra', {'automatic': False}),

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")