4242 StaticNATRule ,
4343 VirtualMachine ,
4444 VPC ,
45- VpcOffering )
45+ VpcOffering ,
46+ Hypervisor )
4647from marvin .lib .common import (get_domain ,
4748 get_template ,
4849 get_zone ,
@@ -145,6 +146,27 @@ def __init__(self):
145146 "Dns" : 'VirtualRouter'
146147 }
147148 },
149+ "shared_network_config_drive_offering" : {
150+ "name" : 'shared_network_config_drive_offering' ,
151+ "displaytext" : 'shared_network_config_drive_offering' ,
152+ "guestiptype" : 'shared' ,
153+ "supportedservices" : 'Dhcp,UserData' ,
154+ "traffictype" : 'GUEST' ,
155+ "specifyVlan" : "True" ,
156+ "specifyIpRanges" : "True" ,
157+ "availability" : 'Optional' ,
158+ "serviceProviderList" : {
159+ "Dhcp" : "VirtualRouter" ,
160+ "UserData" : 'ConfigDrive'
161+ }
162+ },
163+ "publiciprange2" : {
164+ "gateway" : "10.219.1.1" ,
165+ "netmask" : "255.255.255.0" ,
166+ "startip" : "10.219.1.2" ,
167+ "endip" : "10.219.1.5" ,
168+ "forvirtualnetwork" : "false"
169+ },
148170 "acl" : {
149171 "network_all_1" : {
150172 "name" : "SharedNetwork-All-1" ,
@@ -513,17 +535,22 @@ def update_provider_state(self, new_state):
513535 :rtype: str
514536 """
515537 self .debug ("Updating Service Provider ConfigDrive to %s" % new_state )
516- configdriveprovider = NetworkServiceProvider .list (
517- self .api_client ,
518- name = "ConfigDrive" ,
519- physicalnetworkid = self .vsp_physical_network .id )[0 ]
538+ configdriveprovider = self .get_configdrive_provider ()
520539 orig_state = configdriveprovider .state
521540 NetworkServiceProvider .update (self .api_client ,
522541 configdriveprovider .id ,
523542 state = new_state )
524543 self .validate_NetworkServiceProvider ("ConfigDrive" , state = new_state )
525544 return orig_state
526545
546+ def _get_test_data (self , key ):
547+ return self .test_data [key ]
548+
549+ def get_configdrive_provider (self ):
550+ return NetworkServiceProvider .list (
551+ self .api_client ,
552+ name = "ConfigDrive" )[0 ]
553+
527554 def verify_network_creation (self , offering = None ,
528555 offering_name = None ,
529556 gateway = None ,
@@ -549,7 +576,7 @@ def verify_network_creation(self, offering=None,
549576 if offering is None :
550577 self .debug ("Creating Nuage VSP network offering..." )
551578 offering = self .create_NetworkOffering (
552- self .test_data [ "nuagevsp" ][ offering_name ] )
579+ self ._get_test_data ( offering_name ) )
553580 self .validate_NetworkOffering (offering , state = "Enabled" )
554581 try :
555582 network = self .create_Network (offering ,
@@ -576,7 +603,7 @@ def verify_vpc_creation(self, offering=None, offering_name=None):
576603 if offering is None :
577604 self .debug ("Creating Nuage VSP VPC offering..." )
578605 offering = self .create_VpcOffering (
579- self .test_data [ "nuagevsp" ][ offering_name ] )
606+ self ._get_test_data ( offering_name ) )
580607 self .validate_VpcOffering (offering , state = "Enabled" )
581608 try :
582609 vpc = self .create_Vpc (offering , cidr = '10.1.0.0/16' )
@@ -627,7 +654,7 @@ def verify_config_drive_content(self, vm,
627654
628655 self .debug ("SSHing into the VM %s" % vm .name )
629656 if ssh_client is None :
630- ssh = self .ssh_into_VM (vm , public_ip , keypair = ssh_key )
657+ ssh = self .ssh_into_VM (vm , public_ip )
631658 else :
632659 ssh = ssh_client
633660 d = {x .name : x for x in ssh .logger .handlers }
@@ -674,7 +701,10 @@ def create_guest_vm(self, networks, acl_item=None,
674701 keypair = keypair )
675702 # Check VM
676703 self .check_VM_state (vm , state = "Running" )
677- self .verify_vsd_vm (vm )
704+
705+ if keypair :
706+ self .decrypt_password (vm )
707+
678708 # Check networks
679709 network_list = []
680710 if isinstance (networks , list ):
@@ -685,10 +715,9 @@ def create_guest_vm(self, networks, acl_item=None,
685715
686716 for network in network_list :
687717 self .validate_Network (network , state = "Implemented" )
688- self .verify_vsd_network (self .domain .id , network , vpc = vpc )
689718
690719 if acl_item is not None :
691- self .verify_vsd_firewall_rule (acl_item )
720+ self .validate_firewall_rule (acl_item )
692721 return vm
693722
694723 # nic_operation_VM - Performs NIC operations such as add, remove, and
@@ -754,12 +783,21 @@ def update_sshkeypair(self, vm):
754783 self .debug ("Sshkey reset to - %s" % self .keypair .name )
755784 vm .start (self .api_client )
756785
786+ vm .details = vm_new_ssh .details
787+
757788 # reset SSH key also resets the password.
758- # the new password is available in VM detail,
759- # named "Encrypted.Password".
760- # It is encrypted using the SSH Public Key,
761- # and thus can be decrypted using the SSH Private Key
789+ self . decrypt_password ( vm )
790+
791+ def decrypt_password ( self , vm ):
792+ """Decrypt VM password
762793
794+ the new password is available in VM detail,
795+ named "Encrypted.Password".
796+ It is encrypted using the SSH Public Key,
797+ and thus can be decrypted using the SSH Private Key
798+
799+ :type vm: VirtualMachine
800+ """
763801 try :
764802 from base64 import b64decode
765803 from Crypto .PublicKey import RSA
@@ -768,15 +806,14 @@ def update_sshkeypair(self, vm):
768806 key = RSA .importKey (pkfile .read ())
769807 cipher = PKCS1_v1_5 .new (key )
770808 new_password = cipher .decrypt (
771- b64decode (vm_new_ssh .details ['Encrypted.Password' ]), None )
809+ b64decode (vm .details ['Encrypted.Password' ]), None )
772810 if new_password :
773811 vm .password = new_password
774812 else :
775813 self .debug ("Failed to decrypt new password" )
776814 except :
777815 self .debug ("Failed to decrypt new password" )
778816
779-
780817 def add_subnet_verify (self , network , services ):
781818 """verify required nic is present in the VM"""
782819
@@ -806,6 +843,9 @@ def add_subnet_verify(self, network, services):
806843 )
807844 return addedsubnet
808845
846+ def ssh_into_VM (self , vm , public_ip , keypair ):
847+ pass
848+
809849
810850class TestConfigDrive (cloudstackTestCase , ConfigDriveUtils ):
811851 """Test user data and password reset functionality
@@ -838,6 +878,9 @@ def setUpClass(cls):
838878 cls .api_client ,
839879 cls .test_data ["service_offering" ])
840880 cls ._cleanup = [cls .service_offering ]
881+
882+ hypervisors = Hypervisor .list (cls .api_client , zoneid = cls .zone .id )
883+ cls .isSimulator = any (h .name == "Simulator" for h in hypervisors )
841884 return
842885
843886 def setUp (self ):
@@ -948,6 +991,39 @@ def validate_NetworkServiceProvider(self, provider_name, state=None):
948991 self .debug ("Successfully validated the creation and state of Network "
949992 "Service Provider - %s" % provider_name )
950993
994+ # validate_PublicIPAddress - Validates if the given public IP address is in
995+ # the expected state form the list of fetched public IP addresses
996+ def validate_PublicIPAddress (self , public_ip , network , static_nat = False ,
997+ vm = None ):
998+ """Validates the Public IP Address"""
999+ self .debug ("Validating the assignment and state of public IP address "
1000+ "- %s" % public_ip .ipaddress .ipaddress )
1001+ public_ips = PublicIPAddress .list (self .api_client ,
1002+ id = public_ip .ipaddress .id ,
1003+ networkid = network .id ,
1004+ isstaticnat = static_nat ,
1005+ listall = True
1006+ )
1007+ self .assertEqual (isinstance (public_ips , list ), True ,
1008+ "List public IP for network should return a "
1009+ "valid list"
1010+ )
1011+ self .assertEqual (public_ips [0 ].ipaddress ,
1012+ public_ip .ipaddress .ipaddress ,
1013+ "List public IP for network should list the assigned "
1014+ "public IP address"
1015+ )
1016+ self .assertEqual (public_ips [0 ].state , "Allocated" ,
1017+ "Assigned public IP is not in the allocated state"
1018+ )
1019+ if static_nat and vm :
1020+ self .assertEqual (public_ips [0 ].virtualmachineid , vm .id ,
1021+ "Static NAT rule is not enabled for the VM on "
1022+ "the assigned public IP"
1023+ )
1024+ self .debug ("Successfully validated the assignment and state of public "
1025+ "IP address - %s" % public_ip .ipaddress .ipaddress )
1026+
9511027 # create_NetworkOffering - Creates Network offering
9521028 def create_NetworkOffering (self , net_offering , suffix = None ,
9531029 conserve_mode = False ):
@@ -1095,7 +1171,8 @@ def validate_Vpc(self, vpc, state=None):
10951171 % vpc .name )
10961172
10971173 # ssh_into_VM - Gets into the shell of the given VM using its public IP
1098- def ssh_into_VM (self , vm , public_ip , reconnect = True , negative_test = False ):
1174+ def ssh_into_VM (self , vm , public_ip , reconnect = True ,
1175+ negative_test = False , keypair = None ):
10991176 self .debug ("SSH into VM with ID - %s on public IP address - %s" %
11001177 (vm .id , public_ip .ipaddress .ipaddress ))
11011178 tries = 1 if negative_test else 3
@@ -1782,22 +1859,18 @@ def test_configdrive_vpc_network(self):
17821859 metadata = True ,
17831860 userdata = expected_user_data ,
17841861 ssh_key = self .keypair )
1785- vpc_public_ip_2 = \
1786- self .acquire_PublicIPAddress (create_tiernetwork2 .network ,
1787- create_vpc .vpc )
1788- self .create_StaticNatRule_For_VM (vm , vpc_public_ip_2 ,
1789- create_tiernetwork2 .network )
1862+
17901863 vm .password = vm .resetPassword (self .api_client )
17911864 self .debug ("Password reset to - %s" % vm .password )
17921865 self .debug ("VM - %s password - %s !" %
17931866 (vm .name , vm .password ))
1794- self .verify_config_drive_content (vm , vpc_public_ip_2 ,
1867+ self .verify_config_drive_content (vm , vpc_public_ip_1 ,
17951868 self .PasswordTest (vm .password ),
17961869 metadata = True ,
17971870 userdata = expected_user_data ,
17981871 ssh_key = self .keypair )
17991872 expected_user_data1 = self .update_userdata (vm , "hellomultinicvm1" )
1800- self .verify_config_drive_content (vm , vpc_public_ip_2 ,
1873+ self .verify_config_drive_content (vm , vpc_public_ip_1 ,
18011874 self .PasswordTest (vm .password ),
18021875 userdata = expected_user_data1 ,
18031876 ssh_key = self .keypair )
@@ -1807,6 +1880,14 @@ def test_configdrive_vpc_network(self):
18071880 self .nic_operation_VM (vm ,
18081881 create_tiernetwork2 .network ,
18091882 operation = "update" )
1883+ vm .stop (self .api_client )
1884+ vm .start (self .api_client )
1885+ vpc_public_ip_2 = \
1886+ self .acquire_PublicIPAddress (create_tiernetwork2 .network ,
1887+ create_vpc .vpc )
1888+ self .create_StaticNatRule_For_VM (vm , vpc_public_ip_2 ,
1889+ create_tiernetwork2 .network )
1890+
18101891 self .verify_config_drive_content (vm , vpc_public_ip_2 ,
18111892 self .PasswordTest (vm .password ),
18121893 metadata = True ,
0 commit comments