1818""" Component tests for - userdata
1919"""
2020# Import Local Modules
21- from marvin .lib .base import (VirtualMachine ,
22- Account ,
23- PublicIPAddress )
21+ from marvin .lib .base import (Account ,
22+ VirtualMachine ,
23+ Volume ,
24+ Template )
2425from nose .plugins .attrib import attr
2526from nuageTestCase import nuageTestCase
26- from marvin .cloudstackAPI import ( createTemplate ,
27- listVolumes )
27+ from marvin .lib . utils import cleanup_resources
28+ from marvin . cloudstackAPI import startVirtualMachine
2829import base64
2930
3031
@@ -69,12 +70,10 @@ def tearDown(self):
6970 # create_template - Takes the VM object as the argument to create the template
7071 def create_template (self , vm ):
7172 self .debug ("CREATE TEMPLATE" )
72- list_volume = list_volumes (
73- self .apiclient ,
74- virtualmachineid = vm .id ,
75- type = 'ROOT' ,
76- listall = True
77- )
73+ list_volume = Volume .list (self .apiclient ,
74+ virtualmachineid = vm .id ,
75+ type = 'ROOT' ,
76+ listall = True )
7877 if isinstance (list_volume , list ):
7978 self .volume = list_volume [0 ]
8079 else :
@@ -115,7 +114,6 @@ def create_and_verify_fw(self, vm, public_ip, network):
115114
116115 # VSD verification
117116 self .verify_vsp_floating_ip (network , vm , public_ip .ipaddress )
118- vm_public_ip = public_ip .ipaddress .ipaddress
119117
120118 fw_rule = self .create_firewall_rule (public_ip , self .test_data ["ingress_rule" ])
121119 self .verify_vsp_firewall_rule (fw_rule )
@@ -131,6 +129,35 @@ def create_and_verify_fw(self, vm, public_ip, network):
131129 if not gotFirewallPolicy :
132130 raise ValueError ('No firewall policy decision in vm interface' )
133131
132+ def stop_vm (self , vm ):
133+ self .debug ("STOP VM" )
134+ vm .stop (self .apiclient )
135+ list_vm_response = VirtualMachine .list (self .apiclient ,
136+ id = vm .id )
137+ if isinstance (list_vm_response , list ):
138+ vm = list_vm_response [0 ]
139+ if vm .state != 'Stopped' :
140+ raise Exception ("Failed to stop VM (ID: %s) " %
141+ self .vm .id )
142+ else :
143+ raise Exception ("Invalid response from list_virtual_machines VM (ID: %s) " %
144+ self .vm .id )
145+
146+ def install_cloud_set_guest_password_script (self , ssh_client ):
147+ self .debug ("GET CLOUD-SET-GUEST-PASSWORD" )
148+ cmd = "cd /etc/init.d;wget http://people.apache.org/~tsp/cloud-set-guest-password"
149+ result = self .execute_cmd (ssh_client , cmd )
150+ self .debug ("WGET CLOUD-SET-GUEST-PASSWORD: " + result )
151+ if "200 OK" not in result :
152+ self .fail ("failed to get file cloud-set-guest-password" )
153+ cmds = ["chmod +x /etc/init.d/cloud-set-guest-password" ,
154+ "chkconfig --add cloud-set-guest-password"
155+ ]
156+ for c in cmds :
157+ result = self .execute_cmd (ssh_client , c )
158+ self .debug ("get_set_password_file cmd " + c )
159+ self .debug ("get_set_password_file result " + result )
160+
134161 @attr (tags = ["advanced" , "nuagevsp" ], required_hardware = "true" )
135162 def test_01_UserDataPasswordReset (self ):
136163 self .debug ("START USER DATA PASSWORD RESET ON VM" )
@@ -211,7 +238,7 @@ def test_01_UserDataPasswordReset(self):
211238 self .stop_vm (self .vm_1 )
212239 self .create_template (self .vm_1 )
213240 self .debug ("DEPLOY VM 2 IN TEST NETWORK WITH NEW TEMPLATE" )
214- self .vm_1 = self .create_VM_in_Network (self .network_1 , "virtual_machine_pr" )
241+ self .vm_2 = self .create_VM_in_Network (self .network_1 , "virtual_machine_pr" )
215242 self .remove_vm2 = True
216243 self .debug ("STARTING VM_2 " )
217244 startCmd = startVirtualMachine .startVirtualMachineCmd ()
@@ -225,7 +252,7 @@ def test_01_UserDataPasswordReset(self):
225252 "Password enabled not working. Password same as virtual_machine password "
226253 )
227254 self .verify_vsp_vm (vm_2a )
228- self .debug ("GET PUBLIC IP, CREATE AND VERIFY FIREWALL RULES" )
255+ self .debug ("GET PUBLIC IP. CREATE AND VERIFIED FIREWALL RULES" )
229256 public_ip_2 = self .acquire_Public_IP (self .network_1 )
230257 self .create_and_verify_fw (self .vm_2 , public_ip_2 , self .network_1 )
231258
0 commit comments