Merge pull request #1560 from nvazquez/gcbug CLOUDSTACK-9386: DS template copies dont get deleted in VMware ESXi with multiple clusters and zone wide storageJIRA TICKET: https://issues.apache.org/jira/browse/CLOUDSTACK-9386
### Introduction In some production environments with multiple clusters it was noticed that unused templates were consuming too much storage. It was discovered that template cleanup was not deleting marked templates on ESXi. ### Description of the problem Suppose we have multiple clusters `(c1, c2,...,cN)` on a data center and template `T` from which we deploy vms on `c1.` Suppose now that we expunge those vms, and there's no other vm instance from template `T,` so this was the actual workflow: 1. CloudStack marks template for cleanup after `storage.cleanup.interval` seconds, by setting `marked_for_gc = 1` on `template_spool_ref` table, for that template. 2. After another `storage.cleanup.interval` seconds a `DestroyCommand` will be sent, to delete template from primary storage 3. On `VmwareResource`, command is processed, and it first picks up a random cluster, say `ci != c1` to look for vm template (using volume's path) and destroy it. But, as template was on `c1` it cannot be found, so it won't be deleted. Entry on `template_spool_ref` is deleted but not the actual template on hypervisor side. ### Proposed solution We propose a way to attack problem shown in point 3, by not picking up a random cluster to look for vm but using vSphere data center. This way we make sure vm template will be deleted in every case, and not depending on random cluster selection * pr/1560: CLOUDSTACK-9386: Find vm on datacenter instead of randomly choosing a cluster Signed-off-by: Koushik Das <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f31d2ddc Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f31d2ddc Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f31d2ddc Branch: refs/heads/master Commit: f31d2ddce924ec30813171974a43d64e3718d91a Parents: 6b9cd28 1384d74 Author: Koushik Das <[email protected]> Authored: Tue Sep 13 14:43:33 2016 +0530 Committer: Koushik Das <[email protected]> Committed: Tue Sep 13 14:43:34 2016 +0530 ---------------------------------------------------------------------- .../vmware/resource/VmwareResource.java | 31 +++++++++++------ .../vmware/resource/VmwareResourceTest.java | 35 ++++++++++++++++++-- 2 files changed, 54 insertions(+), 12 deletions(-) ----------------------------------------------------------------------
