def main():
    if (diskstats.OS_NAME != 'Linux'):
        print('diskstats plugin currently works for Linux only')
        print('os_name: %s' % (diskstats.os_name))
        print('Finished')
        return

    logging.basicConfig(level=logging.INFO)
    diskstats.get_dev_list()
    diskstats.dev_stats_cache = diskstats.collect_diskstats()
    logging.info('netstats_ftest: dev_list: %s' % (diskstats.dev_list))
    logging.debug('netstats_ftest: dev_stats_cache: %s'
                  % (diskstats.dev_stats_cache))
    print('netstats_ftest: ... sleeping for 10 sec...')
    time.sleep(10)
    diskstats.dev_stats_current = diskstats.collect_diskstats()
    logging.debug('netstats_ftest: dev_stats_cur: %s'
                  % (diskstats.dev_stats_current))
    metric_names = ['iops_rw', 'bytes_ps_read', 'bytes_ps_write']

    print_header()
    metric_key_vals = {}
    metric_vals = []
    for i in diskstats.dev_list:
        metric_key_vals = diskstats.calc_metrics(i)
        logging.debug('metric_key_vals: %s' % (metric_key_vals))
        metric_vals = [metric_key_vals[k] for k in metric_names]
        dev_pretty_prints(i, metric_vals)
        logging.debug('metric_vals: %s' % (metric_vals))
def main():
    if (diskstats.OS_NAME != 'Linux'):
        print('diskstats plugin currently works for Linux only')
        print('os_name: %s' % (diskstats.os_name))
        print('Finished')
        return

    logging.basicConfig(level=logging.INFO)
    diskstats.get_dev_list()
    diskstats.dev_stats_cache = diskstats.collect_diskstats()
    logging.info('netstats_ftest: dev_list: %s' % (diskstats.dev_list))
    logging.debug('netstats_ftest: dev_stats_cache: %s' %
                  (diskstats.dev_stats_cache))
    print('netstats_ftest: ... sleeping for 10 sec...')
    time.sleep(10)
    diskstats.dev_stats_current = diskstats.collect_diskstats()
    logging.debug('netstats_ftest: dev_stats_cur: %s' %
                  (diskstats.dev_stats_current))
    metric_names = ['iops_rw', 'bytes_ps_read', 'bytes_ps_write']

    print_header()
    metric_key_vals = {}
    metric_vals = []
    for i in diskstats.dev_list:
        metric_key_vals = diskstats.calc_metrics(i)
        logging.debug('metric_key_vals: %s' % (metric_key_vals))
        metric_vals = [metric_key_vals[k] for k in metric_names]
        dev_pretty_prints(i, metric_vals)
        logging.debug('metric_vals: %s' % (metric_vals))
    def test_1_diskstats_get_dev_list_sku2(self):
        diskstats.dev_list = []
        diskstats.DISKSTATS_FNAME = PROCFS_DISKSTAT_2
        diskstats.get_dev_list()

        self.assertTrue(len(diskstats.dev_list) > 0, "at least one metric")
        self.assertEqual(diskstats.dev_list, DEV_LIST_2, "device lists parsing error")

        # restore the default SKU
        diskstats.DISKSTATS_FNAME = PROCFS_DISKSTAT
    def test_1_diskstats_get_dev_list_sku1(self):
        diskstats.get_dev_list()

        try:
            self.assertTrue(len(diskstats.dev_list) > 0, "at least one metric")
            self.assertEqual(diskstats.dev_list, DEV_LIST, "device lists parsing error")
        except:
            print("dev_list: %s" % (diskstats.dev_list))
            print("expected DEV_LIST: %s" % (DEV_LIST))
            print("Exception: %s" % (sys.exc_info()[0]))
            raise
  def test_1_diskstats_get_dev_list_sku1(self):
    diskstats.get_dev_list()

    try:
      self.assertTrue(len(diskstats.dev_list) > 0, 'at least one metric')
      self.assertEqual(diskstats.dev_list, DEV_LIST, 'device lists parsing error')
    except:
      print('dev_list: %s' % (diskstats.dev_list))
      print('expected DEV_LIST: %s' % (DEV_LIST))
      print('Exception: %s' % (sys.exc_info()[0]))
      raise
    def test_2_diskstats_collection(self):
        diskstats.dev_list = []
        diskstats.DISKSTATS_FNAME = PROCFS_DISKSTAT
        diskstats.get_dev_list()
        stats_names = diskstats.diskstat_fields[3:14]
        dev_stats_current = diskstats.collect_diskstats()

        field_names = [dev_stats_current[(diskstats.dev_list[0], k)] for k in stats_names]
        num_dev = len(diskstats.dev_list)
        num_fields = len(field_names)
        num_expected_fields = (num_fields + 1) * num_dev
        self.assertTrue(len(dev_stats_current) > 0, "at least one metric")
        try:
            self.assertEqual(len(dev_stats_current), num_expected_fields, "unexpected diskstat fields and vals")
        except:
            print("dev_stats_current: %s" % (dev_stats_current))
            print("field_names: %s" % (field_names))
            print("dev_stats_current len: %d" % (len(dev_stats_current)))
            print("Exception: %s" % (sys.exc_info()[0]))
            raise
  def test_1_diskstats_get_dev_list_sku2(self):
    diskstats.dev_list = []
    diskstats.DISKSTATS_FNAME = PROCFS_DISKSTAT_2
    diskstats.device_filter_regexes = ['']
    diskstats.get_dev_list()

    self.assertTrue(len(diskstats.dev_list) > 0, 'at least one metric')
    self.assertEqual(diskstats.dev_list, DEV_LIST_2,
                     'device lists parsing error')
    try:
        self.assertTrue(len(diskstats.dev_list) > 0, 'at least one metric')
        self.assertEqual(diskstats.dev_list, DEV_LIST_2, 'device lists parsing error')
    except:
        print('dev_list: %s' % (diskstats.dev_list))
        print('expected DEV_LIST: %s' % (DEV_LIST_2))
        print('Exception: %s' % (sys.exc_info()[0]))
        raise

    # restore the default SKU
    diskstats.DISKSTATS_FNAME = PROCFS_DISKSTAT
  def test_2_diskstats_collection(self):
    diskstats.dev_list = []
    diskstats.DISKSTATS_FNAME = PROCFS_DISKSTAT
    diskstats.get_dev_list()
    stats_names = diskstats.diskstat_fields[3:14]
    dev_stats_current = diskstats.collect_diskstats()

    field_names = [dev_stats_current[(diskstats.dev_list[0], k)] for k in
                   stats_names]
    num_dev = len(diskstats.dev_list)
    num_fields = len(field_names)
    num_expected_fields = (num_fields + 1) * num_dev;
    self.assertTrue(len(dev_stats_current) > 0,
                    'at least one metric')
    try:
      self.assertEqual(len(dev_stats_current), num_expected_fields,
                       'unexpected diskstat fields and vals')
    except:
      print('dev_stats_current: %s' % (dev_stats_current))
      print('field_names: %s' % (field_names))
      print('dev_stats_current len: %d' % (len(dev_stats_current)))
      print('Exception: %s' % (sys.exc_info()[0]))
      raise