def single_upload(self): """ Uploads a single invocation to resultstore """ config_id = self.flags.config_id config = get_default_configuration(self.flags.invocation_id, config_id) self.create_configuration(config) config_id = config.id.configuration_id target = get_default_target(self.flags.invocation_id, self.flags.target_name) self.create_target(target) target_id = target.id.target_id config_target = get_default_configured_target(self.flags.invocation_id, target_id, config_id) self.create_configured_target(config_target) action = get_default_action(self.flags.invocation_id, target_id, config_id) if self.flags.action_type == 'Test': test_action = action_pb2.TestAction() action.test_action.CopyFrom(test_action) else: build_action = action_pb2.BuildAction() action.build_action.CopyFrom(build_action) self.create_action(action) self._file_upload_helper(target_id, action.id.action_id, config_id) self.finalize_configured_target(self.flags.invocation_id, target_id, config_id) self.finalize_target(self.flags.invocation_id, target_id)
def test_rpc_error(self, ResultStoreUploadStubMock, gen_new_uuid_mock): stub = ResultStoreUploadStubMock() stub.UpdateTarget = MagicMock(return_value=DEFAULT_RPC_ERROR) client = initialize_client(FLAGS) target = get_default_target(TEST_INVOCATION_ID, TEST_TARGET_ID) res = client.update_target(target, ['test']) self.assertEqual(res, DEFAULT_RPC_ERROR)
def test_create_target_success(self, ResultStoreUploadStubMock, gen_new_uuid_mock): stub = ResultStoreUploadStubMock() stub.CreateTarget = MagicMock(side_effect=create_return_target) client = initialize_client(FLAGS) target = get_default_target(TEST_INVOCATION_ID, TEST_TARGET_ID) res = client.create_target(target) self.assertEqual(res.id.target_id, TEST_TARGET_ID) self.assertEqual( res.name, "invocations/{}/targets/{}".format(TEST_INVOCATION_ID, TEST_TARGET_ID))
def create_resource_requests(self, invocation_id, config_id): """ Create upload requests to be batch uploaded Args: invocation_id (str): Invocation to upload to config_id (str): Invocation configuration id to use or create Returns: A list of upload requests """ requests = [] if self.flags.create_config: config = get_default_configuration(invocation_id) config_request = self.create_upload_request( defaultdict(None, {'configuration': config}), config_id=config.id.configuration_id) requests.append(config_request) target = get_default_target(invocation_id) target_id = target.id.target_id target_request = self.create_upload_request( defaultdict(None, {'target': target}), target_id) files = None if self.flags.files: files = self._upload_files(target_id) requests.append(target_request) config_target = get_default_configured_target(invocation_id, target_id, config_id) config_target_request = self.create_upload_request( defaultdict(None, {'configured_target': config_target}), target_id, config_id) requests.append(config_target_request) action = get_default_action(invocation_id, target_id, config_id, files=files) action_id = action.id.action_id action_request = self.create_upload_request( defaultdict(None, {'action': action}), target_id, config_id, action_id) requests.append(action_request) return requests