Skip to content

Commit cc1dcf5

Browse files
Merge remote-tracking branch 'origin/4.19'
Signed-off-by: Rohit Yadav <[email protected]>
2 parents cb0527d + bf11676 commit cc1dcf5

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,42 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri
773773
}
774774
}
775775

776+
private boolean destroyStoragePool(Connect conn, String uuid) throws LibvirtException {
777+
StoragePool sp;
778+
try {
779+
sp = conn.storagePoolLookupByUUIDString(uuid);
780+
} catch (LibvirtException exc) {
781+
logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. Assuming it is already removed");
782+
logger.warn(exc.getStackTrace());
783+
return true;
784+
}
785+
786+
if (sp != null) {
787+
if (sp.isPersistent() == 1) {
788+
sp.destroy();
789+
sp.undefine();
790+
} else {
791+
sp.destroy();
792+
}
793+
sp.free();
794+
795+
return true;
796+
} else {
797+
logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. Assuming it is already removed");
798+
return false;
799+
}
800+
}
801+
802+
private boolean destroyStoragePoolHandleException(Connect conn, String uuid)
803+
{
804+
try {
805+
return destroyStoragePool(conn, uuid);
806+
} catch (LibvirtException e) {
807+
logger.error(String.format("Failed to destroy libvirt pool %s: %s", uuid, e));
808+
}
809+
return false;
810+
}
811+
776812
@Override
777813
public boolean deleteStoragePool(String uuid) {
778814
logger.info("Attempting to remove storage pool " + uuid + " from libvirt");
@@ -783,16 +819,8 @@ public boolean deleteStoragePool(String uuid) {
783819
throw new CloudRuntimeException(e.toString());
784820
}
785821

786-
StoragePool sp = null;
787822
Secret s = null;
788823

789-
try {
790-
sp = conn.storagePoolLookupByUUIDString(uuid);
791-
} catch (LibvirtException e) {
792-
logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. Assuming it is already removed");
793-
return true;
794-
}
795-
796824
/*
797825
* Some storage pools, like RBD also have 'secret' information stored in libvirt
798826
* Destroy them if they exist
@@ -804,13 +832,7 @@ public boolean deleteStoragePool(String uuid) {
804832
}
805833

806834
try {
807-
if (sp.isPersistent() == 1) {
808-
sp.destroy();
809-
sp.undefine();
810-
} else {
811-
sp.destroy();
812-
}
813-
sp.free();
835+
destroyStoragePool(conn, uuid);
814836
if (s != null) {
815837
s.undefine();
816838
s.free();
@@ -828,6 +850,7 @@ public boolean deleteStoragePool(String uuid) {
828850
String result = Script.runSimpleBashScript("sleep 5 && umount " + targetPath);
829851
if (result == null) {
830852
logger.info("Succeeded in unmounting " + targetPath);
853+
destroyStoragePoolHandleException(conn, uuid);
831854
return true;
832855
}
833856
logger.error("Failed to unmount " + targetPath);

test/integration/component/test_acl_sharednetwork_deployVM-impersonation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ def test_deployVM_in_sharedNetwork_as_domainadmin_scope_all_ROOTuser(self):
11711171
self.fail("Domain admin is NOT able to deploy a VM for user in ROOT domain in a shared network with scope=all")
11721172
except Exception as e:
11731173
self.debug("When a Domain admin user deploys a VM for ROOT user in a shared network with scope=all %s" % e)
1174-
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_DOMAIN):
1174+
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_SOURCE):
11751175
self.fail("Error message validation failed when Domain admin is NOT able to deploy a VM for user in ROOT domain in a shared network with scope=all")
11761176

11771177
@attr("simulator_only", tags=["advanced"], required_hardware="false")
@@ -1199,7 +1199,7 @@ def test_deployVM_in_sharedNetwork_as_domainadmin_scope_all_crossdomainuser(self
11991199
self.fail("Domain admin user is able to Deploy VM for a domain user, but there is no access to in a shared network with scope=domain with no subdomain access ")
12001200
except Exception as e:
12011201
self.debug("When a Domain admin user deploys a VM for a domain user, but there is no access to in a shared network with scope=domain with no subdomain access %s" % e)
1202-
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_DOMAIN):
1202+
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_SOURCE):
12031203
self.fail(
12041204
"Error mesage validation failed when Domain admin user tries to Deploy VM for a domain user, but there is no access to in a shared network with scope=domain with no subdomain access ")
12051205

@@ -1405,7 +1405,7 @@ def test_deployVM_in_sharedNetwork_as_domainadmin_scope_domain_nosubdomainaccess
14051405
self.fail("Domain admin is able to deploy a VM for user in ROOT domain in a shared network with scope=Domain and no subdomain access")
14061406
except Exception as e:
14071407
self.debug("When a regular user from ROOT domain deploys a VM in a shared network with scope=domain with no subdomain access %s" % e)
1408-
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_DOMAIN):
1408+
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_SOURCE):
14091409
self.fail(
14101410
"Error message validation failed when Domain admin tries to deploy a VM for user in ROOT domain in a shared network with scope=Domain and no subdomain access")
14111411

@@ -1601,7 +1601,7 @@ def test_deployVM_in_sharedNetwork_as_domainadmin_scope_domain_withsubdomainacce
16011601
self.fail("Domain admin is able to deploy a VM for user in ROOT domain in a shared network with scope=Domain and subdomain access")
16021602
except Exception as e:
16031603
self.debug("When a user from ROOT domain deploys a VM in a shared network with scope=domain with subdomain access %s" % e)
1604-
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_DOMAIN):
1604+
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_SOURCE):
16051605
self.fail(
16061606
"Error message validation failed when Domain admin tries to deploy a VM for user in ROOT domain in a shared network with scope=Domain and subdomain access")
16071607

@@ -1717,7 +1717,7 @@ def test_deployVM_in_sharedNetwork_as_domainadmin_scope_account_differentdomain(
17171717
self.fail("Domain admin is able to deploy a VM for an regular user from a differnt domain in a shared network with scope=account")
17181718
except Exception as e:
17191719
self.debug("When a user from different domain deploys a VM in a shared network with scope=account %s" % e)
1720-
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_DOMAIN):
1720+
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_SOURCE):
17211721
self.fail(
17221722
"Error message validation failed when Domain admin tries to deploy a VM for an regular user from a differnt domain in a shared network with scope=account")
17231723

@@ -1746,7 +1746,7 @@ def test_deployVM_in_sharedNetwork_as_domainadmin_scope_account_ROOTuser(self):
17461746
self.fail("Domain admin is able to deploy a VM for an regular user in ROOT domain in a shared network with scope=account")
17471747
except Exception as e:
17481748
self.debug("When a user from ROOT domain deploys a VM in a shared network with scope=account %s" % e)
1749-
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_DOMAIN):
1749+
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_SOURCE):
17501750
self.fail("Error message validation failed when Domain admin tries to deploy a VM for an regular user in ROOT domain in a shared network with scope=account")
17511751

17521752
## Test cases relating to deploying Virtual Machine as Regular user for other users in shared network with scope=all
@@ -1776,7 +1776,7 @@ def test_deployVM_in_sharedNetwork_as_regularuser_scope_all_anotherusersamedomai
17761776
self.fail("Regular user is allowed to deploy a VM for another user in the same domain in a shared network with scope=all")
17771777
except Exception as e:
17781778
self.debug("When a regular user deploys a VM for another user in the same domain in a shared network with scope=all %s" % e)
1779-
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_ACCOUNT):
1779+
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_SOURCE):
17801780
self.fail("Error message validation failed when Regular user tries to deploy a VM for another user in the same domain in a shared network with scope=all")
17811781

17821782
@attr("simulator_only", tags=["advanced"], required_hardware="false")
@@ -1804,7 +1804,7 @@ def test_deployVM_in_sharedNetwork_as_regularuser_scope_all_crossdomain(self):
18041804
self.fail("Regular user is allowed to deploy a VM for another user in the same domain in a shared network with scope=all")
18051805
except Exception as e:
18061806
self.debug("When a regular user deploys a VM for another user in the same domain in a shared network with scope=all %s" % e)
1807-
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_ACCOUNT):
1807+
if not CloudstackAclException.verifyMsginException(e, CloudstackAclException.NO_PERMISSION_TO_OPERATE_SOURCE):
18081808
self.fail("Error message validation failed when Regular user tries to deploy a VM for another user in the same domain in a shared network with scope=all")
18091809

18101810
@staticmethod

tools/marvin/marvin/cloudstackException.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class CloudstackAclException():
7777
UNABLE_TO_LIST_NETWORK_ACCOUNT = "Can't create/list resources for account"
7878
NO_PERMISSION_TO_ACCESS_ACCOUNT = "does not have permission to access resource Acct"
7979
NOT_AVAILABLE_IN_DOMAIN = "not available in domain"
80+
NO_PERMISSION_TO_OPERATE_SOURCE = "does not have permission to operate with provided resource"
8081

8182
@staticmethod
8283
def verifyMsginException(e,message):

0 commit comments

Comments
 (0)