Skip to content

Commit 7df67c2

Browse files
authored
Merge pull request #1949 from shwetaag/cruds2
Automated Cloudstack bugs 9277 9276 9275 9274 9273 9179 9178 9177
2 parents 3f7fca0 + d5d1bd9 commit 7df67c2

File tree

8 files changed

+821
-24
lines changed

8 files changed

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

test/integration/component/test_escalations_instances.py

Lines changed: 90 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,95 @@ 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+
2117+
# Deploying a VM with keypair 1
2118+
first_vm_created = VirtualMachine.create(
2119+
self.userapiclient,
2120+
self.services["virtual_machine"],
2121+
accountid=self.account.name,
2122+
domainid=self.account.domainid,
2123+
serviceofferingid=self.service_offering.id,
2124+
keypair=new_keypair1.name
2125+
)
2126+
self.assertIsNotNone(
2127+
first_vm_created,
2128+
"VM creation failed"
2129+
)
2130+
# Listing all the VMs for a user again
2131+
list_vms_after = VirtualMachine.list(
2132+
self.userapiclient,id=first_vm_created.id,
2133+
listall=True,
2134+
)
2135+
status = validateList(list_vms_after)
2136+
self.assertEquals(
2137+
PASS,
2138+
status[0],
2139+
"VM creation failed"
2140+
)
2141+
vm = list_vms_after[0]
2142+
self.assertEqual(
2143+
vm.state,
2144+
"Running",
2145+
"VM state should be running after deployment")
2146+
self.assertEqual(vm.keypair , new_keypair1.name , "VM keypair name is not keypair1")
2147+
2148+
try:
2149+
2150+
# Registering second key pair using same public key
2151+
new_keypair2 = SSHKeyPair.register(
2152+
self.userapiclient,
2153+
name="keypair2",
2154+
publickey="ssh-rsa: e6:9a:1e:b5:98:75:88:5d:56:bc:92:7b:43:48:05:b2")
2155+
self.fail("SSH Key creation passed using same public key ")
2156+
except CloudstackAPIException as e:
2157+
self.assertRaises("Exception Raised : %s" % e)
2158+
2159+
return
20712160

20722161

20732162
class TestInstances(cloudstackTestCase):

0 commit comments

Comments
 (0)