Skip to content

Commit 28b598b

Browse files
author
Prasanna Santhanam
committed
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>
1 parent a5189b1 commit 28b598b

3 files changed

Lines changed: 59 additions & 103 deletions

File tree

setup/dev/advanced.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@
218218
"mgtSvrIp": "localhost",
219219
"passwd": "password",
220220
"user": "root",
221-
"port": 8096
221+
"port": 8096,
222+
"hypervisor" : "simulator"
222223
}
223224
]
224225
}

test/integration/component/test_vpc.py

Lines changed: 56 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#Import Local Modules
2121
from nose.plugins.attrib import attr
2222
from marvin.cloudstackTestCase import *
23+
from marvin.cloudstackException import cloudstackAPIException
2324
from marvin.cloudstackAPI import *
2425
from marvin.integration.lib.utils import *
2526
from marvin.integration.lib.base import *
@@ -820,7 +821,7 @@ def test_06_list_vpc_apis_admin(self):
820821
)
821822
return
822823

823-
@attr(tags=["advanced", "intervlan"])
824+
@attr(tags=["advanced", "intervlan", "multiple"])
824825
def test_07_restart_network_vm_running(self):
825826
""" Test Restart VPC when there are multiple networks associated
826827
"""
@@ -1923,8 +1924,7 @@ def test_13_deploy_vm_with_vpc_netdomain(self):
19231924

19241925
@attr(tags=["advanced", "intervlan"])
19251926
def test_14_deploy_vm_1(self):
1926-
""" Test deployment of vm in a network from user account. But the VPC is created
1927-
without account/domain ID
1927+
""" Test vm deploy in network by a user where VPC was created without account/domain ID
19281928
"""
19291929

19301930
# 1. Create VPC without providing account/domain ID.
@@ -1935,18 +1935,19 @@ def test_14_deploy_vm_1(self):
19351935
self.apiclient,
19361936
self.services["account"]
19371937
)
1938-
self.debug("Created account: %s" % user.account.name)
1938+
self.debug("Created account: %s" % user.name)
19391939
self.cleanup.append(user)
19401940

19411941
self.services["vpc"]["cidr"] = "10.1.1.1/16"
19421942
self.debug("creating a VPC network in the account: %s" %
1943-
user.account.name)
1943+
user.name)
19441944

1945-
userapiclient = self.testClient.createNewApiClient(
1946-
UserName=user.account.name,
1947-
DomainName=user.account.domain,
1945+
userapiclient = self.testClient.createUserApiClient(
1946+
UserName=user.name,
1947+
DomainName=user.domain,
19481948
acctType=0)
19491949

1950+
19501951
vpc = VPC.create(
19511952
userapiclient,
19521953
self.services["vpc"],
@@ -1999,8 +2000,7 @@ def test_14_deploy_vm_1(self):
19992000

20002001
@attr(tags=["advanced", "intervlan"])
20012002
def test_15_deploy_vm_2(self):
2002-
""" Test deployment of vm in a network from domain admin account. But the VPC is created
2003-
without account/domain ID
2003+
""" Test deployment of vm in a network in a domain admin account where VPC is created without account/domain ID
20042004
"""
20052005

20062006
# 1. Create VPC without providing account/domain ID.
@@ -2016,18 +2016,18 @@ def test_15_deploy_vm_2(self):
20162016
self.apiclient,
20172017
self.services["account"]
20182018
)
2019-
self.debug("Created account: %s" % user.account.name)
2019+
self.debug("Created account: %s" % user.name)
20202020
self.cleanup.append(user)
20212021

20222022
self.services["vpc"]["cidr"] = "10.1.1.1/16"
20232023
self.debug("creating a VPC network in the account: %s" %
2024-
user.account.name)
2024+
user.name)
20252025

20262026
#0 - User, 1 - Root Admin, 2 - Domain Admin
2027-
userapiclient = self.testClient.createNewApiClient(
2028-
UserName=user.account.name,
2029-
DomainName=self.services["domain"]["name"],
2030-
acctType=2)
2027+
userapiclient = self.testClient.getUserApiClient(
2028+
account=user.name,
2029+
domain=self.services["domain"]["name"],
2030+
type=2)
20312031

20322032
vpc = VPC.create(
20332033
userapiclient,
@@ -2092,23 +2092,23 @@ def test_16_deploy_vm_for_user_by_admin(self):
20922092
self.apiclient,
20932093
self.services["account"]
20942094
)
2095-
self.debug("Created account: %s" % user.account.name)
2095+
self.debug("Created account: %s" % user.name)
20962096
self.cleanup.append(user)
20972097

20982098
self.services["vpc"]["cidr"] = "10.1.1.1/16"
20992099
self.debug("creating a VPC network in the account: %s" %
2100-
user.account.name)
2100+
user.name)
21012101

2102-
userapiclient = self.testClient.createNewApiClient(
2103-
UserName=user.account.name,
2104-
DomainName=user.account.domain,
2105-
acctType=0)
2102+
userapiclient = self.testClient.getUserApiClient(
2103+
account=user.name,
2104+
domain=user.domain,
2105+
type=0)
21062106

21072107
vpc = VPC.create(
21082108
self.apiclient,
21092109
self.services["vpc"],
2110-
account=user.account.name,
2111-
domainid=user.account.domainid,
2110+
account=user.name,
2111+
domainid=user.domainid,
21122112
vpcofferingid=self.vpc_off.id,
21132113
zoneid=self.zone.id,
21142114
)
@@ -2176,82 +2176,39 @@ def test_17_deploy_vm_for_user_by_domain_admin(self):
21762176
self.apiclient,
21772177
self.services["domain_admin"]
21782178
)
2179-
self.debug("Created account: %s" % domain_admin.account.name)
2179+
self.debug("Created account: %s" % domain_admin.name)
21802180
self.cleanup.append(domain_admin)
2181-
da_apiclient = self.testClient.createNewApiClient(
2182-
UserName=domain_admin.account.name,
2183-
#DomainName=self.services["domain"]["name"],
2184-
DomainName=domain_admin.account.domain,
2185-
acctType=2)
2181+
da_apiclient = self.testClient.getUserApiClient(
2182+
account=domain_admin.name,
2183+
domain=domain_admin.domain,
2184+
type=2)
21862185

21872186
user = Account.create(
21882187
self.apiclient,
21892188
self.services["account"]
21902189
)
2191-
self.debug("Created account: %s" % user.account.name)
2190+
self.debug("Created account: %s" % user.name)
21922191
self.cleanup.append(user)
21932192

21942193
self.services["vpc"]["cidr"] = "10.1.1.1/16"
21952194
self.debug("creating a VPC network in the account: %s" %
2196-
user.account.name)
2195+
user.name)
21972196

21982197
#0 - User, 1 - Root Admin, 2 - Domain Admin
2199-
userapiclient = self.testClient.createNewApiClient(
2200-
UserName=user.account.name,
2201-
DomainName=user.account.domain,
2202-
acctType=0)
2203-
2204-
vpc = VPC.create(
2205-
da_apiclient,
2206-
self.services["vpc"],
2207-
account=user.account.name,
2208-
domainid=user.account.domainid,
2209-
vpcofferingid=self.vpc_off.id,
2210-
zoneid=self.zone.id,
2211-
)
2212-
self.validate_vpc_network(vpc)
2213-
2214-
self.network_offering = NetworkOffering.create(
2215-
self.apiclient,
2216-
self.services["network_offering"],
2217-
conservemode=False
2218-
)
2219-
# Enable Network offering
2220-
self.network_offering.update(self.apiclient, state='Enabled')
2221-
self._cleanup.append(self.network_offering)
2222-
2223-
gateway = vpc.cidr.split('/')[0]
2224-
# Split the cidr to retrieve gateway
2225-
# for eg. cidr = 10.0.0.1/24
2226-
# Gateway = 10.0.0.1
2227-
2228-
# Creating network using the network offering created
2229-
self.debug("Creating network with network offering: %s" %
2230-
self.network_offering.id)
2231-
network = Network.create(
2232-
userapiclient,
2233-
self.services["network"],
2234-
networkofferingid=self.network_offering.id,
2235-
zoneid=self.zone.id,
2236-
gateway=gateway,
2237-
vpcid=vpc.id
2238-
)
2239-
self.debug("Created network with ID: %s" % network.id)
2198+
userapiclient = self.testClient.getUserApiClient(
2199+
account=user.name,
2200+
domain=user.domain,
2201+
type=0)
22402202

2241-
# Spawn an instance in that network
2242-
virtual_machine = VirtualMachine.create(
2243-
userapiclient,
2244-
self.services["virtual_machine"],
2245-
serviceofferingid=self.service_offering.id,
2246-
networkids=[str(network.id)]
2247-
)
2248-
self.debug("Deployed VM in network: %s" % network.id)
2249-
2250-
self.assertNotEqual(virtual_machine,
2251-
None,
2252-
"VM creation in the network failed")
2253-
2254-
return
2203+
with self.assertRaises(cloudstackAPIException):
2204+
vpc = VPC.create(
2205+
da_apiclient,
2206+
self.services["vpc"],
2207+
account=user.name,
2208+
domainid=user.domainid,
2209+
vpcofferingid=self.vpc_off.id,
2210+
zoneid=self.zone.id,
2211+
)
22552212

22562213
@attr(tags=["advanced", "intervlan"])
22572214
def test_18_create_net_for_user_diff_domain_by_doadmin(self):
@@ -2271,29 +2228,29 @@ def test_18_create_net_for_user_diff_domain_by_doadmin(self):
22712228
self.apiclient,
22722229
self.services["domain_admin"]
22732230
)
2274-
self.debug("Created account: %s" % domain_admin.account.name)
2231+
self.debug("Created account: %s" % domain_admin.name)
22752232
self.cleanup.append(domain_admin)
2276-
da_apiclient = self.testClient.createNewApiClient(
2277-
UserName=domain_admin.account.name,
2278-
DomainName=self.services["domain"]["name"],
2279-
acctType=2)
2233+
da_apiclient = self.testClient.getUserApiClient(
2234+
account=domain_admin.name,
2235+
domain=self.services["domain"]["name"],
2236+
type=2)
22802237

22812238
user = Account.create(
22822239
self.apiclient,
22832240
self.services["account"]
22842241
)
2285-
self.debug("Created account: %s" % user.account.name)
2242+
self.debug("Created account: %s" % user.name)
22862243
self.cleanup.append(user)
22872244

22882245
self.services["vpc"]["cidr"] = "10.1.1.1/16"
22892246
self.debug("creating a VPC network in the account: %s" %
2290-
user.account.name)
2247+
user.name)
22912248

22922249
#0 - User, 1 - Root Admin, 2 - Domain Admin
2293-
userapiclient = self.testClient.createNewApiClient(
2294-
UserName=user.account.name,
2295-
DomainName=user.account.domain,
2296-
acctType=0)
2250+
userapiclient = self.testClient.getUserApiClient(
2251+
account=user.name,
2252+
domain=user.domain,
2253+
type=0)
22972254

22982255
vpc = VPC.create(
22992256
da_apiclient,
@@ -2467,7 +2424,4 @@ def test_20_update_vpc_name_display_text(self):
24672424

24682425
self.assertEqual(vpc_networks[0].displaytext,
24692426
new_display_text,
2470-
"Updation of VPC display text failed.")
2471-
2472-
2473-
2427+
"Updation of VPC display text failed.")

tools/marvin/marvin/cloudstackTestClient.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def createUserApiClient(self, UserName, DomainName, acctType=0):
121121
apiKey, securityKey, self.connection.asyncTimeout, self.connection.logging)
122122
self.userApiClient = cloudstackAPIClient.CloudStackAPIClient(newUserConnection)
123123
self.userApiClient.connection = newUserConnection
124+
self.userApiClient.hypervisor = self.apiClient.hypervisor
124125
return self.userApiClient
125126

126127
def close(self):

0 commit comments

Comments
 (0)