self.assertEqual('sudo cinder-rootwrap /path/to/conf',
utils.get_root_helper())
+ def test_list_of_dicts_to_dict(self):
+ a = {'id': '1', 'color': 'orange'}
+ b = {'id': '2', 'color': 'blue'}
+ c = {'id': '3', 'color': 'green'}
+ lst = [a, b, c]
+
+ resp = utils.list_of_dicts_to_dict(lst, 'id')
+ self.assertEqual(c['id'], resp['3']['id'])
+
class TemporaryChownTestCase(test.TestCase):
@mock.patch('os.stat')
return (begin, end)
+def list_of_dicts_to_dict(seq, key):
+ """Convert list of dicts to a indexted dict.
+
+ Takes a list of dicts, and converts it a nested dict
+ indexed by <key>
+
+ :param seq: list of dicts
+ :parm key: key in dicts to index by
+
+ example:
+ lst = [{'id': 1, ...}, {'id': 2, ...}...]
+ key = 'id'
+ returns {1:{'id': 1, ...}, 2:{'id':2, ...}
+
+ """
+ return {d[key]: dict(d, index=d[key]) for (i, d) in enumerate(seq)}
+
+
class ProtectedExpatParser(expatreader.ExpatParser):
"""An expat parser which disables DTD's and entities by default."""
"""
return None
+ def update_provider_info(self, volid_list):
+ """Get provider info updates from driver.
+
+ :param volid_list: List of Cinder vol id's to check for updates
+ :return: dict of update {'id': uuid, provider_id: <provider-id>}
+ """
+ return None
+
@six.add_metaclass(abc.ABCMeta)
class LocalVD(object):
LOG.info(_LI("Determined volume DB was not empty at startup."))
return False
+ def _sync_provider_info(self, ctxt, volumes):
+ # NOTE(jdg): For now this just updates provider_id, we can add more
+ # add more items to the update if theyr'e releveant but we need
+ # to be safe in what we allow and add a list of allowed keys
+ # things that make sense are provider_*, replication_status etc
+
+ updates = self.driver.update_provider_info([v['id'] for v in volumes])
+ host_vols = utils.list_of_dicts_to_dict(volumes, 'id')
+
+ for u in updates or []:
+ update = {}
+ # NOTE(JDG): Make sure returned item is in this hosts volumes
+ if host_vols.get(u['id'], None):
+ update['provider_id'] = u['provider_id']
+ if update:
+ self.db.volume_update(ctxt,
+ u['id'],
+ update)
+
def init_host(self):
"""Perform any required initialization."""
return
volumes = self.db.volume_get_all_by_host(ctxt, self.host)
+ self._sync_provider_info(ctxt, volumes)
# FIXME volume count for exporting is wrong
try: