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:
Giulio Fidente 2016-08-25 02:43:22 +02:00
parent 98656b5717
commit d5cdbfb642
3 changed files with 14 additions and 57 deletions

View File

@ -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 ipaddress>=1.0.7;python_version<'3.3' # PSF
passlib>=1.6 # BSD passlib>=1.6 # BSD
python-ironic-inspector-client>=1.5.0 # Apache-2.0 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-ironicclient>=1.6.0 # Apache-2.0
python-mistralclient>=2.0.0 # Apache-2.0 python-mistralclient>=2.0.0 # Apache-2.0
python-openstackclient>=2.1.0 # Apache-2.0 python-openstackclient>=2.1.0 # Apache-2.0

View File

@ -182,8 +182,7 @@ class TestWaitForStackUtil(TestCase):
return e return e
@mock.patch("heatclient.common.event_utils.get_events") @mock.patch("heatclient.common.event_utils.get_events")
@mock.patch('time.sleep', return_value=None) def test_wait_for_stack_ready(self, mock_el):
def test_wait_for_stack_ready(self, sleep_mock, mock_el):
stack = mock.Mock() stack = mock.Mock()
stack.stack_name = 'stack' stack.stack_name = 'stack'
stack.stack_status = "CREATE_COMPLETE" stack.stack_status = "CREATE_COMPLETE"
@ -191,7 +190,6 @@ class TestWaitForStackUtil(TestCase):
complete = utils.wait_for_stack_ready(self.mock_orchestration, 'stack') complete = utils.wait_for_stack_ready(self.mock_orchestration, 'stack')
self.assertTrue(complete) self.assertTrue(complete)
sleep_mock.assert_not_called()
def test_wait_for_stack_ready_no_stack(self): def test_wait_for_stack_ready_no_stack(self):
self.mock_orchestration.stacks.get.return_value = None self.mock_orchestration.stacks.get.return_value = None
@ -201,8 +199,7 @@ class TestWaitForStackUtil(TestCase):
self.assertFalse(complete) self.assertFalse(complete)
@mock.patch("heatclient.common.event_utils.get_events") @mock.patch("heatclient.common.event_utils.get_events")
@mock.patch('time.sleep', return_value=None) def test_wait_for_stack_ready_failed(self, mock_el):
def test_wait_for_stack_ready_failed(self, sleep_mock, mock_el):
stack = mock.Mock() stack = mock.Mock()
stack.stack_name = 'stack' stack.stack_name = 'stack'
stack.stack_status = "CREATE_FAILED" stack.stack_status = "CREATE_FAILED"
@ -212,11 +209,8 @@ class TestWaitForStackUtil(TestCase):
self.assertFalse(complete) self.assertFalse(complete)
sleep_mock.assert_not_called()
@mock.patch("heatclient.common.event_utils.get_events") @mock.patch("heatclient.common.event_utils.get_events")
@mock.patch('time.sleep', return_value=None) def test_wait_for_stack_in_progress(self, mock_el):
def test_wait_for_stack_in_progress(self, sleep_mock, mock_el):
mock_el.side_effect = [[ mock_el.side_effect = [[
self.mock_event('stack', 'aaa', 'Stack CREATE started', self.mock_event('stack', 'aaa', 'Stack CREATE started',
@ -242,8 +236,6 @@ class TestWaitForStackUtil(TestCase):
utils.wait_for_stack_ready(self.mock_orchestration, 'stack') utils.wait_for_stack_ready(self.mock_orchestration, 'stack')
self.assertEqual(2, sleep_mock.call_count)
def test_create_environment_file(self): def test_create_environment_file(self):
json_file_path = "env.json" json_file_path = "env.json"

View File

@ -26,6 +26,7 @@ import six
import socket import socket
import struct import struct
import subprocess import subprocess
import sys
import time import time
import yaml import yaml
@ -271,51 +272,15 @@ def wait_for_stack_ready(orchestration_client, stack_name, marker=None,
return False return False
stack_name = stack.stack_name stack_name = stack.stack_name
while True: if verbose:
out = sys.stdout
events = event_utils.get_events(orchestration_client, else:
stack_id=stack_name, nested_depth=2, out = open(os.devnull, "w")
event_args={'sort_dir': 'asc', stack_status, msg = event_utils.poll_for_events(
'marker': marker}) orchestration_client, stack_name, action=action,
poll_period=5, marker=marker, out=out, nested_depth=2)
if len(events) >= 1: print(msg)
# set marker to last event that was received. return stack_status == '%s_COMPLETE' % action
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)
def nodes_in_states(baremetal_client, states): def nodes_in_states(baremetal_client, states):