def setUp(self): # Login Azure and change the mode self.azure_username = self.params.get('username', '*/AzureSub/*') self.azure_password = self.params.get('password', '*/AzureSub/*') self.azure_mode = self.params.get('azure_mode', '*/storage/*') azure_cli_common.login_azure(username=self.azure_username, password=self.azure_password) # Prepare the vm parameters and create a vm self.vm_params = dict() self.vm_params["username"] = self.params.get('username', '*/VMUser/*') self.vm_params["password"] = self.params.get('password', '*/VMUser/*') self.vm_params["VMSize"] = self.params.get('vm_size', '*/wala_conf/*') self.vm_params["VMName"] = self.params.get('vm_name', '*/wala_conf/*') self.vm_params["DNSName"] = self.vm_params["VMName"] self.vm_params["Image"] = self.params.get('name', '*/Image/*') self.vm_params["Location"] = self.params.get('location', '*/Image/*') self.vm_params["VMName"] = self.params.get('vm_name', '*/wala_conf/*') if self.azure_mode == "asm": azure_cli_common.set_config_mode("asm") self.vm_test01 = azure_asm_vm.VMASM(self.vm_params["VMName"], self.vm_params["VMSize"], self.vm_params) elif self.azure_mode == "arm": azure_cli_common.set_config_mode("asm") self.vm_test01 = azure_arm_vm.VMARM(self.vm_params["VMName"], self.vm_params["VMSize"], self.vm_params) self.log.debug("Create the vm %s", self.vm_params["VMName"]) self.vm_test01.vm_create() self.vm_test01.start()
def setUp(self): if "00_preparation" in self.name.name: utils_misc.host_command("azure account clear -q") time.sleep(3) # Get azure mode and choose test cases self.azure_mode = self.params.get('azure_mode', '*/azure_mode/*') self.log.info("AZURE_MODE: %s", self.azure_mode) if "test_test" in self.name.name: return if self.name.name.split(':')[-1] not in self.params.get('cases', '*/azure_mode/*'): self.skip("Skip case %s in Azure Mode %s" % (self.name.name, self.azure_mode)) # Login Azure and change the mode self.azure_username = self.params.get('username', '*/AzureSub/*') self.azure_password = self.params.get('password', '*/AzureSub/*') azure_cli_common.login_azure(username=self.azure_username, password=self.azure_password) # Source Instances # Set azure mode to ASM mode. Source storage account is classic azure_cli_common.set_config_mode("asm") # Prepare the storage account instance self.sto_src_params = dict() self.sto_src_params["name"] = self.params.get('name', '*/Prepare/storage_account/*') self.sto_src_params["location"] = self.params.get('location', '*/Prepare/storage_account/*') self.sto_src_params["type"] = self.params.get('type', '*/Prepare/storage_account/*') self.sto_src_test01 = azure_asm_vm.StorageAccount(name=self.sto_src_params["name"], params=self.sto_src_params) # Prepare the container instance self.container_src_params = dict() self.container_src_params["name"] = self.params.get('container', '*/Prepare/*') self.container_src_params["storage_account"] = self.sto_src_params["name"] self.container_src_test01 = azure_asm_vm.Container(name=self.container_src_params["name"], storage_account=self.container_src_params["storage_account"], params=self.container_src_params) # Prepare the blob instance self.blob_params = dict() self.blob_params["name"] = self.params.get('name', '*/DiskBlob/*') self.blob_params["container"] = self.container_src_params["name"] self.blob_params["storage_account"] = self.sto_src_params["name"] self.blob_test01 = azure_asm_vm.Blob(name=self.blob_params["name"], container=self.blob_params["container"], storage_account=self.blob_params["storage_account"], params=self.blob_params) self.vhd_file = self.params.get('vhd_file_path', '*/Prepare/*') + self.blob_params["name"] self.log.info("VHD file fullpath: %s" % self.vhd_file) self.no_upload = False if self.blob_test01.check_exist(): self.no_upload = True if "prepare_image" in self.name.name or \ "convert_image" in self.name.name: self.skip("VHD blob already exists. Skip this case") # Image basename (Only for asm mode) if self.azure_mode == "asm": self.image_basename = self.params.get('name', '*/Image/*') # VM basename self.vm_basename = "walaauto"
def setUp(self): # Get azure mode and choose test cases self.azure_mode = self.params.get('azure_mode', '*/azure_mode/*') self.log.debug("AZURE_MODE: %s", self.azure_mode) if self.name.name.split(':')[-1] not in self.params.get('cases', '*/azure_mode/*'): self.skip("Skip case %s in Azure Mode %s" % (self.name.name, self.azure_mode)) # Login Azure and change the mode self.azure_username = self.params.get('username', '*/AzureSub/*') self.azure_password = self.params.get('password', '*/AzureSub/*') azure_cli_common.login_azure(username=self.azure_username, password=self.azure_password) azure_cli_common.set_config_mode(self.azure_mode) # Prepare the vm parameters and create a vm self.vm_params = dict() self.vm_params["username"] = self.params.get('username', '*/VMUser/*') self.vm_params["password"] = self.params.get('password', '*/VMUser/*') self.vm_params["VMSize"] = self.params.get('vm_size', '*/azure_mode/*') self.vm_params["VMName"] = self.params.get('vm_name', '*/azure_mode/*') self.vm_params["VMName"] += self.vm_params["VMSize"].split('_')[-1].lower() self.vm_params["Location"] = self.params.get('location', '*/resourceGroup/*') self.vm_params["region"] = self.params.get('region', '*/resourceGroup/*') self.vm_params["StorageAccountName"] = self.params.get('storage_account', '*/resourceGroup/*') self.vm_params["Container"] = self.params.get('container', '*/resourceGroup/*') self.vm_params["DiskBlobName"] = self.params.get('name', '*/DiskBlob/*') self.vm_params["PublicPort"] = self.params.get('public_port', '*/network/*') self.vm_params["RedhatSubUsername"] = self.params.get('username', '*/RedhatSub/*') self.vm_params["RedhatSubPassword"] = self.params.get('password', '*/RedhatSub/*') if self.azure_mode == "asm": self.vm_params["Image"] = self.params.get('name', '*/Image/*') self.vm_params["DNSName"] = self.vm_params["VMName"] + ".cloudapp.net" self.vm_test01 = azure_asm_vm.VMASM(self.vm_params["VMName"], self.vm_params["VMSize"], self.vm_params["username"], self.vm_params["password"], self.vm_params) else: self.vm_params["DNSName"] = self.vm_params["VMName"] + "." + self.vm_params["region"] + ".cloudapp.azure.com" self.vm_params["ResourceGroupName"] = self.params.get('rg_name', '*/resourceGroup/*') self.vm_params["URN"] = "https://%s.blob.core.windows.net/%s/%s" % (self.vm_params["StorageAccountName"], self.vm_params["Container"], self.vm_params["DiskBlobName"]) self.vm_params["NicName"] = self.vm_params["VMName"] self.vm_params["PublicIpName"] = self.vm_params["VMName"] self.vm_params["PublicIpDomainName"] = self.vm_params["VMName"] self.vm_params["VnetName"] = self.vm_params["VMName"] self.vm_params["VnetSubnetName"] = self.vm_params["VMName"] self.vm_params["VnetAddressPrefix"] = self.params.get('vnet_address_prefix', '*/network/*') self.vm_params["VnetSubnetAddressPrefix"] = self.params.get('vnet_subnet_address_prefix', '*/network/*') self.vm_test01 = azure_arm_vm.VMARM(self.vm_params["VMName"], self.vm_params["VMSize"], self.vm_params["username"], self.vm_params["password"], self.vm_params) self.log.debug("Create the vm %s", self.vm_params["VMName"]) # If vm doesn't exist, create it. If it exists, start it. self.vm_test01.vm_update() if not self.vm_test01.exists(): self.vm_test01.vm_create(self.vm_params) self.vm_test01.wait_for_running() else: if not self.vm_test01.is_running(): self.vm_test01.start() self.vm_test01.wait_for_running() if not self.vm_test01.verify_alive(): self.error("VM %s is not available. Exit." % self.vm_params["VMName"]) self.project = self.params.get("Project", "*/Common/*") self.conf_file = "/etc/waagent.conf" # Increase sudo password timeout self.vm_test01.modify_value("Defaults timestamp_timeout", "-1", "/etc/sudoers", "=")
def setUp(self): # Get azure mode and choose test cases self.azure_mode = self.params.get('azure_mode', '*/azure_mode/*') self.log.debug("AZURE_MODE: %s", self.azure_mode) if self.name.name.split(':')[-1] not in self.params.get('cases', '*/azure_mode/*'): self.skip("Skip case %s in Azure Mode %s" % (self.name.name, self.azure_mode)) # Login Azure and change the mode self.azure_username = self.params.get('username', '*/AzureSub/*') self.azure_password = self.params.get('password', '*/AzureSub/*') azure_cli_common.login_azure(username=self.azure_username, password=self.azure_password) azure_cli_common.set_config_mode(self.azure_mode) # Prepare the vm parameters and create a vm self.vm_params = dict() self.vm_params["username"] = self.params.get('username', '*/VMUser/*') self.vm_params["password"] = self.params.get('password', '*/VMUser/*') self.vm_params["new_username"] = self.params.get('new_username', '*/VMUser/*') self.vm_params["new_password"] = self.params.get('new_password', '*/VMUser/*') self.vm_params["VMSize"] = self.params.get('vm_size', '*/azure_mode/*') self.vm_params["VMName"] = self.params.get('vm_name', '*/azure_mode/*') self.vm_params["VMName"] += self.vm_params["VMSize"].split('_')[-1].lower() self.vm_params["Location"] = self.params.get('location', '*/resourceGroup/*') self.vm_params["region"] = self.params.get('region', '*/resourceGroup/*') self.vm_params["StorageAccountName"] = self.params.get('storage_account', '*/resourceGroup/*') self.vm_params["Container"] = self.params.get('container', '*/resourceGroup/*') self.vm_params["DiskBlobName"] = self.params.get('name', '*/DiskBlob/*') self.vm_params["PublicPort"] = self.params.get('public_port', '*/network/*') if self.azure_mode == "asm": if "resize_vm" in self.name.name: self.skip("No Azure CLI in ASM mode that support this feature. Skip.") self.vm_params["Image"] = self.params.get('name', '*/Image/*') self.vm_params["DNSName"] = self.vm_params["VMName"] + ".cloudapp.net" self.vm_test01 = azure_asm_vm.VMASM(self.vm_params["VMName"], self.vm_params["VMSize"], self.vm_params["username"], self.vm_params["password"], self.vm_params) else: self.vm_params["DNSName"] = self.vm_params["VMName"] + "." + self.vm_params["region"] + ".cloudapp.azure.com" self.vm_params["ResourceGroupName"] = self.params.get('rg_name', '*/resourceGroup/*') self.vm_params["URN"] = "https://%s.blob.core.windows.net/%s/%s" % (self.vm_params["StorageAccountName"], self.vm_params["Container"], self.vm_params["DiskBlobName"]) self.vm_params["NicName"] = self.vm_params["VMName"] self.vm_params["PublicIpName"] = self.vm_params["VMName"] self.vm_params["PublicIpDomainName"] = self.vm_params["VMName"] self.vm_params["VnetName"] = self.vm_params["VMName"] self.vm_params["VnetSubnetName"] = self.vm_params["VMName"] self.vm_params["VnetAddressPrefix"] = self.params.get('vnet_address_prefix', '*/network/*') self.vm_params["VnetSubnetAddressPrefix"] = self.params.get('vnet_subnet_address_prefix', '*/network/*') self.vm_test01 = azure_arm_vm.VMARM(self.vm_params["VMName"], self.vm_params["VMSize"], self.vm_params["username"], self.vm_params["password"], self.vm_params) # azure_cli_common.host_command("cat /dev/zero | ssh-keygen -q -N ''", ignore_status=True) # myname = azure_cli_common.host_command("whoami").strip('\n') # self.host_pubkey_file = "/home/%s/.ssh/id_rsa.pub" % myname self.host_pubkey_file = azure_cli_common.get_sshkey_file() with open(self.host_pubkey_file, 'r') as hf: self.ssh_key_string = hf.read().strip('\n') self.log.debug(self.ssh_key_string) self.log.debug("Create the vm %s", self.vm_params["VMName"]) # If vm doesn't exist, create it. If it exists, start it. self.vm_test01.vm_update() if not self.vm_test01.exists(): self.vm_test01.vm_create(self.vm_params) self.vm_test01.wait_for_running() else: if not self.vm_test01.is_running(): self.vm_test01.start() self.vm_test01.wait_for_running() if not self.vm_test01.verify_alive(): self.error("VM %s is not available. Exit." % self.vm_params["VMName"]) self.project = self.params.get('Project', '*/Common/*') self.conf_file = "/etc/waagent.conf" # Increase sudo password timeout self.vm_test01.modify_value("Defaults timestamp_timeout", "-1", "/etc/sudoers", "=")
def setUp(self): # Get azure mode and choose test cases self.azure_mode = self.params.get('azure_mode', '*/azure_mode/*') self.log.debug("AZURE_MODE: %s", self.azure_mode) if self.name.name.split(':')[-1] not in self.params.get('cases', '*/azure_mode/*'): self.skip("Skip case %s in Azure Mode %s" % (self.name.name, self.azure_mode)) # Login Azure and change the mode self.azure_username = self.params.get('username', '*/AzureSub/*') self.azure_password = self.params.get('password', '*/AzureSub/*') azure_cli_common.login_azure(username=self.azure_username, password=self.azure_password) azure_cli_common.set_config_mode(self.azure_mode) # Prepare the vm parameters and create a vm self.vm_params = dict() self.vm_params["username"] = self.params.get('username', '*/VMUser/*') self.vm_params["password"] = self.params.get('password', '*/VMUser/*') self.vm_params["VMSize"] = self.params.get('vm_size', '*/azure_mode/*') self.vm_params["VMName"] = self.params.get('vm_name', '*/azure_mode/*') self.vm_params["Location"] = self.params.get('location', '*/resourceGroup/*') self.vm_params["region"] = self.params.get('region', '*/resourceGroup/*') self.vm_params["StorageAccountName"] = self.params.get('storage_account', '*/resourceGroup/*') self.vm_params["Container"] = self.params.get('container', '*/resourceGroup/*') self.vm_params["DiskBlobName"] = self.params.get('name', '*/DiskBlob/*') self.vm_params["PublicPort"] = self.params.get('public_port', '*/network/*') if self.azure_mode == "asm": if "disk_attach" in self.name.name: self.vm_params["VMSize"] = "Medium" self.vm_params["VMName"] += self.vm_params["VMSize"].split('_')[-1].lower() self.vm_params["Image"] = self.params.get('name', '*/Image/*') self.vm_params["DNSName"] = self.vm_params["VMName"] + ".cloudapp.net" self.vm_test01 = azure_asm_vm.VMASM(self.vm_params["VMName"], self.vm_params["VMSize"], self.vm_params["username"], self.vm_params["password"], self.vm_params) else: if "disk_attach" in self.name.name: self.vm_params["VMSize"] = "Standard_A2" self.vm_params["VMName"] += self.vm_params["VMSize"].split('_')[-1].lower() self.vm_params["DNSName"] = self.vm_params["VMName"] + "." + self.vm_params["region"] + ".cloudapp.azure.com" self.vm_params["ResourceGroupName"] = self.params.get('rg_name', '*/resourceGroup/*') self.vm_params["URN"] = "https://%s.blob.core.windows.net/%s/%s" % (self.vm_params["StorageAccountName"], self.vm_params["Container"], self.vm_params["DiskBlobName"]) self.vm_params["NicName"] = self.vm_params["VMName"] self.vm_params["PublicIpName"] = self.vm_params["VMName"] self.vm_params["PublicIpDomainName"] = self.vm_params["VMName"] self.vm_params["VnetName"] = self.vm_params["VMName"] self.vm_params["VnetSubnetName"] = self.vm_params["VMName"] self.vm_params["VnetAddressPrefix"] = self.params.get('vnet_address_prefix', '*/network/*') self.vm_params["VnetSubnetAddressPrefix"] = self.params.get('vnet_subnet_address_prefix', '*/network/*') self.vm_test01 = azure_arm_vm.VMARM(self.vm_params["VMName"], self.vm_params["VMSize"], self.vm_params["username"], self.vm_params["password"], self.vm_params) # If vm doesn't exist, create it. If it exists, start it. self.log.debug("Create the vm %s", self.vm_params["VMName"]) self.vm_test01.vm_update() if self.azure_mode == "arm" and self.vm_test01.exists(): if self.vm_test01.params.get("hardwareProfile").get("vmSize") != self.vm_params["VMSize"]: self.vm_test01.delete() self.vm_test01.wait_for_delete() if not self.vm_test01.exists(): self.vm_test01.vm_create(self.vm_params) self.vm_test01.wait_for_running() else: if not self.vm_test01.is_running(): self.vm_test01.start() self.vm_test01.wait_for_running() if not self.vm_test01.verify_alive(): self.error("VM %s is not available. Exit." % self.vm_params["VMName"]) self.project = self.params.get("Project", "*/Common/*") self.conf_file = "/etc/waagent.conf" # Increase sudo password timeout self.vm_test01.modify_value("Defaults timestamp_timeout", "-1", "/etc/sudoers", "=") # Prepare the blob parameters self.blob_list = [] # os disk parameters self.blob_params = dict() self.blob_params["name"] = self.params.get('name', '*/DiskBlob/*') self.blob_params["container"] = self.params.get('container', '*/resourceGroup/*') self.blob_params["storage_account"] = self.params.get('storage_account', '*/resourceGroup/*') if self.azure_mode == "asm": self.blob_test01 = azure_asm_vm.Blob(name=self.blob_params["name"], container=self.blob_params["container"], storage_account=self.blob_params["storage_account"], params=self.blob_params) else: self.blob_params["ResourceGroupName"] = self.params.get('rg_name', '*/resourceGroup/*') self.blob_test01 = azure_arm_vm.Blob(name=self.blob_params["name"], container=self.blob_params["container"], storage_account=self.blob_params["storage_account"], params=self.blob_params) self.blob_list.append(copy.deepcopy(self.blob_test01)) self.blob_params["connection_string"] = self.blob_test01.connection_string # data disk parameters, connection_string is the same with os disk self.disk_number = self.params.get('disk_number', '*/DataDisk/*') for dn in range(self.disk_number): self.blob_params["name"] = self.vm_params["VMName"] + "-disk" + str(dn) + self.vm_test01.postfix() self.blob_params["container"] = self.params.get('container', '*/DataDisk/*') self.blob_params["storage_account"] = self.params.get('storage_account', '*/resourceGroup/*') self.blob_params["size"] = self.params.get('size', '*/disk%s/*' % str(dn + 1)) self.blob_params["host_caching"] = self.params.get('host_caching', '*/disk%s/*' % str(dn + 1)) if self.azure_mode == "asm": self.blob_test01 = azure_asm_vm.Blob(name=self.blob_params["name"], container=self.blob_params["container"], storage_account=self.blob_params["storage_account"], connection_string=self.blob_params["connection_string"], params=self.blob_params) else: self.blob_params["ResourceGroupName"] = self.params.get('region', '*/resourceGroup/*') self.blob_test01 = azure_arm_vm.Blob(name=self.blob_params["name"], container=self.blob_params["container"], storage_account=self.blob_params["storage_account"], connection_string=self.blob_params["connection_string"], params=self.blob_params) self.blob_list.append(copy.deepcopy(self.blob_test01)) for i in self.blob_list: self.log.debug(i.params)
def setUp(self): # Get azure mode and choose test cases self.azure_mode = self.params.get('azure_mode', '*/azure_mode/*') self.log.debug("AZURE_MODE: %s", self.azure_mode) if self.name.name.split(':')[-1] not in self.params.get('cases', '*/azure_mode/*'): self.skip("Skip case %s in Azure Mode %s" % (self.name.name, self.azure_mode)) # Login Azure and change the mode self.azure_username = self.params.get('username', '*/AzureSub/*') self.azure_password = self.params.get('password', '*/AzureSub/*') azure_cli_common.login_azure(username=self.azure_username, password=self.azure_password) # azure_cli_common.set_config_mode(self.azure_mode) # 1. Source # Set azure mode to ASM mode. Source storage account is classic azure_cli_common.set_config_mode("asm") # Prepare the storage account instance self.sto_src_params = dict() self.sto_src_params["name"] = self.params.get('name', '*/Prepare/storage_account/*') self.sto_src_params["location"] = self.params.get('location', '*/Prepare/storage_account/*') self.sto_src_params["type"] = self.params.get('type', '*/Prepare/storage_account/*') self.sto_src_test01 = azure_asm_vm.StorageAccount(name=self.sto_src_params["name"], params=self.sto_src_params) # Create storage account if not self.sto_src_test01.check_exist(): self.sto_src_test01.create(self.sto_src_params) # Prepare the container instance self.container_src_params = dict() self.container_src_params["name"] = self.params.get('container', '*/Prepare/*') self.container_src_params["storage_account"] = self.sto_src_params["name"] self.container_src_test01 = azure_asm_vm.Container(name=self.container_src_params["name"], storage_account=self.container_src_params["storage_account"], params=self.container_src_params) # Create container if not self.container_src_test01.check_exist(): self.container_src_test01.create(self.container_src_params) # Prepare the blob instance self.blob_params = dict() self.blob_params["name"] = self.params.get('name', '*/DiskBlob/*') self.blob_params["container"] = self.container_src_params["name"] self.blob_params["storage_account"] = self.sto_src_params["name"] self.blob_test01 = azure_asm_vm.Blob(name=self.blob_params["name"], container=self.blob_params["container"], storage_account=self.blob_params["storage_account"], params=self.blob_params) self.vhd_file = self.params.get('vhd_file_path', '*/Prepare/*') + self.blob_params["name"] self.log.debug("VHD file fullpath: %s" % self.vhd_file) self.no_upload = False if self.blob_test01.check_exist(): self.no_upload = True if "prepare_image" in self.name.name or \ "convert_image" in self.name.name: self.skip("VHD blob already exists. Skip this case") # 2. Destination # Set azure mode follow the configuration azure_cli_common.set_config_mode(self.azure_mode) # Prepare the storage account instance self.sto_dst_params = dict() self.sto_dst_params["name"] = self.params.get('storage_account', '*/resourceGroup/*') self.sto_dst_params["location"] = self.params.get('location', '*/resourceGroup/*') self.sto_dst_params["type"] = self.params.get('storage_account_type', '*/resourceGroup/*') if self.azure_mode == "asm": self.sto_dst_test01 = azure_asm_vm.StorageAccount(name=self.sto_dst_params["name"], params=self.sto_dst_params) else: self.sto_dst_params["ResourceGroupName"] = self.params.get('rg_name', '*/resourceGroup/*') self.sto_dst_test01 = azure_arm_vm.StorageAccount(name=self.sto_dst_params["name"], params=self.sto_dst_params) # Create storage account if not self.sto_dst_test01.check_exist(): self.sto_dst_test01.create(self.sto_dst_params) self.dst_connection_string = self.sto_dst_test01.conn_show() self.log.debug("self.dst_connection_string=%s" % self.dst_connection_string) # Prepare the container instance self.container_dst_params = dict() self.container_dst_params["name"] = self.params.get('container', '*/resourceGroup/*') self.container_dst_params["storage_account"] = self.sto_dst_params["name"] if self.azure_mode == "asm": self.container_dst_test01 = azure_asm_vm.Container(name=self.container_dst_params["name"], storage_account=self.container_dst_params["storage_account"], params=self.container_dst_params) else: self.container_dst_params["ResourceGroupName"] = self.params.get('rg_name', '*/resourceGroup/*') self.container_dst_test01 = azure_arm_vm.Container(name=self.container_dst_params["name"], storage_account=self.container_dst_params["storage_account"], params=self.container_dst_params) # Create container if not self.container_dst_test01.check_exist(): self.container_dst_test01.create(self.container_dst_params) # Prepare the Image instance (Only for asm mode) if self.azure_mode == "asm": self.image_params = dict() self.image_params["name"] = self.params.get('name', '*/Image/*') self.image_params["blob_url"] = "https://%s.blob.core.windows.net/%s/%s" % \ (self.sto_dst_params["name"], self.container_dst_params["name"], self.blob_params["name"]) self.image_params["location"] = self.sto_dst_params["location"] self.image_test01 = azure_asm_vm.Image(name=self.image_params["name"], params=self.image_params) if self.image_test01.check_exist(): self.image_test01.delete()