コード例 #1
0
ファイル: storage.py プロジェクト: zhanghrp/avocado-azure
    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()
コード例 #2
0
    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()
コード例 #3
0
 def test_03_import_image_to_azure(self):
     """
     1. Upload vhd file to Azure Storage
     2. Copy the vhd to the specific storage account
     3. Create an image base on the vhd
     """
     self.log.info("Import the image to Azure")
     self.log.info("Use ASM mode azure cli commands")
     azure_cli_common.set_config_mode("asm")
     # 1. Upload vhd file to Azure Storage
     # 1.1 Check if vhd blob already exists
     if self.no_upload:
         self.log.info("The vhd blob already exists. Will not upload the vhd.")
     else:
         # 1.2 If doesn't exist, upload vhd to azure
         self.log.info("Begin to upload the vhd")
         self.assertEqual(self.blob_test01.upload(self.vhd_file, self.blob_params), 0,
                          "Fail to upload the VHD file %s to storage account %s container %s" %
                          (self.vhd_file, self.blob_params["storage_account"], self.blob_params["container"]))
         self.log.info("Upload %s to Azure Storage %s Container %s successfully" %
                       (self.vhd_file, self.blob_params["storage_account"], self.blob_params["container"]))
     # 2. Copy the vhd to the specific storage account
     self.assertTrue(self.blob_test01.copy(self.dst_connection_string),
                     "Fail to copy the VHD file %s to storage account %s container %s" %
                     (self.vhd_file, self.sto_dst_params["name"], self.blob_params["container"]))
     # 3. Create an image base on the vhd (only for asm mode)
     if self.azure_mode == "asm":
         self.assertEqual(self.image_test01.create(self.image_params), 0,
                          "Fail to create vm image %s" % self.image_params["name"])
コード例 #4
0
 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"
コード例 #5
0
    def test_00_preparation(self):
        """
        1. Clear azure account(In setup phase)
        2. delete VMs
        3. delete image

        """
        # Create storage account
        if not self.sto_src_test01.check_exist():
            self.sto_src_test01.create(self.sto_src_params)
        # Create container
        if not self.container_src_test01.check_exist():
            self.container_src_test01.create(self.container_src_params)
        # Delete VMs
        azure_cli_common.set_config_mode(self.azure_mode)
        if self.azure_mode == 'asm':
            vm_ins = azure_asm_vm.VM()
            vm_list = vm_ins.vm_list(debug=False)
            for vm_dict in vm_list:
                if self.vm_basename in vm_dict["VMName"]:
                    utils_misc.host_command("azure vm delete %s -q" % vm_dict["VMName"])
                    self.log.info("Delete VM %s" % vm_dict["VMName"])
        else:
            storage_account_list = utils_misc.get_storage_account_list(self.azure_mode)
            for storage_account in storage_account_list:
                storage_account_name = storage_account.keys()[0]
                if not azure_arm_vm.ResourceGroup(storage_account_name).check_exist():
                    continue
                params = dict()
                params["ResourceGroupName"] = storage_account_name
                vm_ins = azure_arm_vm.VM(params=params)
                vm_list = vm_ins.vm_list(debug=False)
                for vm_dict in vm_list:
                    if self.vm_basename in vm_dict["name"]:
                        utils_misc.host_command("azure vm delete %s %s -q" %
                                                (storage_account_name, vm_dict["name"]))
                        self.log.info("Delete VM %s" % vm_dict["name"])
        self.log.info("All VMs are deleted.")
        # Delete Images
        if self.azure_mode == 'asm':
            image_ins = azure_asm_vm.Image()
            image_list = image_ins.list(debug=False)
            for image in image_list:
                if self.image_basename in image["name"]:
                    self.log.info("Delete image %s" % image["name"])
                    image_ins.name = image["name"]
                    image_ins.delete()
        self.log.info("All Images are deleted.")
コード例 #6
0
    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", "=")
コード例 #7
0
    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", "=")
コード例 #8
0
    def test_03_import_image_to_azure(self):
        """
        1. Upload vhd file to Azure Storage
        2. Copy the vhd to the specific storage account
        3. Create an image base on the vhd
        """
        self.log.info("Import the image to Azure")
        self.log.info("Use ASM mode azure cli commands")
        # 1. Upload vhd file to Azure Storage
        # 1.1 Check if vhd blob already exists
        if self.no_upload:
            self.log.info("The vhd blob already exists. Will not upload the vhd.")
        else:
            # 1.2 If doesn't exist, upload vhd to azure
            self.log.info("Begin to upload the vhd")
            self.assertEqual(self.blob_test01.upload(self.vhd_file, self.blob_params), 0,
                             "Fail to upload the VHD file %s to storage account %s container %s" %
                             (self.vhd_file, self.blob_params["storage_account"], self.blob_params["container"]))
            self.log.info("Upload %s to Azure Storage %s Container %s successfully" %
                          (self.vhd_file, self.blob_params["storage_account"], self.blob_params["container"]))
        # 2. Copy the vhd to all the specific storage accounts
        # Get destination storage_account list
        azure_cli_common.set_config_mode(self.azure_mode)
        storage_account_list = utils_misc.get_storage_account_list(self.azure_mode)
        self.log.info(storage_account_list)
        for storage_account in storage_account_list:
            # Destination storage account instance
            sto_dst_params = dict()
            sto_dst_params["name"] = storage_account.keys()[0]
            sto_dst_params["location"] = storage_account[sto_dst_params["name"]]
            if "premium" in sto_dst_params["name"]:
                sto_dst_params["type"] = "PLRS"
            else:
                sto_dst_params["type"] = "LRS"
            if self.azure_mode == "asm":
                sto_dst_test01 = azure_asm_vm.StorageAccount(name=sto_dst_params["name"],
                                                             params=sto_dst_params)
            else:
                sto_dst_params["ResourceGroupName"] = sto_dst_params["name"]
                sto_dst_test01 = azure_arm_vm.StorageAccount(name=sto_dst_params["name"],
                                                             params=sto_dst_params)
                # Destination resource Group Instance
                rg_params = dict()
                rg_params["location"] = sto_dst_params["location"]
                rg_test01 = azure_arm_vm.ResourceGroup(name=sto_dst_params["ResourceGroupName"],
                                                       params=rg_params)
                if not rg_test01.check_exist():
                    self.assertEqual(0, rg_test01.create(),
                                     "Fail to create resource group %s" % sto_dst_params["ResourceGroupName"])
            # Check and create destination storage account
            if not sto_dst_test01.check_exist():
                sto_dst_test01.create(sto_dst_params)
            dst_connection_string = sto_dst_test01.conn_show()
            # Destination container instance
            container_dst_params = dict()
#            container_dst_params["name"] = self.params.get('container', '*/Prepare/*')
            container_dst_params["name"] = self.container_src_params["name"]
            container_dst_params["storage_account"] = sto_dst_params["name"]
            if self.azure_mode == "asm":
                container_dst_test01 = azure_asm_vm.Container(name=container_dst_params["name"],
                                                              storage_account=container_dst_params["storage_account"],
                                                              params=container_dst_params)
            else:
                container_dst_params["ResourceGroupName"] = sto_dst_params["name"]
                container_dst_test01 = azure_arm_vm.Container(name=container_dst_params["name"],
                                                              storage_account=container_dst_params["storage_account"],
                                                              params=container_dst_params)
            # Check and create destination container
            if not container_dst_test01.check_exist():
                container_dst_test01.create(container_dst_params)
            # Destination blob instance
            blob_params = dict()
            blob_params["name"] = self.blob_params["name"]
            blob_params["container"] = container_dst_params["name"]
            blob_params["storage_account"] = sto_dst_params["name"]
            if self.azure_mode == 'asm':
                dest_blob_test01 = azure_asm_vm.Blob(name=blob_params["name"],
                                                container=blob_params["container"],
                                                storage_account=blob_params["storage_account"],
                                                params=blob_params,
                                                connection_string=dst_connection_string)

            else:
                dest_blob_test01 = azure_asm_vm.Blob(name=blob_params["name"],
                                                container=blob_params["container"],
                                                storage_account=blob_params["storage_account"],
                                                params=blob_params,
                                                connection_string=dst_connection_string)
            if not dest_blob_test01.check_exist():
                self.assertTrue(self.blob_test01.copy(dst_connection_string),
                                "Fail to copy the VHD file %s to storage account %s container %s" %
                                (self.blob_params["name"], sto_dst_params["name"], container_dst_params["name"]))
            # 3. Create images in each storage account base on the vhd (only for asm mode)
            if self.azure_mode == "asm":
                image_params = dict()
                image_params["name"] = self.image_basename + "-" + sto_dst_params["name"]
                image_params["blob_url"] = "https://%s.blob.core.windows.net/%s/%s" % \
                                           (sto_dst_params["name"],
                                            container_dst_params["name"],
                                            self.blob_params["name"])
                image_params["location"] = sto_dst_params["location"]
                image_test01 = azure_asm_vm.Image(name=image_params["name"],
                                                  params=image_params)
                if not image_test01.check_exist():
                    self.assertEqual(image_test01.create(image_params), 0,
                                     "Fail to create vm image %s" % image_params["name"])
        # Waiting for the blob copy finish
        time.sleep(120)
コード例 #9
0
    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)
コード例 #10
0
    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()