mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
api: fix listVirtuaMachinesMetrics API for user (#6985)
Fixes #6983 In case of multiple classes for and API class, ApiServer returns an API command class for User role only when ResponseView is set to Restricted in annotation. This PR set Restricted ResponseView for ListVMsMetrics class. It also adds a smoke test for User role account for the listVirtualMachinesMetrics API. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
d331b2f98f
commit
0075717612
@ -43,7 +43,7 @@ import org.apache.cloudstack.response.VmMetricsResponse;
|
||||
* </ul>
|
||||
*/
|
||||
@APICommand(name = ListVMsMetricsCmd.APINAME, description = "Lists VM metrics", responseObject = VmMetricsResponse.class,
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, responseView = ResponseObject.ResponseView.Full,
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, responseView = ResponseObject.ResponseView.Restricted,
|
||||
since = "4.9.3", authorized = {RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
|
||||
public class ListVMsMetricsCmd extends ListVMsCmd implements UserCmd {
|
||||
public static final String APINAME = "listVirtualMachinesMetrics";
|
||||
|
||||
@ -58,16 +58,28 @@ class TestMetrics(cloudstackTestCase):
|
||||
cls.hypervisor
|
||||
)
|
||||
cls._cleanup.append(cls.service_offering)
|
||||
cls.domain = get_domain(cls.apiclient)
|
||||
cls.account = Account.create(
|
||||
cls.apiclient,
|
||||
cls.services["account"],
|
||||
admin=False,
|
||||
domainid=cls.domain.id
|
||||
)
|
||||
cls._cleanup.append(cls.account)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super(TestMetrics, cls).tearDownClass()
|
||||
|
||||
def setUp(self):
|
||||
self.userapiclient = self.testClient.getUserApiClient(
|
||||
UserName=self.account.name,
|
||||
DomainName=self.account.domain
|
||||
)
|
||||
self.cleanup = []
|
||||
|
||||
def tearDown(self):
|
||||
super(TestMetrics, self).tearDown();
|
||||
super(TestMetrics, self).tearDown()
|
||||
|
||||
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
|
||||
def test_list_hosts_metrics(self):
|
||||
@ -117,23 +129,24 @@ class TestMetrics(cloudstackTestCase):
|
||||
|
||||
return
|
||||
|
||||
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
|
||||
def test_list_vms_metrics(self):
|
||||
#deploy VM
|
||||
def run_list_vm_metrics_test(self, is_user):
|
||||
apiclient = self.apiclient
|
||||
if is_user:
|
||||
apiclient = self.userapiclient
|
||||
self.small_virtual_machine = VirtualMachine.create(
|
||||
self.apiclient,
|
||||
self.services["virtual_machine"],
|
||||
serviceofferingid=self.service_offering.id,
|
||||
templateid=self.template.id,
|
||||
zoneid=self.zone.id
|
||||
)
|
||||
apiclient,
|
||||
self.services["virtual_machine"],
|
||||
serviceofferingid=self.service_offering.id,
|
||||
templateid=self.template.id,
|
||||
zoneid=self.zone.id
|
||||
)
|
||||
self.cleanup.append(self.small_virtual_machine)
|
||||
|
||||
|
||||
cmd = listVirtualMachinesMetrics.listVirtualMachinesMetricsCmd()
|
||||
cmd.id = self.small_virtual_machine.id
|
||||
|
||||
lvmm = self.apiclient.listVirtualMachinesMetrics(cmd)[0]
|
||||
lvmm = apiclient.listVirtualMachinesMetrics(cmd)[0]
|
||||
|
||||
self.assertEqual(lvmm.id, self.small_virtual_machine.id)
|
||||
|
||||
@ -144,7 +157,13 @@ class TestMetrics(cloudstackTestCase):
|
||||
self.assertTrue(hasattr(lvmm, 'networkread'))
|
||||
self.assertTrue(hasattr(lvmm, 'networkwrite'))
|
||||
|
||||
return
|
||||
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
|
||||
def test_list_vms_metrics_admin(self):
|
||||
self.run_list_vm_metrics_test(False)
|
||||
|
||||
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
|
||||
def test_list_vms_metrics_user(self):
|
||||
self.run_list_vm_metrics_test(True)
|
||||
|
||||
@attr(tags = ["advanced", "advancedns", "smoke", "basic"], required_hardware="false")
|
||||
def test_list_pstorage_metrics(self):
|
||||
@ -376,4 +395,3 @@ class TestMetrics(cloudstackTestCase):
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user