Use heatclient poll_for_events in wait_for_stack_ready
Resort to the new heatclient builtin to check for the stack status
and removes custom implementation from tripleoclient utils.
Change-Id: I5f48eb87a5e06846cd40c1b61aade60acdcb2a18
(cherry picked from commit 252f43e6e8
)
This commit is contained in:
parent
98656b5717
commit
d5cdbfb642
@ -8,7 +8,7 @@ cliff!=1.16.0,!=1.17.0,>=1.15.0 # Apache-2.0
|
||||
ipaddress>=1.0.7;python_version<'3.3' # PSF
|
||||
passlib>=1.6 # BSD
|
||||
python-ironic-inspector-client>=1.5.0 # Apache-2.0
|
||||
python-heatclient>=1.1.0 # Apache-2.0
|
||||
python-heatclient>=1.4.0 # Apache-2.0
|
||||
python-ironicclient>=1.6.0 # Apache-2.0
|
||||
python-mistralclient>=2.0.0 # Apache-2.0
|
||||
python-openstackclient>=2.1.0 # Apache-2.0
|
||||
|
@ -182,8 +182,7 @@ class TestWaitForStackUtil(TestCase):
|
||||
return e
|
||||
|
||||
@mock.patch("heatclient.common.event_utils.get_events")
|
||||
@mock.patch('time.sleep', return_value=None)
|
||||
def test_wait_for_stack_ready(self, sleep_mock, mock_el):
|
||||
def test_wait_for_stack_ready(self, mock_el):
|
||||
stack = mock.Mock()
|
||||
stack.stack_name = 'stack'
|
||||
stack.stack_status = "CREATE_COMPLETE"
|
||||
@ -191,7 +190,6 @@ class TestWaitForStackUtil(TestCase):
|
||||
|
||||
complete = utils.wait_for_stack_ready(self.mock_orchestration, 'stack')
|
||||
self.assertTrue(complete)
|
||||
sleep_mock.assert_not_called()
|
||||
|
||||
def test_wait_for_stack_ready_no_stack(self):
|
||||
self.mock_orchestration.stacks.get.return_value = None
|
||||
@ -201,8 +199,7 @@ class TestWaitForStackUtil(TestCase):
|
||||
self.assertFalse(complete)
|
||||
|
||||
@mock.patch("heatclient.common.event_utils.get_events")
|
||||
@mock.patch('time.sleep', return_value=None)
|
||||
def test_wait_for_stack_ready_failed(self, sleep_mock, mock_el):
|
||||
def test_wait_for_stack_ready_failed(self, mock_el):
|
||||
stack = mock.Mock()
|
||||
stack.stack_name = 'stack'
|
||||
stack.stack_status = "CREATE_FAILED"
|
||||
@ -212,11 +209,8 @@ class TestWaitForStackUtil(TestCase):
|
||||
|
||||
self.assertFalse(complete)
|
||||
|
||||
sleep_mock.assert_not_called()
|
||||
|
||||
@mock.patch("heatclient.common.event_utils.get_events")
|
||||
@mock.patch('time.sleep', return_value=None)
|
||||
def test_wait_for_stack_in_progress(self, sleep_mock, mock_el):
|
||||
def test_wait_for_stack_in_progress(self, mock_el):
|
||||
|
||||
mock_el.side_effect = [[
|
||||
self.mock_event('stack', 'aaa', 'Stack CREATE started',
|
||||
@ -242,8 +236,6 @@ class TestWaitForStackUtil(TestCase):
|
||||
|
||||
utils.wait_for_stack_ready(self.mock_orchestration, 'stack')
|
||||
|
||||
self.assertEqual(2, sleep_mock.call_count)
|
||||
|
||||
def test_create_environment_file(self):
|
||||
|
||||
json_file_path = "env.json"
|
||||
|
@ -26,6 +26,7 @@ import six
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import yaml
|
||||
|
||||
@ -271,51 +272,15 @@ def wait_for_stack_ready(orchestration_client, stack_name, marker=None,
|
||||
return False
|
||||
stack_name = stack.stack_name
|
||||
|
||||
while True:
|
||||
|
||||
events = event_utils.get_events(orchestration_client,
|
||||
stack_id=stack_name, nested_depth=2,
|
||||
event_args={'sort_dir': 'asc',
|
||||
'marker': marker})
|
||||
|
||||
if len(events) >= 1:
|
||||
# set marker to last event that was received.
|
||||
marker = getattr(events[-1], 'id', None)
|
||||
|
||||
if verbose:
|
||||
events_log = event_log_formatter(events)
|
||||
print(events_log)
|
||||
|
||||
stack = get_stack(orchestration_client, stack_name)
|
||||
stack_status = stack.stack_status
|
||||
if stack_status == '%s_COMPLETE' % action:
|
||||
print("Stack %(name)s %(status)s" % dict(
|
||||
name=stack_name, status=stack_status))
|
||||
return True
|
||||
elif stack_status == '%s_FAILED' % action:
|
||||
print("Stack %(name)s %(status)s" % dict(
|
||||
name=stack_name, status=stack_status))
|
||||
return False
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
def event_log_formatter(events):
|
||||
"""Return the events in log format."""
|
||||
event_log = []
|
||||
log_format = ("%(event_time)s "
|
||||
"[%(rsrc_name)s]: %(rsrc_status)s %(rsrc_status_reason)s")
|
||||
for event in events:
|
||||
event_time = getattr(event, 'event_time', '')
|
||||
log = log_format % {
|
||||
'event_time': event_time.replace('T', ' '),
|
||||
'rsrc_name': getattr(event, 'resource_name', ''),
|
||||
'rsrc_status': getattr(event, 'resource_status', ''),
|
||||
'rsrc_status_reason': getattr(event, 'resource_status_reason', '')
|
||||
}
|
||||
event_log.append(log)
|
||||
|
||||
return "\n".join(event_log)
|
||||
if verbose:
|
||||
out = sys.stdout
|
||||
else:
|
||||
out = open(os.devnull, "w")
|
||||
stack_status, msg = event_utils.poll_for_events(
|
||||
orchestration_client, stack_name, action=action,
|
||||
poll_period=5, marker=marker, out=out, nested_depth=2)
|
||||
print(msg)
|
||||
return stack_status == '%s_COMPLETE' % action
|
||||
|
||||
|
||||
def nodes_in_states(baremetal_client, states):
|
||||
|
Loading…
Reference in New Issue
Block a user