summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilly Olsen <billy.olsen@gmail.com>2017-03-08 17:18:11 -0700
committerBilly Olsen <billy.olsen@gmail.com>2017-03-09 09:11:06 -0700
commit857a00c65b89dee1a0b8aafc87e23b39df373ec3 (patch)
treecdb627f993d6b7e6db8e96af1411d7b40989b1cb
parent0142d5045a1bec70f85793a05ca307fc432b35b5 (diff)
Revert "Use libblkid instead of CLI"
This reverts commit a7f29e52efdf2a047306fa3d064040c97678d82d which switched to using libblkid instead of invoking the blkid command on the commandline. The replacement code introduced as part of that commit does not actually fix the bug that it was intended to fix and only adds unnecessary complexity to the code. The bug is being tagged by this commit message to help identify the full set of fixes for the actual bug. Change-Id: I21b32197c8db4a3c667c986180cdd213fced2c26 Related-Bug: #1660240
Notes
Notes (review): Code-Review+2: Chris Holcombe <chris.holcombe@canonical.com> Workflow+1: Chris Holcombe <chris.holcombe@canonical.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Thu, 09 Mar 2017 22:52:30 +0000 Reviewed-on: https://review.openstack.org/443418 Project: openstack/charms.ceph Branch: refs/heads/master
-rw-r--r--ceph/__init__.py53
1 files changed, 11 insertions, 42 deletions
diff --git a/ceph/__init__.py b/ceph/__init__.py
index 6982155..b238792 100644
--- a/ceph/__init__.py
+++ b/ceph/__init__.py
@@ -11,7 +11,6 @@
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14from _ctypes import POINTER, byref
15import ctypes 14import ctypes
16import collections 15import collections
17import json 16import json
@@ -321,52 +320,22 @@ def set_hdd_read_ahead(dev_name, read_ahead_sectors=256):
321 320
322def get_block_uuid(block_dev): 321def get_block_uuid(block_dev):
323 """ 322 """
324 This queries blkid to get the uuid for a block device. Note: This function 323 This queries blkid to get the uuid for a block device.
325 needs to be called with root priv. It will raise an error otherwise.
326 :param block_dev: Name of the block device to query. 324 :param block_dev: Name of the block device to query.
327 :return: The UUID of the device or None on Error. Raises OSError 325 :return: The UUID of the device or None on Error.
328 """ 326 """
329 try: 327 try:
330 blkid = ctypes.cdll.LoadLibrary("libblkid.so") 328 block_info = subprocess.check_output(
331 # Header signature 329 ['blkid', '-o', 'export', block_dev])
332 # extern int blkid_probe_lookup_value(blkid_probe pr, const char *name, 330 for tag in block_info.split('\n'):
333 # const char **data, size_t *len); 331 parts = tag.split('=')
334 blkid.blkid_new_probe_from_filename.argtypes = [ctypes.c_char_p] 332 if parts[0] == 'UUID':
335 blkid.blkid_probe_lookup_value.argtypes = [ctypes.c_void_p, 333 return parts[1]
336 ctypes.c_char_p,
337 POINTER(ctypes.c_char_p),
338 POINTER(ctypes.c_ulong)]
339 except OSError as err:
340 log('get_block_uuid loading libblkid.so failed with error: {}'.format(
341 os.strerror(err.errno)),
342 level=ERROR)
343 raise err
344 if not os.path.exists(block_dev):
345 return None 334 return None
346 probe = blkid.blkid_new_probe_from_filename(ctypes.c_char_p(block_dev)) 335 except subprocess.CalledProcessError as err:
347 if probe < 0: 336 log('get_block_uuid failed with error: {}'.format(err.output),
348 log('get_block_uuid new_probe_from_filename failed: {}'.format(
349 os.strerror(probe)),
350 level=ERROR)
351 raise OSError(probe, os.strerror(probe))
352 result = blkid.blkid_do_probe(probe)
353 if result != 0:
354 log('get_block_uuid do_probe failed with error: {}'.format(
355 os.strerror(result)),
356 level=ERROR)
357 raise OSError(result, os.strerror(result))
358 uuid = ctypes.c_char_p()
359 result = blkid.blkid_probe_lookup_value(probe,
360 ctypes.c_char_p(
361 'UUID'.encode('ascii')),
362 byref(uuid), None)
363 if result < 0:
364 log('get_block_uuid lookup_value failed with error: {}'.format(
365 os.strerror(result)),
366 level=ERROR) 337 level=ERROR)
367 raise OSError(result, os.strerror(result)) 338 return None
368 blkid.blkid_free_probe(probe)
369 return ctypes.string_at(uuid).decode('ascii')
370 339
371 340
372def check_max_sectors(save_settings_dict, 341def check_max_sectors(save_settings_dict,