Fix loading object without configured backend
On commit fe9922d21c we added the
possibility of loading objects without configured backend, but there
were still some cases were loading could fail like this:
Traceback (most recent call last):
File "/csi/cinderlib_csi/cinderlib_csi.py", line 127, in dolog
result = f(self, request, context)
File "/csi/cinderlib_csi/cinderlib_csi.py", line 168, in checker
return f(self, request, context)
File "/csi/cinderlib_csi/cinderlib_csi.py", line 210, in wrapper
return func(self, request, context)
File "/csi/cinderlib_csi/cinderlib_csi.py", line 839, in NodeStageVolume
vol = self._get_vol(request.volume_id)
File "/csi/cinderlib_csi/cinderlib_csi.py", line 360, in _get_vol
volume_id=volume_id, backend_name=backend_name, **filters)
File "/csi/cinderlib_csi/cl_crd.py", line 378, in get_volumes
backend_name=backend_name)
File "/csi/cinderlib_csi/cl_crd.py", line 169, in get
resource = cinderlib.load(resource_json)
File "/cinderlib/cinderlib/serialization.py", line 160, in load
return getattr(objects, json_src['class']).load(json_src, save)
File "/cinderlib/cinderlib/objects.py", line 195, in load
backend = cls.backend_class.load_backend(json_src['backend'])
File "/cinderlib/cinderlib/cinderlib.py", line 261, in load_backend
raise Exception('Backend not present in system or json.')
Exception: Backend not present in system or json.
This patch fixes this issue by checking the `fail_on_missing_backend`
configuration option when loading using the base object class.
Also fixes saving of an object that has been loaded without the backend
configured in the system.
This commit is contained in:
@@ -258,7 +258,10 @@ class Backend(object):
|
||||
if len(backend_data) > 1:
|
||||
return cls(**backend_data)
|
||||
|
||||
raise Exception('Backend not present in system or json.')
|
||||
if cls.fail_on_missing_backend:
|
||||
raise Exception('Backend not present in system or json.')
|
||||
|
||||
return backend_name
|
||||
|
||||
def refresh(self):
|
||||
if self._volumes is not None:
|
||||
|
||||
@@ -73,8 +73,6 @@ class Object(object):
|
||||
except KeyError:
|
||||
if self.backend_class.fail_on_missing_backend:
|
||||
raise
|
||||
return backend_name_or_obj
|
||||
|
||||
return backend_name_or_obj
|
||||
|
||||
def __init__(self, backend, **fields_data):
|
||||
@@ -146,7 +144,7 @@ class Object(object):
|
||||
def json(self):
|
||||
ovo = self._ovo.obj_to_primitive()
|
||||
return {'class': type(self).__name__,
|
||||
'backend': self.backend.config,
|
||||
'backend': getattr(self.backend, 'config', self.backend),
|
||||
'ovo': ovo}
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user