Bug #3876

API find_resource by name finds by ID instead when first character of name is a digit

Added by Og Maciel almost 4 years ago. Updated over 3 years ago.

Status:Closed
Priority:Normal
Assigned To:Joseph Magen
Category:API
Target version:Sprint 20
Difficulty: Bugzilla link:
Found in release: Pull request:
Story points-
Velocity based estimate-
Release1.5.0Release relationshipAuto

Description

Noticed that every now and than the Info subcommand for Model returns incorrect results:

DEBUG base:188: LANG=en_US hammer -u admin -p changeme model create --info --hardware-model --name='2ez0obdv' --vendor-class='vafqv7gd'
DEBUG base:191: Hardware model created

DEBUG base:188: LANG=en_US hammer -u admin -p changeme --output csv model info --name='2ez0obdv'
DEBUG base:191: Id,Name,Vendor class,HW model,Info,Created at,Updated at
2,nz1e,"","",--hardware-model,2013/12/13 16:21:53,2013/12/13 16:21:53

F
======================================================================
FAIL: test_create_model_2 (tests.cli.test_model.TestModel)
Create model with specific vendor class
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/omaciel/hacking/robottelo/tests/cli/test_model.py", line 26, in test_create_model_2
    self.assertEqual(result['vendor-class'], model.stdout['Vendor class'])
AssertionError: 'vafqv7gd' != '""'

----------------------------------------------------------------------
Ran 2 tests in 3.636s

FAILED (failures=1)

Noticed that the model name is 2ez0obdv but Info returns a model whose name is nz1e.

Packages:
  • rubygem-hammer_cli_foreman-0.0.12-1.el6.noarch
  • rubygem-hammer_cli-0.0.12-1.el6.noarch

Related issues

Related to Hammer CLI - Bug #3954: Info commands must always use IDs instead of names in api... Closed 01/07/2014

Associated revisions

Revision 823d4e1b
Added by Joseph Magen over 3 years ago

fixes #3876 - API find_resource by name even if name starts with integer

History

#1 Updated by Dmitri Dolguikh almost 4 years ago

  • Assigned To set to Martin Bacovsky

#2 Updated by Og Maciel almost 4 years ago

[root@qetello02 ~]# hammer model list --per-page=10000
---------------------------------------
HW MODEL | VENDOR CLASS | NAME     | ID
---------------------------------------
         |              | 0gzktycs | 31
         |              | 1yzw1    | 19
         | vafqv7gd     | 2ez0obdv | 34
         | ewpon        | 6oymg9y  | 6
         | 5h207        | 7if2cka  | 12
         |              | 7wjru7   | 15
         |              | 810qi    | 25
         |              | 8kat4ujn | 5
         | maei1u7      | at2qr4v4 | 22
         |              | ax1jm    | 32
         |              | b7lml    | 33
         |              | cpqkluf  | 29
         |              | d30g     | 21
         |              | fdbc0a   | 23
         |              | i1myu49  | 11
         |              | i9or0    | 13
         | y6fe1y       | ikbi     | 38
         |              | iv7llawa | 3
         | v0fd3dmi     | jqbuy    | 36
         |              | jvser    | 27
         |              | lt08ex   | 37
         | cq8vh5       | m0pp     | 14
         | 4du0n8k      | me7f2y   | 9
         | 7f0tej       | mhkko    | 16
         | mycds81      | morcok51 | 10
         |              | n68mf8wa | 35
         | 6cqf6d       | naw0     | 18
         |              | nz1e     | 2
         | bsl5         | pxz8mhl  | 26
         | wju8tjp      | q5kpe    | 8
         |              | qyihyfi  | 28
         |              | royja7r7 | 4
         | 23con299     | vt0rc9   | 7
         |              | xw7iar   | 1
         |              | yy59vr   | 30
         | pn6e41       | zga39b   | 20
         | dtpq         | zwn6c    | 24
         |              | zxjo     | 17
---------------------------------------
[root@qetello02 ~]# hammer model list --per-page=10000 | grep 2ez0obdv
         | 2ez0obdv | vafqv7gd     | 34
[root@qetello02 ~]# LANG=en_US hammer -u admin -p changeme --output csv model info --name='2ez0obdv'
Id,Name,Vendor class,HW model,Info,Created at,Updated at
2,nz1e,"","",--hardware-model,2013/12/13 16:21:53,2013/12/13 16:21:53

#3 Updated by Og Maciel over 3 years ago

# hammer -u admin -p changeme --output csv model list --search='name="8m74euv"'
Id,Name,Vendor class,HW model
15,8m74euv,"","" 

Started GET "/api/models?search=name%3D%228m74euv%22&per_page=20&page=1" for 127.0.0.1 at 2014-01-02 15:14:10 -0500
Processing by Api::V2::ModelsController#index as JSON
  Parameters: {"search"=>"name=\"8m74euv\"", "per_page"=>"20", "page"=>"1", "apiv"=>"v2", "model"=>{}}
Authorized user admin(Admin User)
  Rendered api/v2/models/index.rabl within api/v2/layouts/index_layout (3.3ms)
Completed 200 OK in 32ms (Views: 4.1ms | ActiveRecord: 13.5ms)

# hammer -u admin -p changeme --output csv model info --name='8m74euv'
Id,Name,Vendor class,HW model,Info,Created at,Updated at
8,foo,"","","",2014/01/02 16:45:12,2014/01/02 16:45:12

Started GET "/api/models/8m74euv" for 127.0.0.1 at 2014-01-02 15:14:14 -0500
Processing by Api::V2::ModelsController#show as JSON
  Parameters: {"apiv"=>"v2", "id"=>"8m74euv", "model"=>{}}
Authorized user admin(Admin User)
  Rendered api/v2/models/show.rabl (1.4ms)
Completed 200 OK in 28ms (Views: 2.1ms | ActiveRecord: 14.0ms)

#4 Updated by Dominic Cleal over 3 years ago

  • Project changed from Hammer CLI to Foreman
  • Category set to API
  • Assigned To deleted (Martin Bacovsky)

Hammer's using the model's name in the GET /models/:id, but Foreman's then interpreting the name as an ID, taking the first digit of the name to be the ID (e.g. the example in comment 3 shows it returns ID 8 as the name starts with a '8').

There's definitely an API bug here, since an ID with mixed digits and letters should always be interpreted as a name. However I'm wondering now about cases where we have names passed that are purely numeric, should Hammer cope with these? (Do we need a better API, or for Hammer to always use searches first?)

I'm reassigning this bug to core/API, but Martin/Tomas, please clone/create a new one if you agree with the above concern.

#5 Updated by Dominic Cleal over 3 years ago

  • Subject changed from hammer model info sporadically returns incorrect data to API find_resource by name finds by ID instead when first character of name is a digit

#6 Updated by Tomáš Strachota over 3 years ago

I agree this is an api bug. I don't think there's a reliable way to pass both names and ids in one parameter. We need to perform searches in hammer.
Created #3954.

#7 Updated by Dominic Cleal over 3 years ago

  • Target version set to Sprint 19

#8 Updated by Tomáš Strachota over 3 years ago

  • Related to Bug #3954: Info commands must always use IDs instead of names in api calls added

#9 Updated by Joseph Magen over 3 years ago

  • Status changed from New to Assigned
  • Assigned To set to Joseph Magen
  • Target version changed from Sprint 19 to Sprint 20

#10 Updated by Joseph Magen over 3 years ago

  • Status changed from Assigned to Ready For Testing

#11 Updated by Dominic Cleal over 3 years ago

  • Release set to 1.5.0

#12 Updated by Joseph Magen over 3 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

Also available in: Atom PDF