Decoupled Goal from Strategy
In this changeset, I decoupled the notion of Goal from the Strategy by making it a distinct object. Goals are plugins that can be loaded just like for the strategies. Partially Implements: blueprint efficacy-indicator Change-Id: I4378dccd508170b305aa968843228bbc8af78895
This commit is contained in:
@@ -28,7 +28,7 @@ from watcher.tests.objects import utils as obj_utils
|
||||
class TestDefaultAuditHandler(base.DbTestCase):
|
||||
def setUp(self):
|
||||
super(TestDefaultAuditHandler, self).setUp()
|
||||
obj_utils.create_test_goal(self.context, id=1, name="DUMMY")
|
||||
obj_utils.create_test_goal(self.context, id=1, name="dummy")
|
||||
audit_template = obj_utils.create_test_audit_template(
|
||||
self.context)
|
||||
self.audit = obj_utils.create_test_audit(
|
||||
|
||||
50
watcher/tests/decision_engine/fake_goals.py
Normal file
50
watcher/tests/decision_engine/fake_goals.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2016 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 watcher.decision_engine.goal import base as base_goal
|
||||
|
||||
|
||||
class FakeGoal(base_goal.Goal):
|
||||
|
||||
NAME = NotImplemented
|
||||
DISPLAY_NAME = NotImplemented
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
return cls.NAME
|
||||
|
||||
@classmethod
|
||||
def get_display_name(cls):
|
||||
return cls.DISPLAY_NAME
|
||||
|
||||
@classmethod
|
||||
def get_translatable_display_name(cls):
|
||||
return cls.DISPLAY_NAME
|
||||
|
||||
|
||||
class FakeDummy1(FakeGoal):
|
||||
NAME = "dummy_1"
|
||||
DISPLAY_NAME = "Dummy 1"
|
||||
|
||||
|
||||
class FakeDummy2(FakeGoal):
|
||||
NAME = "dummy_2"
|
||||
DISPLAY_NAME = "Dummy 2"
|
||||
|
||||
|
||||
class FakeOtherDummy2(FakeGoal):
|
||||
NAME = "dummy_2"
|
||||
DISPLAY_NAME = "Other Dummy 2"
|
||||
@@ -23,10 +23,9 @@ CONF = cfg.CONF
|
||||
|
||||
class FakeStrategy(base_strategy.BaseStrategy):
|
||||
|
||||
GOAL_NAME = NotImplemented
|
||||
GOAL_DISPLAY_NAME = NotImplemented
|
||||
NAME = NotImplemented
|
||||
DISPLAY_NAME = NotImplemented
|
||||
GOAL_NAME = NotImplemented
|
||||
|
||||
@classmethod
|
||||
def get_name(cls):
|
||||
@@ -44,14 +43,6 @@ class FakeStrategy(base_strategy.BaseStrategy):
|
||||
def get_goal_name(cls):
|
||||
return cls.GOAL_NAME
|
||||
|
||||
@classmethod
|
||||
def get_goal_display_name(cls):
|
||||
return cls.GOAL_DISPLAY_NAME
|
||||
|
||||
@classmethod
|
||||
def get_translatable_goal_display_name(cls):
|
||||
return cls.GOAL_DISPLAY_NAME
|
||||
|
||||
@classmethod
|
||||
def get_config_opts(cls):
|
||||
return []
|
||||
@@ -61,9 +52,8 @@ class FakeStrategy(base_strategy.BaseStrategy):
|
||||
|
||||
|
||||
class FakeDummy1Strategy1(FakeStrategy):
|
||||
GOAL_NAME = "DUMMY_1"
|
||||
GOAL_DISPLAY_NAME = "Dummy 1"
|
||||
NAME = "STRATEGY_1"
|
||||
GOAL_NAME = "dummy_1"
|
||||
NAME = "strategy_1"
|
||||
DISPLAY_NAME = "Strategy 1"
|
||||
|
||||
@classmethod
|
||||
@@ -74,21 +64,18 @@ class FakeDummy1Strategy1(FakeStrategy):
|
||||
|
||||
|
||||
class FakeDummy1Strategy2(FakeStrategy):
|
||||
GOAL_NAME = "DUMMY_1"
|
||||
GOAL_DISPLAY_NAME = "Dummy 1"
|
||||
NAME = "STRATEGY_2"
|
||||
GOAL_NAME = "dummy_1"
|
||||
NAME = "strategy_2"
|
||||
DISPLAY_NAME = "Strategy 2"
|
||||
|
||||
|
||||
class FakeDummy2Strategy3(FakeStrategy):
|
||||
GOAL_NAME = "DUMMY_2"
|
||||
GOAL_DISPLAY_NAME = "Dummy 2"
|
||||
NAME = "STRATEGY_3"
|
||||
GOAL_NAME = "dummy_2"
|
||||
NAME = "strategy_3"
|
||||
DISPLAY_NAME = "Strategy 3"
|
||||
|
||||
|
||||
class FakeDummy2Strategy4(FakeStrategy):
|
||||
GOAL_NAME = "DUMMY_2"
|
||||
GOAL_DISPLAY_NAME = "Other Dummy 2"
|
||||
NAME = "STRATEGY_4"
|
||||
GOAL_NAME = "dummy_2"
|
||||
NAME = "strategy_4"
|
||||
DISPLAY_NAME = "Strategy 4"
|
||||
|
||||
0
watcher/tests/decision_engine/goal/__init__.py
Normal file
0
watcher/tests/decision_engine/goal/__init__.py
Normal file
78
watcher/tests/decision_engine/goal/test_goal_loader.py
Normal file
78
watcher/tests/decision_engine/goal/test_goal_loader.py
Normal file
@@ -0,0 +1,78 @@
|
||||
# -*- 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.
|
||||
|
||||
import mock
|
||||
from stevedore import extension
|
||||
|
||||
from watcher.common import exception
|
||||
from watcher.decision_engine.goal import goals
|
||||
from watcher.decision_engine.loading import default as default_loading
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestDefaultGoalLoader(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDefaultGoalLoader, self).setUp()
|
||||
self.goal_loader = default_loading.DefaultGoalLoader()
|
||||
|
||||
def test_load_goal_with_empty_model(self):
|
||||
self.assertRaises(
|
||||
exception.LoadingError, self.goal_loader.load, None)
|
||||
|
||||
def test_goal_loader(self):
|
||||
dummy_goal_name = "dummy"
|
||||
# Set up the fake Stevedore extensions
|
||||
fake_extmanager_call = extension.ExtensionManager.make_test_instance(
|
||||
extensions=[extension.Extension(
|
||||
name=dummy_goal_name,
|
||||
entry_point="%s:%s" % (
|
||||
goals.Dummy.__module__,
|
||||
goals.Dummy.__name__),
|
||||
plugin=goals.Dummy,
|
||||
obj=None,
|
||||
)],
|
||||
namespace="watcher_goals",
|
||||
)
|
||||
|
||||
with mock.patch.object(extension, "ExtensionManager") as m_ext_manager:
|
||||
m_ext_manager.return_value = fake_extmanager_call
|
||||
loaded_goal = self.goal_loader.load("dummy")
|
||||
|
||||
self.assertEqual("dummy", loaded_goal.name)
|
||||
self.assertEqual("Dummy goal", loaded_goal.display_name)
|
||||
|
||||
def test_load_dummy_goal(self):
|
||||
goal_loader = default_loading.DefaultGoalLoader()
|
||||
loaded_goal = goal_loader.load("dummy")
|
||||
self.assertIsInstance(loaded_goal, goals.Dummy)
|
||||
|
||||
|
||||
class TestLoadGoalsWithDefaultGoalLoader(base.TestCase):
|
||||
|
||||
goal_loader = default_loading.DefaultGoalLoader()
|
||||
|
||||
# test matrix (1 test execution per goal entry point)
|
||||
scenarios = [
|
||||
(goal_name,
|
||||
{"goal_name": goal_name, "goal_cls": goal_cls})
|
||||
for goal_name, goal_cls
|
||||
in goal_loader.list_available().items()]
|
||||
|
||||
def test_load_goals(self):
|
||||
goal = self.goal_loader.load(self.goal_name)
|
||||
self.assertIsNotNone(goal)
|
||||
self.assertEqual(self.goal_cls.get_name(), goal.name)
|
||||
@@ -13,31 +13,25 @@
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
from stevedore import extension
|
||||
|
||||
from watcher.common import exception
|
||||
from watcher.decision_engine.strategy.loading import default as default_loading
|
||||
from watcher.decision_engine.loading import default as default_loading
|
||||
from watcher.decision_engine.strategy.strategies import dummy_strategy
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestDefaultStrategyLoader(base.TestCase):
|
||||
|
||||
def test_load_strategy_with_empty_model(self):
|
||||
strategy_loader = default_loading.DefaultStrategyLoader()
|
||||
self.assertRaises(exception.LoadingError, strategy_loader.load, None)
|
||||
def setUp(self):
|
||||
super(TestDefaultStrategyLoader, self).setUp()
|
||||
self.strategy_loader = default_loading.DefaultStrategyLoader()
|
||||
|
||||
def test_load_strategy_is_basic(self):
|
||||
strategy_loader = default_loading.DefaultStrategyLoader()
|
||||
expected_strategy = 'basic'
|
||||
selected_strategy = strategy_loader.load(expected_strategy)
|
||||
self.assertEqual(
|
||||
selected_strategy.id,
|
||||
expected_strategy,
|
||||
'The default strategy should be basic')
|
||||
def test_load_strategy_with_empty_model(self):
|
||||
self.assertRaises(
|
||||
exception.LoadingError, self.strategy_loader.load, None)
|
||||
|
||||
def test_strategy_loader(self):
|
||||
dummy_strategy_name = "dummy"
|
||||
@@ -56,10 +50,10 @@ class TestDefaultStrategyLoader(base.TestCase):
|
||||
|
||||
with mock.patch.object(extension, "ExtensionManager") as m_ext_manager:
|
||||
m_ext_manager.return_value = fake_extmanager_call
|
||||
strategy_loader = default_loading.DefaultStrategyLoader()
|
||||
loaded_strategy = strategy_loader.load("dummy")
|
||||
loaded_strategy = self.strategy_loader.load(
|
||||
"dummy")
|
||||
|
||||
self.assertEqual("dummy", loaded_strategy.id)
|
||||
self.assertEqual("dummy", loaded_strategy.name)
|
||||
self.assertEqual("Dummy strategy", loaded_strategy.display_name)
|
||||
|
||||
def test_load_dummy_strategy(self):
|
||||
@@ -67,6 +61,18 @@ class TestDefaultStrategyLoader(base.TestCase):
|
||||
loaded_strategy = strategy_loader.load("dummy")
|
||||
self.assertIsInstance(loaded_strategy, dummy_strategy.DummyStrategy)
|
||||
|
||||
def test_endpoints(self):
|
||||
for endpoint in strategy_loader.list_available():
|
||||
self.assertIsNotNone(self.strategy_loader.load(endpoint))
|
||||
|
||||
class TestLoadStrategiesWithDefaultStrategyLoader(base.TestCase):
|
||||
|
||||
strategy_loader = default_loading.DefaultStrategyLoader()
|
||||
|
||||
scenarios = [
|
||||
(strategy_name,
|
||||
{"strategy_name": strategy_name, "strategy_cls": strategy_cls})
|
||||
for strategy_name, strategy_cls
|
||||
in strategy_loader.list_available().items()]
|
||||
|
||||
def test_load_strategies(self):
|
||||
strategy = self.strategy_loader.load(self.strategy_name)
|
||||
self.assertIsNotNone(strategy)
|
||||
self.assertEqual(self.strategy_cls.get_name(), strategy.name)
|
||||
|
||||
@@ -18,7 +18,7 @@ import mock
|
||||
from oslo_config import cfg
|
||||
|
||||
from watcher.common import exception
|
||||
from watcher.decision_engine.strategy.loading import default as default_loader
|
||||
from watcher.decision_engine.loading import default as default_loader
|
||||
from watcher.decision_engine.strategy.selection import (
|
||||
default as default_selector)
|
||||
from watcher.decision_engine.strategy import strategies
|
||||
@@ -34,7 +34,7 @@ class TestStrategySelector(base.TestCase):
|
||||
|
||||
@mock.patch.object(default_loader.DefaultStrategyLoader, 'load')
|
||||
def test_select_with_strategy_name(self, m_load):
|
||||
expected_goal = 'DUMMY'
|
||||
expected_goal = 'dummy'
|
||||
expected_strategy = "dummy"
|
||||
strategy_selector = default_selector.DefaultStrategySelector(
|
||||
expected_goal, expected_strategy, osc=None)
|
||||
@@ -45,7 +45,7 @@ class TestStrategySelector(base.TestCase):
|
||||
@mock.patch.object(default_loader.DefaultStrategyLoader, 'list_available')
|
||||
def test_select_with_goal_name_only(self, m_list_available, m_load):
|
||||
m_list_available.return_value = {"dummy": strategies.DummyStrategy}
|
||||
expected_goal = 'DUMMY'
|
||||
expected_goal = 'dummy'
|
||||
expected_strategy = "dummy"
|
||||
strategy_selector = default_selector.DefaultStrategySelector(
|
||||
expected_goal, osc=None)
|
||||
@@ -54,13 +54,13 @@ class TestStrategySelector(base.TestCase):
|
||||
|
||||
def test_select_non_existing_strategy(self):
|
||||
strategy_selector = default_selector.DefaultStrategySelector(
|
||||
"DUMMY", "NOT_FOUND")
|
||||
"dummy", "NOT_FOUND")
|
||||
self.assertRaises(exception.LoadingError, strategy_selector.select)
|
||||
|
||||
@mock.patch.object(default_loader.DefaultStrategyLoader, 'list_available')
|
||||
def test_select_no_available_strategy_for_goal(self, m_list_available):
|
||||
m_list_available.return_value = {}
|
||||
strategy_selector = default_selector.DefaultStrategySelector(
|
||||
"DUMMY")
|
||||
"dummy")
|
||||
self.assertRaises(exception.NoAvailableStrategyForGoal,
|
||||
strategy_selector.select)
|
||||
|
||||
@@ -18,10 +18,11 @@ import mock
|
||||
|
||||
from watcher.common import context
|
||||
from watcher.common import utils
|
||||
from watcher.decision_engine.strategy.loading import default
|
||||
from watcher.decision_engine.loading import default
|
||||
from watcher.decision_engine import sync
|
||||
from watcher import objects
|
||||
from watcher.tests.db import base
|
||||
from watcher.tests.decision_engine import fake_goals
|
||||
from watcher.tests.decision_engine import fake_strategies
|
||||
|
||||
|
||||
@@ -43,12 +44,28 @@ class TestSyncer(base.DbTestCase):
|
||||
fake_strategies.FakeDummy2Strategy4,
|
||||
})
|
||||
|
||||
self.m_available_goals = mock.Mock(return_value={
|
||||
fake_goals.FakeDummy1.get_name(): fake_goals.FakeDummy1,
|
||||
fake_goals.FakeDummy2.get_name(): fake_goals.FakeDummy2,
|
||||
})
|
||||
|
||||
p_goals_load = mock.patch.object(
|
||||
default.DefaultGoalLoader, 'load',
|
||||
side_effect=lambda goal: self.m_available_goals()[goal]())
|
||||
p_goals = mock.patch.object(
|
||||
default.DefaultGoalLoader, 'list_available',
|
||||
self.m_available_goals)
|
||||
p_strategies = mock.patch.object(
|
||||
default.DefaultStrategyLoader, 'list_available',
|
||||
self.m_available_strategies)
|
||||
|
||||
p_goals.start()
|
||||
p_goals_load.start()
|
||||
p_strategies.start()
|
||||
|
||||
self.syncer = sync.Syncer()
|
||||
self.addCleanup(p_goals.stop)
|
||||
self.addCleanup(p_goals_load.stop)
|
||||
self.addCleanup(p_strategies.stop)
|
||||
|
||||
@mock.patch.object(objects.Strategy, "soft_delete")
|
||||
@@ -94,7 +111,7 @@ class TestSyncer(base.DbTestCase):
|
||||
objects.Goal(self.ctx, id=i) for i in range(1, 10)]
|
||||
m_g_list.return_value = [
|
||||
objects.Goal(self.ctx, id=1, uuid=utils.generate_uuid(),
|
||||
name="DUMMY_1", display_name="Dummy 1")
|
||||
name="dummy_1", display_name="Dummy 1",)
|
||||
]
|
||||
m_s_list.return_value = []
|
||||
|
||||
@@ -124,10 +141,10 @@ class TestSyncer(base.DbTestCase):
|
||||
objects.Goal(self.ctx, id=i) for i in range(1, 10)]
|
||||
m_g_list.return_value = [
|
||||
objects.Goal(self.ctx, id=1, uuid=utils.generate_uuid(),
|
||||
name="DUMMY_1", display_name="Dummy 1")
|
||||
name="dummy_1", display_name="Dummy 1",)
|
||||
]
|
||||
m_s_list.return_value = [
|
||||
objects.Strategy(self.ctx, id=1, name="STRATEGY_1",
|
||||
objects.Strategy(self.ctx, id=1, name="strategy_1",
|
||||
goal_id=1, display_name="Strategy 1")
|
||||
]
|
||||
self.syncer.sync()
|
||||
@@ -154,10 +171,10 @@ class TestSyncer(base.DbTestCase):
|
||||
m_g_get_by_name, m_s_list, m_s_create, m_s_save, m_s_soft_delete):
|
||||
m_g_get_by_name.side_effect = [
|
||||
objects.Goal(self.ctx, id=i) for i in range(1, 10)]
|
||||
m_g_list.return_value = [
|
||||
objects.Goal(self.ctx, id=1, uuid=utils.generate_uuid(),
|
||||
name="DUMMY_2", display_name="original")
|
||||
]
|
||||
m_g_list.return_value = [objects.Goal(
|
||||
self.ctx, id=1, uuid=utils.generate_uuid(),
|
||||
name="dummy_2", display_name="original",
|
||||
)]
|
||||
m_s_list.return_value = []
|
||||
self.syncer.sync()
|
||||
|
||||
@@ -185,10 +202,10 @@ class TestSyncer(base.DbTestCase):
|
||||
objects.Goal(self.ctx, id=i) for i in range(1, 10)]
|
||||
m_g_list.return_value = [
|
||||
objects.Goal(self.ctx, id=1, uuid=utils.generate_uuid(),
|
||||
name="DUMMY_1", display_name="Dummy 1")
|
||||
name="dummy_1", display_name="Dummy 1",)
|
||||
]
|
||||
m_s_list.return_value = [
|
||||
objects.Strategy(self.ctx, id=1, name="STRATEGY_1",
|
||||
objects.Strategy(self.ctx, id=1, name="strategy_1",
|
||||
goal_id=1, display_name="original")
|
||||
]
|
||||
self.syncer.sync()
|
||||
@@ -208,29 +225,32 @@ class TestSyncer(base.DbTestCase):
|
||||
# that were saved in DB
|
||||
|
||||
# Should stay unmodified after sync()
|
||||
goal1 = objects.Goal(self.ctx, id=1, uuid=utils.generate_uuid(),
|
||||
name="DUMMY_1", display_name="Dummy 1")
|
||||
goal1 = objects.Goal(
|
||||
self.ctx, id=1, uuid=utils.generate_uuid(),
|
||||
name="dummy_1", display_name="Dummy 1",)
|
||||
# Should be modified by the sync()
|
||||
goal2 = objects.Goal(self.ctx, id=2, uuid=utils.generate_uuid(),
|
||||
name="DUMMY_2", display_name="Original")
|
||||
goal2 = objects.Goal(
|
||||
self.ctx, id=2, uuid=utils.generate_uuid(),
|
||||
name="dummy_2", display_name="Original",
|
||||
)
|
||||
goal1.create()
|
||||
goal2.create()
|
||||
|
||||
# Should stay unmodified after sync()
|
||||
strategy1 = objects.Strategy(
|
||||
self.ctx, id=1, name="STRATEGY_1", uuid=utils.generate_uuid(),
|
||||
self.ctx, id=1, name="strategy_1", uuid=utils.generate_uuid(),
|
||||
display_name="Strategy 1", goal_id=goal1.id)
|
||||
# Should stay unmodified after sync()
|
||||
strategy2 = objects.Strategy(
|
||||
self.ctx, id=2, name="STRATEGY_2", uuid=utils.generate_uuid(),
|
||||
self.ctx, id=2, name="strategy_2", uuid=utils.generate_uuid(),
|
||||
display_name="Strategy 2", goal_id=goal2.id)
|
||||
# Should be modified by the sync()
|
||||
strategy3 = objects.Strategy(
|
||||
self.ctx, id=3, name="STRATEGY_3", uuid=utils.generate_uuid(),
|
||||
self.ctx, id=3, name="strategy_3", uuid=utils.generate_uuid(),
|
||||
display_name="Original", goal_id=goal2.id)
|
||||
# Should be modified by the sync()
|
||||
strategy4 = objects.Strategy(
|
||||
self.ctx, id=4, name="STRATEGY_4", uuid=utils.generate_uuid(),
|
||||
self.ctx, id=4, name="strategy_4", uuid=utils.generate_uuid(),
|
||||
display_name="Original", goal_id=goal2.id)
|
||||
strategy1.create()
|
||||
strategy2.create()
|
||||
@@ -288,10 +308,10 @@ class TestSyncer(base.DbTestCase):
|
||||
self.assertEqual(4, len(after_strategies))
|
||||
self.assertEqual(4, len(after_audit_templates))
|
||||
self.assertEqual(
|
||||
{"DUMMY_1", "DUMMY_2"},
|
||||
{"dummy_1", "dummy_2"},
|
||||
set([g.name for g in after_goals]))
|
||||
self.assertEqual(
|
||||
{"STRATEGY_1", "STRATEGY_2", "STRATEGY_3", "STRATEGY_4"},
|
||||
{"strategy_1", "strategy_2", "strategy_3", "strategy_4"},
|
||||
set([s.name for s in after_strategies]))
|
||||
created_goals = {
|
||||
ag.name: ag for ag in after_goals
|
||||
@@ -341,33 +361,39 @@ class TestSyncer(base.DbTestCase):
|
||||
def test_end2end_sync_goals_with_removed_goal_and_strategy(self):
|
||||
# ### Setup ### #
|
||||
|
||||
# We Simulate the fact that we removed 2 strategies
|
||||
# as well as the DUMMY_2 goal
|
||||
# We simulate the fact that we removed 2 strategies
|
||||
self.m_available_strategies.return_value = {
|
||||
fake_strategies.FakeDummy1Strategy1.get_name():
|
||||
fake_strategies.FakeDummy1Strategy1
|
||||
}
|
||||
|
||||
# We simulate the fact that we removed the dummy_2 goal
|
||||
self.m_available_goals.return_value = {
|
||||
fake_goals.FakeDummy1.get_name(): fake_goals.FakeDummy1,
|
||||
}
|
||||
# Should stay unmodified after sync()
|
||||
goal1 = objects.Goal(self.ctx, id=1, uuid=utils.generate_uuid(),
|
||||
name="DUMMY_1", display_name="Dummy 1")
|
||||
goal1 = objects.Goal(
|
||||
self.ctx, id=1, uuid=utils.generate_uuid(),
|
||||
name="dummy_1", display_name="Dummy 1",
|
||||
)
|
||||
# To be removed by the sync()
|
||||
goal2 = objects.Goal(self.ctx, id=2, uuid=utils.generate_uuid(),
|
||||
name="DUMMY_2", display_name="Dummy 2")
|
||||
goal2 = objects.Goal(
|
||||
self.ctx, id=2, uuid=utils.generate_uuid(),
|
||||
name="dummy_2", display_name="Dummy 2",
|
||||
)
|
||||
goal1.create()
|
||||
goal2.create()
|
||||
|
||||
# Should stay unmodified after sync()
|
||||
strategy1 = objects.Strategy(
|
||||
self.ctx, id=1, name="STRATEGY_1", uuid=utils.generate_uuid(),
|
||||
self.ctx, id=1, name="strategy_1", uuid=utils.generate_uuid(),
|
||||
display_name="Strategy 1", goal_id=goal1.id)
|
||||
# To be removed by the sync()
|
||||
strategy2 = objects.Strategy(
|
||||
self.ctx, id=2, name="STRATEGY_2", uuid=utils.generate_uuid(),
|
||||
self.ctx, id=2, name="strategy_2", uuid=utils.generate_uuid(),
|
||||
display_name="Strategy 2", goal_id=goal1.id)
|
||||
# To be removed by the sync()
|
||||
strategy3 = objects.Strategy(
|
||||
self.ctx, id=3, name="STRATEGY_3", uuid=utils.generate_uuid(),
|
||||
self.ctx, id=3, name="strategy_3", uuid=utils.generate_uuid(),
|
||||
display_name="Original", goal_id=goal2.id)
|
||||
strategy1.create()
|
||||
strategy2.create()
|
||||
@@ -413,10 +439,10 @@ class TestSyncer(base.DbTestCase):
|
||||
self.assertEqual(1, len(after_strategies))
|
||||
self.assertEqual(2, len(after_audit_templates))
|
||||
self.assertEqual(
|
||||
{"DUMMY_1"},
|
||||
{"dummy_1"},
|
||||
set([g.name for g in after_goals]))
|
||||
self.assertEqual(
|
||||
{"STRATEGY_1"},
|
||||
{"strategy_1"},
|
||||
set([s.name for s in after_strategies]))
|
||||
created_goals = [ag for ag in after_goals
|
||||
if ag.uuid not in [bg.uuid for bg in before_goals]]
|
||||
|
||||
Reference in New Issue
Block a user