Bug #20785
closedKickstart repository assigned in UI to hostgroup difficult to set using Hammer
Description
Assigning kickstart repository to hostgroup works in UI. Synced Content dropdown makes sure that only kickstart repos from lifecycle env and content view (previously selected in the form) can be selected as a synced content.
Using hammer/API, there are no checks. Any existing repository id can be passed as --kickstart-repository-id and it is accepted. We should not allow repositories that are not in associated content view to be set.
More importantly, there are multiple records with the same repo name, but user is always presented only with one record representing the repo. This makes it impossible to assign the same repo via hammer as I did using UI, because I cannot list all the repo records and find out the id for kickstart repo in a lifecycle environment.
Steps to reproduce:
1) create kickstart repo, sync, add to content view, publish
Mine looks like this, notice the kickstart repo ids:
[root@foreman ~]# hammer content-view info --id 2 ID: 2 Name: RHEL 7 SOE Label: RHEL_7_SOE Composite: false Description: Standard Operating Environment for RHEL7 Content Host Count: 0 Organization: Default Organization Yum Repositories: 1) ID: 1 Name: Red Hat Enterprise Linux 7 Server Kickstart x86_64 7.4 Label: Red_Hat_Enterprise_Linux_7_Server_Kickstart_x86_64_7_4 2) ID: 2 Name: Red Hat Enterprise Linux 7 Server RPMs x86_64 7Server Label: Red_Hat_Enterprise_Linux_7_Server_RPMs_x86_64_7Server 3) ID: 3 Name: Tools Label: Tools Docker Repositories: OSTree Repositories: Puppet Modules: Lifecycle Environments: 1) ID: 1 Name: Library Versions: 1) ID: 2 Version: 1.0 Published: 2017/08/29 06:40:41 Components: Activation Keys: 1) ak-rhel-7 [root@foreman ~]# hammer content-view version info --environment Library --content-view-id 2 ID: 2 Name: RHEL 7 SOE 1.0 Version: 1.0 Description: Content View ID: 2 Content View Name: RHEL 7 SOE Content View Label: RHEL_7_SOE Lifecycle Environments: 1) ID: 1 Name: Library Label: Library Repositories: 1) ID: 8 Name: Tools Label: Tools 2) ID: 6 Name: Red Hat Enterprise Linux 7 Server RPMs x86_64 7Server Label: Red_Hat_Enterprise_Linux_7_Server_RPMs_x86_64_7Server 3) ID: 4 Name: Red Hat Enterprise Linux 7 Server Kickstart x86_64 7.4 Label: Red_Hat_Enterprise_Linux_7_Server_Kickstart_x86_64_7_4
2) go to the UI, create a hostgroup with content view from step 1) and appropriate lifecycle env (Library in my case), select kickstart repo and save
3) find out the id of kickstart repo assigned to hostgroup, use curl because hammer does not support this:
[root@foreman ~]# curl -H "Accept: application/json" -H "Content-Type: application/json" -k -X GET -u admin:changeme https://$(hostname)/api/v2/hostgroups/3 | json_reformat % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1586 0 1586 0 0 9598 0 --:--:-- --:--:-- --:--:-- 9612 { "content_source_id": 1, "content_source_name": "cisco-c240m3-01.rhts.eng.bos.redhat.com", "content_view_id": 2, "content_view_name": "RHEL 7 SOE", "lifecycle_environment_id": 1, "lifecycle_environment_name": "Library", "kickstart_repository_id": 5, "subnet_id": 1, "subnet_name": "192.168.73.0/24", "operatingsystem_id": 1, "operatingsystem_name": "RHEL Server 7.4", "domain_id": 2, "domain_name": "example.com", "environment_id": 1, ...
4) Both 'content-view info' and 'content-view version info' show the kickstart repos, but they have ids 1 and 4, not 5. There is no way to get the id of the repo that was assigned in UI, because it is never listed.
Maybe we could add kickstart_repository_name and handle the association of correct record because we know lifecycle env and content view.
Updated by John Mitsch about 7 years ago
- Subject changed from Kickstart repository assigned in UI to hostgroup cannot be assigned using Hammer to Kickstart repository assigned in UI to hostgroup difficult to set using Hammer
- Translation missing: en.field_release set to 250
a workaround is to use -d and look at API output
Updated by Brad Buckingham about 7 years ago
- Target version changed from 160 to 217
Updated by Jonathon Turel about 7 years ago
- Status changed from New to Assigned
- Assignee set to Jonathon Turel
Updated by Partha Aji about 7 years ago
- Related to Bug #21146: show kickstart repository name in hammer added
Updated by Partha Aji about 7 years ago
- Related to Bug #21147: show kickstart repository name in content facet json added
Updated by Partha Aji about 7 years ago
I have addressed couple of points referred to in this issue. Mainly the display of Kickstart repository name for hostgroups and hosts via hammer. Look at the associated issues (21146 and 21147).
Basically the repository information you see when you run
hammer content-view info --id 2
is different . That shows the list of repositories associated to the unpublished content view (i.e repos you added/removed).
What we are interested w.r.t KS repository id is the repository id pointing to a content view environment which you have appropriately captured with
# hammer content-view version info --environment Library --content-view-id 2
Given that the issue of ks repo display in hammer is being handled I propose scope of this bug be reduced to
- Using hammer/API, there are no checks. Any existing repository id can be passed as --kickstart-repository-id and it is accepted. We should not allow repositories that are not in associated content view to be set.
- Maybe we could add kickstart_repository_name and handle the association of correct record because we know lifecycle env and content view.
The latter may require to be addressed in a separate redmine issue depending on where the change is...
Updated by Partha Aji about 7 years ago
For the validation you probably need a logic that looks like
validate :check_kickstart_repository, allow_blank: true def check_kickstart_repository(record) if !host.operatingsystem.is_a?(Redhat) msg = _("Cannot associate a kickstart repository to a host belonging to non-redhat family.") errors.add(:kickstart_repository, msg) elsif content_source.blank? msg = _("Cannot associate a kickstart repository: No content source selected") errors.add(:kickstart_repository, msg) elsif !host.operatingsystem.kickstart_repos(host).any? { |repo| repo[:id] == kickstart_repository_id } msg = _("No such repository in the hosts content view, environment, content source, os and architecture ") errors.add(:kickstart_repository, msg) end end
in your katello/app/models/katello/host/content_facet.rb
Updated by Jonathon Turel about 7 years ago
- Related to Bug #21196: Support kickstart repository name parameter for host and hostgroup added
Updated by Jonathon Turel about 7 years ago
For now I am going to address the validation issues mentioned here. I've opened a separate issue to track supporting the KS repo name for host and hostgroup: http://projects.theforeman.org/issues/21196
Updated by The Foreman Bot about 7 years ago
- Status changed from Assigned to Ready For Testing
- Pull request https://github.com/Katello/katello/pull/6987 added
Updated by Brad Buckingham about 7 years ago
- Target version changed from 217 to 225
Updated by The Foreman Bot about 7 years ago
- Pull request https://github.com/Katello/katello/pull/7011 added
Updated by The Foreman Bot about 7 years ago
- Pull request https://github.com/Katello/katello/pull/7014 added
Updated by Jonathon Turel about 7 years ago
- Pull request deleted (
https://github.com/Katello/katello/pull/7011, https://github.com/Katello/katello/pull/6987)
Updated by Anonymous about 7 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset katello|81410e9e377d463ec717d113608692c572f93b3c.