Merge "Convergence: Fix unit tests"
This commit is contained in:
commit
d8baa1f65c
@ -11,6 +11,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_messaging.rpc import dispatcher
|
||||
import six
|
||||
@ -56,6 +57,7 @@ class StackServiceAdoptTest(common.HeatTestCase):
|
||||
|
||||
def test_stack_adopt_with_params(self):
|
||||
cfg.CONF.set_override('enable_stack_adopt', True, enforce_type=True)
|
||||
cfg.CONF.set_override('convergence_engine', False, enforce_type=True)
|
||||
env = {'parameters': {"app_dbx": "test"}}
|
||||
template, adopt_data = self._get_adopt_data_and_template(env)
|
||||
result = self.man.create_stack(self.ctx, "test_adopt_with_params",
|
||||
@ -67,8 +69,28 @@ class StackServiceAdoptTest(common.HeatTestCase):
|
||||
self.assertEqual(env['parameters'],
|
||||
stack.raw_template.environment['parameters'])
|
||||
|
||||
@mock.patch.object(parser.Stack, '_converge_create_or_update')
|
||||
@mock.patch.object(parser.Stack, '_send_notification_and_add_event')
|
||||
def test_convergence_stack_adopt_with_params(self,
|
||||
mock_converge,
|
||||
mock_send_notif):
|
||||
cfg.CONF.set_override('enable_stack_adopt', True, enforce_type=True)
|
||||
cfg.CONF.set_override('convergence_engine', True, enforce_type=True)
|
||||
env = {'parameters': {"app_dbx": "test"}}
|
||||
template, adopt_data = self._get_adopt_data_and_template(env)
|
||||
result = self.man.create_stack(self.ctx, "test_adopt_with_params",
|
||||
template, {}, None,
|
||||
{'adopt_stack_data': str(adopt_data)})
|
||||
|
||||
stack = stack_object.Stack.get_by_id(self.ctx, result['stack_id'])
|
||||
self.assertEqual(template, stack.raw_template.template)
|
||||
self.assertEqual(env['parameters'],
|
||||
stack.raw_template.environment['parameters'])
|
||||
self.assertTrue(mock_converge.called)
|
||||
|
||||
def test_stack_adopt_saves_input_params(self):
|
||||
cfg.CONF.set_override('enable_stack_adopt', True, enforce_type=True)
|
||||
cfg.CONF.set_override('convergence_engine', False, enforce_type=True)
|
||||
env = {'parameters': {"app_dbx": "foo"}}
|
||||
input_params = {
|
||||
"parameters": {"app_dbx": "bar"}
|
||||
@ -83,8 +105,30 @@ class StackServiceAdoptTest(common.HeatTestCase):
|
||||
self.assertEqual(input_params['parameters'],
|
||||
stack.raw_template.environment['parameters'])
|
||||
|
||||
@mock.patch.object(parser.Stack, '_converge_create_or_update')
|
||||
@mock.patch.object(parser.Stack, '_send_notification_and_add_event')
|
||||
def test_convergence_stack_adopt_saves_input_params(
|
||||
self, mock_converge, mock_send_notif):
|
||||
cfg.CONF.set_override('enable_stack_adopt', True, enforce_type=True)
|
||||
cfg.CONF.set_override('convergence_engine', True, enforce_type=True)
|
||||
env = {'parameters': {"app_dbx": "foo"}}
|
||||
input_params = {
|
||||
"parameters": {"app_dbx": "bar"}
|
||||
}
|
||||
template, adopt_data = self._get_adopt_data_and_template(env)
|
||||
result = self.man.create_stack(self.ctx, "test_adopt_saves_inputs",
|
||||
template, input_params, None,
|
||||
{'adopt_stack_data': str(adopt_data)})
|
||||
|
||||
stack = stack_object.Stack.get_by_id(self.ctx, result['stack_id'])
|
||||
self.assertEqual(template, stack.raw_template.template)
|
||||
self.assertEqual(input_params['parameters'],
|
||||
stack.raw_template.environment['parameters'])
|
||||
self.assertTrue(mock_converge.called)
|
||||
|
||||
def test_stack_adopt_stack_state(self):
|
||||
cfg.CONF.set_override('enable_stack_adopt', True, enforce_type=True)
|
||||
cfg.CONF.set_override('convergence_engine', False, enforce_type=True)
|
||||
env = {'parameters': {"app_dbx": "test"}}
|
||||
template, adopt_data = self._get_adopt_data_and_template(env)
|
||||
result = self.man.create_stack(self.ctx, "test_adopt_stack_state",
|
||||
@ -95,6 +139,23 @@ class StackServiceAdoptTest(common.HeatTestCase):
|
||||
self.assertEqual((parser.Stack.ADOPT, parser.Stack.IN_PROGRESS),
|
||||
(stack.action, stack.status))
|
||||
|
||||
@mock.patch.object(parser.Stack, '_converge_create_or_update')
|
||||
@mock.patch.object(parser.Stack, '_send_notification_and_add_event')
|
||||
def test_convergence_stack_adopt_stack_state(self, mock_converge,
|
||||
mock_send_notif):
|
||||
cfg.CONF.set_override('enable_stack_adopt', True, enforce_type=True)
|
||||
cfg.CONF.set_override('convergence_engine', True, enforce_type=True)
|
||||
env = {'parameters': {"app_dbx": "test"}}
|
||||
template, adopt_data = self._get_adopt_data_and_template(env)
|
||||
result = self.man.create_stack(self.ctx, "test_adopt_stack_state",
|
||||
template, {}, None,
|
||||
{'adopt_stack_data': str(adopt_data)})
|
||||
|
||||
stack = stack_object.Stack.get_by_id(self.ctx, result['stack_id'])
|
||||
self.assertEqual((parser.Stack.ADOPT, parser.Stack.IN_PROGRESS),
|
||||
(stack.action, stack.status))
|
||||
self.assertTrue(mock_converge.called)
|
||||
|
||||
def test_stack_adopt_disabled(self):
|
||||
# to test disable stack adopt
|
||||
cfg.CONF.set_override('enable_stack_adopt', False, enforce_type=True)
|
||||
|
@ -64,12 +64,10 @@ class StackCreateTest(common.HeatTestCase):
|
||||
|
||||
mock_tmpl.assert_called_once_with(template, files=None, env=stk.env)
|
||||
mock_env.assert_called_once_with(params)
|
||||
mock_stack.assert_called_once_with(self.ctx, stack_name, stk.t,
|
||||
owner_id=None, nested_depth=0,
|
||||
user_creds_id=None,
|
||||
stack_user_project_id=None,
|
||||
convergence=False,
|
||||
parent_resource=None)
|
||||
mock_stack.assert_called_once_with(
|
||||
self.ctx, stack_name, stk.t, owner_id=None, nested_depth=0,
|
||||
user_creds_id=None, stack_user_project_id=None,
|
||||
convergence=cfg.CONF.convergence_engine, parent_resource=None)
|
||||
|
||||
if environment_files:
|
||||
mock_merge.assert_called_once_with(environment_files, None, params)
|
||||
@ -122,12 +120,10 @@ class StackCreateTest(common.HeatTestCase):
|
||||
|
||||
mock_tmpl.assert_called_once_with(template, files=None, env=stk.env)
|
||||
mock_env.assert_called_once_with(params)
|
||||
mock_stack.assert_called_once_with(self.ctx, stack_name, stk.t,
|
||||
owner_id=None, nested_depth=0,
|
||||
user_creds_id=None,
|
||||
stack_user_project_id=None,
|
||||
convergence=False,
|
||||
parent_resource=None)
|
||||
mock_stack.assert_called_once_with(
|
||||
self.ctx, stack_name, stk.t, owner_id=None, nested_depth=0,
|
||||
user_creds_id=None, stack_user_project_id=None,
|
||||
convergence=cfg.CONF.convergence_engine, parent_resource=None)
|
||||
|
||||
def test_stack_create_invalid_stack_name(self):
|
||||
stack_name = 'service_create_test_stack_invalid_name'
|
||||
@ -188,12 +184,10 @@ class StackCreateTest(common.HeatTestCase):
|
||||
|
||||
mock_tmpl.assert_called_once_with(template, files=None, env=stk.env)
|
||||
mock_env.assert_called_once_with(params)
|
||||
mock_stack.assert_called_once_with(ctx_no_pwd, stack_name, stk.t,
|
||||
owner_id=None, nested_depth=0,
|
||||
user_creds_id=None,
|
||||
stack_user_project_id=None,
|
||||
convergence=False,
|
||||
parent_resource=None)
|
||||
mock_stack.assert_called_once_with(
|
||||
ctx_no_pwd, stack_name, stk.t, owner_id=None, nested_depth=0,
|
||||
user_creds_id=None, stack_user_project_id=None,
|
||||
convergence=cfg.CONF.convergence_engine, parent_resource=None)
|
||||
mock_tmpl.reset_mock()
|
||||
mock_env.reset_mock()
|
||||
mock_stack.reset_mock()
|
||||
@ -211,12 +205,10 @@ class StackCreateTest(common.HeatTestCase):
|
||||
|
||||
mock_tmpl.assert_called_once_with(template, files=None, env=stk.env)
|
||||
mock_env.assert_called_once_with(params)
|
||||
mock_stack.assert_called_once_with(ctx_no_user, stack_name, stk.t,
|
||||
owner_id=None, nested_depth=0,
|
||||
user_creds_id=None,
|
||||
stack_user_project_id=None,
|
||||
convergence=False,
|
||||
parent_resource=None)
|
||||
mock_stack.assert_called_once_with(
|
||||
ctx_no_user, stack_name, stk.t, owner_id=None, nested_depth=0,
|
||||
user_creds_id=None, stack_user_project_id=None,
|
||||
convergence=cfg.CONF.convergence_engine, parent_resource=None)
|
||||
|
||||
@mock.patch.object(stack_object.Stack, 'count_total_resources')
|
||||
def test_stack_create_total_resources_equals_max(self, ctr):
|
||||
@ -247,12 +239,10 @@ class StackCreateTest(common.HeatTestCase):
|
||||
|
||||
mock_tmpl.assert_called_once_with(template, files=None, env=stk.env)
|
||||
mock_env.assert_called_once_with(params)
|
||||
mock_stack.assert_called_once_with(self.ctx, stack_name, stk.t,
|
||||
owner_id=None, nested_depth=0,
|
||||
user_creds_id=None,
|
||||
stack_user_project_id=None,
|
||||
convergence=False,
|
||||
parent_resource=None)
|
||||
mock_stack.assert_called_once_with(
|
||||
self.ctx, stack_name, stk.t, owner_id=None, nested_depth=0,
|
||||
user_creds_id=None, stack_user_project_id=None,
|
||||
convergence=cfg.CONF.convergence_engine, parent_resource=None)
|
||||
|
||||
self.assertEqual(stk.identifier(), result)
|
||||
root_stack_id = stk.root_stack_id()
|
||||
@ -283,6 +273,7 @@ class StackCreateTest(common.HeatTestCase):
|
||||
@mock.patch.object(threadgroup, 'ThreadGroup')
|
||||
@mock.patch.object(stack.Stack, 'validate')
|
||||
def test_stack_create_nested(self, mock_validate, mock_tg):
|
||||
convergence_engine = cfg.CONF.convergence_engine
|
||||
stack_name = 'service_create_nested_test_stack'
|
||||
mock_tg.return_value = tools.DummyThreadGroup()
|
||||
|
||||
@ -304,7 +295,7 @@ class StackCreateTest(common.HeatTestCase):
|
||||
owner_id=None, nested_depth=1,
|
||||
user_creds_id=None,
|
||||
stack_user_project_id=None,
|
||||
convergence=False,
|
||||
convergence=convergence_engine,
|
||||
parent_resource=None)
|
||||
|
||||
mock_validate.assert_called_once_with()
|
||||
|
@ -448,6 +448,7 @@ class ResourceTest(common.HeatTestCase):
|
||||
exception.ResourceFailure, scheduler.TaskRunner(res.update, utmpl))
|
||||
|
||||
def test_update_replace_rollback(self):
|
||||
cfg.CONF.set_override('convergence_engine', False, enforce_type=True)
|
||||
res, utmpl = self._setup_resource_for_update(
|
||||
res_name='test_update_replace_rollback')
|
||||
res.restore_prev_rsrc = mock.Mock()
|
||||
@ -458,6 +459,7 @@ class ResourceTest(common.HeatTestCase):
|
||||
self.assertTrue(res.restore_prev_rsrc.called)
|
||||
|
||||
def test_update_replace_rollback_restore_prev_rsrc_error(self):
|
||||
cfg.CONF.set_override('convergence_engine', False, enforce_type=True)
|
||||
res, utmpl = self._setup_resource_for_update(
|
||||
res_name='restore_prev_rsrc_error')
|
||||
res.restore_prev_rsrc = mock.Mock(side_effect=Exception)
|
||||
|
Loading…
Reference in New Issue
Block a user