clean up and change the volume desription to have the instance id

fake mode works with all the tests

mounting a volume is causing a database name of #mysql50#lost+found to be created

pep8 fixes
This commit is contained in:
Craig Vyvial 2012-05-01 13:21:22 -05:00
parent 777f492d1b
commit 2ab45887ea
8 changed files with 123 additions and 23 deletions

View File

@ -53,7 +53,7 @@ nova_service_name = Compute Service
add_addresses = True
# Config options for enabling volume service
reddwarf_volume_support = False
reddwarf_volume_support = True
nova_volume_service_type = volume
nova_volume_service_name = Volume Service
device_path = /dev/vdb

View File

@ -56,7 +56,7 @@ nova_service_name = Compute Service
add_addresses = True
# Config options for enabling volume service
reddwarf_volume_support = False
reddwarf_volume_support = True
nova_volume_service_type = volume
nova_volume_service_name = Volume Service
device_path = /dev/vdb

View File

@ -52,5 +52,4 @@ class Mgmt(extensions.ExtensionsDescriptor):
deserializer=wsgi.RequestDeserializer(),
serializer=serializer)
resources.append(resource)
return resources

View File

@ -56,4 +56,3 @@ class MgmtInstanceController(InstanceController):
return wsgi.Result(str(e), 404)
return wsgi.Result(views.InstanceView(server,
add_addresses=self.add_addresses).data(), 200)

View File

@ -45,6 +45,7 @@ class InstanceView(object):
instance_dict['ip'] = ip
return {"instance": instance_dict}
class InstancesView(InstanceView):
def __init__(self, instances, add_addresses=False):

View File

@ -411,7 +411,8 @@ class MySqlAdmin(object):
information_schema.schemata
WHERE
schema_name not in
('mysql', 'information_schema', 'lost+found')
('mysql', 'information_schema',
'lost+found', '#mysql50#lost+found')
ORDER BY
schema_name ASC;
''')
@ -503,7 +504,7 @@ class DBaaSAgent(object):
# status end_mysql_install set with install_and_secure()
app = MySqlApp(self.status)
restart_mysql = False
if not device_path is None:
if device_path:
VolumeHelper.format(device_path)
if app.is_installed(pkg):
#stop and do not update database

View File

@ -64,7 +64,6 @@ def load_volumes(context, server_id, client=None):
volume_client = create_nova_volume_client(context)
try:
volumes = []
if utils.bool_from_string(volume_support):
volumes_info = client.volumes.get_server_volumes(server_id)
volume_ids = [attachments.volumeId for attachments in
volumes_info]
@ -174,11 +173,11 @@ class Instance(object):
@classmethod
def _create_volume(cls, context, db_info, volume_size):
volume_support = config.Config.get("reddwarf_volume_support", 'False')
LOG.debug(_("Volume support = %s") % volume_support)
LOG.debug(_("reddwarf volume support = %s") % volume_support)
if utils.bool_from_string(volume_support):
LOG.debug(_("Starting to create the volume for the instance"))
volume_client = create_nova_volume_client(context)
volume_desc = ("mysql volume for %s" % context.tenant)
volume_desc = ("mysql volume for %s" % db_info.id)
volume_ref = volume_client.volumes.create(
volume_size,
display_name="mysql-%s" % db_info.id,

View File

@ -84,7 +84,8 @@ class FakeFlavors(object):
class FakeServer(object):
def __init__(self, parent, owner, id, name, image_id, flavor_ref):
def __init__(self, parent, owner, id, name, image_id, flavor_ref,
block_device_mapping):
self.owner = owner # This is a context.
self.id = id
self.parent = parent
@ -93,6 +94,8 @@ class FakeServer(object):
self.flavor_ref = flavor_ref
self.events = EventSimulator()
self.schedule_status("BUILD", 0.0)
LOG.debug("block_device_mapping = %s" % block_device_mapping)
self.block_device_mapping = block_device_mapping
@property
def addresses(self):
@ -153,17 +156,20 @@ class FakeServers(object):
return self.context.is_admin or \
server.owner.tenant == self.context.tenant
def create(self, name, image_id, flavor_ref, files):
def create(self, name, image_id, flavor_ref, files, block_device_mapping):
id = "FAKE_%d" % self.next_id
self.next_id += 1
server = FakeServer(self, self.context, id, name, image_id, flavor_ref)
server = FakeServer(self, self.context, id, name, image_id, flavor_ref,
block_device_mapping)
self.db[id] = server
server.schedule_status("ACTIVE", 1)
LOG.info("FAKE_SERVERS_DB : %s" % str(FAKE_SERVERS_DB))
return server
def get(self, id):
if id not in self.db:
LOG.error("Couldn't find id %s, collection=%s" % (id, self.db))
LOG.error("Couldn't find server id %s, collection=%s" % (id,
self.db))
raise nova_exceptions.NotFound(404, "Not found")
else:
if self.can_see(id):
@ -181,6 +187,25 @@ class FakeServers(object):
self.events.add_event(time_from_now, delete_server)
class FakeServerVolumes(object):
def __init__(self, context):
self.context = context
def get_server_volumes(self, server_id):
class ServerVolumes(object):
def __init__(self, block_device_mapping):
LOG.debug("block_device_mapping = %s" % block_device_mapping)
device = block_device_mapping['vdb']
(self.volumeId,
self.type,
self.size,
self.delete_on_terminate) = device.split(":")
fake_servers = FakeServers(self.context, FLAVORS)
server = fake_servers.get(server_id)
return [ServerVolumes(server.block_device_mapping)]
FLAVORS = FakeFlavors()
@ -190,11 +215,87 @@ class FakeClient(object):
self.context = context
self.flavors = FLAVORS
self.servers = FakeServers(context, self.flavors)
self.volumes = FakeServerVolumes(context)
def fake_create_nova_client(context):
return FakeClient(context)
class FakeVolume(object):
def __init__(self, parent, owner, id, size, display_name,
display_description):
self.parent = parent
self.owner = owner # This is a context.
self.id = id
self.size = size
self.display_name = display_name
self.display_description = display_description
self.events = EventSimulator()
self.schedule_status("BUILD", 0.0)
def __repr__(self):
return ("FakeVolume(id=%s, size=%s, "
"display_name=%s, display_description=%s)") % (self.id,
self.size, self.display_name, self.display_description)
def schedule_status(self, new_status, time_from_now):
"""Makes a new status take effect at the given time."""
def set_status():
self._current_status = new_status
self.events.add_event(time_from_now, set_status)
@property
def status(self):
return self._current_status
FAKE_VOLUMES_DB = {}
class FakeVolumes(object):
def __init__(self, context):
self.context = context
self.db = FAKE_VOLUMES_DB
self.next_id = 10
self.events = EventSimulator()
def can_see(self, id):
"""Can this FakeVolumes, with its context, see some resource?"""
server = self.db[id]
return self.context.is_admin or \
server.owner.tenant == self.context.tenant
def get(self, id):
if id not in self.db:
LOG.error("Couldn't find volume id %s, collection=%s" % (id,
self.db))
raise nova_exceptions.NotFound(404, "Not found")
else:
if self.can_see(id):
return self.db[id]
else:
raise nova_exceptions.NotFound(404, "Bad permissions")
def create(self, size, display_name=None, display_description=None):
id = "FAKE_VOL_%d" % self.next_id
self.next_id += 1
volume = FakeVolume(self, self.context, id, size, display_name,
display_description)
self.db[id] = volume
volume.schedule_status("available", 2)
LOG.info("FAKE_VOLUMES_DB : %s" % FAKE_VOLUMES_DB)
return volume
class FakeVolumeClient(object):
def __init__(self, context):
self.context = context
self.volumes = FakeVolumes(context)
def fake_create_nova_volume_client(context):
return FakeClient(context)
return FakeVolumeClient(context)