summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Page <james.page@ubuntu.com>2017-11-29 12:12:20 +0000
committerJames Page <james.page@ubuntu.com>2017-11-29 12:29:23 +0000
commite1a0b3558bd3fc7cb785e921e63942e172c58726 (patch)
tree1dc06915a36374f669f31d2ab4be5a2f0451c8dd
parentccaffa0a599559414ac74048d6ec48d44158e5f3 (diff)
Deal with partitions without NAME labels
Partition NAME labels are optional; update parser to deal with an empty name. Change-Id: I179d74670a7e6b35b23f7423e5356db4199d53e6 Closes-Bug: 1731639
Notes
Notes (review): Code-Review+2: Chris MacNaughton <chris.macnaughton@canonical.com> Workflow+1: Chris MacNaughton <chris.macnaughton@canonical.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 01 Dec 2017 12:16:52 +0000 Reviewed-on: https://review.openstack.org/523856 Project: openstack/charms.ceph Branch: refs/heads/master
-rw-r--r--ceph/utils.py30
-rw-r--r--unit_tests/partx_output2
-rw-r--r--unit_tests/test_utils.py2
3 files changed, 24 insertions, 10 deletions
diff --git a/ceph/utils.py b/ceph/utils.py
index 33703f0..6331f9c 100644
--- a/ceph/utils.py
+++ b/ceph/utils.py
@@ -944,15 +944,27 @@ def get_partition_list(dev):
944 # For each line of output 944 # For each line of output
945 for partition in partitions: 945 for partition in partitions:
946 parts = partition.split() 946 parts = partition.split()
947 partitions_list.append( 947 try:
948 Partition(number=parts[0], 948 partitions_list.append(
949 start=parts[1], 949 Partition(number=parts[0],
950 end=parts[2], 950 start=parts[1],
951 sectors=parts[3], 951 end=parts[2],
952 size=parts[4], 952 sectors=parts[3],
953 name=parts[5], 953 size=parts[4],
954 uuid=parts[6]) 954 name=parts[5],
955 ) 955 uuid=parts[6])
956 )
957 except IndexError:
958 partitions_list.append(
959 Partition(number=parts[0],
960 start=parts[1],
961 end=parts[2],
962 sectors=parts[3],
963 size=parts[4],
964 name="",
965 uuid=parts[5])
966 )
967
956 return partitions_list 968 return partitions_list
957 except subprocess.CalledProcessError: 969 except subprocess.CalledProcessError:
958 raise 970 raise
diff --git a/unit_tests/partx_output b/unit_tests/partx_output
index 9964245..12e910f 100644
--- a/unit_tests/partx_output
+++ b/unit_tests/partx_output
@@ -1,2 +1,4 @@
11 2099200 8377310 6278111 3G ceph\x20data 6e99ac59-1aa3-4812-abd7-9c886a151dd4 11 2099200 8377310 6278111 3G ceph\x20data 6e99ac59-1aa3-4812-abd7-9c886a151dd4
22 2048 2099199 2097152 1G ceph\x20journal 0333f202-256c-4867-a85c-3e3c92abd461 22 2048 2099199 2097152 1G ceph\x20journal 0333f202-256c-4867-a85c-3e3c92abd461
33 1050624 273680383 272629760 130G 21a38dc5-bc0d-4b9e-9151-2e480c081cca
44 273680384 500118158 226437775 108G b351d068-08b5-4d1c-a90c-e72f6b742cc8
diff --git a/unit_tests/test_utils.py b/unit_tests/test_utils.py
index 9e98be9..627dc3b 100644
--- a/unit_tests/test_utils.py
+++ b/unit_tests/test_utils.py
@@ -227,7 +227,7 @@ class CephTestCase(unittest.TestCase):
227 with open('unit_tests/partx_output', 'r') as partx_out: 227 with open('unit_tests/partx_output', 'r') as partx_out:
228 output.return_value = partx_out.read().encode('UTF-8') 228 output.return_value = partx_out.read().encode('UTF-8')
229 partition_list = utils.get_partition_list('/dev/xvdb') 229 partition_list = utils.get_partition_list('/dev/xvdb')
230 self.assertEqual(len(partition_list), 2) 230 self.assertEqual(len(partition_list), 4)
231 231
232 @patch.object(utils.subprocess, 'check_output') 232 @patch.object(utils.subprocess, 'check_output')
233 def test_get_ceph_pg_stat(self, output): 233 def test_get_ceph_pg_stat(self, output):