diff --git a/xCAT-server/xCAT-wsapi/xcatws.cgi b/xCAT-server/xCAT-wsapi/xcatws.cgi index 86bf86e9a..4fa3bcd58 100755 --- a/xCAT-server/xCAT-wsapi/xcatws.cgi +++ b/xCAT-server/xCAT-wsapi/xcatws.cgi @@ -2871,6 +2871,12 @@ sub tablerowhdl { # Error returned, most likely invalid table, substitute a better error msg @$responses[0]->{error} = "No such table: @tables"; } + # Check if there is any real data in response + # One key ('xcatdsource' => '') is always returned. + # If no other keys in response - no matches on key or attribute were returned from xcatd + if (keys @$responses[0] <= 1) { + @$responses[0]->{error} = "No table rows matched specified keys or attributes"; + } return $responses; } diff --git a/xCAT-test/autotest/testcase/restapi/table/cases0 b/xCAT-test/autotest/testcase/restapi/table/cases0 index 16f9fd640..e424ad8f4 100644 --- a/xCAT-test/autotest/testcase/restapi/table/cases0 +++ b/xCAT-test/autotest/testcase/restapi/table/cases0 @@ -19,6 +19,20 @@ check:rc==200 check:output=~"mask":"255.0.0.0" end +start:get_network_table_with_attr_selection_error_rest +description: get all attribute matching networks table entries with REST API, invalid attribute name +cmd:restapitest -m GET -r /tables/networks/rows/abc=255.0.0.0 -u $$username -p $$password +check:rc==147 +check:output=~No table rows +end + +start:get_network_table_with_attr_selection_error_rest2 +description: get all attribute matching networks table entries with REST API, no match +cmd:restapitest -m GET -r /tables/networks/rows/mask=a.b.c.d -u $$username -p $$password +check:rc==147 +check:output=~No table rows +end + start:get_network_table_with_attr_selection_rest2 description: get attribute matching networks table attributes with REST API cmd:restapitest -m GET -r /tables/networks/rows/mask=255.0.0.0/gateway -u $$username -p $$password