Bug 746035

Summary: autosubscribe should NOT consider existing future entitlements when determining what pools and quantity should be autosubscribed
Product: [Community] Candlepin Reporter: John Sefler <jsefler>
Component: candlepinAssignee: Bryan Kearney <bkearney>
Status: CLOSED CURRENTRELEASE QA Contact: John Sefler <jsefler>
Severity: high Docs Contact:
Priority: unspecified    
Version: 0.5CC: alikins, bkearney, skallesh, spandey
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Solaris   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-07-17 13:04:17 UTC Type: ---
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: 682238    

Description John Sefler 2011-10-13 17:46:42 UTC
Description of problem:
If I subscribe to a future subscription for coverage of a product I currently have installed, those future entitlements should be disregarded by autosubscribe when determining what should be subscribed to satisfy compliance today.


Version-Release number of selected component (if applicable):
[root@jsefler-onprem-62server product]# rpm -q subscription-manager
subscription-manager-0.96.14-1.git.3.b926c9e.el6.x86_64


How reproducible:


Steps to Reproduce:

NON MULTI-ENTITLEMENT EXAMPLE WITH TESTDATA....

[root@jsefler-onprem-62server ~]# date
Thu Oct 13 12:50:01 EDT 2011
[root@jsefler-onprem-62server ~]# ls /etc/pki/product/
100000000000008.pem
[root@jsefler-onprem-62server ~]# subscription-manager register --username testuser1 --password password --org admin
The system has been registered with id: b7107a6d-4aff-4a29-9ae7-0ccaf7e3069d 
[root@jsefler-onprem-62server ~]# subscription-manager list --avail --ondate 2013-01-01 | grep awesomeos-x86_64-s390x -A4 -B1
ProductName:       	Awesome OS for x86_64/s390x
ProductId:         	awesomeos-x86_64-s390x   
PoolId:            	8a90f8c632f985e40132f98777dd045b
Quantity:          	15                       
Multi-Entitlement: 	No                       
Expires:           	09/30/2013               
[root@jsefler-onprem-62server ~]# subscription-manager subscribe --pool 8a90f8c632f985e40132f98777dd045b
Successfully subscribed the system to Pool 8a90f8c632f985e40132f98777dd045b
[root@jsefler-onprem-62server ~]# subscription-manager list --installed
+-------------------------------------------+
    Installed Product Status
+-------------------------------------------+

ProductName:        	Awesome OS for x86_64/s390x Bits
Version:            	3.11                     
Arch:               	x86_64,s390x             
Status:             	Future Subscription      
Starts:             	09/30/2012               
Expires:            	09/30/2013      
         
[root@jsefler-onprem-62server ~]# subscription-manager facts --list | grep valid
system.entitlements_valid: False


^^^ AT THIS POINT WE ARE SUCCESSFULLY SUBSCRIBED TO A FUTURE SUBSCRIPTION THAT COVERS OUR ONLY INSTALLED PRODUCT, YET WE ARE STILL NOT VALID/COMPLIANT TODAY.  THIS IS ALL CORRECT!  NOW LET"S ATTEMPT TO AUTOSUBSCRIBE OURSELF INTO COMPLIANCE TODAY...


[root@jsefler-onprem-62server ~]# subscription-manager subscribe --auto
Installed Product Current Status:

ProductName:         	Awesome OS for x86_64/s390x Bits
Status:               	Future Subscription      

[root@jsefler-onprem-62server ~]# subscription-manager list --consumed
+-------------------------------------------+
    Consumed Product Subscriptions
+-------------------------------------------+


ProductName:        	Awesome OS for x86_64/s390x Bits
ContractNumber:     	47                       
AccountNumber:      	12331131231              
SerialNumber:       	1769047610219925677      
Active:             	True                     
QuantityUsed:       	1                        
Begins:             	09/30/2012               
Expires:            	09/30/2013               

[root@jsefler-onprem-62server ~]# subscription-manager facts --list | grep valid
system.entitlements_valid: False
[root@jsefler-onprem-62server ~]# 


BANG!  AUTOSUBSCRIBE DID MAKE US COMPLIANT TODAY.  INFACT, IT DID NOTHING.

NOTE THAT I CAN MANUALLY SUBSCRIBE TO A SUBSCRIPTION AVAILABLE TODAY AND DO A BETTER JOB THAN AUTOSUBSCRIBE....

[root@jsefler-onprem-62server ~]# subscription-manager list --avail | grep awesomeos-x86_64-s390x -A4 -B1
ProductName:       	Awesome OS for x86_64/s390x
ProductId:         	awesomeos-x86_64-s390x   
PoolId:            	8a90f8c632f985e40132f987781f0464
Quantity:          	10                       
Multi-Entitlement: 	No                       
Expires:           	10/10/2012               
--
ProductName:       	Awesome OS for x86_64/s390x
ProductId:         	awesomeos-x86_64-s390x   
PoolId:            	8a90f8c632f985e40132f9877845046d
Quantity:          	5                        
Multi-Entitlement: 	No                       
Expires:           	10/10/2012               
[root@jsefler-onprem-62server ~]# subscription-manager subscribe --pool 8a90f8c632f985e40132f987781f0464
Successfully subscribed the system to Pool 8a90f8c632f985e40132f987781f0464
[root@jsefler-onprem-62server ~]# subscription-manager list --consumed
+-------------------------------------------+
    Consumed Product Subscriptions
+-------------------------------------------+


ProductName:        	Awesome OS for x86_64/s390x Bits
ContractNumber:     	47                       
AccountNumber:      	12331131231              
SerialNumber:       	1769047610219925677      
Active:             	True                     
QuantityUsed:       	1                        
Begins:             	09/30/2012               
Expires:            	09/30/2013               


ProductName:        	Awesome OS for x86_64/s390x Bits
ContractNumber:     	47                       
AccountNumber:      	12331131231              
SerialNumber:       	5618451125635857818      
Active:             	True                     
QuantityUsed:       	1                        
Begins:             	10/11/2011               
Expires:            	10/10/2012               

[root@jsefler-onprem-62server ~]# subscription-manager facts --list | grep valid
system.entitlements_valid: True

^^^
SEE. I CAN DO A BETTER JOB THAN AUTOSUBSCRIBE :)  NOW I AM COMPLIANT/VALID.

Comment 1 John Sefler 2011-10-13 17:47:31 UTC
HERE IS A MULTI-ENTITLEMENT CASE WITH TESTDATA....


[root@jsefler-onprem-62server ~]# date
Thu Oct 13 13:13:00 EDT 2011
[root@jsefler-onprem-62server ~]# ls /etc/pki/product/100000000000002.pem 
/etc/pki/product/100000000000002.pem
[root@jsefler-onprem-62server ~]# subscription-manager facts --list | grep cpu.socket
cpu.cpu_socket(s): 4
lscpu.cpu_socket(s): 4

[root@jsefler-onprem-62server ~]# subscription-manager register --username testuser1 --password password --org admin
The system has been registered with id: 42d42105-49ff-49b0-8dc5-8fb6b96f0b4e 

[root@jsefler-onprem-62server ~]# subscription-manager list --avail --ondate 2013-01-01| grep awesomeos-x86_64 -A4 -B1 | grep Yes -B4 -A1
ProductName:       	Awesome OS for x86_64    
ProductId:         	awesomeos-x86_64         
PoolId:            	8a90f8c632f985e40132f9877c9d053c
Quantity:          	15                       
Multi-Entitlement: 	Yes                      
Expires:           	09/30/2013               

[root@jsefler-onprem-62server ~]# subscription-manager subscribe --pool=8a90f8c632f985e40132f9877c9d053c --quantity=1
Successfully subscribed the system to Pool 8a90f8c632f985e40132f9877c9d053c
[root@jsefler-onprem-62server ~]# subscription-manager list --consumed
+-------------------------------------------+
    Consumed Product Subscriptions
+-------------------------------------------+


ProductName:        	Awesome OS for x86_64 Bits
ContractNumber:     	31                       
AccountNumber:      	12331131231              
SerialNumber:       	2986802716899926028      
Active:             	True                     
QuantityUsed:       	1                        
Begins:             	09/30/2012               
Expires:            	09/30/2013               

[root@jsefler-onprem-62server ~]# subscription-manager list --installed
+-------------------------------------------+
    Installed Product Status
+-------------------------------------------+

ProductName:        	Awesome OS for x86_64 Bits
Version:            	3.11                     
Arch:               	x86_64                   
Status:             	Future Subscription      
Starts:             	09/30/2012               
Expires:            	09/30/2013 

[root@jsefler-onprem-62server ~]# subscription-manager facts --list | grep valid
system.entitlements_valid: False



TECHNICALLY AT THIS POINT WE ARE "PARTIALLY SUBSCRIBED" USING A "FUTURE SUBSCRIPTION" THAT WILL COVER 1 SOCKET OF OUR 4 SOCKET MACHINE.  MOREOVER WE ARE NOT VALID/COMPLIANT TODAY.  ALL OF THIS IS CORRECT.

NOW LET'S ATTEMPT TO AUTOSUBSCRIBE AND GET COMPLIANT TODAY!


[root@jsefler-onprem-62server ~]# subscription-manager subscribe --auto
Installed Product Current Status:

ProductName:         	Awesome OS for x86_64 Bits
Status:               	Subscribed               

[root@jsefler-onprem-62server ~]# subscription-manager list --consumed
+-------------------------------------------+
    Consumed Product Subscriptions
+-------------------------------------------+


ProductName:        	Awesome OS for x86_64 Bits
ContractNumber:     	30                       
AccountNumber:      	12331131231              
SerialNumber:       	5442050938821748098      
Active:             	True                     
QuantityUsed:       	3                        
Begins:             	10/11/2011               
Expires:            	10/10/2012               


ProductName:        	Awesome OS for x86_64 Bits
ContractNumber:     	31                       
AccountNumber:      	12331131231              
SerialNumber:       	2986802716899926028      
Active:             	True                     
QuantityUsed:       	1                        
Begins:             	09/30/2012               
Expires:            	09/30/2013               

[root@jsefler-onprem-62server ~]# subscription-manager facts --list | grep valid
system.entitlements_valid: True



^^^ BANG!!!  AUTOSUBSCRIBE SUCCESSFULLY SUBSCRIBED TO THE REMAINING QUANTITY (3) TO MEET THE SOCKET REQUIREMENTS.  HOWEVER. WE SHOULD NOT BE VALID/COMPLIANT SINCE ONE OF THE COVERING SUBSCRIPTIONS IS IN THE FUTURE!  INSTEAD, AUTOSUBSCRIBE SHOULD HAVE SUBSCRIBED TO A QUANTITY OF (4) TO SATISFY COMPLIANCE TODAY.  THE FUTURE SUBSCRIPTION SHOULD NOT HAVE BEEN FACTORED IN BY AUTOSUBSCRIBE.

Comment 2 Adrian Likins 2011-10-14 18:03:13 UTC
Root cause of this looks to be entitlements being created with current date as the start date instead of the start date of the pool. 

patch out for review:


commit fdcd64f5a75fcdbf81dd394e3e45c8c51a16ddee
Author: Adrian Likins <alikins>
Date:   Fri Oct 14 13:39:12 2011 -0400

    746035: set entitlement start dates to start date of pool
    
    Previously, they were set to "now", which meant subscribing to
    pools that started in the future got the wrong entitlement
    start date. Which meant that any checks of this "is this
    entitlement valid _now_" would be wrong. For this particular
    bug, that meant autosubscribe would consider a product entitled
    even though it is only entitled for the future.

Comment 3 Adrian Likins 2011-10-14 18:04:27 UTC
Also, the change is in candlepin, not subscription-manager,so this could get pushed back.

Comment 5 Adrian Likins 2011-11-11 15:38:28 UTC
commit fa957a9ededfcf2feabd2a3f94f87d8ac9e0149f
Author: Adrian Likins <alikins>
Date:   Fri Oct 14 13:39:12 2011 -0400

    746035: set entitlement start dates to start date of pool
    
    Previously, they were set to "now", which meant subscribing to
    pools that started in the future got the wrong entitlement
    start date. Which meant that any checks of this "is this
    entitlement valid _now_" would be wrong. For this particular
    bug, that meant autosubscribe would consider a product entitled
    even though it is only entitled for the future.

Comment 6 Bryan Kearney 2012-07-17 13:04:17 UTC
Marking all community bugs modified or beyong as closed.