Remove TaskRunner from SwiftSignal
Change-Id: I0484979f0c1bf42f8537f631e7bcd83324085862 Partial-Bug: #1393268
This commit is contained in:
parent
307a3be102
commit
423041730f
|
@ -14,6 +14,7 @@
|
|||
import json
|
||||
import urlparse
|
||||
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
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 properties
|
||||
from heat.engine import resource
|
||||
from heat.engine import scheduler
|
||||
from heat.engine import support
|
||||
from heat.openstack.common import log as logging
|
||||
|
||||
|
@ -106,7 +106,7 @@ class SwiftSignalHandle(resource.Resource):
|
|||
elif key == self.ENDPOINT:
|
||||
return self.data().get(self.ENDPOINT)
|
||||
elif key == self.CURL_CLI:
|
||||
return ('curl -i -X PUT \'%s\'' %
|
||||
return ("curl -i -X PUT '%s'" %
|
||||
self.data().get(self.ENDPOINT))
|
||||
|
||||
def handle_delete(self):
|
||||
|
@ -227,35 +227,8 @@ class SwiftSignal(resource.Resource):
|
|||
|
||||
def handle_create(self):
|
||||
self._validate_handle_url()
|
||||
runner = scheduler.TaskRunner(self._wait)
|
||||
runner.start(timeout=float(self.properties.get(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
|
||||
started_at = timeutils.utcnow()
|
||||
return started_at, float(self.properties[self.TIMEOUT])
|
||||
|
||||
def get_signals(self):
|
||||
try:
|
||||
|
@ -335,8 +308,25 @@ class SwiftSignal(resource.Resource):
|
|||
data[signal[self.UNIQUE_ID]] = signal[self.DATA]
|
||||
return data
|
||||
|
||||
def check_create_complete(self, runner):
|
||||
return runner.step()
|
||||
def check_create_complete(self, create_data):
|
||||
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):
|
||||
if key == self.DATA:
|
||||
|
|
|
@ -12,11 +12,12 @@
|
|||
# under the License.
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
import json
|
||||
import time
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
from swiftclient import client as swiftclient_client
|
||||
from swiftclient import exceptions as swiftclient_exceptions
|
||||
|
@ -362,11 +363,9 @@ class SwiftSignalTest(common.HeatTestCase):
|
|||
st.create()
|
||||
self.assertEqual(('CREATE', 'COMPLETE'), st.state)
|
||||
|
||||
@mock.patch.object(scheduler, 'wallclock')
|
||||
@mock.patch.object(swift.SwiftClientPlugin, '_create')
|
||||
@mock.patch.object(resource.Resource, 'physical_resource_name')
|
||||
def test_multiple_signals_same_id_timeout(self, mock_name, mock_swift,
|
||||
mock_clock):
|
||||
def test_multiple_signals_same_id_timeout(self, mock_name, mock_swift):
|
||||
st = create_stack(swiftsignal_template)
|
||||
handle = st['test_wait_condition_handle']
|
||||
|
||||
|
@ -382,9 +381,11 @@ class SwiftSignalTest(common.HeatTestCase):
|
|||
mock_swift_object.get_object.return_value = (obj_header,
|
||||
json.dumps({'id': 1}))
|
||||
|
||||
time_now = time.time()
|
||||
time_series = [t + time_now for t in xrange(1, 100)]
|
||||
scheduler.wallclock.side_effect = time_series
|
||||
time_now = timeutils.utcnow()
|
||||
time_series = [datetime.timedelta(0, t) + time_now
|
||||
for t in xrange(1, 100)]
|
||||
timeutils.set_time_override(time_series)
|
||||
self.addCleanup(timeutils.clear_time_override)
|
||||
|
||||
st.create()
|
||||
self.assertIn("Resource CREATE failed: SwiftSignalTimeout",
|
||||
|
|
Loading…
Reference in New Issue