Breaking down region tests

region tests will be run in smoke and regression. In smoke we only test
the basic creation of a region. More extensive testing of duplicate
regions, test for updating region atteributes is in component.

Separated the class for testing accounts within region (account sync)
into a a new suite.

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
This commit is contained in:
Prasanna Santhanam 2013-05-08 12:39:34 +05:30
parent 5ef2f1f26f
commit 548a8d8c1f
4 changed files with 387 additions and 391 deletions

View File

@ -21,423 +21,120 @@ from marvin.cloudstackAPI import *
from marvin.integration.lib.utils import *
from marvin.integration.lib.base import *
from marvin.integration.lib.common import *
from marvin import remoteSSHClient
from nose.plugins.attrib import attr
from random import choice
class Services:
"""
"""
def __init__(self):
self.services = {
"domain": {
"name": "testuuid",
"domainUUID": "domain1"
},
"account": {
"email": "test@test.com",
"firstname": "Testuuid",
"lastname": "Useruuid",
"username": "test",
# Random characters are appended for unique
# username
"password": "password",
"accountUUID": "account1",
"userUUID": "user1"
},
"user": {
"email": "test@test.com",
"firstname": "Testuuid",
"lastname": "Useruuid",
"username": "test",
# Random characters are appended for unique
# username
"password": "password",
"userUUID": "user2"
},
"ostype": 'CentOS 5.3 (64-bit)',
"region": {
"regionid": "2",
"regionname": "Region2",
"regionendpoint": "http://region2:8080/client"
}
"region": {
"regionid": "2",
"regionname": "Region2",
"regionendpoint": "http://region2:8080/client"
}
}
class TestRegions(cloudstackTestCase):
"""Test Regions - CRUD tests for regions
"""
Testing Regions related Apis
"""
@classmethod
def setUpClass(cls):
cls.api_client = super(TestRegions, cls).getClsTestClient().getApiClient()
cls.services = Services().services
cls.domain = get_domain(cls.api_client, cls.services)
cls.cleanup = []
cls.domain = get_domain(cls.api_client, cls.services)
cls.cleanup = []
return
@attr(tags=["basic", "advanced"])
def test_createAccountWithUUID(self):
"""
Test for creating Account by passing id parameter
def setUp(self):
pseudo_random_int = choice(xrange(1, 200))
self.services["region"]["regionid"] = pseudo_random_int
self.services["region"]["regionname"] = "region" + str(pseudo_random_int)
self.services["region"]["regionendpoint"] = "http://region" + str(pseudo_random_int) + ":8080/client"
# Validate the following
# 1.Create an Account by passing id parameter.Verify the account is created.
# 2.List this account by passing id parameter.Verify that list account is able to lis this account.
# 3.Delete account should succeed.
"""
account = Account.create(
self.api_client,
self.services["account"],
domainid=self.domain.id
)
self.assertIn ( self.services["account"]["accountUUID"] , account.id,
"Account is not created with the accountId passed")
list_account = Account.list(self.api_client,
id=account.id
)
self.assertEqual(
isinstance(list_account, list),
True,
"Check for list account response by uuid failed"
)
print (list_account)
account_response = list_account[0]
print (account_response)
self.assertEqual( account_response.id,
account.id,
"listAccount response does not match with account Id "
)
self.assertEqual(
account_response.user[0].firstname,
self.services["account"]["firstname"],
"listAccount response does not match with account firstname"
)
self.cleanup.append(account)
return
@attr(tags=["basic", "advanced"])
def test_createUserWithUUID(self):
"""
Test for creating User by passing id parameter
# Validate the following
# 1.Create a User by passing id parameter.Verify the user is created.
# 2.List this user by passing id parameter.Verify that list user is able to list this user.
# 3.Delete User should succeed.
"""
user = User.create(
self.api_client,
self.services["user"],
account="Admin",
domainid=self.domain.id
)
self.assertIn ( self.services["user"]["userUUID"] , user.id,
"User is not created successfully with the userId passed")
list_user = User.list(self.api_client,
id=user.id
)
self.assertEqual(
isinstance(list_user, list),
True,
"Check for list user response by uuid failed"
)
user_response = list_user[0]
self.assertEqual( user_response.id,
user.id,
"list User response does not match with user Id "
)
self.assertEqual(
user_response.firstname,
self.services["user"]["firstname"],
"listUser response does not match with user firstname"
)
user.delete(self.api_client)
list_user = User.list(self.api_client,
id=user.id
)
self.assertIsNone(
list_user,
"Deletion of user failed"
)
return
@attr(tags=["basic", "advanced"])
def test_createdomainWithUUID(self):
"""
Test for creating Domain by passing id parameter
# Validate the following
# 1.Create a domain by passing id parameter.Verify the domain is created.
# 2.List this domain by passing id parameter.Verify that list domain is able to list this domain.
# 3.Delete domain should succeed.
"""
domain = Domain.create(
self.api_client,
self.services["domain"]
)
self.assertIn ( self.services["domain"]["domainUUID"] , domain.id,
"Domain is not created with the doaminId passed")
list_domain = Domain.list(self.api_client,
id=domain.id
)
self.assertEqual(
isinstance(list_domain, list),
True,
"Check for list domain response by uuid failed"
)
domain_response = list_domain[0]
self.assertEqual( domain_response.id,
domain.id,
"list domain response does not match with domain Id "
)
self.assertIn(
self.services["domain"]["name"],
domain_response.name,
"list domaiin response does not match with user firstname"
)
try:
domain.delete(self.api_client)
except Exception as e:
self.fail("Failed to delete domain: %s" % e)
return
@attr(tags=["basic", "advanced"])
def test_createRegion(self):
"""
Test for add Region
"""
region = Region.create(self.api_client,
self.region = Region.create(self.api_client,
self.services["region"]
)
)
self.cleanup = []
self.cleanup.append(self.region)
list_region = Region.list(self.api_client,
list_region = Region.list(self.api_client,
id=self.services["region"]["regionid"]
)
self.assertEqual(
isinstance(list_region, list),
True,
"Check for list Region response"
)
region_response = list_region[0]
print (region_response)
print (self.services["region"])
)
self.assertEqual(
str(region_response.id),
self.services["region"]["regionid"],
"listRegion response does not match with region Id created"
)
isinstance(list_region, list),
True,
msg="Region creation failed"
)
self.assertEqual(
region_response.name,
self.services["region"]["regionname"],
"listRegion response does not match with region name created"
)
self.assertEqual(
region_response.endpoint,
self.services["region"]["regionendpoint"],
"listRegion response does not match with region endpoint created"
)
region = region.delete(self.api_client)
return
@attr(tags=["basic", "advanced"])
def test_createDupRegion(self):
"""
Test for duplicate checks on id and name parameters when adding regions
"""
self.services["region"]["regionid"]="5"
self.services["region"]["regionname"]="Region5"
self.services["region"]["regionendpoint"]="http://region5:8080/client"
region = Region.create(self.api_client,
self.services["region"]
)
list_region = Region.list(self.api_client,
id=self.services["region"]["regionid"]
)
self.assertEqual(
isinstance(list_region, list),
True
)
"""
Creating regions with duplicate id should not be allowed
@attr(tags=["simulator", "basic", "advanced"])
def test_createRegionWithExistingRegionId(self):
"""Test for duplicate checks on region id
"""
self.services["region"]["regionname"] = random_gen() #alter region name but not id
self.assertRaises(Exception, Region.create, self.api_client, self.services["region"])
self.services["region"]["regionid"]="5"
self.services["region"]["regionname"]="Region51"
self.services["region"]["regionendpoint"]="http://region51:8080/client"
@attr(tags=["simulator", "basic", "advanced"])
def test_createRegionWithExistingRegionName(self):
"""Test for duplicate checks on region name
"""
random_int = choice(xrange(1, 200))
self.services["region"]["regionid"] = random_int #alter id but not name
self.services["region"]["regionendpoint"] = "http://region" + str(random_int) + ":8080/client"
self.assertRaises(Exception, Region.create, self.api_client, self.services["region"])
try:
region = Region.create(self.api_client,
self.services["region"]
)
self.assertIsNone(region,
"Creating regions with duplicate id is allowed"
)
except:
print " Creating Region with duplicate Id is not allowed"
pass
"""
Creating regions with duplicate name should not be allowed
"""
self.services["region"]["regionid"]="51"
self.services["region"]["regionname"]="Region5"
self.services["region"]["regionendpoint"]="http://region51:8080/client"
try:
region = Region.create(self.api_client,
self.services["region"]
)
except:
print " Creating Region with duplicate Name is not allowed"
pass
region.delete(self.api_client)
return
@attr(tags=["basic", "advanced"])
@attr(tags=["simulator", "basic", "advanced"])
def test_updateRegion(self):
"""
Test for update Region
"""
""" Test for update Region
"""
self.services["region"]["regionname"] = "Region3" + random_gen()
self.services["region"]["regionendpoint"] = "http://region3updated:8080/client"
self.services["region"]["regionid"]="3"
self.services["region"]["regionname"]="Region3"
self.services["region"]["regionendpoint"]="http://region3:8080/client"
region = Region.create(self.api_client,
self.services["region"]
)
updated_region = self.region.update(self.api_client,
self.services["region"]
)
self.services["region"]["regionname"]="Region3upd"
self.services["region"]["regionendpoint"]="http://region3upd:8080/client"
list_region = Region.list(self.api_client,
id=self.services["region"]["regionid"]
)
updated_region = region.update(self.api_client,
self.services["region"]
)
self.assertEqual(
isinstance(list_region, list),
True,
"Check for list Region response"
)
region_response = list_region[0]
list_region = Region.list(self.api_client,
id=self.services["region"]["regionid"]
)
self.assertEqual(
region_response.id,
updated_region.id,
"listRegion response does not match with region Id created"
)
self.assertEqual(
isinstance(list_region, list),
True,
"Check for list Region response"
)
region_response = list_region[0]
self.assertEqual(
region_response.name,
updated_region.name,
"listRegion response does not match with region name created"
)
self.assertEqual(
region_response.endpoint,
updated_region.endpoint,
"listRegion response does not match with region endpoint created"
)
self.assertEqual(
str(region_response.id),
self.services["region"]["regionid"],
"listRegion response does not match with region Id created"
)
def tearDown(self):
""" Test for delete region as cleanup
"""
try:
#Clean up
cleanup_resources(self.api_client, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
self.assertEqual(
region_response.name,
self.services["region"]["regionname"],
"listRegion response does not match with region name created"
)
self.assertEqual(
region_response.endpoint,
self.services["region"]["regionendpoint"],
"listRegion response does not match with region endpoint created"
)
region.delete(self.api_client)
return
@attr(tags=["basic", "advanced"])
def test_deleteRegion(self):
"""
Test for delete Region
"""
self.services["region"]["regionid"]="4"
self.services["region"]["regionname"]="Region4"
self.services["region"]["regionendpoint"]="http://region4:8080/client"
region = Region.create(self.api_client,
self.services["region"]
)
list_region = Region.list(self.api_client,
id=self.services["region"]["regionid"]
)
print (list_region);
self.assertEqual(
len(list_region),
1,
"Check for Region response"
)
region = region.delete(self.api_client)
list_region = Region.list(self.api_client,
id=self.services["region"]["regionid"]
)
print (list_region);
self.assertIsNone(list_region,
"Check for empty Region response"
)
return
@classmethod
def tearDown(cls):
try:
cls.api_client = super(TestRegions, cls).getClsTestClient().getApiClient()
#Clean up
cleanup_resources(cls.api_client, cls.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
@classmethod
def tearDownClass(cls):
"""
Nothing to do
"""
pass

View File

@ -0,0 +1,206 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from marvin.cloudstackTestCase import *
from marvin.cloudstackAPI import *
from marvin.integration.lib.utils import *
from marvin.integration.lib.base import *
from marvin.integration.lib.common import *
from nose.plugins.attrib import attr
class Services:
def __init__(self):
self.services = {
"domain": {
"name": "testuuid",
"domainUUID": "domain1"
},
"account": {
"email": "test@test.com",
"firstname": "Testuuid",
"lastname": "Useruuid",
"username": "test",
"password": "password",
"accountUUID": "account1",
"userUUID": "user1"
},
"user": {
"email": "test@test.com",
"firstname": "Testuuid",
"lastname": "Useruuid",
"username": "test",
"password": "password",
"userUUID": "user2"
},
}
class TestRegionsAccounts(cloudstackTestCase):
"""Test Accounts in Regions - CRUD tests for accounts in regions
"""
@classmethod
def setUpClass(cls):
cls.api_client = super(TestRegionsAccounts, cls).getClsTestClient().getApiClient()
cls.services = Services().services
cls.domain = get_domain(cls.api_client, cls.services)
cls.cleanup = []
return
@attr(tags=["simulator", "basic", "advanced"])
def test_createAccountWithUUID(self):
"""Test for creating account by passing id parameter
# Validate the following
# 1.Create an Account by passing id parameter.Verify the account is created.
# 2.List this account by passing id parameter.Verify that list account is able to lis this account.
# 3.Delete account should succeed.
"""
account = Account.create(
self.api_client,
self.services["account"],
domainid=self.domain.id
)
self.assertIn(self.services["account"]["accountUUID"], account.id,
"Account is not created with the accountId passed")
list_account = Account.list(self.api_client,
id=account.id)
self.assertEqual(
isinstance(list_account, list),
True,
"Check for list account response by uuid failed"
)
account_response = list_account[0]
self.assertEqual(account_response.id,
account.id,
"listAccount response does not match with account Id "
)
self.assertEqual(
account_response.user[0].firstname,
self.services["account"]["firstname"],
"listAccount response does not match with account firstname"
)
self.cleanup.append(account)
return
@attr(tags=["simulator", "basic", "advanced"])
def test_createUserWithUUID(self):
"""Test for creating User by passing id parameter
# Validate the following
# 1.Create a User by passing id parameter.Verify the user is created.
# 2.List this user by passing id parameter.Verify that list user is able to list this user.
# 3.Delete User should succeed.
"""
user = User.create(
self.api_client,
self.services["user"],
account="admin",
domainid=self.domain.id
)
self.assertIn(self.services["user"]["userUUID"], user.id,
"User is not created successfully with the userId passed")
list_user = User.list(self.api_client, id=user.id)
self.assertEqual(
isinstance(list_user, list),
True,
"Check for list user response by uuid failed"
)
user_response = list_user[0]
self.assertEqual(user_response.id,
user.id,
"list User response does not match with user Id "
)
self.assertEqual(
user_response.firstname,
self.services["user"]["firstname"],
"listUser response does not match with user firstname"
)
user.delete(self.api_client)
list_user = User.list(self.api_client,
id=user.id
)
self.assertIsNone(
list_user,
"Deletion of user failed"
)
return
@attr(tags=["simulator", "basic", "advanced"])
def test_createdomainWithUUID(self):
"""Test for creating Domain by passing id parameter
# Validate the following
# 1.Create a domain by passing id parameter.Verify the domain is created.
# 2.List this domain by passing id parameter.Verify that list domain is able to list this domain.
# 3.Delete domain should succeed.
"""
domain = Domain.create(
self.api_client,
self.services["domain"]
)
self.assertIn(self.services["domain"]["domainUUID"], domain.id,
"Domain is not created with the doaminId passed")
list_domain = Domain.list(self.api_client,
id=domain.id
)
self.assertEqual(
isinstance(list_domain, list),
True,
"Check for list domain response by uuid failed"
)
domain_response = list_domain[0]
self.assertEqual(domain_response.id,
domain.id,
"list domain response does not match with domain Id "
)
self.assertIn(
self.services["domain"]["name"],
domain_response.name,
"list domaiin response does not match with user firstname"
)
try:
domain.delete(self.api_client)
except Exception as e:
self.fail("Failed to delete domain: %s" % e)
return
@classmethod
def tearDownClass(cls):
try:
#Clean up
cleanup_resources(cls.api_client, cls.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)

View File

@ -0,0 +1,93 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from marvin.cloudstackTestCase import *
from marvin.cloudstackAPI import *
from marvin.integration.lib.utils import *
from marvin.integration.lib.base import *
from marvin.integration.lib.common import *
from nose.plugins.attrib import attr
class Services:
def __init__(self):
self.services = {
"region": {
"regionid": "2",
"regionname": "Region2",
"regionendpoint": "http://region2:8080/client"
}
}
class TestRegions(cloudstackTestCase):
"""Test Regions - basic region creation
"""
@classmethod
def setUpClass(cls):
cls.api_client = super(TestRegions, cls).getClsTestClient().getApiClient()
cls.services = Services().services
cls.domain = get_domain(cls.api_client, cls.services)
cls.cleanup = []
@attr(tags=["simulator", "basic", "advanced"])
def test_createRegion(self):
""" Test for create region
"""
region = Region.create(self.api_client,
self.services["region"]
)
list_region = Region.list(self.api_client,
id=self.services["region"]["regionid"]
)
self.assertEqual(
isinstance(list_region, list),
True,
"Check for list Region response"
)
region_response = list_region[0]
self.assertEqual(
str(region_response.id),
self.services["region"]["regionid"],
"listRegion response does not match with region Id created"
)
self.assertEqual(
region_response.name,
self.services["region"]["regionname"],
"listRegion response does not match with region name created"
)
self.assertEqual(
region_response.endpoint,
self.services["region"]["regionendpoint"],
"listRegion response does not match with region endpoint created"
)
self.cleanup.append(region)
return
@classmethod
def tearDownClass(cls):
try:
#Clean up
cleanup_resources(cls.api_client, cls.cleanup)
list_region = Region.list(cls.api_client, id=cls.services["region"]["regionid"])
assert list_region is None, "Region deletion fails"
except Exception as e:
raise Exception("Warning: Region cleanup/delete fails with : %s" % e)

View File

@ -40,8 +40,8 @@ class Domain:
cmd = createDomain.createDomainCmd()
if "domainUUID" in services:
cmd.domainid = "-".join([services["domainUUID"],random_gen()])
if "domainUUID" in services:
cmd.domainid = "-".join([services["domainUUID"], random_gen()])
if name:
cmd.name = "-".join([name, random_gen()])
@ -3151,9 +3151,9 @@ class Region:
cmd = updateRegion.updateRegionCmd()
cmd.id = self.id
if services["regionendpoint"]:
cmd.endpoint = services["regionendpoint"]
cmd.endpoint = services["regionendpoint"]
if services["regionname"]:
cmd.name = services["regionname"]
cmd.name = services["regionname"]
region = apiclient.updateRegion(cmd)
return region