Gris Ge
2015-07-02 06:22:47 UTC
Issue:
volume_raid_create() will incorrectly raise ErrorNumber.INVALID_ARGUMENT
about disk not from the same controller when trying to create
volume on second controller.
Root cause:
Old code skip the controller number check when controller ID is 0.
On second controller, the check will look like 1 != '1', that
means raise error anyway.
Fix:
Convert string to int before checking controller ID.
Don't skip controller ID check on 0.
Special thanks to Bruno Goncalves who found this bug.
Signed-off-byr Gris Ge <***@redhat.com>
Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/megaraid/megaraid.py | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/plugin/megaraid/megaraid.py b/plugin/megaraid/megaraid.py
index d921c8e..1aadd4f 100644
--- a/plugin/megaraid/megaraid.py
+++ b/plugin/megaraid/megaraid.py
@@ -700,19 +700,23 @@ def volume_raid_create(self, name, raid_type, disks, strip_size,
(cur_ctrl_num, cur_enclosure_num, slot_num) = \
disk.plugin_data.split(':')
- if ctrl_num and cur_ctrl_num != ctrl_num:
+ cur_ctrl_num = int(cur_ctrl_num)
+ cur_enclosure_num = int(cur_enclosure_num)
+
+ if ctrl_num is not None and cur_ctrl_num != ctrl_num:
raise LsmError(
ErrorNumber.INVALID_ARGUMENT,
"Illegal input disks argument: disks are not from the "
"same controller/system.")
- if enclosure_num and cur_enclosure_num != enclosure_num:
+ if enclosure_num is not None and \
+ cur_enclosure_num != enclosure_num:
raise LsmError(
ErrorNumber.INVALID_ARGUMENT,
"Illegal input disks argument: disks are not from the "
"same disk enclosure.")
- ctrl_num = int(cur_ctrl_num)
+ ctrl_num = cur_ctrl_num
enclosure_num = cur_enclosure_num
slot_nums.append(slot_num)
@@ -722,7 +726,7 @@ def volume_raid_create(self, name, raid_type, disks, strip_size,
cmds = [
"/c%s" % ctrl_num, "add", "vd", mega_raid_type,
'size=all', "name=%s" % name,
- "drives=%s:%s" % (enclosure_num, ','.join(slot_nums))]
+ "drives=%d:%s" % (enclosure_num, ','.join(slot_nums))]
if raid_type == Volume.RAID_TYPE_RAID10 or \
raid_type == Volume.RAID_TYPE_RAID50 or \
volume_raid_create() will incorrectly raise ErrorNumber.INVALID_ARGUMENT
about disk not from the same controller when trying to create
volume on second controller.
Root cause:
Old code skip the controller number check when controller ID is 0.
On second controller, the check will look like 1 != '1', that
means raise error anyway.
Fix:
Convert string to int before checking controller ID.
Don't skip controller ID check on 0.
Special thanks to Bruno Goncalves who found this bug.
Signed-off-byr Gris Ge <***@redhat.com>
Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/megaraid/megaraid.py | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/plugin/megaraid/megaraid.py b/plugin/megaraid/megaraid.py
index d921c8e..1aadd4f 100644
--- a/plugin/megaraid/megaraid.py
+++ b/plugin/megaraid/megaraid.py
@@ -700,19 +700,23 @@ def volume_raid_create(self, name, raid_type, disks, strip_size,
(cur_ctrl_num, cur_enclosure_num, slot_num) = \
disk.plugin_data.split(':')
- if ctrl_num and cur_ctrl_num != ctrl_num:
+ cur_ctrl_num = int(cur_ctrl_num)
+ cur_enclosure_num = int(cur_enclosure_num)
+
+ if ctrl_num is not None and cur_ctrl_num != ctrl_num:
raise LsmError(
ErrorNumber.INVALID_ARGUMENT,
"Illegal input disks argument: disks are not from the "
"same controller/system.")
- if enclosure_num and cur_enclosure_num != enclosure_num:
+ if enclosure_num is not None and \
+ cur_enclosure_num != enclosure_num:
raise LsmError(
ErrorNumber.INVALID_ARGUMENT,
"Illegal input disks argument: disks are not from the "
"same disk enclosure.")
- ctrl_num = int(cur_ctrl_num)
+ ctrl_num = cur_ctrl_num
enclosure_num = cur_enclosure_num
slot_nums.append(slot_num)
@@ -722,7 +726,7 @@ def volume_raid_create(self, name, raid_type, disks, strip_size,
cmds = [
"/c%s" % ctrl_num, "add", "vd", mega_raid_type,
'size=all', "name=%s" % name,
- "drives=%s:%s" % (enclosure_num, ','.join(slot_nums))]
+ "drives=%d:%s" % (enclosure_num, ','.join(slot_nums))]
if raid_type == Volume.RAID_TYPE_RAID10 or \
raid_type == Volume.RAID_TYPE_RAID50 or \
--
1.8.3.1
1.8.3.1