Beispiel #1
0
    def setUp(self):
        global g_count
        self.count = g_count
        g_count += 1

        self.req_q = SQS("{}-{}".format(test_req_q, self.count))
        self.in_b = S3("{}-{}".format(test_in_b, self.count))
        self.out_b = S3("{}-{}".format(test_out_b, self.count))
        self.cli = Client("{}-{}".format(test_res_q, self.count),
                          "{}-{}".format(test_req_q, self.count),
                          "{}-{}".format(test_in_b, self.count))
Beispiel #2
0
    def send_file(self, name, really):
        my_queue_name = my_queue_name_prefix + str(uuid.uuid4())
        with SQS(my_queue_name) as my_queue:
            remote_file_name = my_queue_name + "-normal-file.txt"
            if really:
                s3 = S3(args.bucket)
                s3.upload(local_file=name, remote_file=remote_file_name)

            sqs = SQS(args.queue)
            sqs.send(msg=Requests.encode_file(remote_file_name, my_queue_name),
                     attrs={})

            count = 0
            msg = {}
            while count < 100:
                msg = my_queue.recv()
                if msg is None:
                    time.sleep(0.005)
                    count += 1
                else:
                    break
            else:
                self.fail("No response from the server")

            res = Responses.decode(msg["Body"])
            if really:
                self.assertTrue("error" not in res)
                self.assertTrue("s3url" in res)
                parts = res["s3url"].split()
                self.assertEqual(len(parts), 2)
                bucket = parts[0]
                name = parts[1]

                res_s3 = S3(bucket)
                local_file = "{}-downloaded.txt".format(name)
                res_s3.download(local_file=local_file, remote_file=name)
                data = ""
                with open(local_file, "r") as f:
                    data = f.read()
                decoded = json.loads(data)
                os.remove(local_file)
                return decoded
            else:
                self.assertTrue("error" in res)
                self.assertTrue("s3url" not in res)
Beispiel #3
0
def respond_success(queue_name, local_file):
    bucket_name = "titos-{}".format(str(uuid.uuid4()))
    bucket = S3(bucket_name)
    bucket.upload(local_file=local_file, remote_file="a.txt")
    os.remove(local_file)
    SQS(queue_name).send(msg=Responses.encode_success(
        "{} a.txt".format(bucket_name)),
                         attrs={})
    Process(target=delayed_delete, args=(bucket_name, )).start()
Beispiel #4
0
def get_bucket_file_data(in_bucket_name, remote_file):
    local_file = str(uuid.uuid4())

    try:
        bucket = S3(in_bucket_name)
        bucket.download(local_file=local_file, remote_file=remote_file)

        with open(local_file) as f:
            text = f.read()
        return text
    finally:
        os.remove(local_file)
Beispiel #5
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     S3.destroy(self.bucket_name)
Beispiel #6
0
 def __init__(self, queue_name, bucket_name):
     self.queue = SQS(queue_name)
     self.bucket_name = bucket_name
     self.bucket = S3(bucket_name)