Exemple #1
0
    def test_get_proc_comm(self, patch_read_file):
        patch_read_file.read_file.return_value = fileutil.read_file(
            os.path.join(data_dir, "cgroups", "dummy_proc_comm"))
        proc_name = ProcessInfo.get_proc_name(1000)
        self.assertEqual("python", proc_name)

        patch_read_file.read_file.side_effect = raise_ioerror
        # No such file exists; expect None instead.
        with self.assertRaises(IOError):
            ProcessInfo.get_proc_name(1000)

        patch_read_file.read_file.side_effect = raise_exception
        # Other exception; _get_proc_cmdline throws exception.
        with self.assertRaises(ProcessInfoException):
            ProcessInfo._get_proc_comm(1000)  # pylint: disable=protected-access
Exemple #2
0
    def test_get_proc_cmdline(self, patch_read_file):
        patch_read_file.read_file.return_value = fileutil.read_file(
            os.path.join(data_dir, "cgroups", "dummy_proc_cmdline"))
        cmdline = ProcessInfo.get_proc_cmdline(1000)
        self.assertEqual(
            "python -u bin/WALinuxAgent-2.2.45-py2.7.egg -run-exthandlers",
            cmdline)

        patch_read_file.read_file.side_effect = raise_ioerror
        # No such file exists; _get_proc_cmdline throws exception.
        with self.assertRaises(IOError):
            ProcessInfo._get_proc_cmdline(1000)  # pylint: disable=protected-access

        patch_read_file.read_file.side_effect = raise_exception
        # Other exception; _get_proc_cmdline throws exception.
        with self.assertRaises(ProcessInfoException):
            ProcessInfo._get_proc_cmdline(1000)  # pylint: disable=protected-access
Exemple #3
0
    def get_process_info_summary(process_id):
        process_cmdline = DEFAULT_PROCESS_COMMANDLINE
        process_name = DEFAULT_PROCESS_NAME

        # The ProcessName and ProcessCommandLine can generate Exception if the file /proc/<pid>/{comm,cmdline} cease to
        # exist; eg: the process can die, or finish. Which is why we need Default Names, in case we fail to fetch the
        # details from those files.
        try:
            process_cmdline = ProcessInfo.get_proc_cmdline(
                process_id) if not None else DEFAULT_PROCESS_COMMANDLINE
        except Exception as e:  # pylint: disable=C0103
            logger.periodic_info(EVERY_SIX_HOURS, "[PERIODIC] {0}", ustr(e))

        try:
            process_name = ProcessInfo.get_proc_name(
                process_id) if not None else DEFAULT_PROCESS_NAME
        except Exception as e:  # pylint: disable=C0103
            logger.periodic_info(EVERY_SIX_HOURS, "[PERIODIC] {0}", ustr(e))

        return process_id + DELIM + process_name + DELIM + process_cmdline