Merge "Remove TaskRunner from SwiftSignal"
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
import json
|
import json
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
|
from oslo_utils import timeutils
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
@@ -24,7 +25,6 @@ from heat.engine.clients.os import swift
|
|||||||
from heat.engine import constraints
|
from heat.engine import constraints
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine import scheduler
|
|
||||||
from heat.engine import support
|
from heat.engine import support
|
||||||
from heat.openstack.common import log as logging
|
from heat.openstack.common import log as logging
|
||||||
|
|
||||||
@@ -227,35 +227,8 @@ class SwiftSignal(resource.Resource):
|
|||||||
|
|
||||||
def handle_create(self):
|
def handle_create(self):
|
||||||
self._validate_handle_url()
|
self._validate_handle_url()
|
||||||
runner = scheduler.TaskRunner(self._wait)
|
started_at = timeutils.utcnow()
|
||||||
runner.start(timeout=float(self.properties.get(self.TIMEOUT)))
|
return started_at, float(self.properties[self.TIMEOUT])
|
||||||
return runner
|
|
||||||
|
|
||||||
def _wait(self):
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
yield
|
|
||||||
except scheduler.Timeout:
|
|
||||||
count = self.properties.get(self.COUNT)
|
|
||||||
raise SwiftSignalTimeout(self)
|
|
||||||
|
|
||||||
count = self.properties.get(self.COUNT)
|
|
||||||
statuses = self.get_status()
|
|
||||||
if not statuses:
|
|
||||||
continue
|
|
||||||
|
|
||||||
for status in statuses:
|
|
||||||
if status == self.STATUS_FAILURE:
|
|
||||||
failure = SwiftSignalFailure(self)
|
|
||||||
LOG.info(_LI('%(name)s Failed (%(failure)s)'),
|
|
||||||
{'name': str(self), 'failure': str(failure)})
|
|
||||||
raise failure
|
|
||||||
elif status != self.STATUS_SUCCESS:
|
|
||||||
raise exception.Error(_("Unknown status: %s") % status)
|
|
||||||
|
|
||||||
if len(statuses) >= count:
|
|
||||||
LOG.info(_LI("%s Succeeded"), str(self))
|
|
||||||
return
|
|
||||||
|
|
||||||
def get_signals(self):
|
def get_signals(self):
|
||||||
try:
|
try:
|
||||||
@@ -335,8 +308,25 @@ class SwiftSignal(resource.Resource):
|
|||||||
data[signal[self.UNIQUE_ID]] = signal[self.DATA]
|
data[signal[self.UNIQUE_ID]] = signal[self.DATA]
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def check_create_complete(self, runner):
|
def check_create_complete(self, create_data):
|
||||||
return runner.step()
|
if timeutils.is_older_than(*create_data):
|
||||||
|
raise SwiftSignalTimeout(self)
|
||||||
|
|
||||||
|
statuses = self.get_status()
|
||||||
|
|
||||||
|
for status in statuses:
|
||||||
|
if status == self.STATUS_FAILURE:
|
||||||
|
failure = SwiftSignalFailure(self)
|
||||||
|
LOG.info(_LI('%(name)s Failed (%(failure)s)'),
|
||||||
|
{'name': str(self), 'failure': str(failure)})
|
||||||
|
raise failure
|
||||||
|
elif status != self.STATUS_SUCCESS:
|
||||||
|
raise exception.Error(_("Unknown status: %s") % status)
|
||||||
|
|
||||||
|
if len(statuses) >= self.properties[self.COUNT]:
|
||||||
|
LOG.info(_LI("%s Succeeded"), str(self))
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def _resolve_attribute(self, key):
|
def _resolve_attribute(self, key):
|
||||||
if key == self.DATA:
|
if key == self.DATA:
|
||||||
|
|||||||
@@ -12,11 +12,12 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import datetime
|
||||||
import json
|
import json
|
||||||
import time
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
from oslo_utils import timeutils
|
||||||
import six
|
import six
|
||||||
from swiftclient import client as swiftclient_client
|
from swiftclient import client as swiftclient_client
|
||||||
from swiftclient import exceptions as swiftclient_exceptions
|
from swiftclient import exceptions as swiftclient_exceptions
|
||||||
@@ -362,11 +363,9 @@ class SwiftSignalTest(common.HeatTestCase):
|
|||||||
st.create()
|
st.create()
|
||||||
self.assertEqual(('CREATE', 'COMPLETE'), st.state)
|
self.assertEqual(('CREATE', 'COMPLETE'), st.state)
|
||||||
|
|
||||||
@mock.patch.object(scheduler, 'wallclock')
|
|
||||||
@mock.patch.object(swift.SwiftClientPlugin, '_create')
|
@mock.patch.object(swift.SwiftClientPlugin, '_create')
|
||||||
@mock.patch.object(resource.Resource, 'physical_resource_name')
|
@mock.patch.object(resource.Resource, 'physical_resource_name')
|
||||||
def test_multiple_signals_same_id_timeout(self, mock_name, mock_swift,
|
def test_multiple_signals_same_id_timeout(self, mock_name, mock_swift):
|
||||||
mock_clock):
|
|
||||||
st = create_stack(swiftsignal_template)
|
st = create_stack(swiftsignal_template)
|
||||||
handle = st['test_wait_condition_handle']
|
handle = st['test_wait_condition_handle']
|
||||||
|
|
||||||
@@ -382,9 +381,11 @@ class SwiftSignalTest(common.HeatTestCase):
|
|||||||
mock_swift_object.get_object.return_value = (obj_header,
|
mock_swift_object.get_object.return_value = (obj_header,
|
||||||
json.dumps({'id': 1}))
|
json.dumps({'id': 1}))
|
||||||
|
|
||||||
time_now = time.time()
|
time_now = timeutils.utcnow()
|
||||||
time_series = [t + time_now for t in xrange(1, 100)]
|
time_series = [datetime.timedelta(0, t) + time_now
|
||||||
scheduler.wallclock.side_effect = time_series
|
for t in xrange(1, 100)]
|
||||||
|
timeutils.set_time_override(time_series)
|
||||||
|
self.addCleanup(timeutils.clear_time_override)
|
||||||
|
|
||||||
st.create()
|
st.create()
|
||||||
self.assertIn("Resource CREATE failed: SwiftSignalTimeout",
|
self.assertIn("Resource CREATE failed: SwiftSignalTimeout",
|
||||||
|
|||||||
Reference in New Issue
Block a user