Made resize work in fake mode.
This commit is contained in:
parent
700bd4d264
commit
cde1f32b61
@ -42,6 +42,19 @@ execute = openstack_utils.execute
|
||||
isotime = openstack_utils.isotime
|
||||
|
||||
|
||||
def create_method_args_string(*args, **kwargs):
|
||||
"""Returns a string representation of args and keyword args.
|
||||
|
||||
I.e. for args=1,2,3 and kwargs={'a':4, 'b':5} you'd get: "1,2,3,a=4,b=5"
|
||||
"""
|
||||
# While %s turns a var into a string but in some rare cases explicit
|
||||
# str() is less likely to raise an exception.
|
||||
arg_strs = [repr(arg) for arg in args]
|
||||
arg_strs += ['%s=%s' % (repr(key), repr(value))
|
||||
for (key, value) in kwargs.items()]
|
||||
return ','.join(arg_strs)
|
||||
|
||||
|
||||
def stringify_keys(dictionary):
|
||||
if dictionary is None:
|
||||
return None
|
||||
|
@ -384,7 +384,8 @@ class Instance(object):
|
||||
|
||||
def resize_flavor(self, new_flavor_id):
|
||||
self.validate_can_perform_resize()
|
||||
|
||||
LOG.debug("resizing instance %s flavor to %s"
|
||||
% (self.id, new_flavor_id))
|
||||
# Validate that the flavor can be found and that it isn't the same size
|
||||
# as the current one.
|
||||
client = create_nova_client(self.context)
|
||||
@ -401,15 +402,18 @@ class Instance(object):
|
||||
# Set the task to RESIZING and begin the async call before returning.
|
||||
self.db_info.task_status = InstanceTasks.RESIZING
|
||||
self.db_info.save()
|
||||
LOG.debug("Instance %s set to RESIZING." % self.id)
|
||||
self.call_async(self.resize_flavor_async, new_flavor_id,
|
||||
old_flavor_size, new_flavor_size)
|
||||
|
||||
def resize_flavor_async(self, new_flavor_id, old_memory_size,
|
||||
updated_memory_size):
|
||||
try:
|
||||
LOG.debug("Instance %s calling stop_mysql..." % self.id)
|
||||
guest = create_guest_client(self.context, self.db_info.id)
|
||||
guest.stop_mysql()
|
||||
try:
|
||||
LOG.debug("Instance %s calling Compute resize..." % self.id)
|
||||
self.server.resize(new_flavor_id)
|
||||
#TODO(tim.simpson): Figure out some way to message the
|
||||
# following exceptions:
|
||||
@ -419,10 +423,12 @@ class Instance(object):
|
||||
# Wait for the flavor to change.
|
||||
#TODO(tim.simpson): Bring back our good friend poll_until.
|
||||
while(self.server.status == "RESIZE" or
|
||||
self.flavor['id'] != new_flavor_id):
|
||||
str(self.flavor['id']) != str(new_flavor_id)):
|
||||
time.sleep(1)
|
||||
info = self._refresh_compute_server_info()
|
||||
# Confirm the resize with Nova.
|
||||
LOG.debug("Instance %s calling Compute confirm resize..."
|
||||
% self.id)
|
||||
self.server.confirm_resize()
|
||||
except Exception as ex:
|
||||
updated_memory_size = old_memory_size
|
||||
@ -434,6 +440,7 @@ class Instance(object):
|
||||
# This is in the finally because we have to call this, or
|
||||
# else MySQL could stay turned off on an otherwise usable
|
||||
# instance.
|
||||
LOG.debug("Instance %s starting mysql..." % self.id)
|
||||
guest.start_mysql_with_conf_changes(updated_memory_size)
|
||||
finally:
|
||||
self.db_info.task_status = InstanceTasks.NONE
|
||||
|
@ -89,23 +89,16 @@ class FakeGuest(object):
|
||||
def start_mysql_with_conf_changes(self, updated_memory_size):
|
||||
from reddwarf.instance.models import InstanceServiceStatus
|
||||
from reddwarf.instance.models import ServiceStatuses
|
||||
|
||||
def update_db():
|
||||
status = InstanceServiceStatus.find_by(instance_id=self.id)
|
||||
status.status = ServiceStatuses.RUNNING
|
||||
status.save()
|
||||
EventSimulator.add_event(0.5, update_db)
|
||||
status = InstanceServiceStatus.find_by(instance_id=self.id)
|
||||
status.status = ServiceStatuses.RUNNING
|
||||
status.save()
|
||||
|
||||
def stop_mysql(self):
|
||||
from reddwarf.instance.models import InstanceServiceStatus
|
||||
from reddwarf.instance.models import ServiceStatuses
|
||||
|
||||
def update_db():
|
||||
status = InstanceServiceStatus.find_by(instance_id=self.id)
|
||||
status.status = ServiceStatuses.SHUTDOWN
|
||||
status.save()
|
||||
EventSimulator.add_event(0.5, update_db)
|
||||
|
||||
status = InstanceServiceStatus.find_by(instance_id=self.id)
|
||||
status.status = ServiceStatuses.SHUTDOWN
|
||||
status.save()
|
||||
|
||||
def get_or_create(id):
|
||||
if id not in DB:
|
||||
|
@ -65,6 +65,7 @@ class FakeFlavors(object):
|
||||
self.db[new_flavor.id] = new_flavor
|
||||
|
||||
def get(self, id):
|
||||
id = int(id)
|
||||
if id not in self.db:
|
||||
raise nova_exceptions.NotFound(404, "Flavor id not found %s" % id)
|
||||
return self.db[id]
|
||||
@ -101,6 +102,12 @@ class FakeServer(object):
|
||||
def addresses(self):
|
||||
return {"private": [{"addr":"123.123.123.123"}]}
|
||||
|
||||
def confirm_resize(self):
|
||||
if self.status != "VERIFY_RESIZE":
|
||||
raise RuntimeError("Not in resize confirm mode.")
|
||||
self._current_status = "ACTIVE"
|
||||
|
||||
|
||||
def delete(self):
|
||||
self.schedule_status = []
|
||||
self._current_status = "SHUTDOWN"
|
||||
@ -117,6 +124,16 @@ class FakeServer(object):
|
||||
"rel": link_type
|
||||
} for link_type in ['self', 'bookmark']]
|
||||
|
||||
def resize(self, new_flavor_id):
|
||||
self._current_status = "RESIZE"
|
||||
def set_to_confirm_mode():
|
||||
self._current_status = "VERIFY_RESIZE"
|
||||
def set_flavor():
|
||||
flavor = self.parent.flavors.get(new_flavor_id)
|
||||
self.flavor_ref = flavor.links[0]['href']
|
||||
self.events.add_event(1, set_to_confirm_mode)
|
||||
self.events.add_event(1, set_flavor)
|
||||
|
||||
def schedule_status(self, new_status, time_from_now):
|
||||
"""Makes a new status take effect at the given time."""
|
||||
def set_status():
|
||||
|
Loading…
x
Reference in New Issue
Block a user