Bug fix: create_stack() fails when waiting

The create_stack() call had two bugs: If wait was True, it attempted
to call an iterate method that had been moved to _utils; it also did
not return the stack from the get_stack() calls.

Change-Id: I2588e3a84729a8f1b3bfcb6d401c7d51fb16832b
This commit is contained in:
David Shrewsbury 2015-12-14 09:06:03 -05:00
parent fb8ea73f27
commit 451e51340d
3 changed files with 42 additions and 2 deletions

View File

@ -0,0 +1,4 @@
---
fixes:
- The create_stack() call was fixed to call the correct iterator
method and to return the updated stack object when waiting.

View File

@ -730,10 +730,11 @@ class OpenStackCloud(object):
stack = self.manager.submitTask(_tasks.StackCreate(**params))
if not wait:
return stack
for count in _iterate_timeout(
for count in _utils._iterate_timeout(
timeout,
"Timed out waiting for heat stack to finish"):
if self.get_stack(name, cache=False):
stack = self.get_stack(name, cache=False)
if stack:
return stack
def delete_stack(self, name_or_id):

View File

@ -16,6 +16,8 @@
import mock
import testtools
from heatclient.common import template_utils
import shade
from shade import meta
from shade.tests import fakes
@ -76,3 +78,36 @@ class TestStack(base.TestCase):
"Failed to delete stack %s" % stack['id']
):
self.cloud.delete_stack('stack_name')
@mock.patch.object(template_utils, 'get_template_contents')
@mock.patch.object(shade.OpenStackCloud, 'heat_client')
def test_create_stack(self, mock_heat, mock_template):
mock_template.return_value = ({}, {})
self.cloud.create_stack('stack_name')
self.assertTrue(mock_template.called)
mock_heat.stacks.create.assert_called_once_with(
stack_name='stack_name',
disable_rollback=False,
parameters={},
template={},
files={}
)
@mock.patch.object(template_utils, 'get_template_contents')
@mock.patch.object(shade.OpenStackCloud, 'get_stack')
@mock.patch.object(shade.OpenStackCloud, 'heat_client')
def test_create_stack_wait(self, mock_heat, mock_get, mock_template):
stack = {'id': 'stack_id', 'name': 'stack_name'}
mock_template.return_value = ({}, {})
mock_get.side_effect = iter([None, stack])
ret = self.cloud.create_stack('stack_name', wait=True)
self.assertTrue(mock_template.called)
mock_heat.stacks.create.assert_called_once_with(
stack_name='stack_name',
disable_rollback=False,
parameters={},
template={},
files={}
)
self.assertEqual(2, mock_get.call_count)
self.assertEqual(stack, ret)