Skip to content

Commit 3e3a403

Browse files
author
shweta agarwal
committed
automated 9277 9276 9275 9274 9273 9179 9178 9177
1 parent 7017a82 commit 3e3a403

8 files changed

Lines changed: 821 additions & 22 deletions

File tree

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
#Import Local Modules
19+
from marvin.cloudstackTestCase import cloudstackTestCase
20+
from marvin.lib.utils import (cleanup_resources,
21+
validateList,
22+
get_hypervisor_type)
23+
from marvin.lib.base import (Account,
24+
VirtualMachine,
25+
ServiceOffering,
26+
Volume,
27+
DiskOffering,
28+
Template,
29+
listConfigurations,Configurations)
30+
from marvin.lib.common import (get_domain,list_isos,
31+
get_zone,
32+
get_template)
33+
from nose.plugins.attrib import attr
34+
from ast import literal_eval
35+
from marvin.codes import PASS
36+
from marvin.cloudstackException import CloudstackAPIException
37+
from marvin.sshClient import SshClient
38+
from marvin.cloudstackException import CloudstackAPIException
39+
import time
40+
41+
class TestInstance(cloudstackTestCase):
42+
43+
@classmethod
44+
def setUpClass(cls):
45+
try:
46+
cls._cleanup = []
47+
cls.testClient = super(TestInstance, cls).getClsTestClient()
48+
cls.api_client = cls.testClient.getApiClient()
49+
cls.services = cls.testClient.getParsedTestDataConfig()
50+
# Get Domain, Zone, Template
51+
cls.domain = get_domain(cls.api_client)
52+
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
53+
cls.template = get_template(
54+
cls.api_client,
55+
cls.zone.id,
56+
cls.services["ostype"]
57+
)
58+
if cls.zone.localstorageenabled:
59+
cls.storagetype = 'local'
60+
cls.services["service_offerings"]["tiny"]["storagetype"] = 'local'
61+
cls.services["disk_offering"]["storagetype"] = 'local'
62+
else:
63+
cls.storagetype = 'shared'
64+
cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared'
65+
cls.services["disk_offering"]["storagetype"] = 'shared'
66+
67+
cls.services['mode'] = cls.zone.networktype
68+
cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo()
69+
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
70+
cls.services["virtual_machine"]["template"] = cls.template.id
71+
cls.services["custom_volume"]["zoneid"] = cls.zone.id
72+
# Creating Disk offering, Service Offering and Account
73+
cls.disk_offering = DiskOffering.create(
74+
cls.api_client,
75+
cls.services["disk_offering"]
76+
)
77+
cls.service_offering = ServiceOffering.create(
78+
cls.api_client,
79+
cls.services["service_offerings"]["small"]
80+
)
81+
cls.account = Account.create(
82+
cls.api_client,
83+
cls.services["account"],
84+
domainid=cls.domain.id
85+
)
86+
# Getting authentication for user in newly created Account
87+
cls.user = cls.account.user[0]
88+
cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name)
89+
cls._cleanup.append(cls.disk_offering)
90+
cls._cleanup.append(cls.service_offering)
91+
cls._cleanup.append(cls.account)
92+
cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__
93+
except Exception as e:
94+
cls.tearDownClass()
95+
raise Exception("Warning: Exception in setup : %s" % e)
96+
return
97+
98+
def setUp(self):
99+
100+
self.apiClient = self.testClient.getApiClient()
101+
self.cleanup = []
102+
103+
def tearDown(self):
104+
#Clean up, terminate the created volumes
105+
cleanup_resources(self.apiClient, self.cleanup)
106+
return
107+
108+
@classmethod
109+
def tearDownClass(cls):
110+
try:
111+
cleanup_resources(cls.api_client, cls._cleanup)
112+
except Exception as e:
113+
raise Exception("Warning: Exception during cleanup : %s" % e)
114+
115+
def RestartServers(self):
116+
""" Restart management server and usage server """
117+
118+
sshClient = SshClient(
119+
self.mgtSvrDetails["mgtSvrIp"],
120+
22,
121+
self.mgtSvrDetails["user"],
122+
self.mgtSvrDetails["passwd"]
123+
)
124+
command = "service cloudstack-management restart"
125+
sshClient.execute(command)
126+
return
127+
128+
def updateConfigurAndRestart(self,name, value):
129+
Configurations.update(self.apiClient,
130+
name,value )
131+
self.RestartServers()
132+
time.sleep(self.services["sleep"])
133+
134+
@attr(tags=["advanced"], required_hardware="true")
135+
def test1_attach_volume(self):
136+
"""
137+
@desc: Unable to attach 7th Disk to windows server 2012R2 instance
138+
Step1: Set global config vmware.root.disk.controller to 'osdefault'
139+
Step2: Deploy a Windows 2012 R2 instance.
140+
Step3: Attach 6 disks to the VM.
141+
Step4: Try attaching a 7th disk to the VM
142+
Verify that step4 succeeds without any exception
143+
"""
144+
self.hypervisor = str(get_hypervisor_type(self.api_client)).lower()
145+
if self.hypervisor != "vmware":
146+
self.skipTest("This test can be run only on vmware")
147+
self.updateConfigurAndRestart("vmware.root.disk.controller","osdefault")
148+
149+
150+
template = Template.register(
151+
self.userapiclient,
152+
self.services["Windows Server 2012"],
153+
zoneid=self.zone.id,
154+
account=self.account.name,
155+
domainid=self.account.domainid
156+
)
157+
self.assertIsNotNone(template,"Failed to register Windows server 2012 R2 template")
158+
self.debug(
159+
"Registered a template with format {} and id {}".format(
160+
self.services["Windows Server 2012"]["format"],template.id)
161+
)
162+
template.download(self.userapiclient)
163+
self.cleanup.append(template)
164+
165+
# Creating a big service offering for windows VM launch
166+
big_service_offering = ServiceOffering.create(
167+
self.apiClient,
168+
self.services["service_offerings"]["big"]
169+
)
170+
self.cleanup.append(big_service_offering)
171+
vm = VirtualMachine.create(
172+
self.userapiclient,
173+
self.services["virtual_machine"],
174+
accountid=self.account.name,
175+
domainid=self.account.domainid,
176+
serviceofferingid=big_service_offering.id,
177+
templateid=template.id,
178+
zoneid=self.zone.id
179+
)
180+
self.assertIsNotNone(vm,"Failed to deploy virtual machine")
181+
self.cleanup.append(vm)
182+
response = VirtualMachine.list(self.userapiclient,id=vm.id)
183+
status = validateList(response)
184+
self.assertEqual(status[0],PASS,"list vm response returned invalid list")
185+
186+
for i in range(0,7):
187+
self.services["volume"]["diskname"]=i
188+
disk = Volume.create(
189+
self.userapiclient,
190+
self.services["volume"],
191+
zoneid=self.zone.id,
192+
diskofferingid=self.disk_offering.id
193+
)
194+
self.assertIsNotNone(disk,"Failed to create custom volume")
195+
self.cleanup.append(disk)
196+
try:
197+
vm.attach_volume(self.userapiclient,disk)
198+
list_volumes = Volume.list(
199+
self.userapiclient,
200+
listall=self.services["listall"],
201+
id=disk.id
202+
)
203+
204+
attached_volume = list_volumes[0]
205+
self.assertEqual(
206+
disk.id,
207+
attached_volume.id,
208+
"list volume response does not match with the volume created and attached to vm"
209+
)
210+
except Exception as e:
211+
self.fail("Failed to attach {} data disk to Windows server 2012 R2 vm ".format(i))
212+
return
213+
@attr(tags=["advanced"], required_hardware="true")
214+
def test_Scale_VM(self):
215+
"""
216+
@desc:
217+
1. Enable dynamic scaling in Global settings
218+
2. Register an CentOS 7 tempplate(with tools) and tick dynamic scaling
219+
3. Deploy VM with this template
220+
4.Start the VM and try to change service offering
221+
222+
"""
223+
self.hypervisor = str(get_hypervisor_type(self.api_client)).lower()
224+
if self.hypervisor != "xenserver":
225+
self.skipTest("This test can be run only on xenserver")
226+
self.updateConfigurAndRestart("enable.dynamic.scale.vm","true")
227+
template = Template.register(
228+
self.userapiclient,
229+
self.services["CentOS7template"],
230+
zoneid=self.zone.id,
231+
account=self.account.name,
232+
domainid=self.account.domainid
233+
)
234+
self.assertIsNotNone(template,"Failed to register CentOS 7 template")
235+
self.debug(
236+
"Registered a template with format {} and id {}".format(
237+
self.services["Windows Server 2012"]["format"],template.id)
238+
)
239+
template.download(self.userapiclient)
240+
self.cleanup.append(template)
241+
vm = VirtualMachine.create(
242+
self.userapiclient,
243+
self.services["virtual_machine"],
244+
accountid=self.account.name,
245+
domainid=self.account.domainid,
246+
serviceofferingid=self.service_offering.id,
247+
templateid=template.id,
248+
zoneid=self.zone.id
249+
)
250+
self.assertIsNotNone(vm,"Failed to deploy virtual machine")
251+
self.cleanup.append(vm)
252+
response = VirtualMachine.list(self.userapiclient,id=vm.id)
253+
status = validateList(response)
254+
self.assertEqual(status[0],PASS,"list vm response returned invalid list")
255+
self.assertEqual(status[1].state,"Running", "vm is not running")
256+
257+
service_offering = ServiceOffering.create(
258+
self.apiClient,
259+
self.services["service_offerings"]["big"]
260+
)
261+
time.sleep(self.services["sleep"])
262+
vm.scale(self.userapiclient,service_offering.id)
263+
scaleresponse = VirtualMachine.list(self.userapiclient,id=vm.id)
264+
scalestatus = validateList(scaleresponse)
265+
self.assertEqual(scalestatus[0],PASS,"list vm response returned invalid list")
266+
self.assertEqual(scalestatus[1].serviceofferingname,service_offering.name, " service offering is not same")
267+
self.assertEqual(scalestatus[1].serviceofferingid,service_offering.id, " service offering ids are not same")
268+
269+
270+
return

test/integration/component/test_escalations_instances.py

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from marvin.sshClient import SshClient
4343
from nose.plugins.attrib import attr
4444
import time
45-
45+
from marvin.cloudstackException import CloudstackAPIException
4646

4747
class TestListInstances(cloudstackTestCase):
4848
@classmethod
@@ -2068,6 +2068,94 @@ def test_13_vm_nics(self):
20682068
"VM NIC is not same as expected"
20692069
)
20702070
return
2071+
@attr(tags=["advanced", "basic"], required_hardware="true")
2072+
def test_14_Create_vm_with_same_sshkey(self):
2073+
"""
2074+
@Desc: Test to verify API call Register ssh key pair fails when uses same public key for differnet key name
2075+
"""
2076+
2077+
2078+
# Listing all the SSH Key pairs
2079+
list_keypairs_before = SSHKeyPair.list(
2080+
self.userapiclient
2081+
)
2082+
list_keypairs_before_size = 0
2083+
if list_keypairs_before is not None:
2084+
list_keypairs_before_size = len(list_keypairs_before)
2085+
2086+
# Registering first Key pair
2087+
new_keypair1 = SSHKeyPair.register(
2088+
self.userapiclient,
2089+
name="keypair1",
2090+
publickey="ssh-rsa: e6:9a:1e:b5:98:75:88:5d:56:bc:92:7b:43:48:05:b2")
2091+
self.assertIsNotNone(
2092+
new_keypair1,
2093+
"New Key pair generation failed"
2094+
)
2095+
self.assertEquals(
2096+
"keypair1",
2097+
new_keypair1.name,
2098+
"Key Pair not created with given name"
2099+
)
2100+
# Listing all the SSH Key pairs again
2101+
list_keypairs_after = SSHKeyPair.list(
2102+
self.userapiclient
2103+
)
2104+
status = validateList(list_keypairs_after)
2105+
self.assertEquals(
2106+
PASS,
2107+
status[0],
2108+
"Listing of Key pairs failed"
2109+
)
2110+
# Verifying that list size is increased by 1
2111+
self.assertEquals(
2112+
list_keypairs_before_size + 1,
2113+
len(list_keypairs_after),
2114+
"List count is not matching"
2115+
)
2116+
try:
2117+
2118+
# Registering second key pair using same public key
2119+
new_keypair2 = SSHKeyPair.register(
2120+
self.userapiclient,
2121+
name="keypair2",
2122+
publickey="ssh-rsa: e6:9a:1e:b5:98:75:88:5d:56:bc:92:7b:43:48:05:b2")
2123+
self.fail("SSH Key creation passed using same public key ")
2124+
except CloudstackAPIException as e:
2125+
self.assertRaises("Exception Raised : %s" % e)
2126+
2127+
# Deploying a VM with keypair 1
2128+
first_vm_created = VirtualMachine.create(
2129+
self.userapiclient,
2130+
self.services["virtual_machine"],
2131+
accountid=self.account.name,
2132+
domainid=self.account.domainid,
2133+
serviceofferingid=self.service_offering.id,
2134+
keypair=new_keypair1.name
2135+
)
2136+
self.assertIsNotNone(
2137+
first_vm_created,
2138+
"VM creation failed"
2139+
)
2140+
# Listing all the VMs for a user again
2141+
list_vms_after = VirtualMachine.list(
2142+
self.userapiclient,id=first_vm_created.id,
2143+
listall=True,
2144+
)
2145+
status = validateList(list_vms_after)
2146+
self.assertEquals(
2147+
PASS,
2148+
status[0],
2149+
"VM creation failed"
2150+
)
2151+
vm = list_vms_after[0]
2152+
self.assertEqual(
2153+
vm.state,
2154+
"Running",
2155+
"VM state should be running after deployment")
2156+
self.assertEqual(vm.keypair , new_keypair1.name , "VM keypair name is not keypair1")
2157+
2158+
return
20712159

20722160

20732161
class TestInstances(cloudstackTestCase):

0 commit comments

Comments
 (0)