How to use upload_object_to_container method in tempest

Best Python code snippet using tempest_python

gradient_batch_client.py

Source:gradient_batch_client.py Github

copy

Full Screen

...47 self.batch_client = BatchServiceClient(48 self.credentials, batch_url=config.BATCH_ACCOUNT_URL49 )50 # Upload The common files.51 self.common_file = self.upload_object_to_container(52 self.blob_client, config.CONTAINER_NAME, _GRAD_COMMON_FILE, common_data53 )54 # Create the pool that will contain the compute nodes that will execute the55 # tasks.56 try:57 create_pool(self.config, self.batch_client)58 if verbose:59 print("Created pool: ", self.config.POOL_ID)60 except models.BatchErrorException:61 if verbose:62 print("Using pool: ", self.config.POOL_ID)63 def do_grad(self, part_data): # , verbose=True64 """65 calculate the gradient66 """67 start_time = datetime.datetime.now().replace(microsecond=0)68 print("Gradient start time: {}".format(start_time))69 timestamp = datetime.datetime.utcnow().strftime("%H%M%S")70 JOB_ID = self.config.JOB_ID + timestamp71 try:72 global_parameters_resource = batch_client.build_resource_file(73 _GRAD_PART_FILE, part_data74 )75 # Upload the part file76 part_file = self.upload_object_to_container(77 self.blob_client, self.config.CONTAINER_NAME, _GRAD_PART_FILE, part_data78 )79 # Create the job that will run the tasks.80 create_job(self.batch_client, JOB_ID, self.config.POOL_ID)81 # Add the tasks to the job.82 self.add_tasks(part_file, JOB_ID)83 # Pause execution until tasks reach Completed state.84 print("wait_for_tasks_to_complete")85 wait_for_tasks_to_complete(86 self.batch_client, JOB_ID, datetime.timedelta(hours=24)87 )88 print("_download_results")89 results = _download_results(90 self.config,91 self.blob_client,92 self.config.BATCH_DIRECTORY,93 self.K,94 OUTPUT_FILE_PATTERN,95 )96 print("_downloaded_results")97 # TODO: inspect tasks for out of memory and other errors98 if self.config.DELETE_JOB_WHEN_DONE:99 self.batch_client.job.delete(JOB_ID)100 return results101 except Exception as err:102 raise RuntimeError(103 "something went wrong: {}({})".format(104 err.__class__.__name__, getattr(err, "message", "")105 )106 )107 def add_tasks(self, part_file, JOB_ID):108 """109 Adds a task for each input file in the collection to the specified job.110 """111 # print("Adding {} tasks to job [{}]...".format(count, job_id))112 tasks = list()113 for i in range(self.K):114 output_file = self.build_output_file(i)115 command_line = "/bin/bash -c 'echo $AZ_BATCH_TASK_WORKING_DIR && daemon status && scgrad {} {} {} {}'".format(116 _GRAD_COMMON_FILE, _GRAD_PART_FILE, _CONTAINER_OUTPUT_FILE, i117 )118 if self.config.REGISTRY_USERNAME:119 registry = models.ContainerRegistry(120 user_name=self.config.REGISTRY_USERNAME,121 password=self.config.REGISTRY_PASSWORD,122 registry_server=self.config.REGISTRY_SERVER,123 )124 task_container_settings = models.TaskContainerSettings(125 image_name=self.config.DOCKER_IMAGE, registry=registry126 )127 else:128 task_container_settings = models.TaskContainerSettings(129 image_name=self.config.DOCKER_IMAGE130 )131 tasks.append(132 models.TaskAddParameter(133 id="grad_part_{}".format(i),134 command_line=command_line,135 resource_files=[self.common_file, part_file],136 output_files=[output_file],137 container_settings=task_container_settings,138 )139 )140 self.batch_client.task.add_collection(JOB_ID, [tasks[0]])141 def build_output_file(self, i):142 """143 Uploads a local file to an Azure Blob storage container.144 :rtype: `azure.batch.models.ResourceFile`145 :return: A ResourceFile initialized with a SAS URL appropriate for Batch146 tasks.147 """148 # where to store the outputs149 container_dest = models.OutputFileBlobContainerDestination(150 container_url=self.CONTAINER_SAS_URL, path=OUTPUT_FILE_PATTERN.format(i),151 )152 dest = models.OutputFileDestination(container=container_dest)153 # under what conditions should you attempt to extract the outputs?154 upload_options = models.OutputFileUploadOptions(155 upload_condition=models.OutputFileUploadCondition.task_success156 )157 # https://docs.microsoft.com/en-us/azure/batch/batch-task-output-files#specify-output-files-for-task-output158 return models.OutputFile(159 file_pattern=_CONTAINER_OUTPUT_FILE,160 destination=dest,161 upload_options=upload_options,162 )163 def upload_object_to_container(164 self, block_blob_client, container_name, blob_name, obj165 ):166 """167 Uploads a local file to an Azure Blob storage container.168 :param block_blob_client: A blob service client.169 :type block_blob_client: `azure.storage.blob.BlockBlobService`170 :param str container_name: The name of the Azure Blob storage container.171 :param str file_path: The local path to the file.172 :rtype: `azure.batch.models.ResourceFile`173 :return: A ResourceFile initialized with a SAS URL appropriate for Batch174 tasks.175 """176 # print("Uploading file {} to container [{}]...".format(blob_name, container_name))177 block_blob_client.create_blob_from_text(...

Full Screen

Full Screen

test_object_storage_basic_ops.py

Source:test_object_storage_basic_ops.py Github

copy

Full Screen

...31 * delete a container.32 """33 self.get_swift_stat()34 container_name = self.create_container()35 obj_name, obj_data = self.upload_object_to_container(container_name)36 self.list_and_check_container_objects(container_name,37 present_obj=[obj_name])38 self.download_and_verify(container_name, obj_name, obj_data)39 self.delete_object(container_name, obj_name)40 self.list_and_check_container_objects(container_name,41 not_present_obj=[obj_name])42 self.delete_container(container_name)43 @decorators.idempotent_id('916c7111-cb1f-44b2-816d-8f760e4ea910')44 @test.services('object_storage')45 def test_swift_acl_anonymous_download(self):46 """This test will cover below steps:47 1. Create container48 2. Upload object to the new container49 3. Change the ACL of the container50 4. Check if the object can be download by anonymous user51 5. Delete the object and container52 """53 container_name = self.create_container()54 obj_name, _ = self.upload_object_to_container(container_name)55 obj_url = '%s/%s/%s' % (self.object_client.base_url,56 container_name, obj_name)57 resp, _ = self.object_client.raw_request(obj_url, 'GET')58 self.assertEqual(resp.status, 401)59 self.change_container_acl(container_name, '.r:*')60 resp, _ = self.object_client.raw_request(obj_url, 'GET')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful