Bug #20742

Host reports command is dysfunctional

Added by Tomáš Strachota 3 months ago. Updated 5 days ago.

Status:Closed
Priority:High
Assigned To:Martin Bacovsky
Category:Reporting
Target version:Foreman - Team Ivan - Iteration 23
Difficulty: Bugzilla link:1297017
Found in release: Pull request:https://github.com/theforeman/hammer-cli-foreman/pull/340
Story points-
Velocity based estimate-
Release hammer-cli-foreman-0.12.0Release relationshipAuto

Description

hammer host reports allow specifying the host by either --id or --name. None of the methods actually work.

Using --name
Ends up with 400 error

> hammer host reports --name sandy-oberdorf.tstracho-laptop
Error: 400 Bad Request

caused by:

[ INFO 2017-08-25 12:27:34 API] GET /api/reports
[DEBUG 2017-08-25 12:27:34 API] Params: {
    :search => "name = \"sandy-oberdorf.tstracho-laptop\"" 
}
[DEBUG 2017-08-25 12:27:34 API] Headers: {
    :params => {
        :search => "name = \"sandy-oberdorf.tstracho-laptop\"" 
    }
}
[ERROR 2017-08-25 12:27:34 API] 400 Bad Request
[DEBUG 2017-08-25 12:27:34 API] {
    "error" => {
        "message" => "Field 'name' not recognized for searching!",
          "class" => "ScopedSearch::QueryNotSupported" 
    }
}

Using --id
Returns empty list

hammer host reports --id 13
---|------|-------------|---------|-----------|--------|------------------|---------|--------
ID | HOST | LAST REPORT | APPLIED | RESTARTED | FAILED | RESTART FAILURES | SKIPPED | PENDING
---|------|-------------|---------|-----------|--------|------------------|---------|--------

which is caused by wrong search condition:

[ INFO 2017-08-25 12:54:59 API] GET /api/reports
[DEBUG 2017-08-25 12:54:59 API] Params: {
        "page" => 1,
    "per_page" => 1000,
          "id" => "13",
     "host_id" => "13" 
}
[DEBUG 2017-08-25 12:54:59 API] Headers: {
    :params => {
            "page" => 1,
        "per_page" => 1000,
              "id" => "13",
         "host_id" => "13" 
    }
}
[DEBUG 2017-08-25 12:54:59 API] Using authenticator: HammerCLIForeman::Api::SessionAuthenticatorWrapper
[DEBUG 2017-08-25 12:54:59 API] Response: {
       "total" => 135,
    "subtotal" => 0,
        "page" => 1,
    "per_page" => 1000,
      "search" => " host = 13",
        "sort" => {
           "by" => nil,
        "order" => nil
    },
     "results" => []
}


Note that searching by "host = <HOSTNAME>" would work as intended (tested in the UI).

The fix should be quite simple: modify the command to use "host = X" or "host.id = X" search query according to what parameters were used.


Related issues

Related to Hammer CLI - Bug #14510: Hammer should use /config_reports rather than /reports New 04/06/2016
Related to Foreman - Feature #21602: Add scoped_search on host id for reports Closed 11/08/2017

Associated revisions

Revision d9b0280b
Added by Martin Bacovsky 5 days ago

Fixes #20742 - Make hammer host reports work

Added proper mapping of id and name options to search queries. Made host
parameter required. I found out there is no name in reports and fixed
the id resolver. --search was fixed. Added some tests.

History

#1 Updated by Tomáš Strachota 3 months ago

  • Related to Bug #14510: Hammer should use /config_reports rather than /reports added

#2 Updated by Tomáš Strachota 3 months ago

At the moment the command also uses an old api endpoint (tracked in http://projects.theforeman.org/issues/14510). It would be good to fix the two issues together.

#3 Updated by Tomáš Strachota 3 months ago

  • Bugzilla link set to 1297017

#4 Updated by Tomáš Strachota 2 months ago

  • Description updated (diff)

#5 Updated by Ondřej Pražák 12 days ago

  • Assigned To set to Ondřej Pražák
  • Status changed from New to Assigned

#6 Updated by Ondřej Pražák 12 days ago

  • Related to Feature #21602: Add scoped_search on host id for reports added

#7 Updated by The Foreman Bot 12 days ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/hammer-cli-foreman/pull/339 added

#8 Updated by The Foreman Bot 7 days ago

  • Pull request https://github.com/theforeman/hammer-cli-foreman/pull/340 added

#9 Updated by Marek Hulán 6 days ago

  • Pull request deleted (https://github.com/theforeman/hammer-cli-foreman/pull/339)

#10 Updated by Martin Bacovsky 6 days ago

  • Target version set to Team Ivan - Iteration 23
  • Assigned To changed from Ondřej Pražák to Martin Bacovsky

#11 Updated by Martin Bacovsky 5 days ago

  • Release set to hammer-cli-foreman-0.12.0

#12 Updated by Martin Bacovsky 5 days ago

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

Also available in: Atom PDF