Package: openstack-cluster-installer
Version: 42.3.0~bpo12+1
Severity: minor
Tags: patch

It looks like something went wrong with the patch which I provided in
#1053506, so the problem still exists. I've attached a rebased patch.

Original code:
if(sizeof($ret["data"]) == 0){
Current code (as at commit c69a4a67):
if(sizeof($ret["data"]) == 0 || sizeof($ret["data"]) == 0){
Suggested fix:
if(!isset($ret["data"]) || sizeof($ret["data"]) == 0){

Original bug report below

---------------

When testing out auto racking, the machine-guess-racking command returns
and error when there is no match, rather than reporting 'No racking info
could be guessed.' as expected

root@oci-01:~# ocicli machine-guess-racking afaf7bc0-9ef4-4ba0-8bd0-2e2eec827346
Could not query API:

In the apache error log:
[Thu Oct 05 10:19:33.193747 2023] [php:error] [pid 262310] [client 
127.0.0.1:49928] PHP Fatal error:  Uncaught TypeError: sizeof(): Argument #1 
($value) must be of type Countable|array, null given in 
/usr/share/openstack-cluster-installer/api.php:1118\nStack trace:\n#0 
/usr/share/openstack-cluster-installer/api.php(4023): api_actions()\n#1 
{main}\n  thrown in /usr/share/openstack-cluster-installer/api.php on line 1118

Line 59 of /usr/share/openstack-cluster-installer/inc/auto_racking.php
contains to following comment:
# No $json["data"] means nothing found.
however in line 1118 of api.php it is assumed that $ret["data"] is an
array

--

Regards
Jim
diff --git a/src/api.php b/src/api.php
index 5d0a921a..60f2a980 100644
--- a/src/api.php
+++ b/src/api.php
@@ -1118,7 +1118,7 @@ function api_actions($con,$conf){
             return $ret;
         }
 
-        if(sizeof($ret["data"]) == 0 || sizeof($ret["data"]) == 0){
+        if(!isset($ret["data"]) || sizeof($ret["data"]) == 0){
             $json["data"] = "No racking info could be guessed.";
         }else{
             $json["data"] = "Machine is in datacenter ".$ret["data"]["dc"]." row ".$ret["data"]["row"]." rack ".$ret["data"]["rack"]." ustart ".$ret["data"]["u_start"]." uend ".$ret["data"]["u_end"].".";

Reply via email to