Bug 682930

Summary: server-side subscription, management-100, looses its multiplied quantity when refresh_pools is applied
Product: [Community] Candlepin Reporter: John Sefler <jsefler>
Component: candlepinAssignee: Justin Harris <jharris>
Status: CLOSED CURRENTRELEASE QA Contact: John Sefler <jsefler>
Severity: high Docs Contact:
Priority: unspecified    
Version: 0.5CC: bkearney, jharris, jkeck, 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-05-30 20:44:26 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 568421    

Description John Sefler 2011-03-08 03:02:11 UTC
Description of problem:
In a very similar re-create scenario as https://bugzilla.redhat.com/show_bug.cgi?id=679617#c0 on a fresh deploy of onpremise candlepin with TESTDATA=1, the original quantity on the productId=management-100 pool is reduced from 1000 to 10 after updating the subscription in the database after calling refresh_pools.


Version-Release number of selected component (if applicable):
[root@jsefler-f14-candlepin candlepin]# git branch
* master
[root@jsefler-f14-candlepin candlepin]# git show-ref master
96d04af7c195be2664de2029fa1edf8842d2f810 refs/heads/master
2cc34e37691e9e06aad2ad3da394dabc24186ca7 refs/remotes/origin/master


How reproducible:


Steps to Reproduce:
1. deployed a new OnPremises candlepin with TESTDATA=1

2. on a configured rhsm client, register and list the
available pool to find the Management Add-On pool id...

201103071843:41.465 - FINE: ssh root.redhat.com subscription-manager list --available
201103071843:42.179 - FINE: Stdout: 
+-------------------------------------------+
    Available Subscriptions
+-------------------------------------------+


ProductName:       	Management Add-On        
ProductId:         	management-100           
PoolId:            	8a90f8b42e92aed0012e92af4aba0124
Quantity:          	1000                     
Expires:           	2012-03-05               


ProductName:       	Management Add-On        
ProductId:         	management-100           
PoolId:            	8a90f8b42e92aed0012e92af4ad20125
Quantity:          	500                      
Expires:           	2012-03-05  


3. subscribe to management-100 poolId=8a90f8b42e92aed0012e92af4aba0124

201103071843:42.634 - FINE: ssh root.redhat.com subscription-manager subscribe --pool=8a90f8b42e92aed0012e92af4aba0124 


4. Update the subscription on the database (I changed the
startDate and endDate)...

201103071843:50.868 - INFO: Now we will change the start and end date of the subscription pool adding one month to enddate and subtracting one month from startdate... 
201103071843:50.879 - FINE: Executing SQL: update cp_subscription set enddate='2012-04-05' where id=(select pool.subscriptionid from cp_pool pool where pool.id='8a90f8b42e92aed0012e92af4aba0124'); 
201103071843:50.904 - INFO: Asserted: Actual value of '1' matches expected value: Updated one row of the cp_subscription table with sql: update cp_subscription set enddate='2012-04-05' where id=(select pool.subscriptionid from cp_pool pool where pool.id='8a90f8b42e92aed0012e92af4aba0124'); 
201103071843:50.906 - FINE: Executing SQL: update cp_subscription set startdate='2011-02-06' where id=(select pool.subscriptionid from cp_pool pool where pool.id='8a90f8b42e92aed0012e92af4aba0124'); 
201103071843:50.915 - INFO: Asserted: Actual value of '1' matches expected value: Updated one row of the cp_subscription table with sql: update cp_subscription set startdate='2011-02-06' where id=(select pool.subscriptionid from cp_pool pool where pool.id='8a90f8b42e92aed0012e92af4aba0124');

5. now refresh pools to pick up the subscription changes

201103071843:50.984 - INFO: Now let's refresh the subscription pools... 
201103071843:50.986 - INFO: SSH alternative to HTTP request: curl -k -u admin:admin --request PUT https://jsefler-f14-candlepin.usersys.redhat.com:8443/candlepin/owners/admin/subscriptions 

6. now unsubscribe from the pool

201103071844:02.306 - FINE: ssh root.redhat.com subscription-manager unsubscribe --serial=5212995414311757 
OR 
subscription-manager unsubscribe --all

7. and list --available expecting to see the pool again (with only its endDate changed)

201103071844:03.350 - FINE: ssh root.redhat.com subscription-manager list --available
201103071844:04.044 - FINE: Stdout: 
+-------------------------------------------+
    Available Subscriptions
+-------------------------------------------+      


ProductName:       	Management Add-On        
ProductId:         	management-100           
PoolId:            	8a90f8b42e92aed0012e92af4aba0124
Quantity:          	10                       
Expires:           	2012-04-05 


ProductName:       	Management Add-On        
ProductId:         	management-100           
PoolId:            	8a90f8b42e92aed0012e92af4ad20125
Quantity:          	5                        
Expires:           	2012-03-05  
   

^^^ NOTICE THAT THE POOL (8a90f8b42e92aed0012e92af4aba0124) EXPIRES DATE CHANGED AS EXPECTED, BUT THE Quantity ALSO CHANGED (on both the management-100 pools) UNEXPECTEDLY.  THAT'S THE BUG.

Comment 1 Justin Harris 2011-03-11 15:27:00 UTC
This was a bug in the new js refactor.  Fixed in commit:  2c02ee19a128afa6e2d9002171523f009462f569

Comment 2 John Sefler 2011-03-12 15:05:26 UTC
Can this fix also be applied to the candlepin 0.2 branch?

Comment 3 Bryan Kearney 2011-03-14 19:28:37 UTC
I believe it is already applied.

Comment 4 Bryan Kearney 2011-03-14 19:28:47 UTC
ibid

Comment 5 John Sefler 2011-03-16 15:18:32 UTC
Verifying Version...
[root@jsefler-f14-candlepin candlepin]# git branch
* 0.2
  master
[root@jsefler-f14-candlepin candlepin]# git show-ref 0.2
7fa0f26c0b967bd0f2a950c45352639bfeef7f7c refs/heads/0.2
9c13d6bf6d83070bbc78638f6ca3bc1dc5267977 refs/remotes/origin/0.2


The automated tests that caught this bug are now passing. Here is the final assert from two tests for each of the ...

201103160632:40.762 - INFO: Forth, in honor of bugzillas 682930, 679617 let's assert that after unsubscribing, the subscription pool's original quantity is restored... 
201103160632:40.762 - INFO: Asserted: Actual value of '500' matches expected value: Assuming that nobody else has recently subscribed to this pool, the original pool quantity should be restored after updating the subscription's start/end dates and unsubscribing from the poolId '8a90f8b42ebe07cc012ebe0861fb0125' (Management Add-On). 


201103160635:05.290 - INFO: Forth, in honor of bugzillas 682930, 679617 let's assert that after unsubscribing, the subscription pool's original quantity is restored... 
201103160635:05.290 - INFO: Asserted: Actual value of '1000' matches expected value: Assuming that nobody else has recently subscribed to this pool, the original pool quantity should be restored after updating the subscription's start/end dates and unsubscribing from the poolId '8a90f8b42ebe07cc012ebe0861980124' (Management Add-On). 

moving to VERIFIED

Comment 6 John Sefler 2011-05-04 14:41:17 UTC
Group move of VERIFIED Candlepin component bugs to RELEASE_PENDING