def test_delete_cached_object(self, bucket_factory, mcg_obj, cld_mgr, awscli_pod, bucketclass_dict): """ Test the deletion of an object that is present in the cache of a cache bucket. """ # Create the cached namespace bucket on top of the namespace resource bucket_obj = bucket_factory(bucketclass=bucketclass_dict)[0] # Upload files to NS bucket writen_objs_names = self.write_files_to_pod_and_upload( mcg_obj, awscli_pod, bucket_to_write=bucket_obj.name, amount=1) if not check_cached_objects_by_name(mcg_obj, bucket_obj.name, writen_objs_names): raise UnexpectedBehaviour("Object was not cached properly") # Delete the object from mcg interface s3_delete_object(mcg_obj, bucket_obj.name, writen_objs_names[0]) sleep(1) if not check_cached_objects_by_name(mcg_obj, bucket_obj.name): raise UnexpectedBehaviour( "Object was not deleted from cache properly") # Check deletion in the cloud provider aws_target_bucket = bucket_obj.bucketclass.namespacestores[0].uls_name aws_obj_list = list( cld_mgr.aws_client.client.Bucket(aws_target_bucket).objects.all()) if writen_objs_names[0] in aws_obj_list: raise UnexpectedBehaviour( "Object was not deleted from cache properly")
def test_read_non_cached_object(self, bucket_factory, mcg_obj, cld_mgr, awscli_pod, bucketclass_dict): """ Test reading an object that is not present in a cache bucket. """ # Create the cached namespace bucket on top of the namespace resource bucket_obj = bucket_factory(bucketclass=bucketclass_dict)[0] s3_creds = { "access_key_id": cld_mgr.aws_client.access_key, "access_key": cld_mgr.aws_client.secret_key, "endpoint": constants.MCG_NS_AWS_ENDPOINT, "region": self.DEFAULT_REGION, } aws_target_bucket = bucket_obj.bucketclass.namespacestores[0].uls_name # Upload files directly to AWS writen_objs_names = self.write_files_to_pod_and_upload( mcg_obj, awscli_pod, bucket_to_write=aws_target_bucket, amount=3, s3_creds=s3_creds, ) if not check_cached_objects_by_name(mcg_obj, bucket_obj.name): raise UnexpectedBehaviour( "Objects were found in the cache of an empty bucket") # Read files from ns bucket self.download_files(mcg_obj, awscli_pod, bucket_to_read=bucket_obj.name) if not check_cached_objects_by_name(mcg_obj, bucket_obj.name, writen_objs_names): raise UnexpectedBehaviour("Objects not cached properly")
def test_list_cached_objects(self, bucket_factory, mcg_obj, cld_mgr, awscli_pod, bucketclass_dict): """ Test the ability to list the object stored in a cache bucket. """ # Create the cached namespace bucket on top of the namespace resource bucket_obj = bucket_factory(bucketclass=bucketclass_dict)[0] # Upload files to NS bucket writen_objs_names = self.write_files_to_pod_and_upload( mcg_obj, awscli_pod, bucket_to_write=bucket_obj.name, amount=3) if not check_cached_objects_by_name(mcg_obj, bucket_obj.name, writen_objs_names): raise UnexpectedBehaviour("Object was not cached properly")
def test_read_stale_object(self, bucket_factory, mcg_obj, cld_mgr, awscli_pod, bucketclass_dict): """ Test reading a stale object from a cache bucket. """ # Create the cached namespace bucket on top of the namespace resource bucket_obj = bucket_factory(bucketclass=bucketclass_dict)[0] s3_creds = { "access_key_id": cld_mgr.aws_client.access_key, "access_key": cld_mgr.aws_client.secret_key, "endpoint": constants.MCG_NS_AWS_ENDPOINT, "region": self.DEFAULT_REGION, } aws_target_bucket = bucket_obj.bucketclass.namespacestores[0].uls_name # Upload files to NS bucket writen_objs_names = self.write_files_to_pod_and_upload( mcg_obj, awscli_pod, bucket_to_write=bucket_obj.name, amount=1) if not check_cached_objects_by_name(mcg_obj, bucket_obj.name, writen_objs_names): raise UnexpectedBehaviour("Objects not cached properly") awscli_pod.exec_cmd_on_pod( "mv /original/testfile0.txt /original/testfile1.txt") # Upload files directly to AWS self.write_files_to_pod_and_upload( mcg_obj, awscli_pod, bucket_to_write=aws_target_bucket, amount=1, s3_creds=s3_creds, ) awscli_pod.exec_cmd_on_pod( "mv /original/testfile1.txt /original/testfile0.txt") # using sleep and not TimeoutSampler because we need to wait throughout the whole ttl sleep(bucketclass_dict["namespace_policy_dict"]["ttl"] / 1000) # Read files from ns bucket self.download_files(mcg_obj, awscli_pod, bucket_to_read=bucket_obj.name) if self.compare_dirs(awscli_pod): raise UnexpectedBehaviour( "Updated file was not fetched after ttl was exceeded")
def test_read_cached_object(self, bucket_factory, mcg_obj, cld_mgr, awscli_pod, bucketclass_dict): """ Test reading an object that is present in a cache bucket. """ # Create the cached namespace bucket on top of the namespace resource bucket_obj = bucket_factory(bucketclass=bucketclass_dict)[0] s3_creds = { "access_key_id": cld_mgr.aws_client.access_key, "access_key": cld_mgr.aws_client.secret_key, "endpoint": constants.MCG_NS_AWS_ENDPOINT, "region": self.DEFAULT_REGION, } aws_target_bucket = bucket_obj.bucketclass.namespacestores[0].uls_name # Upload files to NS bucket writen_objs_names = self.write_files_to_pod_and_upload( mcg_obj, awscli_pod, bucket_to_write=bucket_obj.name, amount=1) if not check_cached_objects_by_name(mcg_obj, bucket_obj.name, writen_objs_names): raise UnexpectedBehaviour("Objects not cached properly") # Upload files directly to AWS self.write_files_to_pod_and_upload( mcg_obj, awscli_pod, bucket_to_write=aws_target_bucket, amount=1, s3_creds=s3_creds, ) # Read files from ns bucket self.download_files(mcg_obj, awscli_pod, bucket_to_read=bucket_obj.name) # Compare dirs should return false since we expect the cached object to return # instead of the new object currently present in the original dir if self.compare_dirs(awscli_pod): raise UnexpectedBehaviour("Cached object was not downloaded")