Skip to content

Commit fe48bbe

Browse files
author
Prasanna Santhanam
committed
moving out the vmpasswd into its own suite
vm passwords are extended features that don't need to be part of the smoke suite. Signed-off-by: Prasanna Santhanam <tsp@apache.org>
1 parent 3075d0c commit fe48bbe

3 files changed

Lines changed: 243 additions & 171 deletions

File tree

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
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+
import marvin
18+
from marvin.cloudstackTestCase import *
19+
from marvin.cloudstackAPI import *
20+
from marvin.remoteSSHClient import remoteSSHClient
21+
from marvin.integration.lib.utils import *
22+
from marvin.integration.lib.base import *
23+
from marvin.integration.lib.common import *
24+
from nose.plugins.attrib import attr
25+
26+
27+
_multiprocess_shared_ = True
28+
class Services:
29+
"""Test VM Life Cycle Services
30+
"""
31+
32+
def __init__(self):
33+
self.services = {
34+
"disk_offering":{
35+
"displaytext": "Small",
36+
"name": "Small",
37+
"disksize": 1
38+
},
39+
"account": {
40+
"email": "test@test.com",
41+
"firstname": "Test",
42+
"lastname": "User",
43+
"username": "test",
44+
# Random characters are appended in create account to
45+
# ensure unique username generated each time
46+
"password": "password",
47+
},
48+
"service_offerings":
49+
{
50+
"small":
51+
{
52+
# Small service offering ID to for change VM
53+
# service offering from medium to small
54+
"name": "Small Instance",
55+
"displaytext": "Small Instance",
56+
"cpunumber": 1,
57+
"cpuspeed": 100,
58+
"memory": 256,
59+
},
60+
},
61+
"template": {
62+
"displaytext": "Cent OS Template",
63+
"name": "Cent OS Template",
64+
"passwordenabled": True,
65+
},
66+
"sleep": 60,
67+
"timeout": 10,
68+
"ostype": 'CentOS 5.3 (64-bit)',
69+
# CentOS 5.3 (64-bit)
70+
}
71+
72+
@unittest.skip("Additional test")
73+
class TestVMPasswordEnabled(cloudstackTestCase):
74+
75+
@classmethod
76+
def setUpClass(cls):
77+
cls.api_client = super(
78+
TestVMPasswordEnabled,
79+
cls
80+
).getClsTestClient().getApiClient()
81+
cls.services = Services().services
82+
83+
# Get Zone, Domain and templates
84+
domain = get_domain(cls.api_client, cls.services)
85+
zone = get_zone(cls.api_client, cls.services)
86+
template = get_template(
87+
cls.api_client,
88+
zone.id,
89+
cls.services["ostype"]
90+
)
91+
# Set Zones and disk offerings
92+
cls.services["small"]["zoneid"] = zone.id
93+
cls.services["small"]["template"] = template.id
94+
95+
# Create VMs, NAT Rules etc
96+
cls.account = Account.create(
97+
cls.api_client,
98+
cls.services["account"],
99+
domainid=domain.id
100+
)
101+
102+
cls.small_offering = ServiceOffering.create(
103+
cls.api_client,
104+
cls.services["service_offerings"]["small"]
105+
)
106+
107+
cls.virtual_machine = VirtualMachine.create(
108+
cls.api_client,
109+
cls.services["small"],
110+
accountid=cls.account.account.name,
111+
domainid=cls.account.account.domainid,
112+
serviceofferingid=cls.small_offering.id,
113+
mode=cls.services["mode"]
114+
)
115+
#Stop virtual machine
116+
cls.virtual_machine.stop(cls.api_client)
117+
118+
# Poll listVM to ensure VM is stopped properly
119+
timeout = cls.services["timeout"]
120+
while True:
121+
time.sleep(cls.services["sleep"])
122+
123+
# Ensure that VM is in stopped state
124+
list_vm_response = list_virtual_machines(
125+
cls.api_client,
126+
id=cls.virtual_machine.id
127+
)
128+
129+
if isinstance(list_vm_response, list):
130+
131+
vm = list_vm_response[0]
132+
if vm.state == 'Stopped':
133+
break
134+
135+
if timeout == 0:
136+
raise Exception(
137+
"Failed to stop VM (ID: %s) in change service offering" %
138+
vm.id)
139+
140+
timeout = timeout - 1
141+
142+
list_volume = list_volumes(
143+
cls.api_client,
144+
virtualmachineid=cls.virtual_machine.id,
145+
type='ROOT',
146+
listall=True
147+
)
148+
if isinstance(list_volume, list):
149+
cls.volume = list_volume[0]
150+
else:
151+
raise Exception(
152+
"Exception: Unable to find root volume foe VM: %s" %
153+
cls.virtual_machine.id)
154+
155+
cls.services["template"]["ostype"] = cls.services["ostype"]
156+
#Create templates for Edit, Delete & update permissions testcases
157+
cls.pw_enabled_template = Template.create(
158+
cls.api_client,
159+
cls.services["template"],
160+
cls.volume.id,
161+
account=cls.account.account.name,
162+
domainid=cls.account.account.domainid
163+
)
164+
# Delete the VM - No longer needed
165+
cls.virtual_machine.delete(cls.api_client)
166+
cls.services["small"]["template"] = cls.pw_enabled_template.id
167+
168+
cls.vm = VirtualMachine.create(
169+
cls.api_client,
170+
cls.services["small"],
171+
accountid=cls.account.account.name,
172+
domainid=cls.account.account.domainid,
173+
serviceofferingid=cls.small_offering.id,
174+
mode=cls.services["mode"]
175+
)
176+
cls._cleanup = [
177+
cls.small_offering,
178+
cls.pw_enabled_template,
179+
cls.account
180+
]
181+
182+
@classmethod
183+
def tearDownClass(cls):
184+
# Cleanup VMs, templates etc.
185+
cleanup_resources(cls.api_client, cls._cleanup)
186+
return
187+
188+
def setUp(self):
189+
self.apiclient = self.testClient.getApiClient()
190+
self.dbclient = self.testClient.getDbConnection()
191+
self.cleanup = []
192+
193+
def tearDown(self):
194+
#Clean up, terminate the created instances
195+
cleanup_resources(self.apiclient, self.cleanup)
196+
return
197+
198+
@attr(tags = ["advanced", "advancedns", "smoke", "basic", "sg"])
199+
def test_11_get_vm_password(self):
200+
"""Test get VM password for password enabled template"""
201+
202+
# Validate the following
203+
# 1. Create an account
204+
# 2. Deploy VM with default service offering and "password enabled"
205+
# template. Vm should be in running state.
206+
# 3. Stop VM deployed in step 2
207+
# 4. Reset VM password. SSH with new password should be successful
208+
209+
self.debug("Stopping VM: %s" % self.vm.name)
210+
self.vm.stop(self.apiclient)
211+
212+
# Sleep to ensure VM is stopped properly
213+
time.sleep(self.services["sleep"])
214+
215+
self.debug("Resetting VM password for VM: %s" % self.vm.name)
216+
password = self.vm.resetPassword(self.apiclient)
217+
self.debug("Password reset to: %s" % password)
218+
219+
self.debug("Starting VM to verify new password..")
220+
self.vm.start(self.apiclient)
221+
self.debug("VM - %s stated!" % self.vm.name)
222+
223+
vms = VirtualMachine.list(self.apiclient, id=self.vm.id, listall=True)
224+
self.assertEqual(
225+
isinstance(vms, list),
226+
True,
227+
"List VMs should retun valid response for VM: %s" % self.vm.name
228+
)
229+
virtual_machine = vms[0]
230+
231+
self.assertEqual(
232+
virtual_machine.state,
233+
"Running",
234+
"VM state should be running"
235+
)
236+
try:
237+
self.debug("SSHing into VM: %s" % self.vm.ssh_ip)
238+
self.vm.password = password
239+
ssh = self.vm.get_ssh_client()
240+
except Exception as e:
241+
self.fail("SSH into VM: %s failed" % self.vm.ssh_ip)
242+
return

0 commit comments

Comments
 (0)