Project

General

Profile

Bug #15336

Org/Location removal results in a ISE

Added by Partha Aji about 4 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Organizations and Locations
Target version:
Difficulty:
Triaged:
Bugzilla link:

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1343108
Description of problem:
The organization removal task is not atomic:
If the organization has some managed resources associated, its removal will fail:

# hammer -u admin -p changeme organization delete --id 3
[............  ] [95%]
foo is being used by a hidden Host::Managed resource

However, Candlepin manages to remove the Owner:

[candlepin.log - hashes truncated]

2016-06-06 09:34:43,813 [thread=http-8443-2] [req=83f71be1, org=] INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=DELETE, uri=/candlepin/owners/foo
2016-06-06 09:34:43,831 [thread=http-8443-2] [req=83f71be1, org=] INFO  org.candlepin.resource.OwnerResource - Cleaning up owner: Owner [id: 8a90c0b855, key: foo]
2016-06-06 09:34:43,890 [thread=http-8443-2] [req=83f71be1, org=] INFO  org.candlepin.resource.OwnerResource - Deleting owner: Owner [id: 8a90c0b855, key: foo]
2016-06-06 09:34:43,897 [thread=http-8443-2] [req=83f71be1, org=] INFO  org.candlepin.audit.HornetqEventDispatcher - Sending event: Event [id=null, target=OWNER, type=DELETED, time=Mon Jun 06 09:34:43 EDT 2016, entity=8a90c0b855]

This leaves satellite in inconsistent state, where candlepin no longer recognizes the org while it still exists in the DB. Any action involving this organization (even uploading a manifest for other org) ends up in error:


2016-06-06 09:35:00,643 [thread=http-8443-2] [req=1ad875b0, org=] INFO  org.candlepin.common.filter.LoggingFilter - Request: verb=GET, uri=/candlepin/owners/foo
2016-06-06 09:35:00,663 [thread=http-8443-2] [req=1ad875b0, org=] INFO  org.candlepin.resteasy.interceptor.AuthInterceptor - No such entity: Organization id: foo
2016-06-06 09:35:00,664 [thread=http-8443-2] [req=1ad875b, org=] INFO  org.candlepin.common.filter.LoggingFilter - Response: status=404, content-type="application/json", time=21

Version-Release number of selected component (if applicable):
6.2.0 bet (GA14.1)

How reproducible:
always

Steps to Reproduce:
1. create an organization
2. have a host assigned to this org (you can use the satellite host itself)
3. try to delete this organization (this should fail)
4. try to create a new org and upload a manifest to it (this fails due to missing org above))

Actual results:
- candlepin removes the Org

Expected results:
- candlepin does not remove anything if the removal results in error in satellite (the removal task should be atomic)

Additional info:


Related issues

Related to Foreman - Tracker #10022: Taxonomies related issuesNew2015-04-05

Related to Foreman - Bug #15552: Org deletion needs to show a page listing the hosts attached to the orgNew2016-06-30
Is duplicate of Katello - Bug #15149: Missing warning when trying to delete organization with assigned hostsDuplicate2016-05-23

Associated revisions

Revision 1a753b07 (diff)
Added by Partha Aji about 4 years ago

Fixes #15336 - Enables proper deletion of Orgs

Prior to this commit if you had an Org/Location with a host and tried to
the delete the Org. You would end up with an error that looks like

<Org> is used by <Host> (RuntimeError)

Basic error is these 2 areas

https://github.com/theforeman/foreman/blob/develop/app/models/taxonomies/organization.rb#L8
and
https://github.com/theforeman/foreman/blob/develop/app/models/taxonomy.rb#L2

```before_destroy EnsureNotUsedBy.new(:hosts)```

The above code is in the super class Taxonomy. This checks to make sure
no associations are there for the organization before destroying.

```has_many_hosts :dependent => :nullify```
The above code is in the sub class Organization/Location. This nullifies
the host association on the deletion of organization/location object.

We basically need ```has_many_hosts :dependent => :nullify``` to run
before ```before_destroy EnsureNotUsedBy.new(:hosts)```

For the proper ordering of these checks

This commit tries to address that ordering issue

Revision b0f8d18e (diff)
Added by Dominic Cleal about 4 years ago

refs #15336 - use i18n variable names and plural form

History

#1 Updated by Partha Aji about 4 years ago

  • Project changed from Katello to Foreman
  • Subject changed from Candlepin removes OwnerResource even when deleting the Organization fails in Satellite to Org/Location removal results in a ISE
  • Category deleted (Organizations and Locations)

Steps to Reproduce:
1. create an organization
2. have a host assigned to this org (you can use the satellite host itself)
3. try to delete this organization (this should fail)
4. try to create a new org and upload a manifest to it (this fails due to missing org above))

Error Encountered:


] <Org> is used by <Host> (RuntimeError)
 | /home/vagrant/katello/app/models/katello/concerns/organization_extensions.rb:116:in `destroy!'
 | /home/vagrant/katello/app/lib/actions/katello/organization/destroy.rb:29:in `block in finalize'
 | /home/vagrant/foreman/app/models/concerns/foreman/thread_session.rb:72:in `as'
 | /home/vagrant/foreman/app/models/concerns/foreman/thread_session.rb:78:in `as_anonymous_admin'
 | /home/vagrant/katello/app/lib/actions/katello/organization/destroy.rb:28:in `finalize'
 | /home/vagrant/.rvm/gems/ruby-2.2.4/gems/dynflow-0.8.11/lib/dynflow/action.rb:528:in `block (2 levels) in execute_finalize'
 | /home/vagrant/.rvm/gems/ruby-2.2.4/gems/dynflow-0.8.11/lib/dynflow/middleware/stack.rb:26:in `call'


Basic error is these 2 areas

https://github.com/theforeman/foreman/blob/develop/app/models/taxonomies/organization.rb#L8 and https://github.com/theforeman/foreman/blob/develop/app/models/taxonomy.rb#L2

before_destroy EnsureNotUsedBy.new(:hosts)

The above code is in the super class Taxonomy. This checks to make sure no associations are there for the organization before destroying.

has_many_hosts :dependent => :nullify

The above code is in the sub class Organization/Location. This nullifies the host association on the deletion of organization/location object.

We basically need ```has_many_hosts :dependent => :nullify``` to run before ```before_destroy EnsureNotUsedBy.new(:hosts)```

For the proper ordering of these checks

#2 Updated by The Foreman Bot about 4 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3576 added

#3 Updated by Marek Hulán about 4 years ago

#4 Updated by Marek Hulán about 4 years ago

  • Category set to Organizations and Locations

#5 Updated by The Foreman Bot about 4 years ago

  • Pull request https://github.com/theforeman/foreman/pull/3616 added

#6 Updated by Dominic Cleal about 4 years ago

  • Related to Bug #15552: Org deletion needs to show a page listing the hosts attached to the org added

#7 Updated by Partha Aji about 4 years ago

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

#8 Updated by Dominic Cleal about 4 years ago

  • Legacy Backlogs Release (now unused) set to 160

#9 Updated by Justin Sherrill about 4 years ago

  • Is duplicate of Bug #15149: Missing warning when trying to delete organization with assigned hosts added

Also available in: Atom PDF