forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_deploy_vm_userdata_multi_nic.py
More file actions
188 lines (161 loc) · 6.84 KB
/
Copy pathtest_deploy_vm_userdata_multi_nic.py
File metadata and controls
188 lines (161 loc) · 6.84 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# 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.
# this script will cover VMdeployment with Userdata tests for MultiNic
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.base import (Account,
Network,
NetworkOffering,
ServiceOffering,
VirtualMachine)
from marvin.lib.common import (get_domain,
get_template,
get_zone,
list_virtual_machines)
from marvin.lib.utils import cleanup_resources
from nose.plugins.attrib import attr
import base64
import random
import string
_multiprocess_shared_ = True
class TestDeployVmWithUserDataMultiNic(cloudstackTestCase):
"""Tests for UserData
"""
@classmethod
def setUpClass(cls):
cls.testClient = super(TestDeployVmWithUserDataMultiNic, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.test_data = cls.testClient.getParsedTestDataConfig()
# Get Domain, Zone, Template
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(
cls.api_client,
cls.testClient.getZoneForTests())
cls.template = get_template(
cls.api_client,
cls.zone.id,
cls.test_data["ostype"]
)
if cls.zone.localstorageenabled:
cls.storagetype = 'local'
cls.test_data["service_offerings"][
"tiny"]["storagetype"] = 'local'
else:
cls.storagetype = 'shared'
cls.test_data["service_offerings"][
"tiny"]["storagetype"] = 'shared'
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.test_data["service_offerings"]["tiny"]
)
# Create Network offering without userdata
cls.network_offering_nouserdata = NetworkOffering.create(
cls.api_client,
cls.test_data["network_offering"]
)
# Enable Network offering
cls.network_offering_nouserdata.update(cls.api_client, state='Enabled')
# Create Network Offering with all the services
cls.network_offering_all = NetworkOffering.create(
cls.api_client,
cls.test_data["isolated_network_offering"]
)
# Enable Network offering
cls.network_offering_all.update(cls.api_client, state='Enabled')
cls._cleanup = [
cls.service_offering,
cls.network_offering_nouserdata,
cls.network_offering_all
]
# Generate userdata of 2500 bytes. This is larger than the 2048 bytes limit.
# CS however allows for upto 4K bytes in the code. So this must succeed.
# Overall, the query length must not exceed 4K, for then the json decoder
# will fail this operation at the marvin client side itcls.
cls.userdata = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(2500))
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
self.dbclient = self.testClient.getDbConnection()
self.account = Account.create(
self.apiclient,
self.test_data["account"],
admin=True,
domainid=self.domain.id
)
self.cleanup = []
return
def tearDown(self):
try:
self.account.delete(self.apiclient)
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["simulator", "devcloud", "basic", "advanced"], required_hardware="false")
def test_deployvm_multinic(self):
"""Test userdata update when non default nic is without userdata for deploy and update
"""
self.userdata = base64.encodebytes(self.userdata.encode()).decode()
network1 = Network.create(
self.apiclient,
self.test_data["isolated_network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering_all.id,
zoneid=self.zone.id
)
self.test_data["network_without_acl"]["netmask"] = "255.255.255.128"
network2 = Network.create(
self.apiclient,
self.test_data["network_without_acl"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering_nouserdata.id,
gateway="10.2.1.1",
zoneid=self.zone.id
)
deployVmResponse = VirtualMachine.create(
self.apiclient,
services=self.test_data["virtual_machine_userdata"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
networkids=[str(network1.id), str(network2.id)],
templateid=self.template.id,
zoneid=self.zone.id
)
vms = list_virtual_machines(
self.apiclient,
account=self.account.name,
domainid=self.account.domainid,
id=deployVmResponse.id
)
self.assertTrue(len(vms) > 0, "There are no Vms deployed in the account %s" % self.account.name)
vm = vms[0]
self.assertTrue(vm.id == str(deployVmResponse.id), "Vm deployed is different from the test")
self.assertTrue(vm.state == "Running", "VM is not in Running state")
try:
updateresponse = deployVmResponse.update(self.apiclient, userdata=self.userdata)
except Exception as e:
self.fail("Failed to update userdata: %s" % e)
self.debug("virtual machine update response is: %s" % updateresponse)
@classmethod
def tearDownClass(cls):
try:
# Cleanup resources used
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)