refactor atomics actions

We decided to still use atomic_actions field.
First step, save new atomic actions format in database,
and convert the new format to old format where the atomic
actions needs to be used.
Blueprint: improve-atomic-actions

Co-Authored-By: chenhb-zte <chen.haibing1@zte.com.cn>

Change-Id: I8aecd5bad319aa61d5f8a20a2c2fe9bacdc0e81a
This commit is contained in:
Andrey Kurilin 2016-09-08 15:48:01 +03:00 committed by chenhb
parent e3dcae4e36
commit de6c27e713
3 changed files with 9 additions and 7 deletions

View File

@ -41,12 +41,10 @@ class CalculateAtomic(scenario.Scenario, utils.RandomNameGeneratorMixin):
:param number_of_atomics: int number of atomics to run :param number_of_atomics: int number of atomics to run
""" """
tmp_name = "tmp_actions" tmp_name = "tmp_actions"
atomic_inst = atomic.ActionTimerMixin()
calc_atomic_name = "calculate_%s_atomics" % number_of_atomics calc_atomic_name = "calculate_%s_atomics" % number_of_atomics
with atomic.ActionTimer(self, calc_atomic_name): with atomic.ActionTimer(self, calc_atomic_name):
for _ in range(number_of_atomics): for _ in range(number_of_atomics):
with atomic.ActionTimer(self, tmp_name): with atomic.ActionTimer(atomic_inst, tmp_name):
pass pass
self._atomic_actions = {
calc_atomic_name: self._atomic_actions[calc_atomic_name]}

View File

@ -58,7 +58,7 @@ class StackTestCase(test.ScenarioTestCase):
@mock.patch("rally.plugins.openstack.services.heat.main.open") @mock.patch("rally.plugins.openstack.services.heat.main.open")
@mock.patch("rally.plugins.openstack.services.heat.main.Stack._wait") @mock.patch("rally.plugins.openstack.services.heat.main.Stack._wait")
def test_create(self, mock_stack__wait, mock_open, mock_task_atomic): def test_create(self, mock_stack__wait, mock_open, mock_task_atomic):
mock_scenario = mock.MagicMock() mock_scenario = mock.MagicMock(_atomic_actions=[])
mock_scenario.generate_random_name.return_value = "fake_name" mock_scenario.generate_random_name.return_value = "fake_name"
mock_open().read.return_value = "fake_content" mock_open().read.return_value = "fake_content"
mock_new_stack = { mock_new_stack = {
@ -87,7 +87,8 @@ class StackTestCase(test.ScenarioTestCase):
@mock.patch("rally.plugins.openstack.services.heat.main.open") @mock.patch("rally.plugins.openstack.services.heat.main.open")
@mock.patch("rally.plugins.openstack.services.heat.main.Stack._wait") @mock.patch("rally.plugins.openstack.services.heat.main.Stack._wait")
def test_update(self, mock_stack__wait, mock_open, mock_task_atomic): def test_update(self, mock_stack__wait, mock_open, mock_task_atomic):
mock_scenario = mock.MagicMock(stack_id="fake_id") mock_scenario = mock.MagicMock(
stack_id="fake_id", _atomic_actions=[])
mock_parameters = mock.Mock() mock_parameters = mock.Mock()
mock_open().read.return_value = "fake_content" mock_open().read.return_value = "fake_content"
stack = main.Stack( stack = main.Stack(

View File

@ -22,6 +22,7 @@ from oslotest import base
from oslotest import mockpatch from oslotest import mockpatch
from rally.common import db from rally.common import db
from rally.common import objects
from rally import plugins from rally import plugins
from tests.unit import fakes from tests.unit import fakes
@ -46,7 +47,9 @@ class TestCase(base.BaseTestCase):
plugins.load() plugins.load()
def _test_atomic_action_timer(self, atomic_actions, name): def _test_atomic_action_timer(self, atomic_actions, name):
action_duration = atomic_actions.get(name) _old_atomic_actions = objects.Task.convert_atomic_actions(
atomic_actions)
action_duration = _old_atomic_actions.get(name)
self.assertIsNotNone(action_duration) self.assertIsNotNone(action_duration)
self.assertIsInstance(action_duration, float) self.assertIsInstance(action_duration, float)