def _cpu_info(): cmd = 'cat /proc/cpuinfo' retcode, result = utils.run_command(cmd) if retcode == 0: return result else: print('Error getting cpuinfo: {}'.format(result)) return ''
def _socket_count(): cmd = 'grep -i "physical id" /proc/cpuinfo | sort -u | wc -l' retcode, result = utils.run_command(cmd) lines = result.splitlines() if retcode == 0 and lines: return int(lines[0]) else: print('Error getting cpuinfo scocket count: {}'.format(result)) return -1
def _model_name(): cmd = "cat /proc/cpuinfo | grep 'model name' | sort --unique" retcode, result = utils.run_command(cmd) lines = result.splitlines() if retcode == 0 and lines: model_name_parts = lines[0].split(':') return model_name_parts[1].strip() else: print('Error getting cpuinfo model name: {}'.format(result)) return ''
def create_drive_from_devices(data_dir, devices): """Creates a drive at data_dir based on number of devices passed.""" cmd = 'sudo mountpoint -q {}'.format(data_dir) retcode, _ = utils.run_command(cmd) if retcode: if len(devices) > 1: create_drive_raid(data_dir, devices) else: create_single_drive(data_dir, devices[0]) else: print('Skipping drive creation since path {} already exists'.format( data_dir))
def _core_count(): cmd = "cat /proc/cpuinfo | grep 'cpu cores' | sort --unique" retcode, result = utils.run_command(cmd) lines = result.splitlines() if retcode == 0 and lines: core_count_parts = lines[0].split(':') # Cores * sockets = total cores for the system. core_count = int(core_count_parts[1].strip()) total_cores = core_count * _socket_count() return total_cores else: print('Error getting cpuinfo core count: {}'.format(result)) return -1
def create_ram_disk(data_dir, disk_size): """Create a RAM disk.""" cmd = 'sudo mountpoint -q {}'.format(data_dir) retcode, _ = utils.run_command(cmd) if retcode: cmds = [] cmds.append('sudo mkdir -p {}'.format(data_dir)) cmds.append('sudo mount -t tmpfs -o size={}m tmpfs {}'.format( disk_size, data_dir)) utils.run_commands(cmds) else: print('RAM disk or something else is mounted at {}'.format(data_dir))
def get_nvme_devices(): """Returns list paths to nvme devices.""" devices = [] cmd = 'sudo lsblk' retcode, log = utils.run_command(cmd) if retcode: raise Exception('"{}" failed with code:{} and log:\n{}'.format( cmd, retcode, log)) lines = log.splitlines() if lines: for line in lines: if line.startswith('nvme'): parts = line.split() devices.append('/dev/' + parts[0].strip()) return devices
def create_gce_nvme_raid(data_dir, list_of_devices): """Creates a raid zero array of nvme drives.""" cmd = 'sudo mountpoint -q {}'.format(data_dir) retcode, _ = utils.run_command(cmd) if retcode: cmds = [] # GCE nvme drives some times are in an odd state and # think they are in another raid. mdadm doe snot have -y option. # or the kokoro images were left dirty? and that is where the info # comes from. cmds.append('yes | sudo mdadm --create /dev/md0 --level=0 ' '--raid-devices={} {}'.format( len(list_of_devices), ' '.join(list_of_devices))) cmds.append('sudo mkfs.ext4 -F /dev/md0') cmds.append('sudo mkdir -p {}'.format(data_dir)) cmds.append('sudo mount /dev/md0 {}'.format(data_dir)) cmds.append('sudo chmod a+w {}'.format(data_dir)) utils.run_commands(cmds) print('Created and mounted RAID array at {}'.format(data_dir)) else: print('Skipping RAID array creation since path {} already exists'.format( data_dir))