Skip to content

Commit

Permalink
Fix nova-manage backend_add with sr_uuid
Browse files Browse the repository at this point in the history
Fixes bug 950964

Remove FIXME in db.sm_backend_conf_get_by_sr
Add first() to sm_backend_conf_get_by_sr query
Change db/api.py:sm_backend_conf_get_by_sr to call correct impl method
Have nova-manage generate an actuall sr_uuid instead of always 'None'
Actually update backend values when specifying uuid

Change-Id: I620da4563d8c936b5a072c4683ae145280104fc2
  • Loading branch information
ameade committed Mar 9, 2012
1 parent 1c68d20 commit 77495cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
48 changes: 22 additions & 26 deletions bin/nova-manage
Expand Up @@ -1793,58 +1793,54 @@ class StorageManagerCommands(object):
# TODO Add backend_introduce.
ctxt = context.get_admin_context()
params = dict(map(self._splitfun, args))
sr_uuid = utils.gen_uuid()

if flavor_label is None:
print "error: backend needs to be associated with flavor"
sys.exit(2)

try:
flavors = db.sm_flavor_get(ctxt, flavor_label)

except exception.NotFound as ex:
print "error: %s" % ex
sys.exit(2)

config_params = " ".join(['%s=%s' %
(key, params[key]) for key in params])

if 'sr_uuid' in params:
sr_uuid = params['sr_uuid']
try:
backend = db.sm_backend_conf_get_by_sr(ctxt,
params['sr_uuid'])
backend = db.sm_backend_conf_get_by_sr(ctxt, sr_uuid)
except exception.DBError, e:
_db_error(e)

if backend:
if len(backend) > 1:
print 'error: Multiple backends found with given sr_uuid'
sys.exit(2)

print 'Backend config found. Would you like to recreate this?'
print '(WARNING:Recreating will destroy all VDIs on backend!!)'
c = raw_input('Proceed? (y/n) ')
if c == 'y' or c == 'Y':
try:
db.sm_backend_conf_update(ctxt, backend['id'],
dict(created=False))
dict(created=False,
flavor_id=flavors['id'],
sr_type=sr_type,
config_params=config_params))
except exception.DBError, e:
_db_error(e)
return

else:
print 'Backend config not found. Would you like to create it?'
print '(WARNING: Creating will destroy all data on backend!!!)'
c = raw_input('Proceed? (y/n) ')
if c != 'y' and c != 'Y':
return

print '(WARNING: Creating will destroy all data on backend!!!)'
c = raw_input('Proceed? (y/n) ')
if c == 'y' or c == 'Y':
if flavor_label is None:
print "error: backend needs to be associated with flavor"
sys.exit(2)

try:
flavors = db.sm_flavor_get(ctxt, flavor_label)

except exception.NotFound as ex:
print "error: %s" % ex
sys.exit(2)

config_params = "".join(['%s=%s ' %
(key, params[key]) for key in params])

try:
db.sm_backend_conf_create(ctxt,
dict(flavor_id=flavors['id'],
sr_uuid=None,
sr_uuid=sr_uuid,
sr_type=sr_type,
config_params=config_params))
except exception.DBError, e:
Expand Down
2 changes: 1 addition & 1 deletion nova/db/api.py
Expand Up @@ -1718,7 +1718,7 @@ def sm_backend_conf_get(context, sm_backend_conf_id):

def sm_backend_conf_get_by_sr(context, sr_uuid):
"""Get a specific SM Backend Config."""
return IMPL.sm_backend_conf_get(context, sr_uuid)
return IMPL.sm_backend_conf_get_by_sr(context, sr_uuid)


def sm_backend_conf_get_all(context):
Expand Down
4 changes: 2 additions & 2 deletions nova/db/sqlalchemy/api.py
Expand Up @@ -4214,9 +4214,9 @@ def sm_backend_conf_get(context, sm_backend_id):
@require_admin_context
def sm_backend_conf_get_by_sr(context, sr_uuid):
session = get_session()
# FIXME(sirp): shouldn't this have a `first()` qualifier attached?
return model_query(context, models.SMBackendConf, read_deleted="yes").\
filter_by(sr_uuid=sr_uuid)
filter_by(sr_uuid=sr_uuid).\
first()


@require_admin_context
Expand Down

0 comments on commit 77495cf

Please sign in to comment.