forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_regions.py
More file actions
139 lines (121 loc) · 4.77 KB
/
Copy pathtest_regions.py
File metadata and controls
139 lines (121 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# 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.lib.utils import *
from marvin.lib.base import *
from marvin.lib.common import *
from nose.plugins.attrib import attr
from random import choice
class Services:
def __init__(self):
self.services = {
"region": {
"regionid": "2",
"regionname": "Region2",
"regionendpoint": "http://region2:8080/client"
}
}
class TestRegions(cloudstackTestCase):
"""Test Regions - CRUD tests for regions
"""
@classmethod
def setUpClass(cls):
cls.api_client = super(TestRegions, cls).getClsTestClient().getApiClient()
cls.services = Services().services
cls.domain = get_domain(cls.api_client)
cls.cleanup = []
return
def setUp(self):
pseudo_random_int = choice(xrange(2, 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"
self.region = Region.create(self.api_client,
self.services["region"]
)
self.cleanup = []
self.cleanup.append(self.region)
list_region = Region.list(self.api_client,
id=self.services["region"]["regionid"]
)
self.assertEqual(
isinstance(list_region, list),
True,
msg="Region creation failed"
)
@attr(tags=["simulator", "basic", "advanced"], required_hardware="false")
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"])
@attr(tags=["simulator", "basic", "advanced"], required_hardware="false")
def test_createRegionWithExistingRegionName(self):
"""Test for duplicate checks on region name
"""
random_int = choice(xrange(2, 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"])
@attr(tags=["simulator", "basic", "advanced"], required_hardware="false")
def test_updateRegion(self):
""" Test for update Region
"""
self.services["region"]["regionname"] = "Region3" + random_gen()
self.services["region"]["regionendpoint"] = "http://region3updated:8080/client"
updated_region = self.region.update(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(
region_response.id,
updated_region.id,
"listRegion response does not match with region Id created"
)
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"
)
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)
@classmethod
def tearDownClass(cls):
"""
Nothing to do
"""
pass