Get rid of create state in Instance
We don't want to store any state in the Instance object, instead take advantage of the new mechanism whereby the result of handle_create() is passed to check_active(). This makes the autoscaling code uglier for now (since it must still store the instance state in the instance), but this will go away when we move to using co-routines to create resources in parallel. Change-Id: Ib11c8da22900453eb9713eba5106859c8a09dbe2
This commit is contained in:
parent
9bd13ec4d5
commit
f3454692fb
@ -84,7 +84,8 @@ class InstanceGroup(resource.Resource):
|
||||
|
||||
def check_active(self, instances):
|
||||
if instances:
|
||||
check_active = lambda i: i.check_active(override=False)
|
||||
check_active = lambda i: i.check_active(i._create_data,
|
||||
override=False)
|
||||
remaining = itertools.dropwhile(check_active, instances)
|
||||
instances[:] = list(remaining)
|
||||
if not instances:
|
||||
@ -151,6 +152,7 @@ class InstanceGroup(resource.Resource):
|
||||
won't wait for it in create().
|
||||
'''
|
||||
if override:
|
||||
self._create_data = create_data
|
||||
return True
|
||||
return super(GroupedInstance, self).check_active(create_data)
|
||||
|
||||
|
@ -114,7 +114,6 @@ class Instance(resource.Resource):
|
||||
super(Instance, self).__init__(name, json_snippet, stack)
|
||||
self.ipaddress = None
|
||||
self.mime_string = None
|
||||
self._server_status = None
|
||||
|
||||
def _set_ipaddress(self, networks):
|
||||
'''
|
||||
@ -311,14 +310,13 @@ class Instance(resource.Resource):
|
||||
if server is not None:
|
||||
self.resource_id_set(server.id)
|
||||
|
||||
self._server_status = server.status
|
||||
return server
|
||||
|
||||
def check_active(self, create_data=None):
|
||||
if self._server_status == 'ACTIVE':
|
||||
def check_active(self, server):
|
||||
if server.status == 'ACTIVE':
|
||||
return True
|
||||
|
||||
server = self.nova().servers.get(self.resource_id)
|
||||
self._server_status = server.status
|
||||
server.get()
|
||||
if server.status == 'BUILD':
|
||||
return False
|
||||
if server.status == 'ACTIVE':
|
||||
|
@ -88,11 +88,12 @@ class AutoScalingTest(unittest.TestCase):
|
||||
|
||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||
self.m.StubOutWithMock(instance.Instance, 'check_active')
|
||||
cookie = object()
|
||||
for x in range(num):
|
||||
instance.Instance.handle_create().AndReturn(None)
|
||||
instance.Instance.check_active(None).AndReturn(False)
|
||||
instance.Instance.handle_create().AndReturn(cookie)
|
||||
instance.Instance.check_active(cookie).AndReturn(False)
|
||||
eventlet.sleep(mox.IsA(int)).AndReturn(None)
|
||||
instance.Instance.check_active(None).MultipleTimes().AndReturn(True)
|
||||
instance.Instance.check_active(cookie).MultipleTimes().AndReturn(True)
|
||||
|
||||
def _stub_lb_reload(self, expected_list, unset=True):
|
||||
if unset:
|
||||
|
@ -68,11 +68,12 @@ class InstanceGroupTest(unittest.TestCase):
|
||||
|
||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||
self.m.StubOutWithMock(instance.Instance, 'check_active')
|
||||
cookie = object()
|
||||
for x in range(num):
|
||||
instance.Instance.handle_create().AndReturn(None)
|
||||
instance.Instance.check_active(None).AndReturn(False)
|
||||
instance.Instance.handle_create().AndReturn(cookie)
|
||||
instance.Instance.check_active(cookie).AndReturn(False)
|
||||
eventlet.sleep(mox.IsA(int)).AndReturn(None)
|
||||
instance.Instance.check_active(None).MultipleTimes().AndReturn(True)
|
||||
instance.Instance.check_active(cookie).MultipleTimes().AndReturn(True)
|
||||
|
||||
def create_instance_group(self, t, stack, resource_name):
|
||||
resource = asc.InstanceGroup(resource_name,
|
||||
|
@ -148,10 +148,9 @@ class MetadataRefreshTest(unittest.TestCase):
|
||||
|
||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||
self.m.StubOutWithMock(instance.Instance, 'check_active')
|
||||
instance.Instance.handle_create().AndReturn(None)
|
||||
instance.Instance.check_active(None).AndReturn(True)
|
||||
instance.Instance.handle_create().AndReturn(None)
|
||||
instance.Instance.check_active(None).AndReturn(True)
|
||||
for cookie in (object(), object()):
|
||||
instance.Instance.handle_create().AndReturn(cookie)
|
||||
instance.Instance.check_active(cookie).AndReturn(True)
|
||||
self.m.StubOutWithMock(instance.Instance, 'FnGetAtt')
|
||||
|
||||
return stack
|
||||
@ -213,8 +212,9 @@ class WaitCondMetadataUpdateTest(unittest.TestCase):
|
||||
|
||||
self.m.StubOutWithMock(instance.Instance, 'handle_create')
|
||||
self.m.StubOutWithMock(instance.Instance, 'check_active')
|
||||
instance.Instance.handle_create().AndReturn(None)
|
||||
instance.Instance.check_active(None).AndReturn(True)
|
||||
cookie = object()
|
||||
instance.Instance.handle_create().AndReturn(cookie)
|
||||
instance.Instance.check_active(cookie).AndReturn(True)
|
||||
|
||||
self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone')
|
||||
wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(self.fc)
|
||||
|
Loading…
Reference in New Issue
Block a user