def fill_container(rgw, container_name, user_id, oc, cc, size): """ Uploads objects to the container Args: rgw(object): RGW object container_name(str): Container name user_id(str): User ID oc(int): object count cc(int): container count size(int): Object size """ swift_object_name = utils.gen_s3_object_name("%s.container.%s" % (user_id, cc), oc) log.info("object name: %s" % swift_object_name) object_path = os.path.join(TEST_DATA_PATH, swift_object_name) log.info("object path: %s" % object_path) data_info = manage_data.io_generator(object_path, size) # upload object if data_info is False: raise TestExecError("data creation failed") log.info("uploading object: %s" % object_path) with open(object_path, "r") as fp: rgw.put_object( container_name, swift_object_name, contents=fp.read(), content_type="text/plain", ) return swift_object_name
def upload_file(bucket_name, file_name=None, file_size=1024, test_data_path=None): """ Uploads file to the bucket Args: bucket_name(str): Name of the bucket file_name(str): Name of the file to be uploaded file_size(int): Size of the file to be uploaded, defaults to 1024 test_data_path(str): Local test data path Returns: File information """ # If no file_name passed, it generates file_name and returns in file information # It is to have support for file which is already created if file_name is None: file_name = utils.gen_s3_object_name(bucket_name, 1) local_file_path = test_data_path + "/" + file_name file_info = io_generator(local_file_path, file_size) file_info["name"] = file_name upload_file_method = S3CMD(operation="put") remote_s3_path = f"s3://{bucket_name}/{file_name}" command = upload_file_method.command( params=[local_file_path, remote_s3_path]) try: upload_file_response = exec_shell_cmd(command) log.debug(f"Response for upload file command: {upload_file_response}") except Exception as e: raise S3CommandExecError(message=str(e)) assert "100%" in str( upload_file_response), "upload file operation not succeeded" return file_info
def upload_objects(user_info, bucket, config): log.info('s3 objects to create: %s' % config.objects_count) for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name(bucket.name, oc) resuables.upload_object(s3_object_name, bucket, TEST_DATA_PATH, config, user_info)
def test_exec(config): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) # preparing data user_names = ['tuffy', 'scooby', 'max'] tenant1 = 'tenant' cmd = 'radosgw-admin user create --uid=%s --display-name="%s" --tenant=%s' % ( user_names[0], user_names[0], tenant1) out = utils.exec_shell_cmd(cmd) if out is False: raise TestExecError("RGW User creation error") log.info('output :%s' % out) v1_as_json = json.loads(out) log.info('creted user_id: %s' % v1_as_json['user_id']) cmd2 = 'radosgw-admin subuser create --uid=%s$%s --subuser=%s:swift --tenant=%s --access=full' % ( tenant1, user_names[0], user_names[0], tenant1) out2 = utils.exec_shell_cmd(cmd2) if out2 is False: raise TestExecError("sub-user creation error") v2_as_json = json.loads(out2) log.info('created subuser: %s' % v2_as_json['subusers'][0]['id']) cmd3 = 'radosgw-admin key create --subuser=%s:swift --uid=%s$%s --tenant=%s --key-type=swift --gen-secret' % ( user_names[0], user_names[0], tenant1, tenant1) out3 = utils.exec_shell_cmd(cmd3) if out3 is False: raise TestExecError("secret_key gen error") v3_as_json = json.loads(out3) log.info('created subuser: %s\nsecret_key generated: %s' % ( v3_as_json['swift_keys'][0]['user'], v3_as_json['swift_keys'][0]['secret_key'])) user_info = {'user_id': v3_as_json['swift_keys'][0]['user'], 'key': v3_as_json['swift_keys'][0]['secret_key']} auth = Auth(user_info) rgw = auth.do_auth() for cc in range(config.container_count): container_name = utils.gen_bucket_name_from_userid(user_info['user_id'], rand_no=cc) container = swiftlib.resource_op({'obj': rgw, 'resource': 'put_container', 'args': [container_name]}) if container is False: raise TestExecError("Resource execution failed: container creation faield") for oc,size in list(config.mapped_sizes.items()): swift_object_name = utils.gen_s3_object_name('%s.container.%s' % (user_names[0], cc), oc) log.info('object name: %s' % swift_object_name) object_path = os.path.join(TEST_DATA_PATH, swift_object_name) log.info('object path: %s' % object_path) data_info = manage_data.io_generator(object_path, size) if data_info is False: TestExecError("data creation failed") log.info('uploading object: %s' % object_path) with open(object_path, 'r') as fp: rgw.put_object(container_name, swift_object_name, contents=fp.read(), content_type='text/plain') # check for any crashes during the execution crash_info=reusable.check_for_crash() if crash_info: raise TestExecError("ceph daemon crash found!")
def test_exec(config, requester): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) log.info('requester type: %s' % requester) # create user all_users_info = s3lib.create_users(config.user_count) for each_user in all_users_info: # authenticate auth = Auth(each_user, ssl=config.ssl) rgw_conn = auth.do_auth() # create buckets log.info('no of buckets to create: %s' % config.bucket_count) for bc in range(config.bucket_count): bucket_name_to_create = utils.gen_bucket_name_from_userid( each_user['user_id'], rand_no=bc) log.info('creating bucket with name: %s' % bucket_name_to_create) # bucket = s3_ops.resource_op(rgw_conn, 'Bucket', bucket_name_to_create) bucket = resuables.create_bucket(bucket_name=bucket_name_to_create, rgw=rgw_conn, user_info=each_user) bucket_request_payer = s3lib.resource_op({ 'obj': rgw_conn, 'resource': 'BucketRequestPayment', 'args': [bucket.name] }) # change the bucket request payer to 'requester' payer = {'Payer': requester} response = s3lib.resource_op({ 'obj': bucket_request_payer, 'resource': 'put', 'kwargs': dict(RequestPaymentConfiguration=payer) }) log.info(response) if response is not None: response = HttpResponseParser(response) if response.status_code == 200: log.info('bucket created') else: raise TestExecError( "bucket request payer modification failed") else: raise TestExecError("bucket request payer modification failed") payer = bucket_request_payer.payer log.info('bucket request payer: %s' % payer) if payer != 'Requester': TestExecError('Request payer is not set or changed properly ') log.info('s3 objects to create: %s' % config.objects_count) if config.objects_count is not None: for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name(bucket.name, oc) resuables.upload_object(s3_object_name, bucket, TEST_DATA_PATH, config, each_user)
def upload_objects(user_info, bucket, config): log.info('s3 objects to create: %s' % config.objects_count) for oc in range(config.objects_count): s3_object_name = utils.gen_s3_object_name(bucket.name, oc) resuables.upload_object(s3_object_name, bucket, TEST_DATA_PATH, config, user_info)
def test_exec(config): test_info = AddTestInfo('Test Byte range') io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) try: test_info.started_info() # create user all_users_info = s3lib.create_users(config.user_count) for each_user in all_users_info: # authenticate auth = Auth(each_user, ssl=config.ssl) rgw_conn = auth.do_auth() rgw_conn2 = auth.do_auth_using_client() # create buckets log.info('no of buckets to create: %s' % config.bucket_count) for bc in range(config.bucket_count): bucket_name = utils.gen_bucket_name_from_userid(each_user['user_id'], rand_no=1) bucket = resuables.create_bucket(bucket_name, rgw_conn, each_user) # uploading data log.info('s3 objects to create: %s' % config.objects_count) for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name(bucket.name, oc) resuables.upload_object(s3_object_name, bucket, TEST_DATA_PATH, config, each_user) log.info('testing for negative range') response = rgw_conn2.get_object(Bucket=bucket.name, Key=s3_object_name, Range='-2--1') log.info('response: %s\n' % response) log.info('Content-Lenght: %s' % response['ContentLength']) log.info('s3_object_size: %s' % (config.obj_size * 1024 * 1024)) if response['ContentLength'] != config.obj_size * 1024 * 1024: TestExecError("Content Lenght not matched") log.info('testing for one positive and one negative range') response = rgw_conn2.get_object(Bucket=bucket.name, Key=s3_object_name, Range='-1-3') log.info('response: %s\n' % response) log.info('Content-Length: %s' % response['ContentLength']) log.info('s3_object_size: %s' % (config.obj_size * 1024 * 1024)) if response['ContentLength'] != config.obj_size * 1024 * 1024: TestExecError("Content Lenght not matched") test_info.success_status('test passed') sys.exit(0) except Exception as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status('test failed') sys.exit(1) except TestExecError as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status('test failed') sys.exit(1)
def test_acls_public_read(u1_rgw_conn, u1, u2_rgw_conn, u1_bucket, u2_bucket): # test for public_read s3_ops = ResourceOps() u1_bucket_acl = s3_ops.resource_op(u1_rgw_conn, 'BucketAcl', u1_bucket.name) log.info('setting bucket acl: %s' % ACLS[1]) u1_bucket_acl.put(ACL=ACLS[1]) # access bucket_info of u1_bucket from u2 log.info('u1 bucket info') u1_bucket_info = s3_ops.resource_op(u1_rgw_conn, 'Bucket', u1_bucket.name) log.info(u1_bucket_info.name) log.info(u1_bucket_info.creation_date) log.info(u1_bucket_info.load()) s3_object_name = utils.gen_s3_object_name(u1_bucket.name, rand_no=0) log.info('s3 object name: %s' % s3_object_name) s3_object_path = os.path.join(TEST_DATA_PATH, s3_object_name) log.info('s3 object path: %s' % s3_object_path) s3_object_size = utils.get_file_size(config.objects_size_range['min'], config.objects_size_range['max']) data_info = manage_data.io_generator(s3_object_path, s3_object_size) if data_info is False: TestExecError("data creation failed") log.info('uploading s3 object: %s' % s3_object_path) upload_info = dict({'access_key': u1['access_key']}, **data_info) object_uploaded_status = s3_ops.resource_op(u1_bucket, 'upload_file', s3_object_path, s3_object_name, **upload_info) if object_uploaded_status is False: raise TestExecError("Resource execution failed: object upload failed") if object_uploaded_status is None: log.info('object uploaded') log.info( 'trying to access u1 bucket and its objects info from u2 after setting u1 bucket acls to public read' ) access_u1_bucket_from_u2 = s3_ops.resource_op(u2_rgw_conn, 'Bucket', u1_bucket.name) try: all_objects = access_u1_bucket_from_u2.objects.all() for obj in all_objects: log.info('obj name: %s' % obj.key) except Exception as e: msg = 'access given to read, but still failing to read' raise TestExecError(msg) log.info('tryring to delete u1_bucket from u2') try: u1_bucket_deleted_response = access_u1_bucket_from_u2.delete() response = HttpResponseParser(u1_bucket_deleted_response) log.info(response) except Exception as e: msg = 'access not given to write, hence fialing' log.info(msg) else: raise TestExecError("acces not given, but still bucket got deleted")
def fill_container( rgw, container_name, user_id, oc, cc, size, multipart=False, split_size=0, header=None, ): swift_object_name = utils.gen_s3_object_name( "%s.container.%s" % (user_id, cc), oc) log.info("object name: %s" % swift_object_name) object_path = os.path.join(TEST_DATA_PATH, swift_object_name) log.info("object path: %s" % object_path) data_info = manage_data.io_generator(object_path, size) # upload object if multipart == True: mp_dir = os.path.join(TEST_DATA_PATH, swift_object_name + ".mp.parts") log.info(f"mp part dir: {mp_dir}") log.info("making multipart object part dir") mkdir = utils.exec_shell_cmd("sudo mkdir %s" % mp_dir) if mkdir is False: raise TestExecError("mkdir failed creating mp_dir_name") utils.split_file(object_path, split_size, mp_dir + "/") parts_list = sorted(glob.glob(mp_dir + "/" + "*")) log.info("parts_list: %s" % parts_list) log.info("no of parts: %s" % len(parts_list)) for each_part in parts_list: log.info("trying to upload part: %s" % each_part) with open(each_part, "r") as fp: etag = rgw.put_object( container_name, swift_object_name + "/" + each_part, contents=fp.read(), content_type="text/plain", headers=header, ) return swift_object_name else: if data_info is False: raise TestExecError("data creation failed") log.info("uploading object: %s" % object_path) with open(object_path, "r") as fp: rgw.put_object( container_name, swift_object_name, contents=fp.read(), content_type="text/plain", headers=header, ) return swift_object_name
def test_exec(config): test_info = AddTestInfo("Test Byte range") io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) test_info.started_info() # create user all_users_info = s3lib.create_users(config.user_count) for each_user in all_users_info: # authenticate auth = Auth(each_user) rgw_conn = auth.do_auth() rgw_conn2 = auth.do_auth_using_client() # create buckets log.info("no of buckets to create: %s" % config.bucket_count) for bc in range(config.bucket_count): bucket_name = utils.gen_bucket_name_from_userid( each_user["user_id"], rand_no=1 ) bucket = reusable.create_bucket(bucket_name, rgw_conn, each_user) # uploading data log.info("s3 objects to create: %s" % config.objects_count) for oc, size in config.mapped_sizes.items(): config.obj_size = size s3_object_name = utils.gen_s3_object_name(bucket.name, oc) reusable.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user ) log.info("testing for negative range") response = rgw_conn2.get_object( Bucket=bucket.name, Key=s3_object_name, Range="-2--1" ) log.info("response: %s\n" % response) log.info("Content-Lenght: %s" % response["ContentLength"]) log.info("s3_object_size: %s" % (config.obj_size * 1024 * 1024)) if response["ContentLength"] != config.obj_size * 1024 * 1024: TestExecError("Content Lenght not matched") log.info("testing for one positive and one negative range") response = rgw_conn2.get_object( Bucket=bucket.name, Key=s3_object_name, Range="-1-3" ) log.info("response: %s\n" % response) log.info("Content-Length: %s" % response["ContentLength"]) log.info("s3_object_size: %s" % (config.obj_size * 1024 * 1024)) if response["ContentLength"] != config.obj_size * 1024 * 1024: TestExecError("Content Lenght not matched")
def test_exec(config): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() write_bucket_io_info = BucketIoInfo() io_info_initialize.initialize(basic_io_structure.initial()) ceph_conf = CephConfOp() rgw_service = RGWService() # check the default data log backing default_data_log = reusable.get_default_datalog_type() log.info(f"{default_data_log} is the default data log backing") # check sync status if a multisite cluster reusable.check_sync_status() # create user all_users_info = s3lib.create_users(config.user_count) for each_user in all_users_info: # authenticate auth = Auth(each_user, ssl=config.ssl) rgw_conn = auth.do_auth() objects_created_list = [] # change the default datalog backing to FIFO if config.test_ops.get("change_datalog_backing", False): logtype = config.test_ops["change_datalog_backing"] log.info(f"change default datalog backing to {logtype}") cmd = f"radosgw-admin datalog type --log-type={logtype}" change_datalog_type = utils.exec_shell_cmd(cmd) if change_datalog_type is False: raise TestExecError("Failed to change the datalog type to fifo") log.info( "restart the rgw daemons and sleep of 30secs for rgw daemon to be up " ) srv_restarted = rgw_service.restart() time.sleep(30) if srv_restarted is False: raise TestExecError("RGW service restart failed") else: log.info("RGW service restarted") if config.test_ops["create_bucket"] is True: log.info("no of buckets to create: %s" % config.bucket_count) for bc in range(config.bucket_count): bucket_name_to_create = utils.gen_bucket_name_from_userid( each_user["user_id"], rand_no=bc ) log.info("creating bucket with name: %s" % bucket_name_to_create) bucket = reusable.create_bucket( bucket_name_to_create, rgw_conn, each_user ) if config.test_ops.get("enable_version", False): log.info("enable bucket version") reusable.enable_versioning( bucket, rgw_conn, each_user, write_bucket_io_info ) if config.test_ops["create_object"] is True: # uploading data log.info( "top level s3 objects to create: %s" % config.objects_count ) for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name( bucket_name_to_create, oc ) log.info("s3 object name: %s" % s3_object_name) s3_object_path = os.path.join(TEST_DATA_PATH, s3_object_name) log.info("s3 object path: %s" % s3_object_path) if config.test_ops.get("upload_type") == "multipart": log.info("upload type: multipart") reusable.upload_mutipart_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, ) else: log.info("upload type: normal") reusable.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, ) objects_created_list.append((s3_object_name, s3_object_path)) # deleting the local file created after upload if config.local_file_delete is True: log.info("deleting local file created after the upload") utils.exec_shell_cmd("rm -rf %s" % s3_object_path) # delete object and bucket if config.test_ops.get("delete_bucket_object", False): if config.test_ops.get("enable_version", False): for name, path in objects_created_list: reusable.delete_version_object( bucket, name, path, rgw_conn, each_user ) else: reusable.delete_objects(bucket) time.sleep(30) reusable.delete_bucket(bucket) # check for any ERRORs in datalog list. ref- https://bugzilla.redhat.com/show_bug.cgi?id=1917687 error_in_data_log_list = reusable.check_datalog_list() if error_in_data_log_list: raise TestExecError("Error in datalog list") # check for data log markers. ref: https://bugzilla.redhat.com/show_bug.cgi?id=1831798#c22 data_log_marker = reusable.check_datalog_marker() log.info(f"The data_log_marker is: {data_log_marker}") # check sync status if a multisite cluster reusable.check_sync_status() # check for any crashes during the execution crash_info = reusable.check_for_crash()
def test_exec(config): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) # create user all_users_info = s3lib.create_users(config.user_count) for each_user in all_users_info: # authenticate auth = Auth(each_user, ssl=config.ssl) rgw_conn = auth.do_auth() rgw_conn2 = auth.do_auth_using_client() # create buckets if config.test_ops["create_bucket"] is True: log.info("no of buckets to create: %s" % config.bucket_count) for bc in range(config.bucket_count): bucket_name = utils.gen_bucket_name_from_userid( each_user["user_id"], rand_no=1) bucket = reusable.create_bucket(bucket_name, rgw_conn, each_user) if config.test_ops["enable_versioning"] is True: log.info("bucket versionig test on bucket: %s" % bucket.name) # bucket_versioning = s3_ops.resource_op(rgw_conn, 'BucketVersioning', bucket.name) bucket_versioning = s3lib.resource_op({ "obj": rgw_conn, "resource": "BucketVersioning", "args": [bucket.name], }) version_status = s3lib.resource_op({ "obj": bucket_versioning, "resource": "status", "args": None }) if version_status is None: log.info("bucket versioning still not enabled") # enabling bucket versioning version_enable_status = s3lib.resource_op({ "obj": bucket_versioning, "resource": "enable", "args": None }) response = HttpResponseParser(version_enable_status) if response.status_code == 200: log.info("version enabled") else: raise TestExecError("version enable failed") if config.test_ops["create_object"] is True: # upload data for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name( bucket.name, oc) if config.test_ops["version_count"] > 0: for vc in range(config.test_ops["version_count"]): log.info("version count for %s is %s" % (s3_object_name, str(vc))) log.info("modifying data: %s" % s3_object_name) reusable.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, append_data=True, append_msg="hello object for version: %s\n" % str(vc), ) else: log.info("s3 objects to create: %s" % config.objects_count) reusable.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, ) bucket_life_cycle = s3lib.resource_op({ "obj": rgw_conn, "resource": "BucketLifecycleConfiguration", "args": [bucket.name], }) life_cycle = basic_lifecycle_config(prefix="key", days=20, id="rul1") put_bucket_life_cycle = s3lib.resource_op({ "obj": bucket_life_cycle, "resource": "put", "kwargs": dict(LifecycleConfiguration=life_cycle), }) log.info("put bucket life cycle:\n%s" % put_bucket_life_cycle) if put_bucket_life_cycle is False: raise TestExecError( "Resource execution failed: bucket creation faield") if put_bucket_life_cycle is not None: response = HttpResponseParser(put_bucket_life_cycle) if response.status_code == 200: log.info("bucket life cycle added") else: raise TestExecError("bucket lifecycle addition failed") else: raise TestExecError("bucket lifecycle addition failed") log.info("trying to retrieve bucket lifecycle config") get_bucket_life_cycle_config = s3lib.resource_op({ "obj": rgw_conn2, "resource": "get_bucket_lifecycle_configuration", "kwargs": dict(Bucket=bucket.name), }) if get_bucket_life_cycle_config is False: raise TestExecError( "bucket lifecycle config retrieval failed") if get_bucket_life_cycle_config is not None: response = HttpResponseParser(get_bucket_life_cycle_config) if response.status_code == 200: log.info("bucket life cycle retrieved") else: raise TestExecError( "bucket lifecycle config retrieval failed") else: raise TestExecError("bucket life cycle retrieved") if config.test_ops["create_object"] is True: for oc in range(config.objects_count): s3_object_name = utils.gen_s3_object_name( bucket.name, oc) if config.test_ops["version_count"] > 0: if (config.test_ops.get("delete_versioned_object", None) is True): log.info( "list all the versions of the object and delete the " "current version of the object") log.info("all versions for the object: %s\n" % s3_object_name) versions = bucket.object_versions.filter( Prefix=s3_object_name) t1 = [] for version in versions: log.info( "key_name: %s --> version_id: %s" % (version.object_key, version.version_id)) t1.append(version.version_id) s3_object = s3lib.resource_op({ "obj": rgw_conn, "resource": "Object", "args": [bucket.name, s3_object_name], }) # log.info('object version to delete: %s -> %s' % (versions[0].object_key, # versions[0].version_id)) delete_response = s3_object.delete() log.info("delete response: %s" % delete_response) if delete_response["DeleteMarker"] is True: log.info( "object delete marker is set to true") else: raise TestExecError( "'object delete marker is set to false" ) log.info( "available versions for the object after delete marker is set" ) t2 = [] versions_after_delete_marker_is_set = ( bucket.object_versions.filter( Prefix=s3_object_name)) for version in versions_after_delete_marker_is_set: log.info( "key_name: %s --> version_id: %s" % (version.object_key, version.version_id)) t2.append(version.version_id) t2.pop() if t1 == t2: log.info("versions remained intact") else: raise TestExecError( "versions are not intact after delete marker is set" ) # modify bucket lifecycle configuration, modify expiration days here for the test case. if config.test_ops.get("modify_lifecycle", False) is True: log.info("modifying lifecycle configuration") life_cycle_modifed = basic_lifecycle_config( prefix="key", days=15, id="rul1", status="Disabled") put_bucket_life_cycle = s3lib.resource_op({ "obj": bucket_life_cycle, "resource": "put", "kwargs": dict(LifecycleConfiguration=life_cycle_modifed), }) log.info("put bucket life cycle:\n%s" % put_bucket_life_cycle) if put_bucket_life_cycle is False: raise TestExecError( "Resource execution failed: bucket creation faield" ) if put_bucket_life_cycle is not None: response = HttpResponseParser(put_bucket_life_cycle) if response.status_code == 200: log.info("bucket life cycle added") else: raise TestExecError( "bucket lifecycle addition failed") else: raise TestExecError("bucket lifecycle addition failed") log.info("trying to retrieve bucket lifecycle config") get_bucket_life_cycle_config = s3lib.resource_op({ "obj": rgw_conn2, "resource": "get_bucket_lifecycle_configuration", "kwargs": dict(Bucket=bucket.name), }) if get_bucket_life_cycle_config is False: raise TestExecError( "bucket lifecycle config retrieval failed") if get_bucket_life_cycle_config is not None: response = HttpResponseParser( get_bucket_life_cycle_config) modified_expiration_days = get_bucket_life_cycle_config[ "Rules"][0]["Expiration"]["Days"] log.info("modified expiration days: %s" % modified_expiration_days) if (response.status_code == 200 and modified_expiration_days == 15): log.info( "bucket life cycle retrieved after modifying") else: raise TestExecError( "bucket lifecycle config retrieval failed after modifying" ) else: raise TestExecError( "bucket lifecycle config retrieval failed after modifying" ) # disable bucket lifecycle configuration if config.test_ops.get("disable_lifecycle", False) is True: log.info("disabling lifecycle configuration") life_cycle_disabled_config = basic_lifecycle_config( prefix="key", days=20, id="rul1", status="Disabled") put_bucket_life_cycle = s3lib.resource_op({ "obj": bucket_life_cycle, "resource": "put", "kwargs": dict( LifecycleConfiguration=life_cycle_disabled_config), }) log.info("put bucket life cycle:\n%s" % put_bucket_life_cycle) if put_bucket_life_cycle is False: raise TestExecError( "Resource execution failed: bucket creation faield" ) if put_bucket_life_cycle is not None: response = HttpResponseParser(put_bucket_life_cycle) if response.status_code == 200: log.info("bucket life cycle added") else: raise TestExecError( "bucket lifecycle addition failed") else: raise TestExecError("bucket lifecycle addition failed") log.info("trying to retrieve bucket lifecycle config") get_bucket_life_cycle_config = s3lib.resource_op({ "obj": rgw_conn2, "resource": "get_bucket_lifecycle_configuration", "kwargs": dict(Bucket=bucket.name), }) if get_bucket_life_cycle_config is False: raise TestExecError( "bucket lifecycle config retrieval failed") if get_bucket_life_cycle_config is not None: response = HttpResponseParser( get_bucket_life_cycle_config) if (response.status_code == 200 and get_bucket_life_cycle_config["Rules"][0] ["Status"] == "Disabled"): log.info("disabled_status: %s" % get_bucket_life_cycle_config["Rules"][0] ["Status"]) log.info( "bucket life cycle retrieved after disabled") else: raise TestExecError( "bucket lifecycle config retrieval failed after disabled" ) else: raise TestExecError( "bucket lifecycle config retrieval failed after disabled" ) # check for any crashes during the execution crash_info = reusable.check_for_crash() if crash_info: raise TestExecError("ceph daemon crash found!")
def test_exec(config): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() write_bucket_io_info = BucketIoInfo() io_info_initialize.initialize(basic_io_structure.initial()) ceph_conf = CephConfOp() rgw_service = RGWService() # create user all_users_info = s3lib.create_users(config.user_count) for each_user in all_users_info: # authenticate auth = Auth(each_user, ssl=config.ssl) rgw_conn = auth.do_auth() # authenticate sns client. rgw_sns_conn = auth.do_auth_sns_client() # authenticate with s3 client rgw_s3_client = auth.do_auth_using_client() # get ceph version ceph_version_id, ceph_version_name = utils.get_ceph_version() objects_created_list = [] if config.test_ops["create_bucket"] is True: log.info("no of buckets to create: %s" % config.bucket_count) for bc in range(config.bucket_count): bucket_name_to_create = utils.gen_bucket_name_from_userid( each_user["user_id"], rand_no=bc) bucket = reusable.create_bucket(bucket_name_to_create, rgw_conn, each_user) if config.test_ops.get("enable_version", False): log.info("enable bucket version") reusable.enable_versioning(bucket, rgw_conn, each_user, write_bucket_io_info) # create topic with endpoint if config.test_ops["create_topic"] is True: endpoint = config.test_ops.get("endpoint") ack_type = config.test_ops.get("ack_type") topic_id = str(uuid.uuid4().hex[:16]) persistent = False topic_name = "cephci-kafka-" + ack_type + "-ack-type-" + topic_id log.info( f"creating a topic with {endpoint} endpoint with ack type {ack_type}" ) if config.test_ops.get("persistent_flag", False): log.info("topic with peristent flag enabled") persistent = config.test_ops.get("persistent_flag") topic = notification.create_topic(rgw_sns_conn, endpoint, ack_type, topic_name, persistent) # get topic attributes if config.test_ops.get("get_topic_info", False): log.info("get topic attributes") get_topic_info = notification.get_topic( rgw_sns_conn, topic, ceph_version_name) # put bucket notification with topic configured for event if config.test_ops["put_get_bucket_notification"] is True: event = config.test_ops.get("event_type") notification_name = "notification-" + str(event) notification.put_bucket_notification( rgw_s3_client, bucket_name_to_create, notification_name, topic, event, ) # get bucket notification log.info( f"get bucket notification for bucket : {bucket_name_to_create}" ) notification.get_bucket_notification( rgw_s3_client, bucket_name_to_create) # create objects if config.test_ops["create_object"] is True: # uploading data log.info("s3 objects to create: %s" % config.objects_count) for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name( bucket_name_to_create, oc) log.info("s3 object name: %s" % s3_object_name) s3_object_path = os.path.join(TEST_DATA_PATH, s3_object_name) log.info("s3 object path: %s" % s3_object_path) if config.test_ops.get("upload_type") == "multipart": log.info("upload type: multipart") reusable.upload_mutipart_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, ) else: log.info("upload type: normal") reusable.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, ) # copy objects if config.test_ops.get("copy_object", False): log.info("copy object") status = rgw_s3_client.copy_object( Bucket=bucket_name_to_create, Key="copy_of_object" + s3_object_name, CopySource={ "Bucket": bucket_name_to_create, "Key": s3_object_name, }, ) if status is None: raise TestExecError("copy object failed") # delete objects if config.test_ops.get("delete_bucket_object", False): if config.test_ops.get("enable_version", False): for name, path in objects_created_list: reusable.delete_version_object(bucket, name, path, rgw_conn, each_user) else: reusable.delete_objects(bucket) # start kafka broker and consumer event_record_path = "/home/cephuser/event_record" start_consumer = notification.start_kafka_broker_consumer( topic_name, event_record_path) if start_consumer is False: raise TestExecError("Kafka consumer not running") # verify all the attributes of the event record. if event not received abort testcase log.info("verify event record attributes") verify = notification.verify_event_record(event, bucket_name_to_create, event_record_path, ceph_version_name) if verify is False: raise EventRecordDataError( "Event record is empty! notification is not seen") # delete topic logs on kafka broker notification.del_topic_from_kafka_broker(topic_name) # check sync status if a multisite cluster reusable.check_sync_status() # check for any crashes during the execution crash_info = reusable.check_for_crash() if crash_info: raise TestExecError("ceph daemon crash found!")
def test_exec(config): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) rgw_service = RGWService() # create pool pool_name = '.rgw.buckets.special' pg_num = '8' pgp_num = '8' pool_create = 'sudo ceph osd pool create "%s" %s %s replicated' % ( pool_name, pg_num, pgp_num) pool_create_exec = utils.exec_shell_cmd(pool_create) if pool_create_exec is False: raise TestExecError("Pool creation failed") # create realm realm_name = 'buz-tickets' log.info('creating realm name') realm_create = 'sudo radosgw-admin realm create --rgw-realm=%s' % realm_name realm_create_exec = utils.exec_shell_cmd(realm_create) if realm_create_exec is False: raise TestExecError("cmd execution failed") # sample output of create realm """ { "id": "0956b174-fe14-4f97-8b50-bb7ec5e1cf62", "name": "buz-tickets", "current_period": "1950b710-3e63-4c41-a19e-46a715000980", "epoch": 1 } """ log.info('modify zonegroup ') modify = 'sudo radosgw-admin zonegroup modify --rgw-zonegroup=default --rgw-realm=%s --master' % realm_name modify_exec = utils.exec_shell_cmd(modify) if modify_exec is False: raise TestExecError("cmd execution failed") # get the zonegroup zonegroup_file = 'zonegroup.json' get_zonegroup = 'sudo radosgw-admin zonegroup --rgw-zonegroup=default get > %s' % zonegroup_file get_zonegroup_exec = utils.exec_shell_cmd(get_zonegroup) if get_zonegroup_exec is False: raise TestExecError("cmd execution failed") add_to_placement_targets = {"name": "special-placement", "tags": []} fp = open(zonegroup_file, 'r') zonegroup_txt = fp.read() fp.close() log.info('got zonegroup info: \n%s' % zonegroup_txt) zonegroup = json.loads(zonegroup_txt) log.info('adding placement targets') zonegroup['placement_targets'].append(add_to_placement_targets) with open(zonegroup_file, 'w') as fp: json.dump(zonegroup, fp) zonegroup_set = 'sudo radosgw-admin zonegroup set < %s' % zonegroup_file zonegroup_set_exec = utils.exec_shell_cmd(zonegroup_set) if zonegroup_set_exec is False: raise TestExecError("cmd execution failed") log.info('zone group update completed') log.info('getting zone file') # get zone log.info('getting zone info') zone_file = 'zone.json' get_zone = 'sudo radosgw-admin zone --rgw-zone=default get > zone.json' get_zone_exec = utils.exec_shell_cmd(get_zone) if get_zone_exec is False: raise TestExecError("cmd execution failed") fp = open(zone_file, 'r') zone_info = fp.read() fp.close() log.info('zone_info :\n%s' % zone_info) zone_info_cleaned = json.loads(zone_info) special_placement_info = { "key": "special-placement", "val": { "index_pool": ".rgw.buckets.index", "data_pool": ".rgw.buckets.special", "data_extra_pool": ".rgw.buckets.extra" } } log.info('adding special placement info') zone_info_cleaned['placement_pools'].append(special_placement_info) with open(zone_file, 'w+') as fp: json.dump(zone_info_cleaned, fp) zone_file_set = 'sudo radosgw-admin zone set < %s' % zone_file zone_file_set_exec = utils.exec_shell_cmd(zone_file_set) if zone_file_set_exec is False: raise TestExecError("cmd execution failed") log.info('zone info updated ') zone_group_update_set = 'radosgw-admin period update --commit' zone_group_update_set_exec = utils.exec_shell_cmd(zone_group_update_set) log.info(zone_group_update_set_exec) restarted = rgw_service.restart() if restarted is False: raise TestExecError("service restart failed") if config.rgw_client == 'rgw': log.info('client type is rgw') rgw_user_info = s3_swift_lib.create_users(1) auth = Auth(rgw_user_info) rgw_conn = auth.do_auth() # create bucket bucket_name = utils.gen_bucket_name_from_userid( rgw_user_info['user_id'], 0) bucket = resuables.create_bucket(bucket_name, rgw_conn, rgw_user_info) # create object s3_object_name = utils.gen_s3_object_name(bucket_name, 0) resuables.upload_object(s3_object_name, bucket, TEST_DATA_PATH, config, rgw_user_info) if config.rgw_client == 'swift': log.info('client type is swift') user_names = ['tuffy', 'scooby', 'max'] tenant = 'tenant' umgmt = UserMgmt() umgmt.create_tenant_user(tenant_name=tenant, user_id=user_names[0], displayname=user_names[0]) user_info = umgmt.create_subuser(tenant_name=tenant, user_id=user_names[0]) auth = Auth(user_info) rgw = auth.do_auth() container_name = utils.gen_bucket_name_from_userid( user_info['user_id'], rand_no=0) container = s3_swift_lib.resource_op({ 'obj': rgw, 'resource': 'put_container', 'args': [container_name] }) if container is False: raise TestExecError( "Resource execution failed: container creation faield") swift_object_name = utils.gen_s3_object_name( '%s.container.%s' % (user_names[0], 0), 0) log.info('object name: %s' % swift_object_name) object_path = os.path.join(TEST_DATA_PATH, swift_object_name) log.info('object path: %s' % object_path) object_size = utils.get_file_size(config.objects_size_range['min'], config.objects_size_range['max']) data_info = manage_data.io_generator(object_path, object_size) # upload object if data_info is False: TestExecError("data creation failed") log.info('uploading object: %s' % object_path) with open(object_path, 'r') as fp: rgw.put_object(container_name, swift_object_name, contents=fp.read(), content_type='text/plain')
def test_exec(config): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() write_bucket_io_info = BucketIoInfo() io_info_initialize.initialize(basic_io_structure.initial()) ceph_conf = CephConfOp() rgw_service = RGWService() log.info('starting IO') config.user_count = 1 user_info = s3lib.create_users(config.user_count) user_info = user_info[0] auth = Auth(user_info, ssl=config.ssl) rgw_conn = auth.do_auth() log.info('sharding configuration will be added now.') if config.sharding_type == 'dynamic': log.info('sharding type is dynamic') # for dynamic, # the number of shards should be greater than [ (no of objects)/(max objects per shard) ] # example: objects = 500 ; max object per shard = 10 # then no of shards should be at least 50 or more time.sleep(15) log.info('making changes to ceph.conf') ceph_conf.set_to_ceph_conf('global', ConfigOpts.rgw_max_objs_per_shard, str(config.max_objects_per_shard)) ceph_conf.set_to_ceph_conf('global', ConfigOpts.rgw_dynamic_resharding, 'True') num_shards_expected = config.objects_count / config.max_objects_per_shard log.info('num_shards_expected: %s' % num_shards_expected) log.info('trying to restart services ') srv_restarted = rgw_service.restart() time.sleep(30) if srv_restarted is False: raise TestExecError("RGW service restart failed") else: log.info('RGW service restarted') config.bucket_count = 1 objects_created_list = [] log.info('no of buckets to create: %s' % config.bucket_count) bucket_name = utils.gen_bucket_name_from_userid(user_info['user_id'], rand_no=1) bucket = reusable.create_bucket(bucket_name, rgw_conn, user_info) if config.test_ops.get('enable_version', False): log.info('enable bucket version') reusable.enable_versioning(bucket, rgw_conn, user_info, write_bucket_io_info) log.info('s3 objects to create: %s' % config.objects_count) for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name(bucket.name, oc) s3_object_path = os.path.join(TEST_DATA_PATH, s3_object_name) if config.test_ops.get('enable_version', False): reusable.upload_version_object(config, user_info, rgw_conn, s3_object_name, config.obj_size, bucket, TEST_DATA_PATH) else: reusable.upload_object(s3_object_name, bucket, TEST_DATA_PATH, config, user_info) objects_created_list.append((s3_object_name, s3_object_path)) if config.sharding_type == 'manual': log.info('sharding type is manual') # for manual. # the number of shards will be the value set in the command. time.sleep(15) log.info('in manual sharding') cmd_exec = utils.exec_shell_cmd( 'radosgw-admin bucket reshard --bucket=%s --num-shards=%s ' '--yes-i-really-mean-it' % (bucket.name, config.shards)) if cmd_exec is False: raise TestExecError("manual resharding command execution failed") sleep_time = 600 log.info(f'verification starts after waiting for {sleep_time} seconds') time.sleep(sleep_time) op = utils.exec_shell_cmd("radosgw-admin metadata get bucket:%s" % bucket.name) json_doc = json.loads(op) bucket_id = json_doc['data']['bucket']['bucket_id'] op2 = utils.exec_shell_cmd( "radosgw-admin metadata get bucket.instance:%s:%s" % (bucket.name, bucket_id)) json_doc2 = json.loads((op2)) num_shards_created = json_doc2['data']['bucket_info']['num_shards'] log.info('no_of_shards_created: %s' % num_shards_created) if config.sharding_type == 'manual': if config.shards != num_shards_created: raise TestExecError("expected number of shards not created") log.info('Expected number of shards created') if config.sharding_type == 'dynamic': log.info('Verify if resharding list is empty') reshard_list_op = json.loads( utils.exec_shell_cmd("radosgw-admin reshard list")) if not reshard_list_op: log.info( 'for dynamic number of shards created should be greater than or equal to number of expected shards' ) log.info('no_of_shards_expected: %s' % num_shards_expected) if int(num_shards_created) >= int(num_shards_expected): log.info('Expected number of shards created') else: raise TestExecError('Expected number of shards not created') if config.test_ops.get('delete_bucket_object', False): if config.test_ops.get('enable_version', False): for name, path in objects_created_list: reusable.delete_version_object(bucket, name, path, rgw_conn, user_info) else: reusable.delete_objects(bucket) reusable.delete_bucket(bucket)
def test_exec(config): test_info = AddTestInfo('create m buckets with n objects') try: test_info.started_info() # get user with open('user_details') as fout: all_users_info = simplejson.load(fout) for each_user in all_users_info: # authenticate auth = Auth(each_user) rgw_conn = auth.do_auth_using_client() rgw = auth.do_auth() bucket_list = [] buckets = rgw_conn.list_buckets() log.info('buckets are %s' % buckets) for each_bucket in buckets['Buckets']: bucket_list.append(each_bucket['Name']) for bucket_name in bucket_list: # create 'bucket' resource object bucket = rgw.Bucket(bucket_name) log.info('In bucket: %s' % bucket_name) if config.test_ops['create_object'] is True: # uploading data log.info('s3 objects to create: %s' % config.objects_count) for oc in range(config.objects_count): s3_object_name = utils.gen_s3_object_name(bucket_name, oc) log.info('s3 object name: %s' % s3_object_name) s3_object_path = os.path.join(TEST_DATA_PATH, s3_object_name) log.info('s3 object path: %s' % s3_object_path) s3_object_size = utils.get_file_size(config.objects_size_range['min'], config.objects_size_range['max']) data_info = manage_data.io_generator(s3_object_path, s3_object_size) if data_info is False: TestExecError("data creation failed") log.info('uploading s3 object: %s' % s3_object_path) upload_info = dict({'access_key': each_user['access_key']}, **data_info) # object_uploaded_status = bucket.upload_file(s3_object_path, s3_object_name) object_uploaded_status = s3lib.resource_op({'obj': bucket, 'resource': 'upload_file', 'args': [s3_object_path, s3_object_name], 'extra_info': upload_info}) if object_uploaded_status is False: raise TestExecError("Resource execution failed: object upload failed") if object_uploaded_status is None: log.info('object uploaded') if config.test_ops['download_object'] is True: log.info('trying to download object: %s' % s3_object_name) s3_object_download_name = s3_object_name + "." + "download" s3_object_download_path = os.path.join(TEST_DATA_PATH, s3_object_download_name) log.info('s3_object_download_path: %s' % s3_object_download_path) log.info('downloading to filename: %s' % s3_object_download_name) # object_downloaded_status = bucket.download_file(s3_object_path, s3_object_name) object_downloaded_status = s3lib.resource_op({'obj': bucket, 'resource': 'download_file', 'args': [s3_object_name, s3_object_download_path], }) if object_downloaded_status is False: raise TestExecError("Resource execution failed: object download failed") if object_downloaded_status is None: log.info('object downloaded') if config.test_ops['delete_bucket_object'] is True: log.info('listing all objects in bucket: %s' % bucket.name) # objects = s3_ops.resource_op(bucket, 'objects', None) objects = s3lib.resource_op({'obj': bucket, 'resource': 'objects', 'args': None}) log.info('objects :%s' % objects) # all_objects = s3_ops.resource_op(objects, 'all') all_objects = s3lib.resource_op({'obj': objects, 'resource': 'all', 'args': None}) log.info('all objects: %s' % all_objects) for obj in all_objects: log.info('object_name: %s' % obj.key) log.info('deleting all objects in bucket') # objects_deleted = s3_ops.resource_op(objects, 'delete') objects_deleted = s3lib.resource_op({'obj': objects, 'resource': 'delete', 'args': None}) log.info('objects_deleted: %s' % objects_deleted) if objects_deleted is False: raise TestExecError('Resource execution failed: Object deletion failed') if objects_deleted is not None: response = HttpResponseParser(objects_deleted[0]) if response.status_code == 200: log.info('objects deleted ') else: raise TestExecError("objects deletion failed") else: raise TestExecError("objects deletion failed") # wait for object delete info to sync time.sleep(60) log.info('deleting bucket: %s' % bucket.name) # bucket_deleted_status = s3_ops.resource_op(bucket, 'delete') bucket_deleted_status = s3lib.resource_op({'obj': bucket, 'resource': 'delete', 'args': None}) log.info('bucket_deleted_status: %s' % bucket_deleted_status) if bucket_deleted_status is not None: response = HttpResponseParser(bucket_deleted_status) if response.status_code == 204: log.info('bucket deleted ') else: raise TestExecError("bucket deletion failed") else: raise TestExecError("bucket deletion failed") test_info.success_status('test passed') sys.exit(0) except Exception as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status('test failed') sys.exit(1) except TestExecError as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status('test failed') sys.exit(1)
def test_exec(config): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) ceph_config_set = CephConfOp() rgw_service = RGWService() if config.sts is None: raise TestExecError("sts policies are missing in yaml config") # create users config.user_count = 2 users_info = s3lib.create_users(config.user_count) # user1 is the owner user1, user2 = users_info[0], users_info[1] log.info("adding sts config to ceph.conf") sesison_encryption_token = "abcdefghijklmnoq" ceph_config_set.set_to_ceph_conf( "global", ConfigOpts.rgw_sts_key, sesison_encryption_token ) ceph_config_set.set_to_ceph_conf("global", ConfigOpts.rgw_s3_auth_use_sts, "True") srv_restarted = rgw_service.restart() time.sleep(30) if srv_restarted is False: raise TestExecError("RGW service restart failed") else: log.info("RGW service restarted") auth = Auth(user1, ssl=config.ssl) iam_client = auth.do_auth_iam_client() policy_document = json.dumps(config.sts["policy_document"]).replace(" ", "") policy_document = policy_document.replace("<user_name>", user2["user_id"]) role_policy = json.dumps(config.sts["role_policy"]).replace(" ", "") add_caps_cmd = ( 'sudo radosgw-admin caps add --uid="{user_id}" --caps="roles=*"'.format( user_id=user1["user_id"] ) ) utils.exec_shell_cmd(add_caps_cmd) role_name = f"S3RoleOf.{user1['user_id']}" log.info(f"role_name: {role_name}") log.info("creating role") create_role_response = iam_client.create_role( AssumeRolePolicyDocument=policy_document, Path="/", RoleName=role_name, ) log.info("create_role_response") log.info(create_role_response) policy_name = f"policy.{user1['user_id']}" log.info(f"policy_name: {policy_name}") log.info("putting role policy") put_policy_response = iam_client.put_role_policy( RoleName=role_name, PolicyName=policy_name, PolicyDocument=role_policy ) log.info("put_policy_response") log.info(put_policy_response) auth = Auth(user2, ssl=config.ssl) sts_client = auth.do_auth_sts_client() log.info("assuming role") assume_role_response = sts_client.assume_role( RoleArn=create_role_response["Role"]["Arn"], RoleSessionName=user1["user_id"], DurationSeconds=3600, ) log.info(assume_role_response) assumed_role_user_info = { "access_key": assume_role_response["Credentials"]["AccessKeyId"], "secret_key": assume_role_response["Credentials"]["SecretAccessKey"], "session_token": assume_role_response["Credentials"]["SessionToken"], "user_id": user2["user_id"], } log.info("got the credentials after assume role") s3client = Auth(assumed_role_user_info, ssl=config.ssl) s3_client_rgw = s3client.do_auth() io_info_initialize.initialize(basic_io_structure.initial()) write_user_info = AddUserInfo() basic_io_structure = BasicIOInfoStructure() user_info = basic_io_structure.user( **{ "user_id": assumed_role_user_info["user_id"], "access_key": assumed_role_user_info["access_key"], "secret_key": assumed_role_user_info["secret_key"], } ) write_user_info.add_user_info(user_info) buckets_created = [] if config.test_ops["create_bucket"] is True: log.info("no of buckets to create: %s" % config.bucket_count) for bc in range(config.bucket_count): bucket_name = utils.gen_bucket_name_from_userid( assumed_role_user_info["user_id"], rand_no=bc ) log.info("creating bucket with name: %s" % bucket_name) bucket = reusable.create_bucket( bucket_name, s3_client_rgw, assumed_role_user_info ) buckets_created.append(bucket) if config.test_ops["create_object"] is True: for bucket in buckets_created: # uploading data log.info("s3 objects to create: %s" % config.objects_count) for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name(bucket.name, oc) log.info("s3 object name: %s" % s3_object_name) s3_object_path = os.path.join(TEST_DATA_PATH, s3_object_name) log.info("s3 object path: %s" % s3_object_path) if config.test_ops.get("upload_type") == "multipart": log.info("upload type: multipart") reusable.upload_mutipart_object( s3_object_name, bucket, TEST_DATA_PATH, config, assumed_role_user_info, ) else: log.info("upload type: normal") reusable.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, assumed_role_user_info, ) if config.test_ops["server_side_copy"] is True: bucket1, bucket2 = buckets_created # copy object1 from bucket1 to bucket2 with the same name as in bucket1 log.info("copying first object from bucket1 to bucket2") all_keys_in_buck1 = [] for obj in bucket1.objects.all(): all_keys_in_buck1.append(obj.key) copy_source = {"Bucket": bucket1.name, "Key": all_keys_in_buck1[0]} copy_object_name = all_keys_in_buck1[0] + "_copied_obj" log.info(f"copy object name: {copy_object_name}") bucket2.copy(copy_source, copy_object_name) # list the objects in bucket2 log.info("listing all objects im bucket2 after copy") all_bucket2_objs = [] for obj in bucket2.objects.all(): log.info(obj.key) all_bucket2_objs.append(obj.key) # check for object existence in bucket2 if copy_object_name in all_bucket2_objs: log.info("server side copy successful") else: raise TestExecError("server side copy operation was not successful") # check for any crashes during the execution crash_info = reusable.check_for_crash() if crash_info: raise TestExecError("ceph daemon crash found!")
def test_exec(config): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() write_bucket_io_info = BucketIoInfo() io_info_initialize.initialize(basic_io_structure.initial()) ceph_conf = CephConfOp() rgw_service = RGWService() # create user all_users_info = s3lib.create_users(config.user_count) if config.test_ops.get("encryption_algorithm", None) is not None: log.info("encryption enabled, making ceph config changes") ceph_conf.set_to_ceph_conf("global", ConfigOpts.rgw_crypt_require_ssl, "false") srv_restarted = rgw_service.restart() time.sleep(30) if srv_restarted is False: raise TestExecError("RGW service restart failed") else: log.info("RGW service restarted") for each_user in all_users_info: # authenticate auth = Auth(each_user, ssl=config.ssl) if config.use_aws4 is True: rgw_conn = auth.do_auth(**{"signature_version": "s3v4"}) else: rgw_conn = auth.do_auth() objects_created_list = [] if config.test_ops["create_bucket"] is True: log.info("no of buckets to create: %s" % config.bucket_count) for bc in range(config.bucket_count): bucket_name_to_create = utils.gen_bucket_name_from_userid( each_user["user_id"], rand_no=bc) log.info("creating bucket with name: %s" % bucket_name_to_create) bucket = reusable.create_bucket(bucket_name_to_create, rgw_conn, each_user) if config.test_ops.get("enable_version", False): log.info("enable bucket version") reusable.enable_versioning(bucket, rgw_conn, each_user, write_bucket_io_info) if config.test_ops["create_object"] is True: if config.test_ops["object_structure"] == "flat": # uploading data log.info("top level s3 objects to create: %s" % config.objects_count) for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name( bucket_name_to_create, oc) log.info("s3 object name: %s" % s3_object_name) s3_object_path = os.path.join( TEST_DATA_PATH, s3_object_name) log.info("s3 object path: %s" % s3_object_path) if config.test_ops.get( "upload_type") == "multipart": log.info("upload type: multipart") reusable.upload_mutipart_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, ) else: log.info("upload type: normal") reusable.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, ) objects_created_list.append( (s3_object_name, s3_object_path)) # deleting the local file created after upload if config.local_file_delete is True: log.info( "deleting local file created after the upload" ) utils.exec_shell_cmd("rm -rf %s" % s3_object_path) # this covers listing of a bucket with pseudo directories and objects in it ; Unable to list contents of large buckets https://bugzilla.redhat.com/show_bug.cgi?id=1874645#c72 if config.test_ops["object_structure"] == "pseudo": log.info( f"pseudo directories to create {config.pseudo_dir_count} with {config.objects_count} objects in each" ) for count in range(config.pseudo_dir_count): s3_pseudo_dir_name = utils.gen_s3_object_name( bucket_name_to_create, count) s3_object_path = os.path.join( TEST_DATA_PATH, s3_pseudo_dir_name) manage_data.pseudo_dir_generator(s3_object_path) for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_pseudo_object_name( s3_pseudo_dir_name, oc) log.info("s3 object name: %s" % s3_object_name) s3_object_path = os.path.join( TEST_DATA_PATH, s3_object_name) log.info("s3 object path: %s" % s3_object_path) if config.test_ops.get( "upload_type") == "multipart": log.info("upload type: multipart") reusable.upload_mutipart_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, ) else: log.info("upload type: normal") reusable.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, ) # deleting the local file created after upload if config.local_file_delete is True: log.info( "deleting local file created after the upload" ) utils.exec_shell_cmd("rm -rf %s" % s3_object_path) # listing bucket with only pseudo directories ; Bug allows ordered bucket listing to get stuck -- 4.1 https://bugzilla.redhat.com/show_bug.cgi?id=1853052#c0 if config.test_ops["create_object"] is False: if config.test_ops[ "object_structure"] == "pseudo-dir-only": log.info( f"pseudo directories to create {config.pseudo_dir_count}" ) for count in range(config.pseudo_dir_count): s3_pseudo_dir_name = utils.gen_s3_object_name( bucket_name_to_create, count) utils.create_psuedo_dir(s3_pseudo_dir_name, bucket) # radoslist listing of the bucket if config.test_ops["radoslist"] is True: log.info( "executing the command radosgw-admin bucket radoslist " ) radoslist = utils.exec_shell_cmd( "radosgw-admin bucket radoslist --bucket %s" % bucket_name_to_create) if radoslist is False: raise TestExecError( "Radoslist command execution failed") # get the configuration parameter - rgw_bucket_index_max_aio ceph_version_id, ceph_version_name = utils.get_ceph_version() if ceph_version_name in ["luminous", "nautilus"]: cmd = "ceph daemon `ls -t /var/run/ceph/ceph-client.rgw.*.asok|head -1` config show |grep rgw_bucket_index_max_aio" max_aio_output = utils.exec_shell_cmd(cmd) max_aio = max_aio_output.split()[1] else: cmd = "ceph config get mon rgw_bucket_index_max_aio" max_aio_output = utils.exec_shell_cmd(cmd) max_aio = max_aio_output.rstrip("\n") # bucket stats to get the num_objects of the bucket bucket_stats = utils.exec_shell_cmd( "radosgw-admin bucket stats --bucket %s" % bucket_name_to_create) bucket_stats_json = json.loads(bucket_stats) bkt_num_objects = bucket_stats_json["usage"]["rgw.main"][ "num_objects"] # ordered listing via radosgw-admin command and noting time taken log.info( "measure the execution time taken to list via radosgw-admin command" ) if config.test_ops["radosgw_listing_ordered"] is True: log.info("ordered listing via radosgw-admin command") rgw_cmd_time = reusable.time_to_list_via_radosgw( bucket_name_to_create, "ordered") if rgw_cmd_time > 0: rgw_cmd_time_secs = "{:.4f}".format(rgw_cmd_time) rgw_cmd_time_mins = "{:.4f}".format(rgw_cmd_time / 60) log.info( f"with rgw_bucket_index_max_aio = {max_aio} time taken for ordered listing of {bkt_num_objects} objects is : {rgw_cmd_time_secs} secs ; {rgw_cmd_time_mins} mins" ) else: raise TestExecError( "object listing via radosgw-admin command failed") # unordered listing via radosgw-admin command and noting time taken if config.test_ops["radosgw_listing_ordered"] is False: log.info("unordered listing via radosgw-admin command") rgw_time = reusable.time_to_list_via_radosgw( bucket_name_to_create, "unordered") if rgw_time > 0: rgw_time_secs = "{:.4f}".format(rgw_time) rgw_time_mins = "{:.4f}".format(rgw_time / 60) log.info( f"with rgw_bucket_index_max_aio = {max_aio} time taken for unordered listing of {bkt_num_objects} objects is : {rgw_time_secs} secs ; {rgw_time_mins} mins" ) else: raise TestExecError( "object listing via radosgw-admin command failed") # listing via boto and noting the time taken log.info("measure the execution time taken to list via boto") boto_time = reusable.time_to_list_via_boto( bucket_name_to_create, rgw_conn) if boto_time > 0: boto_time_secs = "{:.4f}".format(boto_time) boto_time_mins = "{:.4f}".format(boto_time / 60) log.info( f"with rgw_bucket_index_max_aio = {max_aio} time taken to list {bkt_num_objects} objects via boto : {boto_time_secs} secs ; {boto_time_mins} mins" ) else: raise TestExecError("object listing via boto failed") # radoslist on all buckets. BZ:https://bugzilla.redhat.com/show_bug.cgi?id=1892265 if config.radoslist_all is True: log.info( "Executing the command radosgw-admin bucket radoslist on all buckets" ) cmd = "radosgw-admin bucket radoslist | grep ERROR" radoslist_all_error = utils.exec_shell_cmd(cmd) if radoslist_all_error: raise TestExecError("ERROR in radoslist command") if config.test_ops.get("delete_bucket_object", False): if config.test_ops.get("enable_version", False): for name, path in objects_created_list: reusable.delete_version_object(bucket, name, path, rgw_conn, each_user) else: reusable.delete_objects(bucket) time.sleep(30) reusable.delete_bucket(bucket) # check sync status if a multisite cluster reusable.check_sync_status() # check for any crashes during the execution crash_info = reusable.check_for_crash() if crash_info: raise TestExecError("ceph daemon crash found!") if config.user_remove is True: reusable.remove_user(each_user)
def test_exec(config): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() write_bucket_io_info = BucketIoInfo() write_key_io_info = KeyIoInfo() io_info_initialize.initialize(basic_io_structure.initial()) # create user all_users_info = s3lib.create_users(config.user_count) extra_user = s3lib.create_users(1)[0] extra_user_auth = Auth(extra_user, ssl=config.ssl) extra_user_conn = extra_user_auth.do_auth() for each_user in all_users_info: # authenticate auth = Auth(each_user, ssl=config.ssl) rgw_conn = auth.do_auth() s3_object_names = [] # create buckets log.info("no of buckets to create: %s" % config.bucket_count) for bc in range(config.bucket_count): bucket_name_to_create = utils.gen_bucket_name_from_userid( each_user["user_id"], rand_no=bc) log.info("creating bucket with name: %s" % bucket_name_to_create) # bucket = s3_ops.resource_op(rgw_conn, 'Bucket', bucket_name_to_create) bucket = s3lib.resource_op({ "obj": rgw_conn, "resource": "Bucket", "args": [bucket_name_to_create] }) # created = s3_ops.resource_op(bucket, 'create', None, **{'access_key': each_user['access_key']}) created = s3lib.resource_op({ "obj": bucket, "resource": "create", "args": None, "extra_info": { "access_key": each_user["access_key"] }, }) if created is False: raise TestExecError( "Resource execution failed: bucket creation faield") if created is not None: response = HttpResponseParser(created) if response.status_code == 200: log.info("bucket created") else: raise TestExecError("bucket creation failed") else: raise TestExecError("bucket creation failed") # getting bucket version object if config.test_ops["enable_version"] is True: log.info("bucket versionig test on bucket: %s" % bucket.name) # bucket_versioning = s3_ops.resource_op(rgw_conn, 'BucketVersioning', bucket.name) bucket_versioning = s3lib.resource_op({ "obj": rgw_conn, "resource": "BucketVersioning", "args": [bucket.name], }) # checking the versioning status # version_status = s3_ops.resource_op(bucket_versioning, 'status') version_status = s3lib.resource_op({ "obj": bucket_versioning, "resource": "status", "args": None }) if version_status is None: log.info("bucket versioning still not enabled") # enabling bucket versioning # version_enable_status = s3_ops.resource_op(bucket_versioning, 'enable') version_enable_status = s3lib.resource_op({ "obj": bucket_versioning, "resource": "enable", "args": None, }) response = HttpResponseParser(version_enable_status) if response.status_code == 200: log.info("version enabled") write_bucket_io_info.add_versioning_status( each_user["access_key"], bucket.name, VERSIONING_STATUS["ENABLED"], ) else: raise TestExecError("version enable failed") if config.objects_count > 0: log.info("s3 objects to create: %s" % config.objects_count) for oc, s3_object_size in list( config.mapped_sizes.items()): # versioning upload s3_object_name = utils.gen_s3_object_name( bucket_name_to_create, str(oc)) s3_object_names.append(s3_object_name) log.info("s3 object name: %s" % s3_object_name) log.info("versioning count: %s" % config.version_count) s3_object_name = utils.gen_s3_object_name( bucket_name_to_create, str(oc)) s3_object_path = os.path.join(TEST_DATA_PATH, s3_object_name) original_data_info = manage_data.io_generator( s3_object_path, s3_object_size) if original_data_info is False: TestExecError("data creation failed") created_versions_count = 0 for vc in range(config.version_count): log.info("version count for %s is %s" % (s3_object_name, str(vc))) log.info("modifying data: %s" % s3_object_name) modified_data_info = manage_data.io_generator( s3_object_path, s3_object_size, op="append", **{ "message": "\nhello for version: %s\n" % str(vc) }) if modified_data_info is False: TestExecError("data modification failed") log.info("uploading s3 object: %s" % s3_object_path) upload_info = dict( { "access_key": each_user["access_key"], "versioning_status": VERSIONING_STATUS["ENABLED"], "version_count_no": vc, }, **modified_data_info) s3_obj = s3lib.resource_op({ "obj": bucket, "resource": "Object", "args": [s3_object_name], "extra_info": upload_info, }) object_uploaded_status = s3lib.resource_op({ "obj": s3_obj, "resource": "upload_file", "args": [modified_data_info["name"]], "extra_info": upload_info, }) if object_uploaded_status is False: raise TestExecError( "Resource execution failed: object upload failed" ) if object_uploaded_status is None: log.info("object uploaded") s3_obj = rgw_conn.Object( bucket.name, s3_object_name) log.info("current_version_id: %s" % s3_obj.version_id) key_version_info = basic_io_structure.version_info( **{ "version_id": s3_obj.version_id, "md5_local": upload_info["md5"], "count_no": vc, "size": upload_info["size"], }) log.info("key_version_info: %s" % key_version_info) write_key_io_info.add_versioning_info( each_user["access_key"], bucket.name, s3_object_path, key_version_info, ) created_versions_count += 1 log.info("created_versions_count: %s" % created_versions_count) log.info("adding metadata") metadata1 = { "m_data1": "this is the meta1 for this obj" } s3_obj.metadata.update(metadata1) metadata2 = { "m_data2": "this is the meta2 for this obj" } s3_obj.metadata.update(metadata2) log.info("metadata for this object: %s" % s3_obj.metadata) log.info("metadata count for object: %s" % (len(s3_obj.metadata))) if not s3_obj.metadata: raise TestExecError( "metadata not created even adding metadata" ) versions = bucket.object_versions.filter( Prefix=s3_object_name) created_versions_count_from_s3 = len( [v.version_id for v in versions]) log.info("created versions count on s3: %s" % created_versions_count_from_s3) if (created_versions_count is created_versions_count_from_s3): log.info( "no new versions are created when added metdata" ) else: raise TestExecError( "version count missmatch, " "possible creation of version on adding metadata" ) s3_object_download_path = os.path.join( TEST_DATA_PATH, s3_object_name + ".download") object_downloaded_status = s3lib.resource_op({ "obj": bucket, "resource": "download_file", "args": [s3_object_name, s3_object_download_path], }) if object_downloaded_status is False: raise TestExecError( "Resource execution failed: object download failed" ) if object_downloaded_status is None: log.info("object downloaded") # checking md5 of the downloaded file s3_object_downloaded_md5 = utils.get_md5( s3_object_download_path) log.info("downloaded_md5: %s" % s3_object_downloaded_md5) log.info("uploaded_md5: %s" % modified_data_info["md5"]) # tail_op = utils.exec_shell_cmd('tail -l %s' % s3_object_download_path) log.info("all versions for the object: %s\n" % s3_object_name) versions = bucket.object_versions.filter( Prefix=s3_object_name) for version in versions: log.info("key_name: %s --> version_id: %s" % (version.object_key, version.version_id)) if config.test_ops.get("set_acl", None) is True: s3_obj_acl = s3lib.resource_op({ "obj": rgw_conn, "resource": "ObjectAcl", "args": [bucket.name, s3_object_name], }) # setting acl to private, just need to set to any acl and # check if its set - check by response code acls_set_status = s3_obj_acl.put(ACL="private") response = HttpResponseParser(acls_set_status) if response.status_code == 200: log.info("ACLs set") else: raise TestExecError("Acls not Set") # get obj details based on version id for version in versions: log.info("getting info for version id: %s" % version.version_id) obj = s3lib.resource_op({ "obj": rgw_conn, "resource": "Object", "args": [bucket.name, s3_object_name], }) log.info( "obj get detils :%s\n" % (obj.get(VersionId=version.version_id))) if config.test_ops["copy_to_version"] is True: # reverting object to one of the versions ( randomly chosen ) version_id_to_copy = random.choice( [v.version_id for v in versions]) log.info("version_id_to_copy: %s" % version_id_to_copy) s3_obj = rgw_conn.Object(bucket.name, s3_object_name) log.info("current version_id: %s" % s3_obj.version_id) copy_response = s3_obj.copy_from( CopySource={ "Bucket": bucket.name, "Key": s3_object_name, "VersionId": version_id_to_copy, }) log.info("copy_response: %s" % copy_response) if copy_response is None: raise TestExecError( "copy object from version id failed") # current_version_id = copy_response['VersionID'] log.info("current_version_id: %s" % s3_obj.version_id) # delete the version_id_to_copy object s3_obj.delete(VersionId=version_id_to_copy) log.info( "all versions for the object after the copy operation: %s\n" % s3_object_name) for version in versions: log.info( "key_name: %s --> version_id: %s" % (version.object_key, version.version_id)) # log.info('downloading current s3object: %s' % s3_object_name) # s3_obj.download_file(s3_object_name + ".download") if config.test_ops["delete_object_versions"] is True: log.info("deleting s3_obj keys and its versions") s3_obj = s3lib.resource_op({ "obj": rgw_conn, "resource": "Object", "args": [bucket.name, s3_object_name], }) log.info("deleting versions for s3 obj: %s" % s3_object_name) for version in versions: log.info("trying to delete obj version: %s" % version.version_id) del_obj_version = s3lib.resource_op({ "obj": s3_obj, "resource": "delete", "kwargs": dict(VersionId=version.version_id), }) log.info("response:\n%s" % del_obj_version) if del_obj_version is not None: response = HttpResponseParser( del_obj_version) if response.status_code == 204: log.info("version deleted ") reusable.delete_version_object( bucket, version.version_id, s3_object_path, rgw_conn, each_user, ) else: raise TestExecError( "version deletion failed") else: raise TestExecError( "version deletion failed") log.info("available versions for the object") versions = bucket.object_versions.filter( Prefix=s3_object_name) for version in versions: log.info( "key_name: %s --> version_id: %s" % (version.object_key, version.version_id)) if config.test_ops.get( "delete_from_extra_user") is True: log.info( "trying to delete objects from extra user") s3_obj = s3lib.resource_op({ "obj": extra_user_conn, "resource": "Object", "args": [bucket.name, s3_object_name], }) log.info("deleting versions for s3 obj: %s" % s3_object_name) for version in versions: log.info("trying to delete obj version: %s" % version.version_id) del_obj_version = s3lib.resource_op({ "obj": s3_obj, "resource": "delete", "kwargs": dict(VersionId=version.version_id), }) log.info("response:\n%s" % del_obj_version) if del_obj_version is not False: response = HttpResponseParser( del_obj_version) if response.status_code == 204: log.info("version deleted ") write_key_io_info.delete_version_info( each_user["access_key"], bucket.name, s3_object_path, version.version_id, ) raise TestExecError( "version and deleted, this should not happen" ) else: log.info( "version did not delete, expected behaviour" ) else: log.info( "version did not delete, expected behaviour" ) if config.local_file_delete is True: log.info("deleting local file") utils.exec_shell_cmd("sudo rm -rf %s" % s3_object_path) if config.test_ops["suspend_version"] is True: log.info("suspending versioning") # suspend_version_status = s3_ops.resource_op(bucket_versioning, 'suspend') suspend_version_status = s3lib.resource_op({ "obj": bucket_versioning, "resource": "suspend", "args": None }) response = HttpResponseParser(suspend_version_status) if response.status_code == 200: log.info("versioning suspended") write_bucket_io_info.add_versioning_status( each_user["access_key"], bucket.name, VERSIONING_STATUS["SUSPENDED"], ) else: raise TestExecError("version suspend failed") # getting all objects in the bucket log.info("getting all objects in the bucket") objects = s3lib.resource_op({ "obj": bucket, "resource": "objects", "args": None }) log.info("objects :%s" % objects) all_objects = s3lib.resource_op({ "obj": objects, "resource": "all", "args": None }) log.info("all objects: %s" % all_objects) log.info("all objects2 :%s " % bucket.objects.all()) for obj in all_objects: log.info("object_name: %s" % obj.key) versions = bucket.object_versions.filter( Prefix=obj.key) log.info("displaying all versions of the object") for version in versions: log.info("key_name: %s --> version_id: %s" % (version.object_key, version.version_id)) if config.test_ops.get("suspend_from_extra_user") is True: log.info("suspending versioning from extra user") # suspend_version_status = s3_ops.resource_op(bucket_versioning, 'suspend') bucket_versioning = s3lib.resource_op({ "obj": extra_user_conn, "resource": "BucketVersioning", "args": [bucket.name], }) suspend_version_status = s3lib.resource_op({ "obj": bucket_versioning, "resource": "suspend", "args": None }) if suspend_version_status is not False: response = HttpResponseParser(suspend_version_status) if response.status_code == 200: log.info("versioning suspended") write_bucket_io_info.add_versioning_status( each_user["access_key"], bucket.name, VERSIONING_STATUS["SUSPENDED"], ) raise TestExecError( "version suspended, this should not happen") else: log.info( "versioning not suspended, expected behaviour") if config.test_ops.get("upload_after_suspend") is True: log.info( "trying to upload after suspending versioning on bucket") for oc, s3_object_size in list(config.mapped_sizes.items()): # non versioning upload s3_object_name = s3_object_names[ oc] + ".after_version_suspending" log.info("s3 object name: %s" % s3_object_name) s3_object_path = os.path.join(TEST_DATA_PATH, s3_object_name) non_version_data_info = manage_data.io_generator( s3_object_path, s3_object_size, op="append", **{"message": "\nhello for non version\n"}) if non_version_data_info is False: TestExecError("data creation failed") log.info("uploading s3 object: %s" % s3_object_path) upload_info = dict( { "access_key": each_user["access_key"], "versioning_status": "suspended", }, **non_version_data_info) s3_obj = s3lib.resource_op({ "obj": bucket, "resource": "Object", "args": [s3_object_name], "extra_info": upload_info, }) object_uploaded_status = s3lib.resource_op({ "obj": s3_obj, "resource": "upload_file", "args": [non_version_data_info["name"]], "extra_info": upload_info, }) if object_uploaded_status is False: raise TestExecError( "Resource execution failed: object upload failed") if object_uploaded_status is None: log.info("object uploaded") s3_obj = s3lib.resource_op({ "obj": rgw_conn, "resource": "Object", "args": [bucket.name, s3_object_name], }) log.info("version_id: %s" % s3_obj.version_id) if s3_obj.version_id is None: log.info("Versions are not created after suspending") else: raise TestExecError( "Versions are created even after suspending") s3_object_download_path = os.path.join( TEST_DATA_PATH, s3_object_name + ".download") object_downloaded_status = s3lib.resource_op({ "obj": bucket, "resource": "download_file", "args": [s3_object_name, s3_object_download_path], }) if object_downloaded_status is False: raise TestExecError( "Resource execution failed: object download failed" ) if object_downloaded_status is None: log.info("object downloaded") # checking md5 of the downloaded file s3_object_downloaded_md5 = utils.get_md5( s3_object_download_path) log.info("s3_object_downloaded_md5: %s" % s3_object_downloaded_md5) log.info("s3_object_uploaded_md5: %s" % non_version_data_info["md5"]) if config.local_file_delete is True: utils.exec_shell_cmd("sudo rm -rf %s" % s3_object_path) if config.test_ops.get("delete_bucket") is True: reusable.delete_bucket(bucket) # check sync status if a multisite cluster reusable.check_sync_status() # check for any crashes during the execution crash_info = reusable.check_for_crash() if crash_info: raise TestExecError("ceph daemon crash found!")
def test_exec(config): """ Executes test based on configuration passed Args: config(object): Test configuration """ s3cmd = "/home/cephuser/venv/bin/s3cmd" io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) user_info = resource_op.create_users(no_of_users_to_create=config.user_count) for user in user_info: user_name = user["user_id"] ip_and_port = s3cmd_reusable.get_rgw_ip_and_port() s3_auth.do_auth(user, ip_and_port) if not config.header_size: return log.info(f"Number of buckets to create: {config.bucket_count}") for bc in range(config.bucket_count): bucket_name = utils.gen_bucket_name_from_userid(user_name, rand_no=0) s3cmd_reusable.create_bucket(bucket_name) log.info(f"Bucket {bucket_name} created") utils.exec_shell_cmd(f"fallocate -l 2m obj25m") header = "".join( random.choices(ascii_uppercase + digits + ascii_lowercase, k=8192) ) log.info( "Generate header within default max_header_size(16384) i.e, 8192(16384/2)" ) obj_name = utils.gen_s3_object_name(bucket_name, 2) cmd = f"{s3cmd} put obj25m --add-header='X-AMZ-Metadata':{header} s3://{bucket_name}/{obj_name}" rc = utils.exec_shell_cmd(cmd) if rc is False: raise AssertionError( "Failed to upload object, since given header size is greater than or equal to max_header_size" ) # Uploaded the object in bucket bucket_info = utils.exec_shell_cmd( f"radosgw-admin object stat --bucket {bucket_name} --object {obj_name}" ) if bucket_info is False: raise AssertionError( f"Failed to get object data: {obj_name} from bucket :{bucket_name}" ) data = json.loads(bucket_info) if "user.rgw.x-amz-metadata" not in data["attrs"].keys(): raise AssertionError("Key not found") if header != data["attrs"]["user.rgw.x-amz-metadata"]: raise AssertionError( "Object header does not match the given metadata header" ) # negative scenario header = "".join( random.choices(ascii_uppercase + digits + ascii_lowercase, k=16384) ) log.info( "Generate random character of size set to default max_header_size: 16384" ) new_obj_name = utils.gen_s3_object_name(bucket_name, 2) cmd = f"{s3cmd} put obj25m --add-header='X-AMZ-Metadata':{header} s3://{bucket_name}/{new_obj_name}" rc = utils.exec_shell_cmd(cmd) if rc: raise AssertionError( "Expected to fail but succeeded, since metadata header is equal to greater than default max_header_size" )
def test_exec(config): test_info = AddTestInfo("create m buckets with n objects with bucket life cycle") io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) try: test_info.started_info() # create user all_users_info = s3lib.create_users(config.user_count, config.cluster_name) for each_user in all_users_info: # authenticate auth = Auth(each_user) rgw_conn = auth.do_auth() rgw_conn2 = auth.do_auth_using_client() # create buckets if config.test_ops["create_bucket"] is True: log.info("no of buckets to create: %s" % config.bucket_count) for bc in range(config.bucket_count): bucket_name = utils.gen_bucket_name_from_userid( each_user["user_id"], rand_no=1 ) bucket = resuables.create_bucket(bucket_name, rgw_conn, each_user) if config.test_ops["create_object"] is True: # uploading data log.info("s3 objects to create: %s" % config.objects_count) for oc in range(config.objects_count): s3_object_name = utils.gen_s3_object_name(bucket.name, oc) resuables.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, ) bucket_life_cycle = s3lib.resource_op( { "obj": rgw_conn, "resource": "BucketLifecycleConfiguration", "args": [bucket.name], } ) life_cycle = basic_lifecycle_config( prefix="key", days=20, id="rul1" ) put_bucket_life_cycle = s3lib.resource_op( { "obj": bucket_life_cycle, "resource": "put", "kwargs": dict(LifecycleConfiguration=life_cycle), } ) log.info("put bucket life cycle:\n%s" % put_bucket_life_cycle) if put_bucket_life_cycle is False: raise TestExecError( "Resource execution failed: bucket creation faield" ) if put_bucket_life_cycle is not None: response = HttpResponseParser(put_bucket_life_cycle) if response.status_code == 200: log.info("bucket life cycle added") else: raise TestExecError("bucket lifecycle addition failed") else: raise TestExecError("bucket lifecycle addition failed") log.info("trying to retrieve bucket lifecycle config") get_bucket_life_cycle_config = s3lib.resource_op( { "obj": rgw_conn2, "resource": "get_bucket_lifecycle_configuration", "kwargs": dict(Bucket=bucket.name), } ) if get_bucket_life_cycle_config is False: raise TestExecError("bucket lifecycle config retrieval failed") if get_bucket_life_cycle_config is not None: response = HttpResponseParser(get_bucket_life_cycle_config) if response.status_code == 200: log.info("bucket life cycle retrieved") else: raise TestExecError( "bucket lifecycle config retrieval failed" ) else: raise TestExecError("bucket life cycle retrieved") test_info.success_status("test passed") sys.exit(0) except Exception as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status("test failed") sys.exit(1) except TestExecError as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status("test failed") sys.exit(1)
def test_exec(config, requester): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) log.info("requester type: %s" % requester) # create user all_users_info = s3lib.create_users(config.user_count) for each_user in all_users_info: # authenticate auth = Auth(each_user, ssl=config.ssl) rgw_conn = auth.do_auth() # create buckets log.info("no of buckets to create: %s" % config.bucket_count) for bc in range(config.bucket_count): bucket_name_to_create = utils.gen_bucket_name_from_userid( each_user["user_id"], rand_no=bc ) log.info("creating bucket with name: %s" % bucket_name_to_create) # bucket = s3_ops.resource_op(rgw_conn, 'Bucket', bucket_name_to_create) bucket = reusable.create_bucket( bucket_name=bucket_name_to_create, rgw=rgw_conn, user_info=each_user ) bucket_request_payer = s3lib.resource_op( { "obj": rgw_conn, "resource": "BucketRequestPayment", "args": [bucket.name], } ) # change the bucket request payer to 'requester' payer = {"Payer": requester} response = s3lib.resource_op( { "obj": bucket_request_payer, "resource": "put", "kwargs": dict(RequestPaymentConfiguration=payer), } ) log.info(response) if response is not None: response = HttpResponseParser(response) if response.status_code == 200: log.info("bucket created") else: raise TestExecError("bucket request payer modification failed") else: raise TestExecError("bucket request payer modification failed") payer = bucket_request_payer.payer log.info("bucket request payer: %s" % payer) if payer != "Requester": TestExecError("Request payer is not set or changed properly ") log.info("s3 objects to create: %s" % config.objects_count) if config.objects_count is not None: for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name(bucket.name, oc) reusable.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user ) # check for any crashes during the execution crash_info = reusable.check_for_crash() if crash_info: raise TestExecError("ceph daemon crash found!")
def test_exec(config): test_info = AddTestInfo("test swift user key gen") io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) try: test_info.started_info() # preparing data user_names = ["tuffy", "scooby", "max"] tenant1 = "tenant" cmd = ( 'radosgw-admin user create --uid=%s --display-name="%s" --tenant=%s --cluster %s' % (user_names[0], user_names[0], tenant1, config.cluster_name) ) out = utils.exec_shell_cmd(cmd) if out is False: raise TestExecError("RGW User creation error") log.info("output :%s" % out) v1_as_json = json.loads(out) log.info("creted user_id: %s" % v1_as_json["user_id"]) cmd2 = ( "radosgw-admin subuser create --uid=%s$%s --subuser=%s:swift --tenant=%s --access=full --cluster %s" % (tenant1, user_names[0], user_names[0], tenant1, config.cluster_name) ) out2 = utils.exec_shell_cmd(cmd2) if out2 is False: raise TestExecError("sub-user creation error") v2_as_json = json.loads(out2) log.info("created subuser: %s" % v2_as_json["subusers"][0]["id"]) cmd3 = ( "radosgw-admin key create --subuser=%s:swift --uid=%s$%s --tenant=%s --key-type=swift --gen-secret " "--cluster %s" % (user_names[0], user_names[0], tenant1, tenant1, config.cluster_name) ) out3 = utils.exec_shell_cmd(cmd3) if out3 is False: raise TestExecError("secret_key gen error") v3_as_json = json.loads(out3) log.info( "created subuser: %s\nsecret_key generated: %s" % ( v3_as_json["swift_keys"][0]["user"], v3_as_json["swift_keys"][0]["secret_key"], ) ) user_info = { "user_id": v3_as_json["swift_keys"][0]["user"], "key": v3_as_json["swift_keys"][0]["secret_key"], } auth = Auth(user_info) rgw = auth.do_auth() for cc in range(config.container_count): container_name = utils.gen_bucket_name_from_userid( user_info["user_id"], rand_no=cc ) container = swiftlib.resource_op( {"obj": rgw, "resource": "put_container", "args": [container_name]} ) if container is False: raise TestExecError( "Resource execution failed: container creation faield" ) for oc in range(config.objects_count): swift_object_name = utils.gen_s3_object_name( "%s.container.%s" % (user_names[0], cc), oc ) log.info("object name: %s" % swift_object_name) object_path = os.path.join(TEST_DATA_PATH, swift_object_name) log.info("object path: %s" % object_path) object_size = utils.get_file_size( config.objects_size_range["min"], config.objects_size_range["max"] ) data_info = manage_data.io_generator(object_path, object_size) if data_info is False: TestExecError("data creation failed") log.info("uploading object: %s" % object_path) with open(object_path, "r") as fp: rgw.put_object( container_name, swift_object_name, contents=fp.read(), content_type="text/plain", ) test_info.success_status("test passed") sys.exit(0) except Exception as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status("test failed") sys.exit(1) except TestExecError as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status("test failed") sys.exit(1)
def test_exec(config): test_info = AddTestInfo("storage_policy for %s" % config.rgw_client) io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) rgw_service = RGWService() try: # create pool pool_name = ".rgw.buckets.special" pg_num = "8" pgp_num = "8" pool_create = 'sudo ceph osd pool create "%s" %s %s replicated' % ( pool_name, pg_num, pgp_num, ) pool_create_exec = utils.exec_shell_cmd(pool_create) if pool_create_exec is False: raise TestExecError("Pool creation failed") # create realm realm_name = "buz-tickets" log.info("creating realm name") realm_create = ( "sudo radosgw-admin realm create --rgw-realm=%s --default" % realm_name ) realm_create_exec = utils.exec_shell_cmd(realm_create) if realm_create_exec is False: raise TestExecError("cmd execution failed") # sample output of create realm """ { "id": "0956b174-fe14-4f97-8b50-bb7ec5e1cf62", "name": "buz-tickets", "current_period": "1950b710-3e63-4c41-a19e-46a715000980", "epoch": 1 } """ log.info("modify zonegroup ") modify = ( "sudo radosgw-admin zonegroup modify --rgw-zonegroup=default --rgw-realm=%s --master --default" % realm_name ) modify_exec = utils.exec_shell_cmd(modify) if modify_exec is False: raise TestExecError("cmd execution failed") # get the zonegroup zonegroup_file = "zonegroup.json" get_zonegroup = ( "sudo radosgw-admin zonegroup --rgw-zonegroup=default get > %s" % zonegroup_file ) get_zonegroup_exec = utils.exec_shell_cmd(get_zonegroup) if get_zonegroup_exec is False: raise TestExecError("cmd execution failed") add_to_placement_targets = {"name": "special-placement", "tags": []} fp = open(zonegroup_file, "r") zonegroup_txt = fp.read() fp.close() log.info("got zonegroup info: \n%s" % zonegroup_txt) zonegroup = json.loads(zonegroup_txt) log.info("adding placement targets") zonegroup["placement_targets"].append(add_to_placement_targets) with open(zonegroup_file, "w") as fp: json.dump(zonegroup, fp) zonegroup_set = "sudo radosgw-admin zonegroup set < %s" % zonegroup_file zonegroup_set_exec = utils.exec_shell_cmd(zonegroup_set) if zonegroup_set_exec is False: raise TestExecError("cmd execution failed") log.info("zone group update completed") log.info("getting zone file") # get zone log.info("getting zone info") zone_file = "zone.json" get_zone = "sudo radosgw-admin zone --rgw-zone=default get > zone.json" get_zone_exec = utils.exec_shell_cmd(get_zone) if get_zone_exec is False: raise TestExecError("cmd execution failed") fp = open(zone_file, "r") zone_info = fp.read() fp.close() log.info("zone_info :\n%s" % zone_info) zone_info_cleaned = json.loads(zone_info) special_placement_info = { "key": "special-placement", "val": { "index_pool": ".rgw.buckets.index", "data_pool": ".rgw.buckets.special", "data_extra_pool": ".rgw.buckets.extra", }, } log.info("adding special placement info") zone_info_cleaned["placement_pools"].append(special_placement_info) print(zone_info_cleaned) with open(zone_file, "w+") as fp: json.dump(zone_info_cleaned, fp) zone_file_set = "sudo radosgw-admin zone set < %s" % zone_file zone_file_set_exec = utils.exec_shell_cmd(zone_file_set) if zone_file_set_exec is False: raise TestExecError("cmd execution failed") log.info("zone info updated ") restarted = rgw_service.restart() if restarted is False: raise TestExecError("service restart failed") if config.rgw_client == "rgw": log.info("client type is rgw") rgw_user_info = s3_swift_lib.create_users(1) auth = Auth(rgw_user_info) rgw_conn = auth.do_auth() # create bucket bucket_name = utils.gen_bucket_name_from_userid(rgw_user_info["user_id"], 0) bucket = resuables.create_bucket(bucket_name, rgw_conn, rgw_user_info) # create object s3_object_name = utils.gen_s3_object_name(bucket_name, 0) resuables.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, rgw_user_info ) if config.rgw_client == "swift": log.info("client type is swift") user_names = ["tuffy", "scooby", "max"] tenant = "tenant" umgmt = UserMgmt() umgmt.create_tenant_user( tenant_name=tenant, user_id=user_names[0], displayname=user_names[0] ) user_info = umgmt.create_subuser(tenant_name=tenant, user_id=user_names[0]) auth = Auth(user_info) rgw = auth.do_auth() container_name = utils.gen_bucket_name_from_userid( user_info["user_id"], rand_no=0 ) container = s3_swift_lib.resource_op( {"obj": rgw, "resource": "put_container", "args": [container_name]} ) if container is False: raise TestExecError( "Resource execution failed: container creation faield" ) swift_object_name = utils.gen_s3_object_name( "%s.container.%s" % (user_names[0], 0), 0 ) log.info("object name: %s" % swift_object_name) object_path = os.path.join(TEST_DATA_PATH, swift_object_name) log.info("object path: %s" % object_path) object_size = utils.get_file_size( config.objects_size_range["min"], config.objects_size_range["max"] ) data_info = manage_data.io_generator(object_path, object_size) # upload object if data_info is False: TestExecError("data creation failed") log.info("uploading object: %s" % object_path) with open(object_path, "r") as fp: rgw.put_object( container_name, swift_object_name, contents=fp.read(), content_type="text/plain", ) test_info.success_status("test passed") sys.exit(0) except Exception as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status("test failed") sys.exit(1) except TestExecError as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status("test failed") sys.exit(1)
def test_exec(config): io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() write_bucket_io_info = BucketIoInfo() write_key_io_info = KeyIoInfo() io_info_initialize.initialize(basic_io_structure.initial()) # create user all_users_info = s3lib.create_users(config.user_count) extra_user = s3lib.create_users(1)[0] extra_user_auth = Auth(extra_user, ssl=config.ssl) extra_user_conn = extra_user_auth.do_auth() for each_user in all_users_info: # authenticate auth = Auth(each_user, ssl=config.ssl) rgw_conn = auth.do_auth() s3_object_names = [] # create buckets log.info('no of buckets to create: %s' % config.bucket_count) for bc in range(config.bucket_count): bucket_name_to_create = utils.gen_bucket_name_from_userid(each_user['user_id'], rand_no=bc) log.info('creating bucket with name: %s' % bucket_name_to_create) # bucket = s3_ops.resource_op(rgw_conn, 'Bucket', bucket_name_to_create) bucket = s3lib.resource_op({'obj': rgw_conn, 'resource': 'Bucket', 'args': [bucket_name_to_create]}) # created = s3_ops.resource_op(bucket, 'create', None, **{'access_key': each_user['access_key']}) created = s3lib.resource_op({'obj': bucket, 'resource': 'create', 'args': None, 'extra_info': {'access_key': each_user['access_key']}}) if created is False: raise TestExecError("Resource execution failed: bucket creation faield") if created is not None: response = HttpResponseParser(created) if response.status_code == 200: log.info('bucket created') else: raise TestExecError("bucket creation failed") else: raise TestExecError("bucket creation failed") # getting bucket version object if config.test_ops['enable_version'] is True: log.info('bucket versionig test on bucket: %s' % bucket.name) # bucket_versioning = s3_ops.resource_op(rgw_conn, 'BucketVersioning', bucket.name) bucket_versioning = s3lib.resource_op({'obj': rgw_conn, 'resource': 'BucketVersioning', 'args': [bucket.name]}) # checking the versioning status # version_status = s3_ops.resource_op(bucket_versioning, 'status') version_status = s3lib.resource_op({'obj': bucket_versioning, 'resource': 'status', 'args': None }) if version_status is None: log.info('bucket versioning still not enabled') # enabling bucket versioning # version_enable_status = s3_ops.resource_op(bucket_versioning, 'enable') version_enable_status = s3lib.resource_op({'obj': bucket_versioning, 'resource': 'enable', 'args': None, }) response = HttpResponseParser(version_enable_status) if response.status_code == 200: log.info('version enabled') write_bucket_io_info.add_versioning_status(each_user['access_key'],bucket.name, VERSIONING_STATUS['ENABLED']) else: raise TestExecError("version enable failed") if config.objects_count > 0: log.info('s3 objects to create: %s' % config.objects_count) for oc, s3_object_size in list(config.mapped_sizes.items()): # versioning upload s3_object_name = utils.gen_s3_object_name(bucket_name_to_create, str(oc)) s3_object_names.append(s3_object_name) log.info('s3 object name: %s' % s3_object_name) log.info('versioning count: %s' % config.version_count) s3_object_name = utils.gen_s3_object_name(bucket_name_to_create, str(oc)) s3_object_path = os.path.join(TEST_DATA_PATH, s3_object_name) original_data_info = manage_data.io_generator(s3_object_path, s3_object_size) if original_data_info is False: TestExecError("data creation failed") created_versions_count = 0 for vc in range(config.version_count): log.info('version count for %s is %s' % (s3_object_name, str(vc))) log.info('modifying data: %s' % s3_object_name) modified_data_info = manage_data.io_generator(s3_object_path, s3_object_size, op='append', **{'message': '\nhello for version: %s\n' % str(vc)}) if modified_data_info is False: TestExecError("data modification failed") log.info('uploading s3 object: %s' % s3_object_path) upload_info = dict({'access_key': each_user['access_key'], 'versioning_status': VERSIONING_STATUS['ENABLED'], 'version_count_no': vc}, **modified_data_info) s3_obj = s3lib.resource_op({'obj': bucket, 'resource': 'Object', 'args': [s3_object_name], 'extra_info': upload_info, }) object_uploaded_status = s3lib.resource_op({'obj': s3_obj, 'resource': 'upload_file', 'args': [modified_data_info['name']], 'extra_info': upload_info}) if object_uploaded_status is False: raise TestExecError("Resource execution failed: object upload failed") if object_uploaded_status is None: log.info('object uploaded') s3_obj = rgw_conn.Object(bucket.name, s3_object_name) log.info('current_version_id: %s' % s3_obj.version_id) key_version_info = basic_io_structure.version_info( **{'version_id': s3_obj.version_id, 'md5_local': upload_info['md5'], 'count_no': vc, 'size': upload_info['size']}) log.info('key_version_info: %s' % key_version_info) write_key_io_info.add_versioning_info(each_user['access_key'], bucket.name, s3_object_path, key_version_info) created_versions_count += 1 log.info('created_versions_count: %s' % created_versions_count) log.info('adding metadata') metadata1 = {"m_data1": "this is the meta1 for this obj"} s3_obj.metadata.update(metadata1) metadata2 = {"m_data2": "this is the meta2 for this obj"} s3_obj.metadata.update(metadata2) log.info('metadata for this object: %s' % s3_obj.metadata) log.info('metadata count for object: %s' % (len(s3_obj.metadata))) if not s3_obj.metadata: raise TestExecError('metadata not created even adding metadata') versions = bucket.object_versions.filter(Prefix=s3_object_name) created_versions_count_from_s3 = len([v.version_id for v in versions]) log.info('created versions count on s3: %s' % created_versions_count_from_s3) if created_versions_count is created_versions_count_from_s3: log.info('no new versions are created when added metdata') else: raise TestExecError("version count missmatch, " "possible creation of version on adding metadata") s3_object_download_path = os.path.join(TEST_DATA_PATH, s3_object_name + ".download") object_downloaded_status = s3lib.resource_op({'obj': bucket, 'resource': 'download_file', 'args': [s3_object_name, s3_object_download_path], }) if object_downloaded_status is False: raise TestExecError("Resource execution failed: object download failed") if object_downloaded_status is None: log.info('object downloaded') # checking md5 of the downloaded file s3_object_downloaded_md5 = utils.get_md5(s3_object_download_path) log.info('downloaded_md5: %s' % s3_object_downloaded_md5) log.info('uploaded_md5: %s' % modified_data_info['md5']) # tail_op = utils.exec_shell_cmd('tail -l %s' % s3_object_download_path) log.info('all versions for the object: %s\n' % s3_object_name) versions = bucket.object_versions.filter(Prefix=s3_object_name) for version in versions: log.info('key_name: %s --> version_id: %s' % (version.object_key, version.version_id)) if config.test_ops.get('set_acl', None) is True: s3_obj_acl = s3lib.resource_op({'obj': rgw_conn, 'resource': 'ObjectAcl', 'args': [bucket.name, s3_object_name]}) # setting acl to private, just need to set to any acl and # check if its set - check by response code acls_set_status = s3_obj_acl.put(ACL='private') response = HttpResponseParser(acls_set_status) if response.status_code == 200: log.info('ACLs set') else: raise TestExecError("Acls not Set") # get obj details based on version id for version in versions: log.info('getting info for version id: %s' % version.version_id) obj = s3lib.resource_op({'obj': rgw_conn, 'resource': 'Object', 'args': [bucket.name, s3_object_name]}) log.info('obj get detils :%s\n' % (obj.get(VersionId=version.version_id))) if config.test_ops['copy_to_version'] is True: # reverting object to one of the versions ( randomly chosen ) version_id_to_copy = random.choice([v.version_id for v in versions]) log.info('version_id_to_copy: %s' % version_id_to_copy) s3_obj = rgw_conn.Object(bucket.name, s3_object_name) log.info('current version_id: %s' % s3_obj.version_id) copy_response = s3_obj.copy_from(CopySource={'Bucket': bucket.name, 'Key': s3_object_name, 'VersionId': version_id_to_copy}) log.info('copy_response: %s' % copy_response) if copy_response is None: raise TestExecError("copy object from version id failed") # current_version_id = copy_response['VersionID'] log.info('current_version_id: %s' % s3_obj.version_id) # delete the version_id_to_copy object s3_obj.delete(VersionId=version_id_to_copy) log.info('all versions for the object after the copy operation: %s\n' % s3_object_name) for version in versions: log.info( 'key_name: %s --> version_id: %s' % (version.object_key, version.version_id)) # log.info('downloading current s3object: %s' % s3_object_name) # s3_obj.download_file(s3_object_name + ".download") if config.test_ops['delete_object_versions'] is True: log.info('deleting s3_obj keys and its versions') s3_obj = s3lib.resource_op({'obj': rgw_conn, 'resource': 'Object', 'args': [bucket.name, s3_object_name]}) log.info('deleting versions for s3 obj: %s' % s3_object_name) for version in versions: log.info('trying to delete obj version: %s' % version.version_id) del_obj_version = s3lib.resource_op({'obj': s3_obj, 'resource': 'delete', 'kwargs': dict(VersionId=version.version_id)}) log.info('response:\n%s' % del_obj_version) if del_obj_version is not None: response = HttpResponseParser(del_obj_version) if response.status_code == 204: log.info('version deleted ') write_key_io_info.delete_version_info(each_user['access_key'], bucket.name, s3_object_path, version.version_id) else: raise TestExecError("version deletion failed") else: raise TestExecError("version deletion failed") log.info('available versions for the object') versions = bucket.object_versions.filter(Prefix=s3_object_name) for version in versions: log.info('key_name: %s --> version_id: %s' % ( version.object_key, version.version_id)) if config.test_ops.get('delete_from_extra_user') is True: log.info('trying to delete objects from extra user') s3_obj = s3lib.resource_op({'obj': extra_user_conn, 'resource': 'Object', 'args': [bucket.name, s3_object_name]}) log.info('deleting versions for s3 obj: %s' % s3_object_name) for version in versions: log.info('trying to delete obj version: %s' % version.version_id) del_obj_version = s3lib.resource_op({'obj': s3_obj, 'resource': 'delete', 'kwargs': dict( VersionId=version.version_id)}) log.info('response:\n%s' % del_obj_version) if del_obj_version is not False: response = HttpResponseParser(del_obj_version) if response.status_code == 204: log.info('version deleted ') write_key_io_info.delete_version_info(each_user['access_key'], bucket.name, s3_object_path, version.version_id) raise TestExecError("version and deleted, this should not happen") else: log.info('version did not delete, expected behaviour') else: log.info('version did not delete, expected behaviour') if config.local_file_delete is True: log.info('deleting local file') utils.exec_shell_cmd('sudo rm -rf %s' % s3_object_path) if config.test_ops['suspend_version'] is True: log.info('suspending versioning') # suspend_version_status = s3_ops.resource_op(bucket_versioning, 'suspend') suspend_version_status = s3lib.resource_op({'obj': bucket_versioning, 'resource': 'suspend', 'args': None}) response = HttpResponseParser(suspend_version_status) if response.status_code == 200: log.info('versioning suspended') write_bucket_io_info.add_versioning_status(each_user['access_key'], bucket.name, VERSIONING_STATUS['SUSPENDED']) else: raise TestExecError("version suspend failed") # getting all objects in the bucket log.info('getting all objects in the bucket') objects = s3lib.resource_op({'obj': bucket, 'resource': 'objects', 'args': None}) log.info('objects :%s' % objects) all_objects = s3lib.resource_op({'obj': objects, 'resource': 'all', 'args': None}) log.info('all objects: %s' % all_objects) log.info('all objects2 :%s ' % bucket.objects.all()) for obj in all_objects: log.info('object_name: %s' % obj.key) versions = bucket.object_versions.filter(Prefix=obj.key) log.info('displaying all versions of the object') for version in versions: log.info( 'key_name: %s --> version_id: %s' % (version.object_key, version.version_id)) if config.test_ops.get('suspend_from_extra_user') is True: log.info('suspending versioning from extra user') # suspend_version_status = s3_ops.resource_op(bucket_versioning, 'suspend') bucket_versioning = s3lib.resource_op({'obj': extra_user_conn, 'resource': 'BucketVersioning', 'args': [bucket.name]}) suspend_version_status = s3lib.resource_op({'obj': bucket_versioning, 'resource': 'suspend', 'args': None}) if suspend_version_status is not False: response = HttpResponseParser(suspend_version_status) if response.status_code == 200: log.info('versioning suspended') write_bucket_io_info.add_versioning_status(each_user['access_key'], bucket.name, VERSIONING_STATUS['SUSPENDED']) raise TestExecError('version suspended, this should not happen') else: log.info('versioning not suspended, expected behaviour') if config.test_ops.get('upload_after_suspend') is True: log.info('trying to upload after suspending versioning on bucket') for oc, s3_object_size in list(config.mapped_sizes.items()): # non versioning upload s3_object_name = s3_object_names[oc] + ".after_version_suspending" log.info('s3 object name: %s' % s3_object_name) s3_object_path = os.path.join(TEST_DATA_PATH, s3_object_name) non_version_data_info = manage_data.io_generator(s3_object_path, s3_object_size, op="append", **{ 'message': '\nhello for non version\n'}) if non_version_data_info is False: TestExecError("data creation failed") log.info('uploading s3 object: %s' % s3_object_path) upload_info = dict({'access_key': each_user['access_key'], 'versioning_status': 'suspended'},**non_version_data_info) s3_obj = s3lib.resource_op({'obj': bucket, 'resource': 'Object', 'args': [s3_object_name], 'extra_info': upload_info}) object_uploaded_status = s3lib.resource_op({'obj': s3_obj, 'resource': 'upload_file', 'args': [non_version_data_info['name']], 'extra_info': upload_info}) if object_uploaded_status is False: raise TestExecError("Resource execution failed: object upload failed") if object_uploaded_status is None: log.info('object uploaded') s3_obj = s3lib.resource_op({'obj': rgw_conn, 'resource': 'Object', 'args': [bucket.name, s3_object_name]}) log.info('version_id: %s' % s3_obj.version_id) if s3_obj.version_id is None: log.info('Versions are not created after suspending') else: raise TestExecError('Versions are created even after suspending') s3_object_download_path = os.path.join(TEST_DATA_PATH, s3_object_name + ".download") object_downloaded_status = s3lib.resource_op({'obj': bucket, 'resource': 'download_file', 'args': [s3_object_name, s3_object_download_path], }) if object_downloaded_status is False: raise TestExecError("Resource execution failed: object download failed") if object_downloaded_status is None: log.info('object downloaded') # checking md5 of the downloaded file s3_object_downloaded_md5 = utils.get_md5(s3_object_download_path) log.info('s3_object_downloaded_md5: %s' % s3_object_downloaded_md5) log.info('s3_object_uploaded_md5: %s' % non_version_data_info['md5']) if config.local_file_delete is True: utils.exec_shell_cmd('sudo rm -rf %s' % s3_object_path)
def test_exec(config): test_info = AddTestInfo( 'create m buckets with n objects with bucket life cycle') io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) try: test_info.started_info() # create user all_users_info = s3lib.create_users(config.user_count) for each_user in all_users_info: # authenticate auth = Auth(each_user, ssl=config.ssl) rgw_conn = auth.do_auth() rgw_conn2 = auth.do_auth_using_client() # create buckets if config.test_ops['create_bucket'] is True: log.info('no of buckets to create: %s' % config.bucket_count) for bc in range(config.bucket_count): bucket_name = utils.gen_bucket_name_from_userid( each_user['user_id'], rand_no=1) bucket = resuables.create_bucket(bucket_name, rgw_conn, each_user) if config.test_ops['enable_versioning'] is True: log.info('bucket versionig test on bucket: %s' % bucket.name) # bucket_versioning = s3_ops.resource_op(rgw_conn, 'BucketVersioning', bucket.name) bucket_versioning = s3lib.resource_op({ 'obj': rgw_conn, 'resource': 'BucketVersioning', 'args': [bucket.name] }) version_status = s3lib.resource_op({ 'obj': bucket_versioning, 'resource': 'status', 'args': None }) if version_status is None: log.info('bucket versioning still not enabled') # enabling bucket versioning version_enable_status = s3lib.resource_op({ 'obj': bucket_versioning, 'resource': 'enable', 'args': None }) response = HttpResponseParser(version_enable_status) if response.status_code == 200: log.info('version enabled') else: raise TestExecError("version enable failed") if config.test_ops['create_object'] is True: # upload data for oc, size in list(config.mapped_sizes.items()): config.obj_size = size s3_object_name = utils.gen_s3_object_name( bucket.name, oc) if config.test_ops['version_count'] > 0: for vc in range( config.test_ops['version_count']): log.info('version count for %s is %s' % (s3_object_name, str(vc))) log.info('modifying data: %s' % s3_object_name) resuables.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user, append_data=True, append_msg= 'hello object for version: %s\n' % str(vc)) else: log.info('s3 objects to create: %s' % config.objects_count) resuables.upload_object( s3_object_name, bucket, TEST_DATA_PATH, config, each_user) bucket_life_cycle = s3lib.resource_op({ 'obj': rgw_conn, 'resource': 'BucketLifecycleConfiguration', 'args': [bucket.name] }) life_cycle = basic_lifecycle_config(prefix="key", days=20, id="rul1") put_bucket_life_cycle = s3lib.resource_op({ "obj": bucket_life_cycle, "resource": "put", "kwargs": dict(LifecycleConfiguration=life_cycle) }) log.info('put bucket life cycle:\n%s' % put_bucket_life_cycle) if put_bucket_life_cycle is False: raise TestExecError( "Resource execution failed: bucket creation faield" ) if put_bucket_life_cycle is not None: response = HttpResponseParser(put_bucket_life_cycle) if response.status_code == 200: log.info('bucket life cycle added') else: raise TestExecError( "bucket lifecycle addition failed") else: raise TestExecError("bucket lifecycle addition failed") log.info('trying to retrieve bucket lifecycle config') get_bucket_life_cycle_config = s3lib.resource_op({ "obj": rgw_conn2, "resource": 'get_bucket_lifecycle_configuration', "kwargs": dict(Bucket=bucket.name) }) if get_bucket_life_cycle_config is False: raise TestExecError( "bucket lifecycle config retrieval failed") if get_bucket_life_cycle_config is not None: response = HttpResponseParser( get_bucket_life_cycle_config) if response.status_code == 200: log.info('bucket life cycle retrieved') else: raise TestExecError( "bucket lifecycle config retrieval failed") else: raise TestExecError("bucket life cycle retrieved") if config.test_ops['create_object'] is True: for oc in range(config.objects_count): s3_object_name = utils.gen_s3_object_name( bucket.name, oc) if config.test_ops['version_count'] > 0: if config.test_ops.get( 'delete_versioned_object', None) is True: log.info( 'list all the versions of the object and delete the ' 'current version of the object') log.info( 'all versions for the object: %s\n' % s3_object_name) versions = bucket.object_versions.filter( Prefix=s3_object_name) t1 = [] for version in versions: log.info( 'key_name: %s --> version_id: %s' % (version.object_key, version.version_id)) t1.append(version.version_id) s3_object = s3lib.resource_op({ 'obj': rgw_conn, 'resource': 'Object', 'args': [bucket.name, s3_object_name] }) # log.info('object version to delete: %s -> %s' % (versions[0].object_key, # versions[0].version_id)) delete_response = s3_object.delete() log.info('delete response: %s' % delete_response) if delete_response['DeleteMarker'] is True: log.info( 'object delete marker is set to true' ) else: raise TestExecError( "'object delete marker is set to false" ) log.info( 'available versions for the object after delete marker is set' ) t2 = [] versions_after_delete_marker_is_set = bucket.object_versions.filter( Prefix=s3_object_name) for version in versions_after_delete_marker_is_set: log.info( 'key_name: %s --> version_id: %s' % (version.object_key, version.version_id)) t2.append(version.version_id) t2.pop() if t1 == t2: log.info('versions remained intact') else: raise TestExecError( 'versions are not intact after delete marker is set' ) # modify bucket lifecycle configuration, modify expiration days here for the test case. if config.test_ops.get('modify_lifecycle', False) is True: log.info('modifying lifecycle configuration') life_cycle_modifed = basic_lifecycle_config( prefix="key", days=15, id="rul1", status="Disabled") put_bucket_life_cycle = s3lib.resource_op({ "obj": bucket_life_cycle, "resource": "put", "kwargs": dict(LifecycleConfiguration=life_cycle_modifed) }) log.info('put bucket life cycle:\n%s' % put_bucket_life_cycle) if put_bucket_life_cycle is False: raise TestExecError( "Resource execution failed: bucket creation faield" ) if put_bucket_life_cycle is not None: response = HttpResponseParser( put_bucket_life_cycle) if response.status_code == 200: log.info('bucket life cycle added') else: raise TestExecError( "bucket lifecycle addition failed") else: raise TestExecError( "bucket lifecycle addition failed") log.info('trying to retrieve bucket lifecycle config') get_bucket_life_cycle_config = s3lib.resource_op({ "obj": rgw_conn2, "resource": 'get_bucket_lifecycle_configuration', "kwargs": dict(Bucket=bucket.name) }) if get_bucket_life_cycle_config is False: raise TestExecError( "bucket lifecycle config retrieval failed") if get_bucket_life_cycle_config is not None: response = HttpResponseParser( get_bucket_life_cycle_config) modified_expiration_days = get_bucket_life_cycle_config[ 'Rules'][0]['Expiration']['Days'] log.info('modified expiration days: %s' % modified_expiration_days) if response.status_code == 200 and modified_expiration_days == 15: log.info( 'bucket life cycle retrieved after modifying' ) else: raise TestExecError( "bucket lifecycle config retrieval failed after modifying" ) else: raise TestExecError( "bucket lifecycle config retrieval failed after modifying" ) # disable bucket lifecycle configuration if config.test_ops.get('disable_lifecycle', False) is True: log.info('disabling lifecycle configuration') life_cycle_disabled_config = basic_lifecycle_config( prefix="key", days=20, id="rul1", status="Disabled") put_bucket_life_cycle = s3lib.resource_op({ "obj": bucket_life_cycle, "resource": "put", "kwargs": dict(LifecycleConfiguration= life_cycle_disabled_config) }) log.info('put bucket life cycle:\n%s' % put_bucket_life_cycle) if put_bucket_life_cycle is False: raise TestExecError( "Resource execution failed: bucket creation faield" ) if put_bucket_life_cycle is not None: response = HttpResponseParser( put_bucket_life_cycle) if response.status_code == 200: log.info('bucket life cycle added') else: raise TestExecError( "bucket lifecycle addition failed") else: raise TestExecError( "bucket lifecycle addition failed") log.info('trying to retrieve bucket lifecycle config') get_bucket_life_cycle_config = s3lib.resource_op({ "obj": rgw_conn2, "resource": 'get_bucket_lifecycle_configuration', "kwargs": dict(Bucket=bucket.name) }) if get_bucket_life_cycle_config is False: raise TestExecError( "bucket lifecycle config retrieval failed") if get_bucket_life_cycle_config is not None: response = HttpResponseParser( get_bucket_life_cycle_config) if response.status_code == 200 and get_bucket_life_cycle_config[ 'Rules'][0]['Status'] == 'Disabled': log.info('disabled_status: %s' % get_bucket_life_cycle_config['Rules'] [0]['Status']) log.info( 'bucket life cycle retrieved after disabled' ) else: raise TestExecError( "bucket lifecycle config retrieval failed after disabled" ) else: raise TestExecError( "bucket lifecycle config retrieval failed after disabled" ) test_info.success_status('test passed') sys.exit(0) except Exception as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status('test failed') sys.exit(1) except TestExecError as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status('test failed') sys.exit(1)
def test_exec(config): test_info = AddTestInfo('test swift user key gen') io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) umgmt = UserMgmt() try: test_info.started_info() # preparing data user_names = ['tuffy', 'scooby', 'max'] tenant = 'tenant' tenant_user_info = umgmt.create_tenant_user( tenant_name=tenant, user_id=user_names[0], displayname=user_names[0], cluster_name=config.cluster_name) user_info = umgmt.create_subuser(tenant_name=tenant, user_id=user_names[0], cluster_name=config.cluster_name) auth = Auth(user_info) rgw = auth.do_auth() for cc in range(config.container_count): container_name = utils.gen_bucket_name_from_userid( user_info['user_id'], rand_no=cc) container = swiftlib.resource_op({ 'obj': rgw, 'resource': 'put_container', 'args': [container_name] }) if container is False: raise TestExecError( "Resource execution failed: container creation faield") for oc in range(config.objects_count): swift_object_name = utils.gen_s3_object_name( '%s.container.%s' % (user_names[0], cc), oc) log.info('object name: %s' % swift_object_name) object_path = os.path.join(TEST_DATA_PATH, swift_object_name) log.info('object path: %s' % object_path) object_size = utils.get_file_size( config.objects_size_range['min'], config.objects_size_range['max']) data_info = manage_data.io_generator(object_path, object_size) # upload object if data_info is False: TestExecError("data creation failed") log.info('uploading object: %s' % object_path) with open(object_path, 'r') as fp: rgw.put_object(container_name, swift_object_name, contents=fp.read(), content_type='text/plain') # download object swift_object_download_fname = swift_object_name + ".download" log.info('download object name: %s' % swift_object_download_fname) swift_object_download_path = os.path.join( TEST_DATA_PATH, swift_object_download_fname) log.info('download object path: %s' % swift_object_download_path) swift_object_downloaded = rgw.get_object( container_name, swift_object_name) with open(swift_object_download_path, 'w') as fp: fp.write(swift_object_downloaded[1]) # modify and re-upload log.info('appending new message to test_data') message_to_append = 'adding new msg after download' fp = open(swift_object_download_path, 'a+') fp.write(message_to_append) fp.close() with open(swift_object_download_path, 'r') as fp: rgw.put_object(container_name, swift_object_name, contents=fp.read(), content_type='text/plain') # delete object log.info('deleting swift object') rgw.delete_object(container_name, swift_object_name) # delete container log.info('deleting swift container') rgw.delete_container(container_name) test_info.success_status('test passed') sys.exit(0) except Exception, e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status('test failed') sys.exit(1)
def test_exec(config): test_info = AddTestInfo("test swift user key gen") io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) umgmt = UserMgmt() try: test_info.started_info() # preparing data user_names = ["tuffy", "scooby", "max"] tenant = "tenant" tenant_user_info = umgmt.create_tenant_user( tenant_name=tenant, user_id=user_names[0], displayname=user_names[0], cluster_name=config.cluster_name, ) user_info = umgmt.create_subuser(tenant_name=tenant, user_id=user_names[0], cluster_name=config.cluster_name) auth = Auth(user_info) rgw = auth.do_auth() for cc in range(config.container_count): container_name = utils.gen_bucket_name_from_userid( user_info["user_id"], rand_no=cc) container = swiftlib.resource_op({ "obj": rgw, "resource": "put_container", "args": [container_name] }) if container is False: raise TestExecError( "Resource execution failed: container creation faield") for oc in range(config.objects_count): swift_object_name = utils.gen_s3_object_name( "%s.container.%s" % (user_names[0], cc), oc) log.info("object name: %s" % swift_object_name) object_path = os.path.join(TEST_DATA_PATH, swift_object_name) log.info("object path: %s" % object_path) object_size = utils.get_file_size( config.objects_size_range["min"], config.objects_size_range["max"]) data_info = manage_data.io_generator(object_path, object_size) # upload object if data_info is False: TestExecError("data creation failed") log.info("uploading object: %s" % object_path) with open(object_path, "r") as fp: rgw.put_object( container_name, swift_object_name, contents=fp.read(), content_type="text/plain", ) # download object swift_object_download_fname = swift_object_name + ".download" log.info("download object name: %s" % swift_object_download_fname) swift_object_download_path = os.path.join( TEST_DATA_PATH, swift_object_download_fname) log.info("download object path: %s" % swift_object_download_path) swift_object_downloaded = rgw.get_object( container_name, swift_object_name) with open(swift_object_download_path, "w") as fp: fp.write(swift_object_downloaded[1]) # modify and re-upload log.info("appending new message to test_data") message_to_append = "adding new msg after download" fp = open(swift_object_download_path, "a+") fp.write(message_to_append) fp.close() with open(swift_object_download_path, "r") as fp: rgw.put_object( container_name, swift_object_name, contents=fp.read(), content_type="text/plain", ) # delete object log.info("deleting swift object") rgw.delete_object(container_name, swift_object_name) # delete container log.info("deleting swift container") rgw.delete_container(container_name) test_info.success_status("test passed") sys.exit(0) except Exception as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status("test failed") sys.exit(1) except TestExecError as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status("test failed") sys.exit(1)
def test_exec(rgw_user_info_file, config): test_info = AddTestInfo('Test Basic IO on S3') io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) write_user_info = AddUserInfo() try: test_info.started_info() with open(rgw_user_info_yaml, 'r') as f: rgw_user_info = yaml.load(f) mount_point = rgw_user_info['nfs_mnt_point'] nfs_ganesha = PrepNFSGanesha(rgw_user_info_file=rgw_user_info_file) mounted = nfs_ganesha.initialize(write_io_info=False) if mounted is False: raise TestExecError("mount failed") if nfs_ganesha.rgw_user_info[ 'nfs_version'] == 4 and nfs_ganesha.rgw_user_info[ 'Pseudo'] is not None: log.info('nfs version: 4') log.info('adding Pseudo path to writable mount point') mount_point = os.path.join(mount_point, nfs_ganesha.rgw_user_info['Pseudo']) log.info('writable mount point with Pseudo: %s' % mount_point) log.info('authenticating rgw user') # authenticate auth = Auth(rgw_user_info) rgw_conn = auth.do_auth() # add user_info io_info yaml file user_info_add = basic_io_structure.user(**rgw_user_info) write_user_info.add_user_info(user_info_add) if config.io_op_config.get('create', None) is True: # create buckets for bc in range(config.bucket_count): bucket_name_to_create = utils.gen_bucket_name_from_userid( rgw_user_info['user_id'], rand_no=bc) bucket = s3_reusables.create_bucket(bucket_name_to_create, rgw_conn, rgw_user_info) # uploading data log.info('s3 objects to create: %s' % config.objects_count) for oc in range(config.objects_count): s3_object_name = utils.gen_s3_object_name( bucket_name_to_create, oc) s3_reusables.upload_object(s3_object_name, bucket, TEST_DATA_PATH, config, rgw_user_info) log.info('verification Starts on NFS mount after %s seconds' % SLEEP_TIME) time.sleep(SLEEP_TIME) read_io_info_on_nfs = ReadIOInfoOnNFS(mount_point) read_io_info_on_nfs.yaml_fname = 'io_info.yaml' read_io_info_on_nfs.initialize_verify_io() read_io_info_on_nfs.verify_if_basedir_created() read_io_info_on_nfs.verify_if_files_created() log.info('verification complete, data intact') created_buckets = read_io_info_on_nfs.base_dirs created_objects = read_io_info_on_nfs.files if config.io_op_config.get('delete', None) is True: log.info('delete operation starts') for bucket_name in created_buckets: bucket = s3lib.resource_op({ 'obj': rgw_conn, 'resource': 'Bucket', 'args': [os.path.basename(bucket_name)] }) # buckets are base dirs in NFS objects = s3lib.resource_op({ 'obj': bucket, 'resource': 'objects', 'args': None }) log.info('deleting all objects in bucket') objects_deleted = s3lib.resource_op({ 'obj': objects, 'resource': 'delete', 'args': None }) log.info('objects_deleted: %s' % objects_deleted) if objects_deleted is False: raise TestExecError( 'Resource execution failed: Object deletion failed' ) if objects_deleted is not None: response = HttpResponseParser(objects_deleted[0]) if response.status_code == 200: log.info('objects deleted ') else: raise TestExecError("objects deletion failed") else: raise TestExecError("objects deletion failed") log.info('deleting bucket: %s' % bucket.name) bucket_deleted_status = s3lib.resource_op({ 'obj': bucket, 'resource': 'delete', 'args': None }) log.info('bucket_deleted_status: %s' % bucket_deleted_status) if bucket_deleted_status is not None: response = HttpResponseParser(bucket_deleted_status) if response.status_code == 204: log.info('bucket deleted ') else: raise TestExecError("bucket deletion failed") else: raise TestExecError("bucket deletion failed") log.info( 'verification on NFS will start after %s seconds for delete operation' % SLEEP_TIME) time.sleep(200) for basedir in created_buckets: exists = os.path.exists(basedir) log.info('exists status: %s' % exists) if exists is True: raise TestExecError( "Basedir or Basedir: %s not deleted on NFS" % basedir) log.info('basedirs deleted') for each_file in created_objects: log.info('verifying existence for: %s' % each_file['file']) exists = os.path.exists(each_file['file']) if exists: raise TestExecError("files not created") log.info('file deleted') log.info( 'verification of files complete, files exists and data intact' ) if config.io_op_config.get('move', None) is True: log.info('move operation starts') for each_file in created_objects: # in s3 move operation is achieved by copying the same object with the new name and # deleting the old object log.info('move operation for :%s' % each_file['file']) new_obj_name = os.path.basename( each_file['file']) + ".moved" log.info('new file name: %s' % new_obj_name) new_object = s3lib.resource_op({ 'obj': rgw_conn, 'resource': 'Object', 'args': [each_file['bucket'], new_obj_name], }) new_object.copy_from( CopySource='%s/%s' % (each_file['bucket'], os.path.basename( each_file['file']))) # old object name old_object = s3lib.resource_op({ 'obj': rgw_conn, 'resource': 'Object', 'args': [ each_file['bucket'], os.path.basename(each_file['file']) ], }) old_object.delete() each_file['file'] = os.path.abspath( os.path.join(mount_point, each_file['bucket'], new_obj_name)) log.info( 'verification on NFS for move operation will start after %s seconds' % SLEEP_TIME) time.sleep(SLEEP_TIME) read_io_info_on_nfs.verify_if_files_created() log.info('move completed, data intact') test_info.success_status('test passed') sys.exit(0) except Exception, e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status('test failed') sys.exit(1)
def test_exec(rgw_user_info_file, config): test_info = AddTestInfo("Test Basic IO on S3") io_info_initialize = IOInfoInitialize() basic_io_structure = BasicIOInfoStructure() io_info_initialize.initialize(basic_io_structure.initial()) write_user_info = AddUserInfo() try: test_info.started_info() with open(rgw_user_info_yaml, "r") as f: rgw_user_info = yaml.safe_load(f) mount_point = rgw_user_info["nfs_mnt_point"] nfs_ganesha = PrepNFSGanesha(rgw_user_info_file=rgw_user_info_file) mounted = nfs_ganesha.initialize(write_io_info=False) if mounted is False: raise TestExecError("mount failed") if (nfs_ganesha.rgw_user_info["nfs_version"] == 4 and nfs_ganesha.rgw_user_info["Pseudo"] is not None): log.info("nfs version: 4") log.info("adding Pseudo path to writable mount point") mount_point = os.path.join(mount_point, nfs_ganesha.rgw_user_info["Pseudo"]) log.info("writable mount point with Pseudo: %s" % mount_point) log.info("authenticating rgw user") # authenticate auth = Auth(rgw_user_info) rgw_conn = auth.do_auth() # add user_info io_info yaml file user_info_add = basic_io_structure.user(**rgw_user_info) write_user_info.add_user_info(user_info_add) if config.io_op_config.get("create", None) is True: # create buckets for bc in range(config.bucket_count): bucket_name_to_create = utils.gen_bucket_name_from_userid( rgw_user_info["user_id"], rand_no=bc) bucket = s3_reusables.create_bucket(bucket_name_to_create, rgw_conn, rgw_user_info) # uploading data log.info("s3 objects to create: %s" % config.objects_count) for oc in range(config.objects_count): s3_object_name = utils.gen_s3_object_name( bucket_name_to_create, oc) config.obj_size = utils.get_file_size( config.objects_size_range.get("min"), config.objects_size_range.get("max"), ) s3_reusables.upload_object(s3_object_name, bucket, TEST_DATA_PATH, config, rgw_user_info) log.info("verification Starts on NFS mount after %s seconds" % SLEEP_TIME) time.sleep(SLEEP_TIME) read_io_info_on_nfs = ReadIOInfoOnNFS(mount_point) read_io_info_on_nfs.yaml_fname = "io_info.yaml" read_io_info_on_nfs.initialize_verify_io() read_io_info_on_nfs.verify_if_basedir_created() read_io_info_on_nfs.verify_if_files_created() log.info("verification complete, data intact") created_buckets = read_io_info_on_nfs.base_dirs created_objects = read_io_info_on_nfs.files if config.io_op_config.get("delete", None) is True: log.info("delete operation starts") for bucket_name in created_buckets: bucket = s3lib.resource_op({ "obj": rgw_conn, "resource": "Bucket", "args": [os.path.basename(bucket_name)], }) # buckets are base dirs in NFS objects = s3lib.resource_op({ "obj": bucket, "resource": "objects", "args": None }) log.info("deleting all objects in bucket") objects_deleted = s3lib.resource_op({ "obj": objects, "resource": "delete", "args": None }) log.info("objects_deleted: %s" % objects_deleted) if objects_deleted is False: raise TestExecError( "Resource execution failed: Object deletion failed" ) if objects_deleted is not None: response = HttpResponseParser(objects_deleted[0]) if response.status_code == 200: log.info("objects deleted ") else: raise TestExecError("objects deletion failed") else: raise TestExecError("objects deletion failed") log.info("deleting bucket: %s" % bucket.name) bucket_deleted_status = s3lib.resource_op({ "obj": bucket, "resource": "delete", "args": None }) log.info("bucket_deleted_status: %s" % bucket_deleted_status) if bucket_deleted_status is not None: response = HttpResponseParser(bucket_deleted_status) if response.status_code == 204: log.info("bucket deleted ") else: raise TestExecError("bucket deletion failed") else: raise TestExecError("bucket deletion failed") log.info( "verification on NFS will start after %s seconds for delete operation" % SLEEP_TIME) time.sleep(200) for basedir in created_buckets: exists = os.path.exists(basedir) log.info("exists status: %s" % exists) if exists is True: raise TestExecError( "Basedir or Basedir: %s not deleted on NFS" % basedir) log.info("basedirs deleted") for each_file in created_objects: log.info("verifying existence for: %s" % each_file["file"]) exists = os.path.exists(each_file["file"]) if exists: raise TestExecError("files not created") log.info("file deleted") log.info( "verification of files complete, files exists and data intact" ) if config.io_op_config.get("move", None) is True: log.info("move operation starts") for each_file in created_objects: # in s3 move operation is achieved by copying the same object with the new name and # deleting the old object log.info("move operation for :%s" % each_file["file"]) new_obj_name = os.path.basename( each_file["file"]) + ".moved" log.info("new file name: %s" % new_obj_name) new_object = s3lib.resource_op({ "obj": rgw_conn, "resource": "Object", "args": [each_file["bucket"], new_obj_name], }) new_object.copy_from( CopySource="%s/%s" % (each_file["bucket"], os.path.basename( each_file["file"]))) # old object name old_object = s3lib.resource_op({ "obj": rgw_conn, "resource": "Object", "args": [ each_file["bucket"], os.path.basename(each_file["file"]), ], }) old_object.delete() each_file["file"] = os.path.abspath( os.path.join(mount_point, each_file["bucket"], new_obj_name)) log.info( "verification on NFS for move operation will start after %s seconds" % SLEEP_TIME) time.sleep(SLEEP_TIME) read_io_info_on_nfs.verify_if_files_created() log.info("move completed, data intact") test_info.success_status("test passed") sys.exit(0) except Exception as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status("test failed") sys.exit(1) except TestExecError as e: log.info(e) log.info(traceback.format_exc()) test_info.failed_status("test failed") sys.exit(1)