Merge "Do not pass rich objects in Cloud LoadBalancer delete"
This commit is contained in:
commit
5f2ba2cc19
@ -461,6 +461,10 @@ class CloudLoadBalancer(resource.Resource):
|
||||
)
|
||||
}
|
||||
|
||||
ACTIVE_STATUS = 'ACTIVE'
|
||||
DELETED_STATUS = 'DELETED'
|
||||
PENDING_DELETE_STATUS = 'PENDING_DELETE'
|
||||
|
||||
def __init__(self, name, json_snippet, stack):
|
||||
super(CloudLoadBalancer, self).__init__(name, json_snippet, stack)
|
||||
self.clb = self.cloud_lb()
|
||||
@ -498,10 +502,10 @@ class CloudLoadBalancer(resource.Resource):
|
||||
|
||||
return (session_persistence, connection_logging, metadata)
|
||||
|
||||
def _check_status(self, loadbalancer, status_list):
|
||||
def _check_active(self):
|
||||
"""Update the loadbalancer state, check the status."""
|
||||
loadbalancer.get()
|
||||
if loadbalancer.status in status_list:
|
||||
loadbalancer = self.clb.get(self.resource_id)
|
||||
if loadbalancer.status == self.ACTIVE_STATUS:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@ -523,17 +527,17 @@ class CloudLoadBalancer(resource.Resource):
|
||||
These properties can only be set after the load balancer is created.
|
||||
"""
|
||||
if self.properties[self.ACCESS_LIST]:
|
||||
while not self._check_status(loadbalancer, ['ACTIVE']):
|
||||
while not self._check_active():
|
||||
yield
|
||||
loadbalancer.add_access_list(self.properties[self.ACCESS_LIST])
|
||||
|
||||
if self.properties[self.ERROR_PAGE]:
|
||||
while not self._check_status(loadbalancer, ['ACTIVE']):
|
||||
while not self._check_active():
|
||||
yield
|
||||
loadbalancer.set_error_page(self.properties[self.ERROR_PAGE])
|
||||
|
||||
if self.properties[self.SSL_TERMINATION]:
|
||||
while not self._check_status(loadbalancer, ['ACTIVE']):
|
||||
while not self._check_active():
|
||||
yield
|
||||
ssl_term = self.properties[self.SSL_TERMINATION]
|
||||
loadbalancer.add_ssl_termination(
|
||||
@ -547,13 +551,13 @@ class CloudLoadBalancer(resource.Resource):
|
||||
self.SSL_TERMINATION_SECURE_TRAFFIC_ONLY])
|
||||
|
||||
if self._valid_HTTPS_redirect_with_HTTP_prot():
|
||||
while not self._check_status(loadbalancer, ['ACTIVE']):
|
||||
while not self._check_active():
|
||||
yield
|
||||
loadbalancer.update(httpsRedirect=True)
|
||||
|
||||
if self.CONTENT_CACHING in self.properties:
|
||||
enabled = self.properties[self.CONTENT_CACHING] == 'ENABLED'
|
||||
while not self._check_status(loadbalancer, ['ACTIVE']):
|
||||
while not self._check_active():
|
||||
yield
|
||||
loadbalancer.content_caching = enabled
|
||||
|
||||
@ -625,11 +629,11 @@ class CloudLoadBalancer(resource.Resource):
|
||||
return loadbalancer
|
||||
|
||||
def check_create_complete(self, loadbalancer):
|
||||
return self._check_status(loadbalancer, ['ACTIVE'])
|
||||
return self._check_active()
|
||||
|
||||
def handle_check(self):
|
||||
loadbalancer = self.clb.get(self.resource_id)
|
||||
if not self._check_status(loadbalancer, ['ACTIVE']):
|
||||
if not self._check_active():
|
||||
raise exception.Error(_("Cloud LoadBalancer is not ACTIVE "
|
||||
"(was: %s)") % loadbalancer.status)
|
||||
|
||||
@ -879,28 +883,30 @@ class CloudLoadBalancer(resource.Resource):
|
||||
return False
|
||||
return True
|
||||
|
||||
def handle_delete(self):
|
||||
@retry_if_immutable
|
||||
def delete_lb(lb):
|
||||
lb.delete()
|
||||
|
||||
def check_delete_complete(self, *args):
|
||||
if self.resource_id is None:
|
||||
return
|
||||
return True
|
||||
|
||||
try:
|
||||
loadbalancer = self.clb.get(self.resource_id)
|
||||
except NotFound:
|
||||
pass
|
||||
else:
|
||||
if loadbalancer.status != 'DELETED':
|
||||
task = scheduler.TaskRunner(delete_lb, loadbalancer)
|
||||
task.start()
|
||||
return task
|
||||
return True
|
||||
|
||||
def check_delete_complete(self, task):
|
||||
if task and not task.step():
|
||||
if loadbalancer.status == self.DELETED_STATUS:
|
||||
return True
|
||||
|
||||
elif loadbalancer.status == self.PENDING_DELETE_STATUS:
|
||||
return False
|
||||
|
||||
return True
|
||||
else:
|
||||
try:
|
||||
loadbalancer.delete()
|
||||
except Exception as exc:
|
||||
if lb_immutable(exc):
|
||||
return False
|
||||
raise
|
||||
|
||||
return False
|
||||
|
||||
def _remove_none(self, property_dict):
|
||||
"""Remove None values that would cause schema validation problems.
|
||||
|
@ -117,6 +117,10 @@ LpTt0Xs1OFZxaNpolW5Qis4os7UmmIRV
|
||||
-----END PRIVATE KEY-----"""
|
||||
|
||||
|
||||
class FakeException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class FakeClient(object):
|
||||
user_agent = "Fake"
|
||||
USER_AGENT = "Fake"
|
||||
@ -349,9 +353,17 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
rsrc = LoadBalancerWithFakeClient(resource_name,
|
||||
resource_defns[resource_name],
|
||||
stack)
|
||||
self.m.StubOutWithMock(rsrc.clb, 'create')
|
||||
|
||||
fake_loadbalancer = FakeLoadBalancer(name=lb_name)
|
||||
fake_loadbalancer.status = 'ACTIVE'
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'create')
|
||||
rsrc.clb.create(lb_name, **lb_body).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(mox.IgnoreArg()).MultipleTimes().AndReturn(
|
||||
fake_loadbalancer)
|
||||
|
||||
return (rsrc, fake_loadbalancer)
|
||||
|
||||
def _get_first_resource_name(self, templ):
|
||||
@ -367,11 +379,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
lb_template),
|
||||
expected_name,
|
||||
expected_body)
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'get')
|
||||
fake_loadbalancer.get().MultipleTimes().AndReturn(None)
|
||||
|
||||
fake_loadbalancer.status = 'ACTIVE'
|
||||
|
||||
return (rsrc, fake_loadbalancer)
|
||||
|
||||
def _set_template(self, templ, **kwargs):
|
||||
@ -698,9 +705,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
"port": 80,
|
||||
"condition": "ENABLED"}]
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'add_nodes')
|
||||
fake_loadbalancer.add_nodes([
|
||||
fake_loadbalancer.Node(address=expected_ip,
|
||||
@ -722,9 +726,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
self.m.VerifyAll()
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.ReplayAll()
|
||||
self.assertRaises(ValueError, rsrc.handle_update, {}, {}, deleted_node)
|
||||
self.m.VerifyAll()
|
||||
@ -747,8 +748,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
id='test-id')]
|
||||
self.m.ReplayAll()
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
expected = [{
|
||||
'ip_version': 'IPv6',
|
||||
'type': 'PUBLIC',
|
||||
@ -779,9 +778,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
{"addresses": [expected_ip], "port": 80, "condition": "ENABLED"},
|
||||
]
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
msg = ("Load Balancer is immutable. Status: 'PENDING_UPDATE'")
|
||||
exc = Exception(msg)
|
||||
|
||||
@ -817,9 +813,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['name'] = "updated_name"
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'update')
|
||||
msg = ("Load Balancer '%s' has a status of 'PENDING_UPDATE' and "
|
||||
"is considered immutable." % rsrc.resource_id)
|
||||
@ -841,9 +834,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['name'] = "updated_name"
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'update')
|
||||
fake_loadbalancer.update(name="updated_name")
|
||||
|
||||
@ -863,9 +853,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template['Properties']['name'] = "updated_name"
|
||||
update_template['Properties']['algorithm'] = "RANDOM"
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'update')
|
||||
fake_loadbalancer.update(name="updated_name", algorithm="RANDOM")
|
||||
|
||||
@ -884,9 +871,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['algorithm'] = "RANDOM"
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'update')
|
||||
fake_loadbalancer.update(algorithm="RANDOM")
|
||||
|
||||
@ -905,9 +889,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['protocol'] = "IMAPS"
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'update')
|
||||
fake_loadbalancer.update(protocol="IMAPS")
|
||||
|
||||
@ -932,9 +913,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['httpsRedirect'] = True
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'update')
|
||||
fake_loadbalancer.update(httpsRedirect=True)
|
||||
|
||||
@ -991,9 +969,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['halfClosed'] = True
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'update')
|
||||
fake_loadbalancer.update(halfClosed=True)
|
||||
|
||||
@ -1012,9 +987,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['port'] = 1234
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'update')
|
||||
fake_loadbalancer.update(port=1234)
|
||||
|
||||
@ -1033,9 +1005,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['timeout'] = 120
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'update')
|
||||
fake_loadbalancer.update(timeout=120)
|
||||
|
||||
@ -1058,9 +1027,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
'statusRegex': "^[234][0-9][0-9]$", 'bodyRegex': ".* testing .*",
|
||||
'hostHeader': "example.com"}
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'add_health_monitor')
|
||||
fake_loadbalancer.add_health_monitor(
|
||||
attemptsBeforeDeactivation=4, bodyRegex='.* testing .*', delay=10,
|
||||
@ -1092,9 +1058,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
del update_template['Properties']['healthMonitor']
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'delete_health_monitor')
|
||||
fake_loadbalancer.delete_health_monitor()
|
||||
|
||||
@ -1114,9 +1077,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['sessionPersistence'] = 'SOURCE_IP'
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
@ -1141,9 +1101,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
del update_template['Properties']['sessionPersistence']
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
@ -1163,9 +1120,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
'securePort': 443, 'privatekey': private_key, 'certificate': cert,
|
||||
'secureTrafficOnly': False}
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'add_ssl_termination')
|
||||
fake_loadbalancer.add_ssl_termination(
|
||||
securePort=443, privatekey=private_key, certificate=cert,
|
||||
@ -1194,9 +1148,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
del update_template['Properties']['sslTermination']
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'delete_ssl_termination')
|
||||
fake_loadbalancer.delete_ssl_termination()
|
||||
|
||||
@ -1216,9 +1167,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['metadata'] = {'a': 1, 'b': 2}
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'set_metadata')
|
||||
fake_loadbalancer.set_metadata({'a': 1, 'b': 2})
|
||||
|
||||
@ -1245,9 +1193,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
del update_template['Properties']['metadata']
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'delete_metadata')
|
||||
fake_loadbalancer.delete_metadata()
|
||||
|
||||
@ -1271,9 +1216,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['errorPage'] = error_page
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'set_error_page')
|
||||
fake_loadbalancer.set_error_page(error_page)
|
||||
|
||||
@ -1301,9 +1243,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
del update_template['Properties']['errorPage']
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'clear_error_page')
|
||||
fake_loadbalancer.clear_error_page()
|
||||
|
||||
@ -1323,9 +1262,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['connectionLogging'] = True
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.ReplayAll()
|
||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
|
||||
@ -1349,9 +1285,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
del update_template['Properties']['connectionLogging']
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
@ -1376,9 +1309,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['connectionLogging'] = False
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
@ -1397,9 +1327,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template['Properties']['connectionThrottle'] = {
|
||||
'maxConnections': 1000}
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'add_connection_throttle')
|
||||
fake_loadbalancer.add_connection_throttle(
|
||||
maxConnections=1000, maxConnectionRate=None, minConnections=None,
|
||||
@ -1428,9 +1355,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
del update_template['Properties']['connectionThrottle']
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'delete_connection_throttle')
|
||||
fake_loadbalancer.delete_connection_throttle()
|
||||
|
||||
@ -1450,9 +1374,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['contentCaching'] = 'ENABLED'
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
scheduler.TaskRunner(rsrc.update, update_template)()
|
||||
@ -1477,9 +1398,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
del update_template['Properties']['contentCaching']
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertEqual(True, fake_loadbalancer.content_caching)
|
||||
@ -1505,9 +1423,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
update_template = copy.deepcopy(rsrc.t)
|
||||
update_template['Properties']['contentCaching'] = 'DISABLED'
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
self.assertEqual(True, fake_loadbalancer.content_caching)
|
||||
@ -1525,12 +1440,15 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
self.m.VerifyAll()
|
||||
|
||||
self.m.UnsetStubs()
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_lb)
|
||||
rsrc.clb.get(mox.IgnoreArg()).AndReturn(fake_lb)
|
||||
rsrc.clb.get(mox.IgnoreArg()).AndRaise(lb.NotFound('foo'))
|
||||
self.m.ReplayAll()
|
||||
|
||||
scheduler.TaskRunner(rsrc.delete)()
|
||||
self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_delete_immutable(self):
|
||||
template = self._set_template(self.lb_template,
|
||||
@ -1538,37 +1456,71 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
rsrc, fake_lb = self._mock_loadbalancer(template, self.lb_name,
|
||||
self.expected_body)
|
||||
self.m.ReplayAll()
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
self.m.VerifyAll()
|
||||
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
|
||||
self.m.UnsetStubs()
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_lb)
|
||||
rsrc.clb.get(mox.IgnoreArg()).AndReturn(fake_lb)
|
||||
rsrc.clb.get(mox.IgnoreArg()).AndRaise(lb.NotFound('foo'))
|
||||
|
||||
self.m.StubOutWithMock(fake_lb, 'delete')
|
||||
fake_lb.delete().AndRaise(Exception('immutable'))
|
||||
fake_lb.delete().AndReturn(None)
|
||||
self.m.ReplayAll()
|
||||
|
||||
scheduler.TaskRunner(rsrc.delete)()
|
||||
self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_check_delete_complete(self):
|
||||
mock_stack = mock.Mock()
|
||||
mock_stack.db_resource_get.return_value = None
|
||||
mock_stack.has_cache_data.return_value = False
|
||||
mock_resdef = mock.Mock(spec=rsrc_defn.ResourceDefinition)
|
||||
mock_loadbalancer = lb.CloudLoadBalancer("test", mock_resdef,
|
||||
mock_stack)
|
||||
def test_delete_non_immutable_exc(self):
|
||||
template = self._set_template(self.lb_template,
|
||||
contentCaching='ENABLED')
|
||||
rsrc, fake_lb = self._mock_loadbalancer(template, self.lb_name,
|
||||
self.expected_body)
|
||||
self.m.ReplayAll()
|
||||
|
||||
mock_task = mock.Mock()
|
||||
mock_task.step.return_value = False
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
|
||||
res = mock_loadbalancer.check_delete_complete(mock_task)
|
||||
self.assertFalse(res)
|
||||
self.m.UnsetStubs()
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(mox.IgnoreArg()).AndReturn(fake_lb)
|
||||
|
||||
mock_task.step.return_value = True
|
||||
self.m.StubOutWithMock(fake_lb, 'delete')
|
||||
fake_lb.delete().AndRaise(FakeException())
|
||||
self.m.ReplayAll()
|
||||
|
||||
res = mock_loadbalancer.check_delete_complete(mock_task)
|
||||
self.assertTrue(res)
|
||||
exc = self.assertRaises(exception.ResourceFailure,
|
||||
scheduler.TaskRunner(rsrc.delete))
|
||||
self.assertIn('FakeException', six.text_type(exc))
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_delete_states(self):
|
||||
template = self._set_template(self.lb_template,
|
||||
contentCaching='ENABLED')
|
||||
rsrc, fake_lb = self._mock_loadbalancer(template, self.lb_name,
|
||||
self.expected_body)
|
||||
self.m.ReplayAll()
|
||||
|
||||
scheduler.TaskRunner(rsrc.create)()
|
||||
|
||||
self.m.UnsetStubs()
|
||||
fake_lb1 = copy.deepcopy(fake_lb)
|
||||
fake_lb2 = copy.deepcopy(fake_lb)
|
||||
fake_lb3 = copy.deepcopy(fake_lb)
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
|
||||
fake_lb1.status = 'ACTIVE'
|
||||
rsrc.clb.get(mox.IgnoreArg()).AndReturn(fake_lb1)
|
||||
fake_lb2.status = 'PENDING_DELETE'
|
||||
rsrc.clb.get(mox.IgnoreArg()).AndReturn(fake_lb2)
|
||||
fake_lb3.status = 'DELETED'
|
||||
rsrc.clb.get(mox.IgnoreArg()).AndReturn(fake_lb3)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
scheduler.TaskRunner(rsrc.delete)()
|
||||
self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_redir(self):
|
||||
mock_stack = mock.Mock()
|
||||
@ -1669,9 +1621,6 @@ class LoadBalancerTest(common.HeatTestCase):
|
||||
"port": 80,
|
||||
"condition": "DRAINING"}]
|
||||
|
||||
self.m.StubOutWithMock(rsrc.clb, 'get')
|
||||
rsrc.clb.get(rsrc.resource_id).AndReturn(fake_loadbalancer)
|
||||
|
||||
self.m.StubOutWithMock(fake_loadbalancer, 'add_nodes')
|
||||
fake_loadbalancer.add_nodes([
|
||||
fake_loadbalancer.Node(address=expected_ip,
|
||||
|
Loading…
x
Reference in New Issue
Block a user