Package: openstack-cluster-installer
Version: 42.3.0~bpo12+1
Tags: patch
When the list of block devices is determined by enc.php there is
different code used for different node types. Some of these assume that
any drive which is not *da can be used as a non-OS block device. This
however is not true when using NVMe drives (whose names are nvme0n1
etc.) and when using RAID (where the second drive should also be
excluded).
I've attached a patch which moves the 'working' code into a common
function and then calls that function everywhere that the block_devices
list is generated.
I haven't tested the patch extensively, but so far 'it works for me' :)
--
Regards
Jim
diff --git a/src/inc/enc.php b/src/inc/enc.php
index 2b116576..3d9db0fc 100644
--- a/src/inc/enc.php
+++ b/src/inc/enc.php
@@ -72,6 +72,46 @@ function get_ssh_keypair($con, $conf, $cluster_id, $hostname, $username){
return $json;
}
+function get_block_devices($con, $machine){
+ $machine_id = $machine['id'];
+ if($machine["install_on_raid"] == "no"){
+ if($machine["dest_blk"] == "none"){
+ $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '%da'";
+ }else{
+ $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '".$machine["dest_blk"]."'";
+ }
+ }else{
+ $os_disks = [$machine["raid_dev0"], $machine["raid_dev1"]];
+ switch($machine["raid_type"]){
+ case "0":
+ case "1":
+ break;
+ case "10":
+ array_push($os_disks, $machine['raid_dev2'], $machine['raid_dev3']);
+ break;
+ case "5":
+ default:
+ die("Not supported yet.");
+ break;
+ }
+ $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT IN ('".join("','", $os_disks)."')";
+ }
+ $q .= " ORDER BY name";
+ $r = mysqli_query($con, $q);
+ $n = mysqli_num_rows($r);
+ if($n < 1){
+ $json["status"] = "error";
+ $json["message"] = "Cannot find block devices (SQL query: $q) line ".__LINE__." file ".__FILE__;
+ return $json;
+ }
+ $disks = [];
+ for($i=0;$i<$n;$i++){
+ $a = mysqli_fetch_array($r);
+ $disks[] = $a["name"];
+ }
+ return $disks;
+}
+
# $role can be either 'cephmon' or 'billmon'
function enc_get_mon_nodes($con,$conf,$cluster_id,$role='cephmon'){
if($role == 'cephmon'){
@@ -2593,33 +2633,7 @@ function puppet_enc($con,$conf){
$enc_file .= " swift_rsync_connection_limit: " . $swift_rsync_connection_limit . "\n";
$enc_file .= " block_devices:\n";
- if($machine["install_on_raid"] == "no"){
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '%da'";
- }else{
- switch($machine["raid_type"]){
- case "0":
- case "1":
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '".$machine["raid_dev0"]."' AND name NOT LIKE '".$machine["raid_dev1"]."'";
- break;
- case "10":
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '".$machine["raid_dev0"]."' AND name NOT LIKE '".$machine["raid_dev1"]."' AND name NOT LIKE '".$machine["raid_dev2"]."' AND name NOT LIKE '".$machine["raid_dev3"]."'";
- break;
- case "5":
- default:
- die("Not supported yet.");
- break;
- }
- }
- $r = mysqli_query($con, $q);
- $n = mysqli_num_rows($r);
- if($n < 1){
- $json["status"] = "error";
- $json["message"] = "Cannot find block devices line ".__LINE__." file ".__FILE__;
- return $json;
- }
- for($i=0;$i<$n;$i++){
- $a = mysqli_fetch_array($r);
- $hdd_name = $a["name"];
+ foreach (get_block_devices($con, $machine) as $hdd_name) {
$enc_file .= " - $hdd_name\n";
}
if($machine["use_oci_sort_dev"] == "yes"){
@@ -2641,38 +2655,7 @@ function puppet_enc($con,$conf){
$enc_file .= " self_signed_api_cert: $self_signed_api_cert\n";
$enc_file .= " zoneid: $machine_location\n";
$enc_file .= " block_devices:\n";
-
- if($machine["install_on_raid"] == "no"){
- if($machine["dest_blk"] == "none"){
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '%da'";
- }else{
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name != '" . $machine["dest_blk"] . "' AND name != '" . $machine["dest_blk"] . "n1'";
- }
- }else{
- switch($machine["raid_type"]){
- case "0":
- case "1":
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '".$machine["raid_dev0"]."' AND name NOT LIKE '".$machine["raid_dev1"]."'";
- break;
- case "10":
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '".$machine["raid_dev0"]."' AND name NOT LIKE '".$machine["raid_dev1"]."' AND name NOT LIKE '".$machine["raid_dev2"]."' AND name NOT LIKE '".$machine["raid_dev3"]."'";
- break;
- case "5":
- default:
- die("Not supported yet.");
- break;
- }
- }
- $r = mysqli_query($con, $q);
- $n = mysqli_num_rows($r);
- if($n < 1){
- $json["status"] = "error";
- $json["message"] = "Cannot find block devices line ".__LINE__." file ".__FILE__;
- return $json;
- }
- for($i=0;$i<$n;$i++){
- $a = mysqli_fetch_array($r);
- $hdd_name = $a["name"];
+ foreach (get_block_devices($con, $machine) as $hdd_name) {
$enc_file .= " - $hdd_name\n";
}
@@ -2864,18 +2847,7 @@ function puppet_enc($con,$conf){
$enc_file .= " ceph_osd_initial_setup: $ceph_osd_initial_setup\n";
$enc_file .= " block_devices:\n";
-
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '%da'";
- $r = mysqli_query($con, $q);
- $n = mysqli_num_rows($r);
- if($n < 1){
- $json["status"] = "error";
- $json["message"] = "Cannot find block devices line ".__LINE__." file ".__FILE__;
- return $json;
- }
- for($i=0;$i<$n;$i++){
- $a = mysqli_fetch_array($r);
- $hdd_name = $a["name"];
+ foreach (get_block_devices($con, $machine) as $hdd_name) {
$enc_file .= " - $hdd_name\n";
}
@@ -3200,18 +3172,7 @@ function puppet_enc($con,$conf){
if($machine["compute_is_cephosd"] == "yes"){
$enc_file .= " block_devices:\n";
-
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '%da'";
- $r = mysqli_query($con, $q);
- $n = mysqli_num_rows($r);
- if($n < 1){
- $json["status"] = "error";
- $json["message"] = "Cannot find block devices line ".__LINE__." file ".__FILE__;
- return $json;
- }
- for($i=0;$i<$n;$i++){
- $a = mysqli_fetch_array($r);
- $hdd_name = $a["name"];
+ foreach (get_block_devices($con, $machine) as $hdd_name) {
$enc_file .= " - $hdd_name\n";
}
}
@@ -3255,17 +3216,7 @@ function puppet_enc($con,$conf){
$enc_file .= " ceph_osd_initial_setup: $ceph_osd_initial_setup\n";
$enc_file .= " block_devices:\n";
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '%da'";
- $r = mysqli_query($con, $q);
- $n = mysqli_num_rows($r);
- if($n < 1){
- $json["status"] = "error";
- $json["message"] = "Cannot find block devices line ".__LINE__." file ".__FILE__;
- return $json;
- }
- for($i=0;$i<$n;$i++){
- $a = mysqli_fetch_array($r);
- $hdd_name = $a["name"];
+ foreach (get_block_devices($con, $machine) as $hdd_name) {
$enc_file .= " - $hdd_name\n";
}
@@ -3416,33 +3367,7 @@ function puppet_enc($con,$conf){
$enc_file .= $enc_rabbits;
}
- if($machine["install_on_raid"] == "no"){
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '%da'";
- }else{
- switch($machine["raid_type"]){
- case "0":
- case "1":
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '".$machine["raid_dev0"]."' AND name NOT LIKE '".$machine["raid_dev1"]."'";
- break;
- case "10":
- $q = "SELECT * FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '".$machine["raid_dev0"]."' AND name NOT LIKE '".$machine["raid_dev1"]."' AND name NOT LIKE '".$machine["raid_dev2"]."' AND name NOT LIKE '".$machine["raid_dev3"]."'";
- break;
- case "5":
- default:
- die("Not supported yet.");
- break;
- }
- }
- $r = mysqli_query($con, $q);
- $n = mysqli_num_rows($r);
- if($n < 1){
- $json["status"] = "error";
- $json["message"] = "Cannot find block devices line ".__LINE__." file ".__FILE__;
- return $json;
- }
- for($i=0;$i<$n;$i++){
- $a = mysqli_fetch_array($r);
- $hdd_name = $a["name"];
+ foreach (get_block_devices($con, $machine) as $hdd_name) {
$enc_file .= " - $hdd_name\n";
}