Ejemplo n.º 1
0
    def test_system_stat_two_cpu_idle(self):
        hold_count1 = 10
        interval1 = 0.1
        name1 = str(uuid.uuid4())
        hold_count2 = int(hold_count1 / 2)
        interval2 = interval1 * 2
        name2 = str(uuid.uuid4())

        systemstats.start_new_system_stat(
            name1,
            "cpu-idle",
            hold_count1,
            interval1)
        systemstats.start_new_system_stat(
            name2,
            "cpu-idle",
            hold_count2,
            interval2)

        time.sleep((hold_count1 + 2) * interval1)
        stats_d = systemstats.get_stats(name1)
        self.assertEqual(len(stats_d['status']), hold_count1)

        time.sleep((hold_count2 + 2) * interval2)
        stats_d = systemstats.get_stats(name2)
        self.assertEqual(len(stats_d['status']), hold_count2)

        systemstats.stop_stats(name1)
        systemstats.stop_stats(name2)
Ejemplo n.º 2
0
    def test_basic_verbose_stat(self):
        hold_count1 = 10
        interval1 = 0.1
        name1 = str(uuid.uuid4())

        systemstats.start_new_system_stat(
            name1,
            "system-stats",
            hold_count1,
            interval1)

        time.sleep((hold_count1 + 2) * interval1)
        stats_d = systemstats.get_stats(name1)
        self.assertEqual(len(stats_d['status']), hold_count1)

        ent_1 = stats_d['status'][0]
        self.assertIn('cpu-load', ent_1)
        self.assertIn('net-bytes-in', ent_1)
        self.assertIn('net-bytes-out', ent_1)
        self.assertIn('disk-read-bytes', ent_1)
        self.assertIn('disk-write-bytes', ent_1)
        self.assertIn('disk-read-ops', ent_1)
        self.assertIn('disk-write-ops', ent_1)
        self.assertIn('timestamp', ent_1)
        systemstats.stop_stats(name1)
Ejemplo n.º 3
0
 def test_system_stat_happy_path_cpu_idle(self):
     hold_count = 10
     interval = 0.1
     name = str(uuid.uuid4())
     systemstats.start_new_system_stat(
         name,
         "cpu-idle",
         hold_count,
         interval)
     time.sleep((hold_count + 2) * interval)
     stats_d = systemstats.get_stats(name)
     self.assertEqual(len(stats_d['status']), hold_count)
     systemstats.stop_stats(name)
Ejemplo n.º 4
0
 def test_system_stat_stop_twice(self):
     hold_count = 10
     interval = 0.1
     name = str(uuid.uuid4())
     systemstats.start_new_system_stat(
         name,
         "cpu-idle",
         hold_count,
         interval)
     systemstats.stop_stats(name)
     self.assertRaises(
         exceptions.AgentOptionValueNotSetException,
         systemstats.stop_stats,
         name)
Ejemplo n.º 5
0
    def test_file_run(self):
        stat_name = str(uuid.uuid4())
        hold_count = 5
        check_interval = 0.1
        # we are now setup for the test
        arguments = {
            "statType": "cpu-idle",
            "statName": stat_name,
            "holdCount": hold_count,
            "checkInterval": check_interval
        }

        plugin = init_system_stat.load_plugin(self.conf_obj, str(uuid.uuid4()),
                                              {}, "init_system_stat",
                                              arguments)
        result = plugin.run()
        result = result.get_reply_doc()
        self.assertEqual(result['return_code'], 0)

        try:
            event_space.poll(timeblock=check_interval * (hold_count + 1))

            arguments = {"statName": stat_name}
            plugin = get_system_stat.load_plugin(self.conf_obj,
                                                 str(uuid.uuid4()), {},
                                                 "get_system_stat", arguments)
            result = plugin.run()
            result = result.get_reply_doc()
            self.assertEqual(result['return_code'], 0)
            self.assertEqual(result['reply_type'], 'cpu_idle_stat_array')
            ro = result['reply_object']
            self.assertEqual(len(ro['status']), hold_count)

            arguments = {"statName": stat_name}
            plugin = delete_system_stat.load_plugin(self.conf_obj,
                                                    str(uuid.uuid4()), {},
                                                    "delete_system_stat",
                                                    arguments)
            result = plugin.run()
            result = result.get_reply_doc()
            self.assertEqual(result['return_code'], 0)
        finally:
            try:
                systemstats.stop_stats(stat_name)
            except Exception as ex:
                print(str(ex))
Ejemplo n.º 6
0
    def test_file_run(self):
        stat_name = str(uuid.uuid4())
        hold_count = 5
        check_interval = 0.1
        # we are now setup for the test
        arguments = {"statType": "cpu-idle",
                     "statName": stat_name,
                     "holdCount": hold_count,
                     "checkInterval": check_interval}

        plugin = init_system_stat.load_plugin(
            self.conf_obj, str(uuid.uuid4()),
            {}, "init_system_stat", arguments)
        result = plugin.run()
        result = result.get_reply_doc()
        self.assertEqual(result['return_code'], 0)

        try:
            event_space.poll(timeblock=check_interval*(hold_count+1))

            arguments = {"statName": stat_name}
            plugin = get_system_stat.load_plugin(
                self.conf_obj, str(uuid.uuid4()),
                {}, "get_system_stat", arguments)
            result = plugin.run()
            result = result.get_reply_doc()
            self.assertEqual(result['return_code'], 0)
            self.assertEqual(result['reply_type'], 'cpu_idle_stat_array')
            ro = result['reply_object']
            self.assertEqual(len(ro['status']), hold_count)

            arguments = {"statName": stat_name}
            plugin = delete_system_stat.load_plugin(
                self.conf_obj, str(uuid.uuid4()),
                {}, "delete_system_stat", arguments)
            result = plugin.run()
            result = result.get_reply_doc()
            self.assertEqual(result['return_code'], 0)
        finally:
            try:
                systemstats.stop_stats(stat_name)
            except Exception as ex:
                print(str(ex))
Ejemplo n.º 7
0
    def test_basic_net_out(self):
        hold_count1 = 10
        interval1 = 0.1
        name1 = str(uuid.uuid4())

        systemstats.start_new_system_stat(
            name1,
            "net-bytes-out",
            hold_count1,
            interval1)

        time.sleep((hold_count1 + 3) * interval1)
        stats_d = systemstats.get_stats(name1)
        self.assertEqual(len(stats_d['status']), hold_count1)

        ent_1 = stats_d['status'][0]
        self.assertIn('net-bytes-out', ent_1)
        self.assertIn('timestamp', ent_1)
        systemstats.stop_stats(name1)
Ejemplo n.º 8
0
    def test_basic_write_ops(self):
        hold_count1 = 10
        interval1 = 0.1
        name1 = str(uuid.uuid4())

        systemstats.start_new_system_stat(
            name1,
            "disk-write-ops",
            hold_count1,
            interval1)

        time.sleep((hold_count1 + 3) * interval1)
        stats_d = systemstats.get_stats(name1)
        self.assertEqual(len(stats_d['status']), hold_count1)

        ent_1 = stats_d['status'][0]
        self.assertIn('disk-write-ops', ent_1)
        self.assertIn('timestamp', ent_1)
        systemstats.stop_stats(name1)
Ejemplo n.º 9
0
 def run(self):
     systemstats.stop_stats(self.args.statName)
     return plugin_base.PluginReply(0, reply_type="void")