def write_data_to_mounted_share_using_dd(self, remote_client, output_file, block_size, block_count, input_file='/dev/zero'): """Writes data to mounted share using dd command Example Usage for writing 512Mb to a file on /mnt/ (remote_client, block_size=1024, block_count=512000, output_file='/mnt/512mb_of_zeros', input_file='/dev/zero') For more information, refer to the dd man page. :param remote_client: An SSH client connection to the Nova instance :param block_size: The size of an individual block in bytes :param block_count: The number of blocks to write :param output_file: Path to the file to be written :param input_file: Path to the file to read from """ block_count = int(block_count) remote_client.exec_command( "sudo sh -c \"dd bs={} count={} if={} of={} conv=fsync" " iflag=fullblock\"".format(block_size, block_count, input_file, output_file))
def write_data_to_mounted_share(self, escaped_string, remote_client, mount_point='/mnt/t1'): remote_client.exec_command( "echo \"{escaped_string}\" " "| sudo tee {mount_point} && sudo sync".format( escaped_string=escaped_string, mount_point=mount_point))
def ping_to_export_location(export, remote_client): ip, version = self.get_ip_and_version_from_export_location(export) try: remote_client.exec_command( "ping{} -c5 -w1 {}".format( '6' if version == 6 else '', ip)) return True except exceptions.SSHExecCommandFailed: return False
def mount_share(self, location, remote_client, target_dir=None, access_to=None): target_dir = target_dir or "/mnt" access_to = access_to or self.access_to mountpoint = location.split(':')[-1] if getattr(self, 'mount_client', None): return self._fuse_client(mountpoint, remote_client, target_dir, access_to=access_to) remote_client.exec_command( "sudo mount -t ceph {location} {target_dir} -o name={access_to}," "secret={access_key}" .format(location=location, target_dir=target_dir, access_to=access_to, access_key=self.access_key))
def unmount_share(self, remote_client, target_dir=None): target_dir = target_dir or "/mnt" if getattr(self, 'mount_client', None): return remote_client.exec_command( "sudo fusermount -uz %s" % target_dir) super(BaseShareScenarioCEPHFSTest, self).unmount_share( remote_client, target_dir=target_dir)
def read_data_from_mounted_share(self, remote_client, mount_point='/mnt/t1'): data = remote_client.exec_command( "sudo cat {mount_point}".format(mount_point=mount_point)) return data.rstrip()
def unmount_share(self, remote_client, target_dir=None): target_dir = target_dir or "/mnt" remote_client.exec_command("sudo umount %s" % target_dir)
def _fuse_client(self, mountpoint, remote_client, target_dir, access_to): remote_client.exec_command( "sudo ceph-fuse {target_dir} --id={access_to} --conf=ceph.conf " "--keyring={access_to}.keyring --client-mountpoint={mountpoint}" .format(target_dir=target_dir, access_to=access_to, mountpoint=mountpoint))
def _provide_access_to_client_identified_by_cephx(self, share=None, access_rule=None, access_level='rw', access_to=None, remote_client=None, locations=None, client=None, oc_size=20971520): """Provide an access to a client identified by cephx authentication :param: share: An existing share. :param: access_rule: An existing access rule. In case we want to create the configuration files in the instance according to an existing access rule. :param: access_level: Share access level; this is not required if "access_rule" is set. :param: access_to: Client to provide access to; this is not required if "access_rule" is set. :param: remote_client: An SSH client connection to the Nova instance. :param: locations: Export locations of shares. :param: client: Client object. :param: oc_size: Set how many bytes of data will the client cache. :return: Share access. """ client = client or self.shares_v2_client if not access_rule: access_to = access_to or data_utils.rand_name( self.__class__.__name__ + '-cephx-id') # Check if access is already granted to the client access_rules_matching_client = client.list_access_rules( share['id'], metadata={'metadata': {'access_to': access_to}})['access_list'] access_rule = (access_rules_matching_client[0] if access_rules_matching_client else None) if not access_rule: access_rule = self._allow_access( share['id'], access_level=access_level, access_to=access_to, access_type="cephx", cleanup=False, client=client) # Set metadata to access rule to be filtered if necessary. # This is necessary to prevent granting access to a client who # already has. client.update_access_metadata( metadata={"access_to": "{}".format(access_to)}, access_id=access_rule['id']) get_access = client.get_access_rule(access_rule['id'])['access'] # Set 'access_key' and 'access_to' attributes for being use in mount # operation. setattr(self, 'access_key', get_access['access_key']) setattr(self, 'access_to', get_access['access_to']) remote_client.exec_command( "sudo crudini --set {access_to}.keyring client.{access_to} key " "{access_key}" .format(access_to=self.access_to, access_key=self.access_key)) remote_client.exec_command( "sudo crudini --set ceph.conf client \"client quota\" true") remote_client.exec_command( "sudo crudini --set ceph.conf client \"client oc size\" {}" .format(oc_size)) if not isinstance(locations, list): locations = [locations] remote_client.exec_command( "sudo crudini --set ceph.conf client \"mon host\" {}" .format(locations[0].split(':/')[0])) return access_rule