def util_test_download_1kb_blob_with_oauth(self): # create file of size 1KB. filename = "test_1kb_blob_upload.txt" file_path = util.create_test_file(filename, 1024) # Upload 1KB file using azcopy. src = file_path dest = util.test_oauth_container_url cmd = util.Command("copy").add_arguments(src).add_arguments(dest). \ add_flags("log-level", "info").add_flags("recursive", "true") util.process_oauth_command(cmd, "") result = cmd.execute_azcopy_copy_command() self.assertTrue(result) # Verifying the uploaded blob. # the resource local path should be the first argument for the azcopy validator. # the resource sas should be the second argument for azcopy validator. dest_validate = util.get_resource_from_oauth_container_validate(filename) result = util.Command("testBlob").add_arguments(file_path).add_arguments(dest_validate).execute_azcopy_verify() self.assertTrue(result) # downloading the uploaded file src = util.get_resource_from_oauth_container(filename) src_validate = util.get_resource_from_oauth_container_validate(filename) dest = util.test_directory_path + "/test_1kb_blob_download.txt" cmd = util.Command("copy").add_arguments(src).add_arguments(dest).add_flags("log-level", "info") util.process_oauth_command(cmd, "") result = cmd.execute_azcopy_copy_command() self.assertTrue(result) # Verifying the downloaded blob result = util.Command("testBlob").add_arguments(dest).add_arguments(src_validate).execute_azcopy_verify() self.assertTrue(result)
def test_download_1kb_blob_oauth(forceOAuthLogin=False, tenantID="", aadEndpoint=""): # create file of size 1KB. filename = "test_1kb_blob_upload.txt" file_path = util.create_test_file(filename, 1024) # Upload 1KB file using azcopy. src = file_path dest = util.test_oauth_container_url cmd = util.Command("copy").add_arguments(src).add_arguments(dest). \ add_flags("log-level", "info").add_flags("recursive", "true") util.process_oauth_command(cmd, "", forceOAuthLogin, tenantID, aadEndpoint) if forceOAuthLogin: result = cmd.execute_azcopy_command_interactive() else: result = cmd.execute_azcopy_copy_command() if not result: print("failed uploading 1KB file to the container") return # Verifying the uploaded blob. # the resource local path should be the first argument for the azcopy validator. # the resource sas should be the second argument for azcopy validator. dest_validate = util.get_resource_from_oauth_container_validate(filename) result = util.Command("testBlob").add_arguments(file_path).add_arguments( dest_validate).execute_azcopy_verify() if not result: print("test_1kb_file test failed") return time.sleep(5) # downloading the uploaded file src = util.get_resource_from_oauth_container(filename) src_validate = util.get_resource_from_oauth_container_validate(filename) dest = util.test_directory_path + "/test_1kb_blob_download.txt" cmd = util.Command("copy").add_arguments(src).add_arguments( dest).add_flags("log-level", "info") util.process_oauth_command(cmd, "", forceOAuthLogin, tenantID, aadEndpoint) if forceOAuthLogin: result = cmd.execute_azcopy_command_interactive() else: result = cmd.execute_azcopy_copy_command() if not result: print("test_download_1kb_blob test case failed") return # Verifying the downloaded blob result = util.Command("testBlob").add_arguments(dest).add_arguments( src_validate).execute_azcopy_verify() if not result: print("test_download_1kb_blob test case failed") return print("test_download_1kb_blob successfully passed")
def util_test_n_1kb_blob_upload(self, number_of_files, use_oauth_session=False): # create dir dir_n_files and 1 kb files inside the dir. dir_name = "dir_" + str(number_of_files) + "_files" dir_n_files_path = util.create_test_n_files(1024, number_of_files, dir_name) if not use_oauth_session: dest = util.test_container_url dest_validate = util.get_resource_sas(dir_name) else: dest = util.test_oauth_container_url dest_validate = util.get_resource_from_oauth_container_validate( dir_name) # execute azcopy command result = util.Command("copy").add_arguments(dir_n_files_path).add_arguments(dest). \ add_flags("recursive", "true").add_flags("log-level", "info").execute_azcopy_copy_command() self.assertTrue(result) # execute the validator. result = util.Command("testBlob").add_arguments(dir_n_files_path).add_arguments(dest_validate). \ add_flags("is-object-dir", "true").execute_azcopy_verify() self.assertTrue(result)
def util_test_1GB_blob_upload(self, use_oauth_session=False): # create 1Gb file filename = "test_1G_blob.txt" file_path = util.create_test_file(filename, 1 * 1024 * 1024 * 1024) # execute azcopy upload. if not use_oauth_session: dest = util.get_resource_sas(filename) dest_validate = dest else: dest = util.get_resource_from_oauth_container(filename) dest_validate = util.get_resource_from_oauth_container_validate( filename) result = util.Command("copy").add_arguments(file_path).add_arguments(dest).add_flags("log-level", "info"). \ add_flags("block-size", "104857600").add_flags("recursive", "true").execute_azcopy_copy_command() self.assertTrue(result) # Verifying the uploaded blob. # adding local file path as first argument. # adding file sas as local argument. # calling the testBlob validator to verify whether blob has been successfully uploaded or not. result = util.Command("testBlob").add_arguments( file_path).add_arguments(dest_validate).execute_azcopy_verify() self.assertTrue(result)
def util_test_1kb_blob_upload(self, use_oauth_session=False): # Creating a single File Of size 1 KB filename = "test1KB.txt" file_path = util.create_test_file(filename, 1024) # executing the azcopy command to upload the 1KB file. src = file_path if not use_oauth_session: dest = util.get_resource_sas(filename) dest_validate = dest else: dest = util.get_resource_from_oauth_container(filename) dest_validate = util.get_resource_from_oauth_container_validate( filename) result = util.Command("copy").add_arguments(src).add_arguments(dest). \ add_flags("log-level", "info").add_flags("recursive", "true").execute_azcopy_copy_command() self.assertTrue(result) # Verifying the uploaded blob. # the resource local path should be the first argument for the azcopy validator. # the resource sas should be the second argument for azcopy validator. result = util.Command("testBlob").add_arguments( file_path).add_arguments(dest_validate).execute_azcopy_verify() self.assertTrue(result)
def test_recursive_download_blob_oauth(forceOAuthLogin=False, tenantID="", aadEndpoint=""): # create directory and 5 files of 1KB inside that directory. dir_name = "dir_" + str(10) + "_files" dir1_path = util.create_test_n_files(1024, 5, dir_name) dest = util.test_oauth_container_url # upload the directory to container through azcopy with recursive set to true. cmd = util.Command("copy").add_arguments(dir1_path).add_arguments(dest).add_flags("log-level", "info") \ .add_flags("recursive", "true") util.process_oauth_command(cmd, "", forceOAuthLogin, tenantID, aadEndpoint) if forceOAuthLogin: result = cmd.execute_azcopy_command_interactive() else: result = cmd.execute_azcopy_copy_command() if not result: print("error uploading recursive dir ", dir1_path) return # verify the uploaded file. dest_validate = util.get_resource_from_oauth_container_validate(dir_name) result = util.Command("testBlob").add_arguments(dir1_path).add_arguments( dest_validate).add_flags("is-object-dir", "true").execute_azcopy_verify() if not result: print("error verify the recursive dir ", dir1_path, " upload") return try: shutil.rmtree(dir1_path) except OSError as e: print("error removing the uploaded files. ", e) return src_download = util.get_resource_from_oauth_container(dir_name) # downloading the directory created from container through azcopy with recursive flag to true. cmd = util.Command("copy").add_arguments(src_download).add_arguments( util.test_directory_path).add_flags("log-level", "info").add_flags( "recursive", "true") util.process_oauth_command(cmd, "", forceOAuthLogin, tenantID, aadEndpoint) if forceOAuthLogin: result = cmd.execute_azcopy_command_interactive() else: result = cmd.execute_azcopy_copy_command() if not result: print("error download recursive dir ", dir1_path) return # verify downloaded blob. result = util.Command("testBlob").add_arguments(dir1_path).add_arguments( dest_validate).add_flags("is-object-dir", "true").execute_azcopy_verify() if not result: print("error verifying the recursive download ") return print("test_recursive_download_blob successfully passed")
def util_test_recursive_download_blob_with_oauth(self): # create directory and 5 files of 1KB inside that directory. dir_name = "util_test_recursive_download_blob_with_oauth_dir_" + str( 10) + "_files" dir1_path = util.create_test_n_files(1024, 5, dir_name) dest = util.test_oauth_container_url # upload the directory to container through azcopy with recursive set to true. cmd = util.Command("copy").add_arguments(dir1_path).add_arguments(dest).add_flags("log-level", "info") \ .add_flags("recursive", "true") util.process_oauth_command(cmd, "") result = cmd.execute_azcopy_copy_command() self.assertTrue(result) # verify the uploaded file. dest_validate = util.get_resource_from_oauth_container_validate( dir_name) result = util.Command("testBlob").add_arguments( dir1_path).add_arguments(dest_validate).add_flags( "is-object-dir", "true").execute_azcopy_verify() self.assertTrue(result) try: shutil.rmtree(dir1_path) except OSError as e: self.fail("error removing the upload files. " + e) src_download = util.get_resource_from_oauth_container(dir_name) # downloading the directory created from container through azcopy with recursive flag to true. cmd = util.Command("copy").add_arguments(src_download).add_arguments( util.test_directory_path).add_flags("log-level", "info").add_flags( "recursive", "true") util.process_oauth_command(cmd, "") result = cmd.execute_azcopy_copy_command() self.assertTrue(result) # verify downloaded blob. result = util.Command("testBlob").add_arguments( dir1_path).add_arguments(dest_validate).add_flags( "is-object-dir", "true").execute_azcopy_verify() self.assertTrue(result)
def util_test_page_blob_upload_1mb(self, use_oauth=False): # create the test gile. file_name = "test_page_blob_1mb.vhd" file_path = util.create_test_file(file_name, 1024 * 1024) # execute azcopy upload. if not use_oauth: dest = util.get_resource_sas(file_name) dest_validate = dest else: dest = util.get_resource_from_oauth_container(file_name) dest_validate = util.get_resource_from_oauth_container_validate( file_name) result = util.Command("copy").add_arguments(file_path).add_arguments(dest).add_flags("log-level", "info"). \ add_flags("block-size", "4194304").add_flags("blobType","PageBlob").execute_azcopy_copy_command() self.assertTrue(result) # execute validator. result = util.Command("testBlob").add_arguments(file_path).add_arguments(dest_validate).\ add_flags("blob-type","PageBlob").execute_azcopy_verify() self.assertTrue(result)