Пример #1
0
    def test_output_should_return_json_when_output_json(self):
        faked_refresh_data = {
            'sysname': 'Linux 3.13.0-100-generic',
            'uptime': '2 days, 22:04:58',
            'loadavg': '0.06 0.04 0.05',
            'hostname': 'vagrant-ubuntu-trusty-64',
            'cores': 1
        }

        self.collector._do_refresh([faked_refresh_data])
        displayer = get_displayer_by_class(OUTPUT_METHOD.json, self.collector,
                                           False, True, False)
        json_data = self.collector.output(displayer)
        expected_resp = {
            'data': [{
                'cores': 1,
                'host': 'vagrant-ubuntu-trusty-64',
                'load average': '0.06 0.04 0.05',
                'name': 'Linux 3.13.0-100-generic',
                'up': '2 days, 22:04:58'
            }],
            'type':
            'host'
        }
        self.assertEqual(expected_resp, json.loads(json_data))
Пример #2
0
 def test_output_should_return_console_output_when_console(self):
     faked_refresh_data = {
         'sysname': 'Linux 3.13.0-100-generic',
         'uptime': '2 days, 22:04:58',
         'loadavg': '0.06 0.04 0.05',
         'hostname': 'vagrant-ubuntu-trusty-64',
         'cores': 1
     }
     displayer = get_displayer_by_class(OUTPUT_METHOD.console,
                                        self.collector, False, True, False)
     self.collector._do_refresh([faked_refresh_data])
     console_data = self.collector.output(displayer)
     expected_resp = [
         'Host statistics',
         'load average   up               host                     cores name                    ',
         '0.06 0.04 0.05 2 days, 22:04:58 vagrant-ubuntu-trusty-64 1     Linux 3.13.0-100-generic',
         '\n'
     ]
     self.assertEqual('\n'.join(expected_resp), console_data)
Пример #3
0
def do_loop(screen, groups, output_method, collectors, consumer):
    """ Display output (or pass it through to ncurses) """

    output = get_output(output_method, screen)
    while 1:
        # process input:
        consumer.consume()
        for collector in collectors:
            if output_method == OUTPUT_METHOD.curses:
                if not poll_keys(screen, output):
                    # bail out immediately
                    return

            process_single_collector(collector, consts.filter_aux)
            if output_method == OUTPUT_METHOD.curses:
                if not poll_keys(screen, output):
                    return

        if output_method == OUTPUT_METHOD.curses:
            process_groups(groups)
        # in the non-curses cases display actually shows the data and refresh
        # clears the screen, so we need to refresh before display to clear the old data.
        if options.clear_screen and output_method != OUTPUT_METHOD.curses:
            output.refresh()
        for collector in collectors:
            displayer = get_displayer_by_class(
                output_method,
                collector,
                show_units=consts.display_units,
                ignore_autohide=not consts.autohide_fields,
                notrim=consts.notrim)
            formatted_data = collector.output(displayer)
            output.display(formatted_data)
        # in the curses case, refresh shows the data queued by display
        if output_method == OUTPUT_METHOD.curses:
            output.refresh()
        if not consts.realtime:
            time.sleep(consts.TICK_LENGTH)
Пример #4
0
 def test_output_should_return_ncurses_output_when_ncurses(self):
     faked_refresh_data = {
         'sysname': 'Linux 3.13.0-100-generic',
         'uptime': '2 days, 22:04:58',
         'loadavg': '0.06 0.04 0.05',
         'hostname': 'vagrant-ubuntu-trusty-64',
         'cores': 1
     }
     displayer = get_displayer_by_class(OUTPUT_METHOD.curses,
                                        self.collector, False, True, False)
     self.collector._do_refresh([faked_refresh_data])
     console_data = self.collector.output(displayer)
     expected_resp = {
         'host': {
             'rows': [{
                 'cores':
                 ColumnType(value='1', header='cores', header_position=2),
                 'host':
                 ColumnType(value='vagrant-ubuntu-trusty-64',
                            header='',
                            header_position=None),
                 'load average':
                 ColumnType(value='0.06 0.04 0.05',
                            header='load average',
                            header_position=1),
                 'name':
                 ColumnType(value='Linux 3.13.0-100-generic',
                            header='',
                            header_position=None),
                 'up':
                 ColumnType(value='2 days, 22:04:58',
                            header='up',
                            header_position=1)
             }],
             'hide': [],
             'noautohide': {
                 'cores': True,
                 'host': True,
                 'load average': True,
                 'name': True,
                 'up': True
             },
             'prepend_column_headers':
             False,
             'highlights': {
                 'cores': False,
                 'host': True,
                 'load average': False,
                 'name': False,
                 'up': False
             },
             'align': {
                 'cores': 0,
                 'host': 0,
                 'load average': 0,
                 'name': 0,
                 'up': 0
             },
             'pos': {
                 'cores': 2,
                 'host': 0,
                 'load average': 4,
                 'name': 3,
                 'up': 1
             },
             'column_header': {
                 'cores': 2,
                 'host': 0,
                 'load average': 1,
                 'name': 0,
                 'up': 1
             },
             'header':
             False,
             'prefix':
             None,
             'statuses': [{
                 'cores': {
                     0: 0,
                     -1: 0
                 },
                 'host': {
                     0: 0,
                     -1: 0
                 },
                 'load average': {
                     0: 0,
                     1: 0,
                     2: 0
                 },
                 'name': {
                     0: 0,
                     1: 0,
                     -1: 0
                 },
                 'up': {
                     0: 0,
                     1: 0,
                     2: 0,
                     -1: 0
                 }
             }],
             'w': {
                 'cores': 7,
                 'host': 24,
                 'load average': 27,
                 'name': 24,
                 'up': 19
             },
             'types': {
                 'up': 0,
                 'cores': 1,
                 'host': 0,
                 'load average': 0,
                 'name': 0
             }
         }
     }
     self.assertEqual(expected_resp, console_data)
Пример #5
0
 def test_get_displayer_by_class_should_raise_exception_when_unknown_method(self):
     with self.assertRaises(Exception):
         get_displayer_by_class('unknown', {}, True, True, True)
Пример #6
0
 def test_get_displayer_by_class_should_return_curses_displayer_when_curses(self, mocked_from_collector):
     collector = mock.Mock()
     get_displayer_by_class(OUTPUT_METHOD.curses, collector, True, True, True)
     mocked_from_collector.assert_called_with(collector, True, True, True)