Fix VPC tests related to user roles

Many vpc tests fail because of incorrect apiClient passed in to create
the VPC, network etc. The exact method used is getUserApiClient to fetch
the apiclient for a specific user.

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
Prasanna Santhanam 2013-06-17 17:31:10 +05:30
parent a5189b1550
commit 28b598b4ac
3 changed files with 59 additions and 103 deletions

View File

@ -218,7 +218,8 @@
"mgtSvrIp": "localhost", "mgtSvrIp": "localhost",
"passwd": "password", "passwd": "password",
"user": "root", "user": "root",
"port": 8096 "port": 8096,
"hypervisor" : "simulator"
} }
] ]
} }

View File

@ -20,6 +20,7 @@
#Import Local Modules #Import Local Modules
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import *
from marvin.cloudstackException import cloudstackAPIException
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import *
from marvin.integration.lib.utils import * from marvin.integration.lib.utils import *
from marvin.integration.lib.base import * from marvin.integration.lib.base import *
@ -820,7 +821,7 @@ class TestVPC(cloudstackTestCase):
) )
return return
@attr(tags=["advanced", "intervlan"]) @attr(tags=["advanced", "intervlan", "multiple"])
def test_07_restart_network_vm_running(self): def test_07_restart_network_vm_running(self):
""" Test Restart VPC when there are multiple networks associated """ Test Restart VPC when there are multiple networks associated
""" """
@ -1923,8 +1924,7 @@ class TestVPC(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"]) @attr(tags=["advanced", "intervlan"])
def test_14_deploy_vm_1(self): def test_14_deploy_vm_1(self):
""" Test deployment of vm in a network from user account. But the VPC is created """ Test vm deploy in network by a user where VPC was created without account/domain ID
without account/domain ID
""" """
# 1. Create VPC without providing account/domain ID. # 1. Create VPC without providing account/domain ID.
@ -1935,18 +1935,19 @@ class TestVPC(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["account"] self.services["account"]
) )
self.debug("Created account: %s" % user.account.name) self.debug("Created account: %s" % user.name)
self.cleanup.append(user) self.cleanup.append(user)
self.services["vpc"]["cidr"] = "10.1.1.1/16" self.services["vpc"]["cidr"] = "10.1.1.1/16"
self.debug("creating a VPC network in the account: %s" % self.debug("creating a VPC network in the account: %s" %
user.account.name) user.name)
userapiclient = self.testClient.createNewApiClient( userapiclient = self.testClient.createUserApiClient(
UserName=user.account.name, UserName=user.name,
DomainName=user.account.domain, DomainName=user.domain,
acctType=0) acctType=0)
vpc = VPC.create( vpc = VPC.create(
userapiclient, userapiclient,
self.services["vpc"], self.services["vpc"],
@ -1999,8 +2000,7 @@ class TestVPC(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"]) @attr(tags=["advanced", "intervlan"])
def test_15_deploy_vm_2(self): def test_15_deploy_vm_2(self):
""" Test deployment of vm in a network from domain admin account. But the VPC is created """ Test deployment of vm in a network in a domain admin account where VPC is created without account/domain ID
without account/domain ID
""" """
# 1. Create VPC without providing account/domain ID. # 1. Create VPC without providing account/domain ID.
@ -2016,18 +2016,18 @@ class TestVPC(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["account"] self.services["account"]
) )
self.debug("Created account: %s" % user.account.name) self.debug("Created account: %s" % user.name)
self.cleanup.append(user) self.cleanup.append(user)
self.services["vpc"]["cidr"] = "10.1.1.1/16" self.services["vpc"]["cidr"] = "10.1.1.1/16"
self.debug("creating a VPC network in the account: %s" % self.debug("creating a VPC network in the account: %s" %
user.account.name) user.name)
#0 - User, 1 - Root Admin, 2 - Domain Admin #0 - User, 1 - Root Admin, 2 - Domain Admin
userapiclient = self.testClient.createNewApiClient( userapiclient = self.testClient.getUserApiClient(
UserName=user.account.name, account=user.name,
DomainName=self.services["domain"]["name"], domain=self.services["domain"]["name"],
acctType=2) type=2)
vpc = VPC.create( vpc = VPC.create(
userapiclient, userapiclient,
@ -2092,23 +2092,23 @@ class TestVPC(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["account"] self.services["account"]
) )
self.debug("Created account: %s" % user.account.name) self.debug("Created account: %s" % user.name)
self.cleanup.append(user) self.cleanup.append(user)
self.services["vpc"]["cidr"] = "10.1.1.1/16" self.services["vpc"]["cidr"] = "10.1.1.1/16"
self.debug("creating a VPC network in the account: %s" % self.debug("creating a VPC network in the account: %s" %
user.account.name) user.name)
userapiclient = self.testClient.createNewApiClient( userapiclient = self.testClient.getUserApiClient(
UserName=user.account.name, account=user.name,
DomainName=user.account.domain, domain=user.domain,
acctType=0) type=0)
vpc = VPC.create( vpc = VPC.create(
self.apiclient, self.apiclient,
self.services["vpc"], self.services["vpc"],
account=user.account.name, account=user.name,
domainid=user.account.domainid, domainid=user.domainid,
vpcofferingid=self.vpc_off.id, vpcofferingid=self.vpc_off.id,
zoneid=self.zone.id, zoneid=self.zone.id,
) )
@ -2176,82 +2176,39 @@ class TestVPC(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["domain_admin"] self.services["domain_admin"]
) )
self.debug("Created account: %s" % domain_admin.account.name) self.debug("Created account: %s" % domain_admin.name)
self.cleanup.append(domain_admin) self.cleanup.append(domain_admin)
da_apiclient = self.testClient.createNewApiClient( da_apiclient = self.testClient.getUserApiClient(
UserName=domain_admin.account.name, account=domain_admin.name,
#DomainName=self.services["domain"]["name"], domain=domain_admin.domain,
DomainName=domain_admin.account.domain, type=2)
acctType=2)
user = Account.create( user = Account.create(
self.apiclient, self.apiclient,
self.services["account"] self.services["account"]
) )
self.debug("Created account: %s" % user.account.name) self.debug("Created account: %s" % user.name)
self.cleanup.append(user) self.cleanup.append(user)
self.services["vpc"]["cidr"] = "10.1.1.1/16" self.services["vpc"]["cidr"] = "10.1.1.1/16"
self.debug("creating a VPC network in the account: %s" % self.debug("creating a VPC network in the account: %s" %
user.account.name) user.name)
#0 - User, 1 - Root Admin, 2 - Domain Admin #0 - User, 1 - Root Admin, 2 - Domain Admin
userapiclient = self.testClient.createNewApiClient( userapiclient = self.testClient.getUserApiClient(
UserName=user.account.name, account=user.name,
DomainName=user.account.domain, domain=user.domain,
acctType=0) type=0)
vpc = VPC.create( with self.assertRaises(cloudstackAPIException):
da_apiclient, vpc = VPC.create(
self.services["vpc"], da_apiclient,
account=user.account.name, self.services["vpc"],
domainid=user.account.domainid, account=user.name,
vpcofferingid=self.vpc_off.id, domainid=user.domainid,
zoneid=self.zone.id, vpcofferingid=self.vpc_off.id,
) zoneid=self.zone.id,
self.validate_vpc_network(vpc) )
self.network_offering = NetworkOffering.create(
self.apiclient,
self.services["network_offering"],
conservemode=False
)
# Enable Network offering
self.network_offering.update(self.apiclient, state='Enabled')
self._cleanup.append(self.network_offering)
gateway = vpc.cidr.split('/')[0]
# Split the cidr to retrieve gateway
# for eg. cidr = 10.0.0.1/24
# Gateway = 10.0.0.1
# Creating network using the network offering created
self.debug("Creating network with network offering: %s" %
self.network_offering.id)
network = Network.create(
userapiclient,
self.services["network"],
networkofferingid=self.network_offering.id,
zoneid=self.zone.id,
gateway=gateway,
vpcid=vpc.id
)
self.debug("Created network with ID: %s" % network.id)
# Spawn an instance in that network
virtual_machine = VirtualMachine.create(
userapiclient,
self.services["virtual_machine"],
serviceofferingid=self.service_offering.id,
networkids=[str(network.id)]
)
self.debug("Deployed VM in network: %s" % network.id)
self.assertNotEqual(virtual_machine,
None,
"VM creation in the network failed")
return
@attr(tags=["advanced", "intervlan"]) @attr(tags=["advanced", "intervlan"])
def test_18_create_net_for_user_diff_domain_by_doadmin(self): def test_18_create_net_for_user_diff_domain_by_doadmin(self):
@ -2271,29 +2228,29 @@ class TestVPC(cloudstackTestCase):
self.apiclient, self.apiclient,
self.services["domain_admin"] self.services["domain_admin"]
) )
self.debug("Created account: %s" % domain_admin.account.name) self.debug("Created account: %s" % domain_admin.name)
self.cleanup.append(domain_admin) self.cleanup.append(domain_admin)
da_apiclient = self.testClient.createNewApiClient( da_apiclient = self.testClient.getUserApiClient(
UserName=domain_admin.account.name, account=domain_admin.name,
DomainName=self.services["domain"]["name"], domain=self.services["domain"]["name"],
acctType=2) type=2)
user = Account.create( user = Account.create(
self.apiclient, self.apiclient,
self.services["account"] self.services["account"]
) )
self.debug("Created account: %s" % user.account.name) self.debug("Created account: %s" % user.name)
self.cleanup.append(user) self.cleanup.append(user)
self.services["vpc"]["cidr"] = "10.1.1.1/16" self.services["vpc"]["cidr"] = "10.1.1.1/16"
self.debug("creating a VPC network in the account: %s" % self.debug("creating a VPC network in the account: %s" %
user.account.name) user.name)
#0 - User, 1 - Root Admin, 2 - Domain Admin #0 - User, 1 - Root Admin, 2 - Domain Admin
userapiclient = self.testClient.createNewApiClient( userapiclient = self.testClient.getUserApiClient(
UserName=user.account.name, account=user.name,
DomainName=user.account.domain, domain=user.domain,
acctType=0) type=0)
vpc = VPC.create( vpc = VPC.create(
da_apiclient, da_apiclient,
@ -2467,7 +2424,4 @@ class TestVPC(cloudstackTestCase):
self.assertEqual(vpc_networks[0].displaytext, self.assertEqual(vpc_networks[0].displaytext,
new_display_text, new_display_text,
"Updation of VPC display text failed.") "Updation of VPC display text failed.")

View File

@ -121,6 +121,7 @@ class cloudstackTestClient(object):
apiKey, securityKey, self.connection.asyncTimeout, self.connection.logging) apiKey, securityKey, self.connection.asyncTimeout, self.connection.logging)
self.userApiClient = cloudstackAPIClient.CloudStackAPIClient(newUserConnection) self.userApiClient = cloudstackAPIClient.CloudStackAPIClient(newUserConnection)
self.userApiClient.connection = newUserConnection self.userApiClient.connection = newUserConnection
self.userApiClient.hypervisor = self.apiClient.hypervisor
return self.userApiClient return self.userApiClient
def close(self): def close(self):