Bug 784124

Summary: manageRootDir=true is broken - it isn't removing files at the dest dir level
Product: [Other] RHQ Project Reporter: John Mazzitelli <mazz>
Component: ProvisioningAssignee: RHQ Project Maintainer <rhq-maint>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 4.2CC: hrupp, skondkar
Target Milestone: ---   
Target Release: RHQ 4.3.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 786603 (view as bug list) Environment:
Last Closed: 2013-08-31 05:55:48 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Bug Depends On:    
Bug Blocks: 786603    

Description John Mazzitelli 2012-01-23 16:30:47 EST
Deploy a bundle without manageRootDir or manageRootDir=true (which is the defualt).

See that it works. Today, me and jay are seeing it broken.
Comment 1 Charles Crouch 2012-01-24 09:38:07 EST
We need to determine which versions this impacts
Comment 2 John Mazzitelli 2012-01-24 13:25:26 EST
looks like our unit tests in this area didn't cover this scenario.

We do have covered the scenario where, upon initial deployment, the manageRootDir=false:

org.rhq.plugins.ant.AntBundlePluginComponentTest.testAntBundleNoManageRootDir()

but not the inverse. I just added:

org.rhq.plugins.ant.AntBundlePluginComponentTest.testAntBundleManageRootDir()

and it does indeed fail.

What does this mean? It means if you have a destination directory (call it /dir/foo) and it isn't empty (i.e. it already has files in it), upon initial bundle deployment, those files will not be removed - they will remain even after the full bundle has been completely deployed.

It is possible that upon bundle upgrade, those files will be removed. I'll add some tests to confirm.
Comment 3 John Mazzitelli 2012-01-26 16:46:34 EST
fyi: There are several other unit test classes covering the deployment stuff in core/util module.
Comment 4 John Mazzitelli 2012-01-26 17:07:38 EST
The problem here is that when you do an INITIAL bundle deployment, and you asked that RHQ manage the destination directory, any files that happened to already exist in the deployment's destination directory were not touched. This should not have been. The dest dir should have started empty because we are being told that we should manage the full destination directory content - which means if there are files in here that are NOT part of the bundle should be removed. This happened correctly during a bundle UPDATE but not when we did the initial deployment for the first time.

Now, when we do the initial deployment AND we are to manage the destination directory, we will backup whatever files we find in the metadata directory's backup location, then we remove the files to get them out of the way. This ensures we start with a clean, empty destination directory.

The main change was done in org.rhq.core.util.updater.Deployer.performInitialDeployment
Comment 5 John Mazzitelli 2012-01-26 17:20:36 EST
git commit to master: 9946f3e2b2b4b0a86ebe001594818f016a4c4130
Comment 6 John Mazzitelli 2012-01-27 10:03:37 EST
forgot to fix a unit test... commited this to master: d8bd668
Comment 7 Mike Foley 2012-01-31 13:32:23 EST
Bundles: https://tcms.engineering.redhat.com/run/33098/   ---COMPLETE
Comment 8 Sunil Kondkar 2012-04-26 09:26:13 EDT
Verified on build#1409 (Version: 4.4.0-SNAPSHOT Build Number: 103c02)

Deployed a bundle without manageRootDir and other with manageRootDir=true

Verified that the initial deployment creates a backup for the existing files in
the destination directory and the files are removed from destination directory.

Below is the audit trail for initial deployment:

DEPLOYMENT DETAILS:
Added Files: 2
    /store/bundle/deploydest
    bundle.properties
Deleted Files: 2
    test.html
    test1.txt
Changed Files: 0
Backed Up Files: 2
    test.html -> /store/test1/.rhqdeployments/10001/backup/test.html
    test1.txt -> /store/test1/.rhqdeployments/10001/backup/test1.txt
Restored Files: 0
Ignored Files: 0
Realized Files: 2
    /store/bundle/deploydest
    bundle.properties
Was Cleaned?: false
Errors: 0

Verified that the manageRootDir=true creates a backup during upgrade.
Below is the deployment audit trail:

DEPLOYMENT DETAILS:
Added Files: 0
Deleted Files: 1
    helloworld.war
Changed Files: 1
    /store/bundle/deploydest
Backed Up Files: 1
    helloworld.war -> /store/test1/.rhqdeployments/10011/backup/helloworld.war
Restored Files: 0
Ignored Files: 0
Realized Files: 2
    /store/bundle/deploydest
    bundle.properties
Was Cleaned?: false
Errors: 0