|
14 | 14 | # KIND, either express or implied. See the License for the |
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | | -""" BVT tests for Primary Storage |
18 | | -""" |
19 | | -import marvin |
| 17 | + |
20 | 18 | 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 |
22 | 24 |
|
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 | + } |
26 | 33 |
|
27 | 34 |
|
| 35 | +@attr(tags = ["simulator", "advanced"]) |
28 | 36 | class TestUpdatePhysicalNetwork(cloudstackTestCase): |
29 | 37 | """ |
30 | | - This test updates the existing physicalnetwork with a new vlan range. |
| 38 | + Test to extend physical network vlan range |
31 | 39 | """ |
32 | 40 | 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() |
41 | 43 |
|
42 | | - self.apiClient = self.testClient.getApiClient() #Get ourselves an API client |
43 | 44 |
|
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): |
61 | 46 | """ |
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 |
67 | 48 | """ |
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") |
88 | 52 |
|
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)) |
97 | 60 |
|
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)) |
104 | 66 |
|
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") |
108 | 71 |
|
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") |
115 | 72 |
|
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): |
118 | 74 | """ |
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: |
121 | 77 | """ |
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") |
125 | 86 |
|
0 commit comments