Bug 1328368

Summary: [API] Inconsistent ERROR response to some GET */invalid-id and */not-existent-id requests
Product: Red Hat Storage Console Reporter: Daniel Horák <dahorak>
Component: coreAssignee: gowtham <gshanmug>
core sub component: monitoring QA Contact: Daniel Horák <dahorak>
Status: CLOSED CURRENTRELEASE Docs Contact:
Severity: unspecified    
Priority: unspecified CC: gshanmug
Version: 2   
Target Milestone: ---   
Target Release: 2   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: rhscon-ceph-0.0.23-1.el7scon.x86_64, rhscon-core-0.0.24-1.el7scon.x86_64, rhscon-ui-0.0.39-1.el7scon.noarch Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-11-19 05:30:57 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Daniel Horák 2016-04-19 08:27:24 UTC
Description of problem:
  API GET request to http://SKYRING-SERVER:8080/api/v1/tasks/INVALID-TASK-ID leads to ERROR 500: Internal Server Error.

  If the task id is in valid format (e.g. aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee) it will properly return ERROR 404: Not Found.
  
Version-Release number of selected component (if applicable):
  rhscon-core-0.0.11-1.el7.x86_64

How reproducible:
  100%

Steps to Reproduce:
1. Login to skyring via API.
2. Send GET request to http://SKYRING-SERVER:8080/api/v1/tasks/INVALID-TASK-ID

Actual results:
  ERROR 500: Internal Server Error.

Expected results:
  ERROR 404: Not Found.
  Or some other suitable "4xx Client Error" response.

Additional info:
Reproducer script:
  #!/bin/bash
  URL="http://SKYRING-SERVER:8080/api/v1"
  #quiet="-q -O-"
  quiet=""
  rm -f cookies.txt
  wget ${quiet} --post-data='{"username":"admin", "password":"admin"}' --save-cookies cookies.txt ${URL}/auth/login -O -
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/tasks/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/tasks/INVALID-TASK-ID
  echo -e "\n"
  wget ${quiet} --post-data='' --load-cookies cookies.txt -p ${URL}/auth/logout
  echo ""

Comment 2 Daniel Horák 2016-04-19 08:57:44 UTC
I'll slightly extend the range of this Bug.

When I tried few other GET requests e.g.:
* tasks/VALID-BUT-NOT-EXISTING-TASK-ID
* tasks/INVALID-TASK-ID
* events/VALID-BUT-NOT-EXISTING-EVENT-ID
* events/INVALID-EVENT-ID
* nodes/VALID-BUT-NOT-EXISTING-NODE-ID
* nodes/INVALID-NODE-ID
* clusters/VALID-BUT-NOT-EXISTING-CLUSTER-ID
* clusters/INVALID-CLUSTER-ID
* clusters/VALID-CLUSTER-ID/storages/VALID-BUT-NOT-EXISTING-STORAGE-ID
* clusters/VALID-CLUSTER-ID/storages/INVALID-STORAGE-ID
* users/NOT-EXISTING-USER

The response is inconsistent. I thing it should follow some rule - e.g.:
1) If the request is valid, but the entity with given ID/name doesn't exists it should return 'ERROR 404: Not Found'.
2) If the request is invalid (e.g. the ID have bad format), it should return 'ERROR 400: Bad Request'.


Updated reproducer:
  #!/bin/bash
  URL="http://SKYRING-SERVER:8080/api/v1"
  CLUSTER_ID='VALID-EXISTING-CLUSTER-ID'
  #quiet="-q -O-"
  quiet=""
  rm -f cookies.txt
  wget ${quiet} --post-data='{"username":"admin", "password":"admin"}' --save-cookies cookies.txt ${URL}/auth/login -O -
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/tasks/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/tasks/INVALID-ID
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/events/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/events/INVALID-ID
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/nodes/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/nodes/INVALID-ID
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/clusters/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/clusters/INVALID-ID
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/clusters/${CLUSTER_ID}/storages/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/clusters/${CLUSTER_ID}/storages/INVALID-ID
  echo -e "\n"
  wget ${quiet} --load-cookies cookies.txt -p ${URL}/users/aaaaaaaa
  echo -e "\n"
  wget ${quiet} --post-data='' --load-cookies cookies.txt -p ${URL}/auth/logout
  echo ""

See also Bug 1298114.

Comment 4 gowtham 2016-07-18 06:30:33 UTC
All the requests are standardized https://review.gerrithub.io/#/c/278275/

Comment 5 Daniel Horák 2016-07-22 08:21:45 UTC
Tested and VERIFIED on USM Serve (RHEL 7.2)
  ceph-ansible-1.0.5-31.el7scon.noarch
  ceph-installer-1.0.14-1.el7scon.noarch
  mongodb-2.6.5-4.1.el7.x86_64
  mongodb-server-2.6.5-4.1.el7.x86_64
  rhscon-ceph-0.0.34-1.el7scon.x86_64
  rhscon-core-0.0.35-1.el7scon.x86_64
  rhscon-core-selinux-0.0.35-1.el7scon.noarch
  rhscon-ui-0.0.49-1.el7scon.noarch

Automatic tests results:
  [17:37:52,216] PASS api/user.get_nonexistent                :  #tests:24    #fails:0     desc.:"ApiTestUsers.user_get_not_found()"
  [17:37:52,220] PASS api/nodes.get_nonexistent               :  #tests:24    #fails:0     desc.:"ApiTestNodes.node_get_not_found()"
  [17:37:52,221] PASS api/nodes.get_invalid_id                :  #tests:24    #fails:0     desc.:"ApiTestNodes.node_get_invalid_id()"
  [17:37:52,224] PASS api/clusters.get_nonexistent            :  #tests:24    #fails:0     desc.:"ApiTestClusters.cluster_get_not_found()"
  [17:37:52,224] PASS api/clusters.get_invalid_id             :  #tests:24    #fails:0     desc.:"ApiTestClusters.cluster_get_invalid_id()"
  [17:37:52,228] PASS api/clusters.storages.get_nonexistent   :  #tests:64    #fails:0     desc.:"ApiTestStorages.cluster_storage_get_not_found()"
  [17:37:52,228] PASS api/clusters.storages.get_invalid_id    :  #tests:64    #fails:0     desc.:"ApiTestStorages.cluster_storage_get_invalid_id()"
  [17:37:52,231] PASS api/tasks.get_nonexistent               :  #tests:24    #fails:0     desc.:"ApiTestTasks.task_get_not_found()"
  [17:37:52,232] PASS api/tasks.get_invalid_id                :  #tests:24    #fails:0     desc.:"ApiTestTasks.task_get_invalid_id()"
  [17:37:52,233] PASS api/events.get_nonexistent              :  #tests:24    #fails:0     desc.:"ApiTestEvents.event_get_not_found()"
  [17:37:52,233] PASS api/events.get_invalid_id               :  #tests:24    #fails:0     desc.:"ApiTestEvents.event_get_invalid_id()"

>> VERIFIED