Bug 1244314

Summary: Disabling used repository_set removes repo already from candlepin and pulp before chcking it is used
Product: Red Hat Satellite Reporter: Peter Vreman <peter.vreman>
Component: Content ManagementAssignee: Brad Buckingham <bbuckingham>
Status: CLOSED ERRATA QA Contact: Tazim Kolhar <tkolhar>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.0.8CC: bbuckingham, chpeters, cwelton, jsherril, mmccune, tkolhar
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
URL: http://projects.theforeman.org/issues/11436
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-10-15 18:20:23 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:
Embargoed:
Bug Depends On:    
Bug Blocks: 1122832    

Description Peter Vreman 2015-07-17 18:32:00 UTC
Description of problem:
Disabling a repository set does the check if it is used in the finalize() step. That means even used repository set will be already be removed from candlepin and pulp. Only the removal from Katello in the finalize step will then not be done

Below the successful Run steps:

 	sequence 		concurrence
6: Actions::Pulp::Repository::Destroy (success) [ 68.70s / 5.42s ]
9: Actions::ElasticSearch::Repository::Destroy (success) [ 61.92s / 61.92s ]
12: Actions::Candlepin::Environment::SetContent (success) [ 0.19s / 0.19s 

See below the failing Finalize step:

3: Actions::ElasticSearch::Reindex (success) [ 3127.81s / 0.15s ]
14: Actions::Katello::Repository::Destroy (error) [ 3127.93s / 0.24s ] Skip

Started at: 2015-07-17 17:17:28 UTC
Ended at: 2015-07-17 18:09:35 UTC
Real time: 3127.93s
Execution time (excluding suspended state): 0.24s
Input:

---
repository:
  id: 21
  name: Red Hat Enterprise Linux 6 Server - Extended Update Support RPMs x86_64 6.5
  label: Red_Hat_Enterprise_Linux_6_Server_-_Extended_Update_Support_RPMs_x86_64_6_5
product:
  id: 19
  name: Red Hat Enterprise Linux Server - Extended Update Support
  label: Red_Hat_Enterprise_Linux_Server_-_Extended_Update_Support
  cp_id: '70'
provider:
  id: 4
  name: Red Hat
organization:
  id: 3
  name: Hilti
  label: Hilti
user_id: 4
finalize_destroy: true
remote_user: hoici-3a181dcb
locale: en

Output:

--- {}

Error:

RuntimeError

Repository cannot be deleted since it has already been included in a published Content View. Please delete all Content View versions containing this repository before attempting to deleting it.

---
- /opt/rh/ruby193/root/usr/share/gems/gems/katello-1.5.0/app/models/katello/model.rb:22:in
  `destroy!'
- /opt/rh/ruby193/root/usr/share/gems/gems/katello-1.5.0/app/lib/actions/katello/repository/destroy.rb:48:in
  `finalize'
- /opt/rh/ruby193/root/usr/share/gems/gems/dynflow-0.7.3/lib/dynflow/action.rb:465:in
  `block (2 levels) in execute_finalize'


After this the Sat6 is unstable as it cannot find the Repo anymore, e.g. listing /products does not work, because of candlepin returns 404-NotFound:

Processing by Katello::Api::Rhsm::CandlepinProxiesController#get as JSON
  Parameters: {"id"=>"f7be3be2-b8eb-44e8-817c-67c577b0e0d3"}
[ERROR 2015-07-17 18:10:35 pulp_rest  #12086] RestClient.get "https://li-lc-1017.hag.hilti.com/pulp/api/v2/repositories/Hilti-Red_Hat_Enterpri
se_Linux_Server_-_Extended_Update_Support-Red_Hat_Enterprise_Linux_6_Server_-_Extended_Update_Support_RPMs_x86_64_6_5//history/sync/", "Accept
"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Authorization"=>"OAuth oauth_consumer_key=\"katello\", oauth_nonce=\"CJ
b8bA2QmBNEQ20uFIID1YLOabMZ0CPTdHVRo\", oauth_signature=\"wIEjIJATYTxk1FYdCkNQdhQ0gUY%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timesta
mp=\"1437156635\", oauth_version=\"1.0\"", "accept"=>"application/json", "content_type"=>"application/json", "pulp-user"=>"hoici-3a181dcb"
 | \n# => 404 NotFound | application/json 1068 bytes



Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1. Enable a RedHat repository
2. Create and Publish Content View using the RedHat repo
3. Disable the RedHat repository
4. List products

Actual results:
Disable task fails in Finalize step
List products does not work

Expected results:
Disable task fails in Plan step
List products works

Additional info:

Comment 1 RHEL Program Management 2015-07-17 18:35:14 UTC
Since this issue was entered in Red Hat Bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

Comment 3 Brad Buckingham 2015-08-19 18:22:59 UTC
Created redmine issue http://projects.theforeman.org/issues/11436 from this bug

Comment 4 Brad Buckingham 2015-08-19 19:31:10 UTC
Created upstream katello PR: 

https://github.com/Katello/katello/pull/5428


With this PR, user would see behavior similar to:

- When there are existing content view versions using the repository:

hammer> repository-set disable --organization-id 1 --product-id 92 --id 3983 --basearch x86_64 --releasever 7Server
Could not disable repository:
  Repository cannot be deleted since it has already been included in a published Content View. Please delete all Content View versions containing this repository before attempting to deleting it.


- When there are no existing content view versions using the repository:

hammer> repository-set disable --organization-id 1 --product-id 92 --id 3983 --basearch x86_64 --releasever 7Server
Repository disabled

Comment 5 Peter Vreman 2015-08-20 14:15:47 UTC
This issue is more generic than described here with the repository-set.

Currently it is allowed to delete a custom product repository that is still in used by a content view. It deleted it from pulp and then stops in the finalize step where the database reports ERROR:  update or delete on table "katello_repositories" violates foreign key constraint "repositories_library_instance_id_fk" on table "katello_repositories"

That should also make creating a unit test case for it more easy.

Comment 6 Brad Buckingham 2015-08-20 15:50:42 UTC
Hi Peter,

Correct.  I ran a test of deleting a custom repository with the changes and the behavior is similar.

- When there are existing content view versions using the repository:

hammer> repository delete --id 1 --product-id 1 --organization-id 1
Could not delete the Repository:
  Repository cannot be deleted since it has already been included in a published Content View. Please delete all Content View versions containing this repository before attempting to deleting it.


- When there are no existing content view versions using the repository:

hammer> repository delete --id 1 --product-id 1 --organization-id 1
Repository deleted

Comment 8 Tazim Kolhar 2015-09-03 07:11:46 UTC
Hi,


  Below are the results of verification
  steps:
  1. Enable a RedHat repository
  2. Create and Publish Content View using the RedHat repo
  3. Disable the RedHat repository
  4. List products

Please note here,
Scenario 1

when content view version is associated with the Redhat repo
I am unable to disable the redhat repo
(screen shot attached)
product is listed 

Scenario 2

when content view version is removed or deleted then
I am able to disable to repository 
product is still listed

please, comment/reply in case anything is missing

thanks 

Thanks and Regards,
Tazim

Comment 11 Tazim Kolhar 2015-10-05 13:10:09 UTC
VERIFIED:
# rpm -qa | grep foreman
ruby193-rubygem-foreman_hooks-0.3.7-2.el7sat.noarch
rubygem-hammer_cli_foreman-0.1.4.14-1.el7sat.noarch
ruby193-rubygem-foreman_bootdisk-4.0.2.13-1.el7sat.noarch
foreman-vmware-1.7.2.40-1.el7sat.noarch
rubygem-hammer_cli_foreman_bootdisk-0.1.2.7-1.el7sat.noarch
foreman-debug-1.7.2.40-1.el7sat.noarch
foreman-proxy-1.7.2.6-1.el7sat.noarch
foreman-1.7.2.40-1.el7sat.noarch
foreman-gce-1.7.2.40-1.el7sat.noarch
ruby193-rubygem-foreman-redhat_access-0.2.3-1.el7sat.noarch
rubygem-hammer_cli_foreman_discovery-0.0.1.10-1.el7sat.noarch
hp-xw6600-02.rhts.eng.bos.redhat.com-foreman-client-1.0-1.noarch
hp-xw6600-02.rhts.eng.bos.redhat.com-foreman-proxy-1.0-2.noarch
foreman-compute-1.7.2.40-1.el7sat.noarch
ruby193-rubygem-foreman_docker-1.2.0.22-1.el7sat.noarch
ruby193-rubygem-foreman-tasks-0.6.15.7-1.el7sat.noarch
rubygem-hammer_cli_foreman_tasks-0.0.3.5-1.el7sat.noarch
foreman-libvirt-1.7.2.40-1.el7sat.noarch
foreman-postgresql-1.7.2.40-1.el7sat.noarch
hp-xw6600-02.rhts.eng.bos.redhat.com-foreman-proxy-client-1.0-1.noarch
foreman-ovirt-1.7.2.40-1.el7sat.noarch
foreman-selinux-1.7.2.13-1.el7sat.noarch
ruby193-rubygem-foreman_discovery-2.0.0.19-1.el7sat.noarch
rubygem-hammer_cli_foreman_docker-0.0.3.9-1.el7sat.noarch
ruby193-rubygem-foreman_gutterball-0.0.1.9-1.el7sat.noarch


steps:
1. Enable a RedHat repository
2. Create and Publish Content View using the RedHat repo
3. Disable the RedHat repository
4. List products

Unable to disable the repo
List products works

Comment 13 errata-xmlrpc 2015-10-15 18:20:23 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2015:1911