Skip to content

Commit a1912d9

Browse files
author
Prasanna Santhanam
committed
Refactoring vlan and globalsetting tests
Refactoring the vlan and global_setting tests to use the marvin libraries instead of command classes. Signed-off-by: Prasanna Santhanam <tsp@apache.org>
1 parent 9572f57 commit a1912d9

3 files changed

Lines changed: 61 additions & 113 deletions

File tree

test/integration/smoke/test_global_settings.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,25 @@
1717
""" P1 tests for updating the granular Configuration parameter with scope and resource id provided.
1818
"""
1919
#Import Local Modules
20-
import marvin
2120
from marvin.cloudstackTestCase import *
2221
from marvin.cloudstackAPI import *
23-
from marvin.remoteSSHClient import remoteSSHClient
2422
from marvin.integration.lib.utils import *
2523
from marvin.integration.lib.base import *
2624
from marvin.integration.lib.common import *
27-
from nose.plugins.attrib import attr
2825
#Import System modules
29-
import unittest
30-
import hashlib
31-
import random
3226

3327
class TestUpdateConfigWithScope(cloudstackTestCase):
3428
"""
35-
This test updates the value of a configuration parameter
36-
which is at zone level(scope)
29+
Test to update a configuration (global setting) at various scopes
3730
"""
3831
def setUp(self):
39-
"""
40-
CloudStack internally saves its passwords in md5 form and that is how we
41-
specify it in the API. Python's hashlib library helps us to quickly hash
42-
strings as follows
43-
"""
44-
mdf = hashlib.md5()
45-
mdf.update('password')
46-
mdf_pass = mdf.hexdigest()
47-
48-
self.apiClient = self.testClient.getApiClient() #Get ourselves an API client
49-
50-
32+
self.apiClient = self.testClient.getApiClient()
5133

5234
def test_UpdateConfigParamWithScope(self):
53-
35+
"""
36+
test update configuration setting at zone level scope
37+
@return:
38+
"""
5439
updateConfigurationCmd = updateConfiguration.updateConfigurationCmd()
5540
updateConfigurationCmd.name = "use.external.dns"
5641
updateConfigurationCmd.value = "true"
@@ -70,13 +55,15 @@ def test_UpdateConfigParamWithScope(self):
7055
returns a non-empty response")
7156

7257
configParam = listConfigurationsResponse[0]
73-
7458
self.assertEqual(configParam.value, updateConfigurationResponse.value, "Check if the update API returned \
7559
is the same as the one we got in the list API")
7660

7761

7862
def tearDown(self):
79-
63+
"""
64+
Reset the configuration back to false
65+
@return:
66+
"""
8067
updateConfigurationCmd = updateConfiguration.updateConfigurationCmd()
8168
updateConfigurationCmd.name = "use.external.dns"
8269
updateConfigurationCmd.value = "false"

test/integration/smoke/test_non_contigiousvlan.py

Lines changed: 50 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -14,112 +14,73 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
""" BVT tests for Primary Storage
18-
"""
19-
import marvin
17+
2018
from marvin import cloudstackTestCase
21-
from marvin.cloudstackTestCase import *
19+
from marvin.cloudstackAPI import *
20+
from marvin.cloudstackTestCase import cloudstackTestCase
21+
from marvin.integration.lib.base import Account
22+
from marvin.integration.lib.base import PhysicalNetwork
23+
from nose.plugins.attrib import attr
2224

23-
import unittest
24-
import hashlib
25-
import random
25+
class Services():
26+
def __init__(self):
27+
self.services = {
28+
"vlan": {
29+
"part": ["4090-4091", "4092-4096"],
30+
"full": "4090-4096",
31+
}
32+
}
2633

2734

35+
@attr(tags = ["simulator", "advanced"])
2836
class TestUpdatePhysicalNetwork(cloudstackTestCase):
2937
"""
30-
This test updates the existing physicalnetwork with a new vlan range.
38+
Test to extend physical network vlan range
3139
"""
3240
def setUp(self):
33-
"""
34-
CloudStack internally saves its passwords in md5 form and that is how we
35-
specify it in the API. Python's hashlib library helps us to quickly hash
36-
strings as follows
37-
"""
38-
mdf = hashlib.md5()
39-
mdf.update('password')
40-
mdf_pass = mdf.hexdigest()
41+
self.vlan = Services().services["vlan"]
42+
self.apiClient = self.testClient.getApiClient()
4143

42-
self.apiClient = self.testClient.getApiClient() #Get ourselves an API client
4344

44-
self.acct = createAccount.createAccountCmd() #The createAccount command
45-
self.acct.accounttype = 0 #We need a regular user. admins have accounttype=1
46-
self.acct.firstname = 'bharat'
47-
self.acct.lastname = 'kumar' #What's up doc?
48-
self.acct.password = mdf_pass #The md5 hashed password string
49-
self.acct.username = 'bharat'
50-
self.acct.email = 'bharat@kumar.com'
51-
self.acct.account = 'bharat'
52-
self.acct.domainid = 1 #The default ROOT domain
53-
self.acctResponse = self.apiClient.createAccount(self.acct)
54-
# using the default debug logger of the test framework
55-
self.debug("successfully created account: %s, user: %s, id: \
56-
%s"%(self.acctResponse.account.account, \
57-
self.acctResponse.account.username, \
58-
self.acctResponse.account.id))
59-
60-
def test_UpdatePhysicalNetwork(self):
45+
def test_extendPhysicalNetworkVlan(self):
6146
"""
62-
Let's start by defining the attributes of our VM that we will be
63-
deploying on CloudStack. We will be assuming a single zone is available
64-
and is configured and all templates are Ready
65-
66-
The hardcoded values are used only for brevity.
47+
Test to update a physical network and extend its vlan
6748
"""
68-
listPhysicalNetworksCmd = listPhysicalNetworks.listPhysicalNetworksCmd()
69-
listPhysicalNetworksResponse = self.apiClient.listPhysicalNetworks(listPhysicalNetworksCmd)
70-
71-
self.assertNotEqual(len(listPhysicalNetworksResponse), 0, "Check if the list API \
72-
returns a non-empty response")
73-
74-
networkid = listPhysicalNetworksResponse[0].id
75-
updatePhysicalNetworkCmd = updatePhysicalNetwork.updatePhysicalNetworkCmd()
76-
updatePhysicalNetworkCmd.id = networkid
77-
updatePhysicalNetworkCmd.vlan = "4090-4091"
78-
updatePhysicalNetworkResponse = self.apiClient.updatePhysicalNetwork(updatePhysicalNetworkCmd)
79-
self.assertNotEqual((updatePhysicalNetworkResponse.len), 0, "Check if the list API \
80-
returns a non-empty response")
81-
82-
updatePhysicalNetworkCmd = updatePhysicalNetwork.updatePhysicalNetworkCmd()
83-
updatePhysicalNetworkCmd.id = networkid
84-
updatePhysicalNetworkCmd.vlan = "4092-4096"
85-
updatePhysicalNetworkResponse = self.apiClient.updatePhysicalNetwork(updatePhysicalNetworkCmd)
86-
self.assertNotEqual((updatePhysicalNetworkResponse.len), 0, "Check if the list API \
87-
returns a non-empty response")
49+
phy_networks = PhysicalNetwork.list(self.apiClient)
50+
self.assertNotEqual(len(phy_networks), 0,
51+
msg="There are no physical networks in the zone")
8852

89-
vlanranges= updatePhysicalNetworkResponse.vlan
90-
range = ""
91-
vlanranges = vlanranges.split(";")
92-
for vlan in vlanranges:
93-
if (vlan == "4090-4096"):
94-
range = vlan
95-
96-
self.assertEqual(range, "4090-4096", "check if adding the range is successful")
53+
self.network = phy_networks[0]
54+
self.networkid = phy_networks[0].id
55+
vlan1 = self.vlan["part"][0]
56+
updatePhysicalNetworkResponse = self.network.update(self.apiClient, id = self.networkid, vlan = vlan1)
57+
self.assert_(updatePhysicalNetworkResponse is not None,
58+
msg="couldn't extend the physical network with vlan %s"%vlan1)
59+
self.assert_(isinstance(self.network, PhysicalNetwork))
9760

98-
updatePhysicalNetworkCmd = updatePhysicalNetwork.updatePhysicalNetworkCmd()
99-
updatePhysicalNetworkCmd.id = networkid
100-
updatePhysicalNetworkCmd.removevlan = "4090-4096"
101-
updatePhysicalNetworkResponse = self.apiClient.updatePhysicalNetwork(updatePhysicalNetworkCmd)
102-
self.assertNotEqual((updatePhysicalNetworkResponse.len), 0, "Check if the list API \
103-
returns a non-empty response")
61+
vlan2 = self.vlan["part"][1]
62+
updatePhysicalNetworkResponse2 = self.network.update(self.apiClient, id = self.networkid, vlan = vlan2)
63+
self.assert_(updatePhysicalNetworkResponse2 is not None,
64+
msg="couldn't extend the physical network with vlan %s"%vlan2)
65+
self.assert_(isinstance(self.network, PhysicalNetwork))
10466

105-
vlanranges= updatePhysicalNetworkResponse.vlan
106-
range = ""
107-
vlanranges = vlanranges.split(";")
67+
vlanranges= updatePhysicalNetworkResponse2.vlan
68+
self.assert_(vlanranges is not None,
69+
"No VLAN ranges found on the deployment")
70+
self.assert_(vlanranges.find(self.vlan["full"]) > 0, "vlan ranges are not extended")
10871

109-
for vlan in vlanranges:
110-
if (vlan == "4090-4096"):
111-
range = vlan
112-
113-
114-
self.assertEqual(range, "", "check if removing the range is successful")
11572

116-
117-
def tearDown(self): # Teardown will delete the Account as well as the VM once the VM reaches "Running" state
73+
def tearDown(self):
11874
"""
119-
And finally let us cleanup the resources we created by deleting the
120-
account. All good unittests are atomic and rerunnable this way
75+
Teardown to update a physical network and shrink its vlan
76+
@return:
12177
"""
122-
deleteAcct = deleteAccount.deleteAccountCmd()
123-
deleteAcct.id = self.acctResponse.account.id
124-
self.apiClient.deleteAccount(deleteAcct)
78+
phy_networks = PhysicalNetwork.list(self.apiClient)
79+
self.assertNotEqual(len(phy_networks), 0,
80+
msg="There are no physical networks in the zone")
81+
self.network = phy_networks[0]
82+
self.networkid = phy_networks[0].id
83+
updateResponse = self.network.update(self.apiClient, id = self.networkid, removevlan = self.vlan["full"])
84+
self.assert_(updateResponse.vlan.find(self.vlan["full"]) > 0,
85+
"VLAN was not removed successfully")
12586

tools/marvin/marvin/integration/lib/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ def list(cls, apiclient, **kwargs):
19941994

19951995
cmd = listPhysicalNetworks.listPhysicalNetworksCmd()
19961996
[setattr(cmd, k, v) for k, v in kwargs.items()]
1997-
return(apiclient.listPhysicalNetworks(cmd))
1997+
return map(lambda pn : PhysicalNetwork(pn.__dict__), apiclient.listPhysicalNetworks(cmd))
19981998

19991999
class SecurityGroup:
20002000
"""Manage Security Groups"""

0 commit comments

Comments
 (0)