Bug 1314714

Summary: Updating content view of a managed host updates katello but not candlepin DB
Product: Red Hat Satellite Reporter: Pavel Moravec <pmoravec>
Component: HostsAssignee: Tomas Strachota <tstrachota>
Status: CLOSED ERRATA QA Contact: Sanket Jagtap <sjagtap>
Severity: high Docs Contact:
Priority: high    
Version: 6.1.6CC: bbuckingham, bkearney, cfouant, ealcaniz, ehelms, kbidarka, ktordeur, pmoravec, sthirugn, tstrachota
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: All   
OS: Linux   
URL: http://projects.theforeman.org/issues/14944
Whiteboard:
Fixed In Version: rubygem-katello-3.0.0.31-1 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1320321 (view as bug list) Environment:
Last Closed: 2016-07-27 11:12:43 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: 1320321    

Description Pavel Moravec 2016-03-04 10:26:46 UTC
Description of problem:
When having a Manager foreman Host that is also a Content Host, an attempt to update content view (and quite expected-ably also lifecycle environment) really updates content view / l.e. for the katello_system. But it does _not_ update the same for candlepin.

This leaves candlepin and foreman DBs (or it's katello part) out of sync, having fatal consequences following this user scenario:

- have some managed hosts in some content view
- wanting to migrate them to a new CV
- doing so via foreman Hosts
- this updates katello_systems in foreman DB but leaves candlepin consumers in old environment(*)
- deleting old content view
  - this passes since katello has no content host there
  - candlepin environemnt is deleted - including all consumers it has
    - more nasty is, due to bz1306628, you wont see details about deleted consumers
- now you have systems with a record in katello but not in candlepin
- getting 410 gone errors
- the usual reaction is to call clean_backend_objects rake script that deletes the systems also from katello

(*) explanatory note: candlepin environment is a pair lifecycle env. and content view, i.e. cp environment 3-15 means l.e. of id 3 and c.v. of id 15. cp environment 1 stands for 1-1.

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

How reproducible:
100%


Steps to Reproduce:
1. Have a Managed Host being also a Content Host (just register it via subscription-manager) - ideally ensure the Host is crated in some nondefault content view and lifecycle environment
2. Use this trivial script to check:

name=pmoravec-test2.sysmgmt.lan

if [ $# -gt 0 ]; then
	echo "using name $1"
	name=$1
fi

su - postgres -c "psql foreman -c \"select uuid,name,environment_id,content_view_id from katello_systems where name = '${name}'\""
su - postgres -c "psql candlepin -c \"select uuid,name,environment_id from cp_consumer where name = '${name}'\""

3. Call the script with argument of FQDN of the Host
4. Edit Host and update Content View (alternativelly, update lifecycle environment)
5. Call the script again
6. Optionally, delete the old content view and try to update the Content Host (i.e. enable some another repo).


Actual results:
3. shows matching katelo and candlepin info about content view / l.e., like:

                 uuid                 |            name            | environment_id | content_view_id 
--------------------------------------+----------------------------+----------------+-----------------
 b66408f6-afd7-4f82-9595-024e8cd16a7f | pmoravec-test2.sysmgmt.lan |              2 |               3
(1 row)

                 uuid                 |            name            | environment_id 
--------------------------------------+----------------------------+----------------
 b66408f6-afd7-4f82-9595-024e8cd16a7f | pmoravec-test2.sysmgmt.lan | 2-3
(1 row)

5. shows a difference - candlepin DB _not_ updated!

                 uuid                 |            name            | environment_id | content_view_id 
--------------------------------------+----------------------------+----------------+-----------------
 b66408f6-afd7-4f82-9595-024e8cd16a7f | pmoravec-test2.sysmgmt.lan |              2 |               4
(1 row)

                 uuid                 |            name            | environment_id 
--------------------------------------+----------------------------+----------------
 b66408f6-afd7-4f82-9595-024e8cd16a7f | pmoravec-test2.sysmgmt.lan | 2-3
(1 row)

6. (optional): candlepin 410 gone error seen, cp_consumers lacking the Content Host (run the script again to see)


Expected results:
5. to show "2-4" or whatever to match pair environment_id - content_view_id

6. no candlepin error, cp_consumers having the Content Host


Additional info:
workaround:
whenever updating a Host that way, update the content host the same - via hammer since webui does not this ability. I.e. updating host to content view id 6, call:

hammer> content-host update --content-view-id 6 --organization-id 1 --name pmoravec-test2.sysmgmt.lan

Reasoning: though it seems to be a redundant step (since katello has updated its db already that way), the routine behind that _will_ call also candlepin udate properly.

This workaround can not be done via WebUI since WebUI will show you proper content view already - and it cant force overriding the _same_ values here.

Comment 3 Pavel Moravec 2016-03-04 14:34:35 UTC
(In reply to Pavel Moravec from comment #0)
> Description of problem:
> When having a Manager foreman Host that is also a Content Host, an attempt

s/Manager/Managed, of course

Comment 4 Pavel Moravec 2016-03-04 15:30:25 UTC
raising 6.1.z? to consider adding to z-stream - it is easy to follow the scenario that has quite fatal consequences.

Comment 6 Christine Fouant 2016-04-26 19:19:45 UTC
I have tried this in multiple scenarios in 6.1.8 and have been unable to reproduce. Are you still able to reproduce?

Comment 7 Pavel Moravec 2016-04-29 09:43:50 UTC
(In reply to Christine Fouant from comment #6)
> I have tried this in multiple scenarios in 6.1.8 and have been unable to
> reproduce. Are you still able to reproduce?

Yes, the same way. Details of reproducer in next private comment.

Comment 9 Tomas Strachota 2016-05-04 13:02:23 UTC
In fact there's no Katello orchestration hooked on Foreman's host form. Everything works as expected when the values are edited from the content host edit form. 

Therefore I believe the simplest "fix" would be just disabling the content view and lifecycle environment fields in Foreman's host controllers for managed hosts with existing content host. The fields will remain editable via forms in Katello where the orchestration works.

Comment 11 Tomas Strachota 2016-05-06 11:55:25 UTC
Created redmine issue http://projects.theforeman.org/issues/14944 from this bug

Comment 12 Tomas Strachota 2016-05-09 12:04:56 UTC
It turned out the issue was already fixed with host facets rework for sat 6.2. Switching to ON_QA.

Comment 13 Bryan Kearney 2016-05-09 12:13:42 UTC
Moving to POST since upstream bug http://projects.theforeman.org/issues/14944 has been closed

Comment 14 Kedar Bidarkar 2016-05-25 16:31:42 UTC
So for Sat6.1.9 , the solution was to disable the CV and L.E fields from the hosts edit page.

For Sat6.2, we can edit the CV and L.E fields from the hosts page.


[root@xyz ~]# ./trivial_script.sh 
                 uuid                 |                            name                             | environment_id | content_view_id 
--------------------------------------+-------------------------------------------------------------+----------------+-----------------
 7e2ef6fd-358d-4c0d-9fb6-62e45accaa1b | abc.redhat.com |              2 |               2
(1 row)

                 uuid                 |                            name                             | environment_id 
--------------------------------------+-------------------------------------------------------------+----------------
 7e2ef6fd-358d-4c0d-9fb6-62e45accaa1b | abc.redhat.com | 2-2
(1 row)


[root@xyz ~]# ./trivial_script.sh 
                 uuid                 |                            name                             | environment_id | content_view_id 
--------------------------------------+-------------------------------------------------------------+----------------+-----------------
 7e2ef6fd-358d-4c0d-9fb6-62e45accaa1b | abc.redhat.com |              2 |               3
(1 row)

                 uuid                 |                            name                             | environment_id 
--------------------------------------+-------------------------------------------------------------+----------------
 7e2ef6fd-358d-4c0d-9fb6-62e45accaa1b | abc.redhat.com | 2-3
(1 row)

So ,now for Sat6.2 we can now see that both env and cv are updated even for CANDELPIN


VERIFIED with sat62-snap(GA)-12.1

Comment 15 Bryan Kearney 2016-07-27 11:12:43 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-2016:1501