Bug 1546021 - Cannot add repositories to content view with repository name using hammer
Summary: Cannot add repositories to content view with repository name using hammer
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Content Views
Version: 6.2.0
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: 6.6.0
Assignee: Partha Aji
QA Contact: Lai
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-02-16 05:35 UTC by Diksha Chaudhari
Modified: 2021-08-30 11:51 UTC (History)
7 users (show)

Fixed In Version: tfm-rubygem-hammer_cli_katello-0.18.0-0
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-07-08 03:45:08 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 26091 0 Normal Closed hammer content-view update fails on --repositories 2020-01-17 15:41:53 UTC
Red Hat Knowledge Base (Solution) 3365661 0 None None None 2018-05-16 05:58:35 UTC

Description Diksha Chaudhari 2018-02-16 05:35:02 UTC
Description of problem: 
Set “Entries per page” to 5 in setting and sync more than 5 repositories on satellite. 
Now adding repositories into content view using repository name doesn’t work with hammer.

Version: Satellite 6.2


Release number of selected component (if applicable):


How reproducible: Always


Steps to Reproduce:
1. Set “Entries per page” in Settings to 5

2. Sync more than 5 repositories on satellite

3. Update a content view to add a repository using repository name.

satellite ~]# hammer content-view list --name cv1
----------------|--------------|--------------|-----------|---------------
Cv ID           | NAME         | LABEL        | COMPOSITE | REPOSITORY IDS
----------------|--------------|--------------|-----------|---------------
26              | cv1          |cv1           |
----------------|--------------|--------------|-----------|---------------


satellite ~]# hammer content-view update --id 26 --repositories 'Red Hat Enterprise Linux 7 Server RPMs x86_64 7Server','Red Hat Enterprise Linux 7 Server - Supplementary RPMs x86_64 7Server' --organization Redhat
Content view updated
[root@rh-satellite ~]# hammer content-view list --name cv1
----------------|--------------|--------------|-----------|---------------
CV ID           | NAME         | LABEL        | COMPOSITE | REPOSITORY IDS
----------------|--------------|--------------|-----------|---------------
26              | cv1          | cv1          |
----------------|--------------|--------------|-----------|---------------


However, using repository-id this seems to work.

satellite ~]# hammer content-view update -id 26 --repository-ids 42,27 --organization Redhat
Content view updated
[root@rh-satellite ~]# hammer content-view list --name cv1
----------------|--------------|--------------|-----------|---------------
CONTENT VIEW ID | NAME         | LABEL        | COMPOSITE | REPOSITORY IDS
----------------|--------------|--------------|-----------|---------------
26              | cv1          |  cv1         |           | 27, 42
----------------|--------------|--------------|-----------|---------------


Actual results:
While adding a repository using repository id, repositories are successfully added while using repository name it is not possible.

Expected results:
Repositories should get added using both repository name and repository id.

Additional info:
Here is debug log

[[32m INFO[0m [34m2018-02-08 10:16:13[0m [36mAPI[0m] GET /katello/api/repositories
[DEBUG [34m2018-02-08 10:16:13[0m [36mAPI[0m] Params: {
              "names" => [
        [0] "Red Hat OpenStack Platform 10 for RHEL 7 RPMs x86_64 7Server",
        [1] "Red Hat OpenStack Platform 10 Developer Tools for RHEL 7 RPMs x86_64 7Server"
    ],
    "organization_id" => 1
}
[DEBUG [34m2018-02-08 10:16:13[0m [36mAPI[0m] Headers: {
    :params => {
                  "names" => [
            [0] "Red Hat OpenStack Platform 10 for RHEL 7 RPMs x86_64 7Server",
            [1] "Red Hat OpenStack Platform 10 Developer Tools for RHEL 7 RPMs x86_64 7Server"
        ],
        "organization_id" => 1
    }
}
[DEBUG [34m2018-02-08 10:16:13[0m [36mAPI[0m] Response: {
       "total" => 66,
    "subtotal" => 66,
        "page" => 1,
    "per_page" => 20,
       "error" => nil,
      "search" => nil,
        "sort" => {
           "by" => nil,
        "order" => nil
    },


Form the debug logs generated while executing hammer command it seems that customer was having total 66 repositories synced while the per_page setting was set to 20, hence while adding repositories hammer was able to get only 20 repositories and rest were all not considered.

Workaround for this issue was changing the per_page size to 20 from satellite GUI
"Administer" -> "Settings" and modify "Entries per page" to 70
After performing the above changes customer was able to add repositories through repository name.

Comment 2 Brad Buckingham 2018-02-19 19:41:20 UTC
This appears to be an issue also on Satellite 6.3; however, the behavior is slightly different.  In 6.3, the CV is updated; however, the first repository in the list is added to the content view.

E.g. 

hammer> content-view update --id 4 --repositories 'Red Hat Enterprise Linux 7 Server RPMs x86_64 7Server, Red Hat Enterprise Linux 7 Server Kickstart x86_64 7.4' --organization "Default Organization"
Content view updated

The above will add "Red Hat Enterprise Linux 7 Server RPMs x86_64 7Server" to the CV.  The PUT request sent to the server, will only contain the ID of that repository vs an array of IDs.  

E.g.

[I] Started PUT "/katello/api/content_views/4" for 192.168.121.66 at 2018-02-19 19:36:28 +0000
[I] Processing by Katello::Api::V2::ContentViewsController#update as JSON
[I]   Parameters: {"repository_ids"=>[2], "api_version"=>"v2", "id"=>"4", "content_view"=>{"repository_ids"=>[2]}}

Comment 8 Matt Ruzicka 2018-11-05 15:04:56 UTC
Verified in a test 6.4 environment and a customer 6.3 environment - appears we have two issues that can cause failure using hammer content-view update by name.


Issue 1: The original issue described in the description can fail if there are more than 20 repos in an organization.  This may appear to succeed with a "Content view updated", but actual fail to add all requested repos. 

Issue #1 workaround: Increase the entries_per_page value to a sufficiently high number to cover all possible repos.

 Example: hammer settings set --name=entries_per_page --value=100


Issue 2: If there are multiple organizations with repos sharing the same name (ie "Red Hat Enterprise Linux 7 Server RPMs x86_64 7Server") it may with the error "Cannot add a repository from an Organization other than $ORG." It appears the content-view update by name logic builds a list of repository IDs from the repo names provided.  When it pulls the list of repository names it does not appear to honor the --organization flag and instead pulls ALL repos for ALL orgs.  The repo id map it then creates internally may include repos for other organizations, causing the failure.

Issue #2 workaround: It appears you must manually build a list of repository IDs for the specific organization and use content-view update using --repository-ids instead of --repositories by name.

----
It seems it would be recommended to avoid using content-view update with --repositories by name if you have multiple organizations with duplicate repository names.

Comment 12 Partha Aji 2019-02-20 03:51:55 UTC
Connecting redmine issue https://projects.theforeman.org/issues/26091 from this bug

Comment 13 Partha Aji 2019-02-20 15:49:27 UTC
Connecting redmine issue https://projects.theforeman.org/issues/26095 from this bug

Comment 14 Bryan Kearney 2019-03-01 21:05:24 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue https://projects.theforeman.org/issues/26091 has been resolved.

Comment 16 Partha Aji 2019-06-24 19:45:53 UTC
Ok sounds like there are layers to this but I propose they be separate bugs

1) If you gave a non existent repository name, The Content View update will show up as "updated" and no repositories added. However adding a valid repo seems to work ok
"""

[vagrant@zeta hammer-cli-katello]$ hammer content-view list
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
CONTENT VIEW ID | NAME                      | LABEL                                | COMPOSITE | LAST PUBLISHED      | REPOSITORY IDS
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
2               | Default Organization View | 0b440a8c-818a-4284-be08-c82705480eba |           | 2019/06/12 21:52:06 |               
1               | Default Organization View | Default_Organization_View            |           | 2019/06/08 06:01:49 |               
3               | myview                    | myview                               |           |                     | 8             
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
[vagrant@zeta hammer-cli-katello]$ hammer content-view update --id=3 --repositories=joy --product=joy --organization-id=1
Content view updated.
[vagrant@zeta hammer-cli-katello]$ hammer content-view list
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
CONTENT VIEW ID | NAME                      | LABEL                                | COMPOSITE | LAST PUBLISHED      | REPOSITORY IDS
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
2               | Default Organization View | 0b440a8c-818a-4284-be08-c82705480eba |           | 2019/06/12 21:52:06 |               
1               | Default Organization View | Default_Organization_View            |           | 2019/06/08 06:01:49 |               
3               | myview                    | myview                               |           |                     | 8             
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
[vagrant@zeta hammer-cli-katello]$ hammer content-view update --id=3 --repositories=joylessExistence --product=joy --organization-id=1
Content view updated.
[vagrant@zeta hammer-cli-katello]$ hammer content-view list
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
CONTENT VIEW ID | NAME                      | LABEL                                | COMPOSITE | LAST PUBLISHED      | REPOSITORY IDS
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
2               | Default Organization View | 0b440a8c-818a-4284-be08-c82705480eba |           | 2019/06/12 21:52:06 |               
1               | Default Organization View | Default_Organization_View            |           | 2019/06/08 06:01:49 |               
3               | myview                    | myview                               |           |                     |               
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------

"""

2) Repositories are uniquely scoped per product. This means we are stuck with a limitation when repository names are provided. 
The anomaly in the behavior of this call is that
You can do something like
hammer content-view update --id=3 --repository-ids=1,2,3,4,5

while using name you are forced to provide a product id
hammer content-view update --id=3 --repositories="Foo, Bar" --product-id=1

Which means you can only add repositories belonging to a single product to the content view. 

I believe both of the above cases need to get solved as separate issues and not be connected with this.

Comment 17 Partha Aji 2019-06-24 20:01:16 UTC
More over there are "hammer content-view add-repository" and "remove-repository" commands for the user if they want fine grained control. So a 3 rd option could be just not supporting the --repositories flag at all.

Comment 24 Partha Aji 2019-07-08 03:45:08 UTC
Created: https://bugzilla.redhat.com/show_bug.cgi?id=1727685
KCS was updated and workaround has been provided here  -> https://access.redhat.com/solutions/3365661

Closing this as wontfix. Use the other bz to track deprecation of the --repositories command.


Note You need to log in before you can comment on or make changes to this bug.