Exemple #1
0
def runtest(testtype='False'):
    """
    Actually run the test for UT
    :param testtype: argument to pass to setup script
    :return: returncode
    """
    # testtype will be 'pass', 'fail', 'skipped'

    # We're iterating against the different UT tests defined in UT-tests folder
    tmpdir = tempfile.mkdtemp(prefix='citellus-tmp')

    # Setup test for 'testtype'
    subprocess.check_output([uttest, uttest, testtype, tmpdir],
                            stderr=subprocess.STDOUT)

    # Run test against it
    res = citellus.docitellus(path=tmpdir, plugins=citplugs)

    plugid = citellus.getids(plugins=citplugs)[0]
    # Get Return code
    rc = res[plugid]['result']['rc']

    # Remove tmp folder
    shutil.rmtree(tmpdir)

    # Check if it passed
    return rc
Exemple #2
0
def callcitellus(path=False, plugins=False, forcerun=False, include=None, exclude=None):
    """
    Do actual execution of citellus against data
    :param exclude: keywords to exclude
    :param include: keywords to include
    :param forcerun: Forces execution of citellus analysis (ignoring saved data in citellus.json)
    :param path: sosreport path
    :param plugins: plugins enabled as provided to citellus
    :return: dict with results
    """

    # Call citellus normally, if existing prior results those will be loaded or executed + saved
    results = citellus.docitellus(path=path, plugins=plugins, forcerun=forcerun, include=include, exclude=exclude, quiet=True)

    # Process plugin output from multiple plugins to be returned as a dictionary of ID's for each plugin
    new_dict = {}
    for item in results:
        name = results[item]['id']
        new_dict[name] = dict(results[item])
    del results

    # cleanup new_dict of unused data
    # trimmed = {}
    # for item in new_dict:
    #     trimmed[item] = {}
    #     # 'id', 'plugin', 'backend', 'path', 'name',
    #     for key in ['result']:
    #         if key in new_dict[item]:
    #             trimmed[item][key] = new_dict[item][key]

    # del new_dict

    return new_dict
    def test_all_plugins_live(self):
        # Run citellus once against them
        results = citellus.docitellus(live=True,
                                      plugins=citplugs,
                                      okay=okay,
                                      failed=failed,
                                      skipped=skipped,
                                      info=info)

        # Process plugin output from multiple plugins
        new_dict = []
        out_dict = []
        for item in results:
            rc = results[item]['result']['rc']
            if rc not in sorted({okay, failed, skipped}):
                print(results[item])
            assert rc in sorted({okay, failed, skipped})
            if rc == failed or rc == skipped:
                print(results[item])
                assert results[item]['result']['err'] != ""
            if results[item]['result']['out'] != "":
                print(results[item])
                assert results[item]['result']['out'] == ""
            out_dict.append(results[item]['result']['out'])

            new_dict.append(rc)

        for each in sorted(set(new_dict)):
            assert each in sorted({okay, failed, skipped, info})
Exemple #4
0
 def test_runplugin_fail(self):
     plugins = citellus.findplugins(folders=[testplugins], include=['exit_failed.sh'])
     results = citellus.docitellus(plugins=plugins)
     plugid = citellus.getids(plugins=plugins)[0]
     assert results[plugid]['result']['rc'] == citellus.RC_FAILED
     assert results[plugid]['result']['out'].endswith('something on stdout\n')
     assert results[plugid]['result']['err'].endswith('something on stderr\n')
Exemple #5
0
def callcitellus(path=False,
                 plugins=False,
                 forcerun=False,
                 include=None,
                 exclude=None):
    """
    Do actual execution of citellus against data
    :param exclude: keywords to exclude
    :param include: keywords to include
    :param forcerun: Forces execution of citellus analysis (ignoring saved data in citellus.json)
    :param path: sosreport path
    :param plugins: plugins enabled as provided to citellus
    :return: dict with results
    """

    # Call citellus normally, if existing prior results those will be loaded or executed + saved
    results = citellus.docitellus(path=path,
                                  plugins=plugins,
                                  forcerun=forcerun,
                                  include=include,
                                  exclude=exclude)

    # Process plugin output from multiple plugins
    new_dict = {}
    for item in results:
        name = results[item]['plugin']
        new_dict[name] = dict(results[item])
    return new_dict
    def test_all_plugins_snapshot(self):
        tmpdir = tempfile.mkdtemp(prefix='citellus-tmp')

        # Setup folder for all tests
        testtype = 'pass'
        for test in uttest:
            subprocess.call([test['plugin'], test['plugin'], testtype, tmpdir])

        # Run citellus once against them
        results = citellus.docitellus(path=tmpdir, plugins=citplugs, okay=okay, failed=failed, skipped=skipped)

        # Remove tmp folder
        shutil.rmtree(tmpdir)

        # Process plugin output from multiple plugins
        new_dict = []
        out_dict = []
        for item in results:
            rc = results[item]['result']['rc']
            if rc not in sorted({okay, failed, skipped}):
                print(results[item])
            assert rc in sorted({okay, failed, skipped})
            if rc == failed or rc == skipped:
                print(results[item])
                assert results[item]['result']['err'] != ""
            new_dict.append(rc)
            if results[item]['result']['out'] != "":
                print(results[item])
                assert results[item]['result']['out]'] == ""
            out_dict.append(results[item]['result']['out'])

        assert sorted(set(new_dict)) == sorted({okay, failed, skipped})
Exemple #7
0
    def test_all_plugins_snapshot(self):
        tmpdir = tempfile.mkdtemp(prefix="citellus-tmp")
        tmpdir2 = tempfile.mkdtemp(prefix="citellus-tmp")

        # Setup folder for all tests
        testtype = "pass"
        for test in uttest:
            subprocess.call([test["plugin"], test["plugin"], testtype, tmpdir])
            subprocess.call(
                [test["plugin"], test["plugin"], testtype, tmpdir2])

        # Run citellus once against them
        results = citellus.docitellus(
            path=tmpdir,
            plugins=citplugs,
            okay=okay,
            failed=failed,
            skipped=skipped,
            info=info,
            web=True,
        )
        maguiresults = magui.domagui(sosreports=[tmpdir, tmpdir2],
                                     citellusplugins=citplugs)

        # Check that citellus.html has been copied
        assert os.access(os.path.join(tmpdir, "citellus.json"), os.R_OK)
        assert os.access(os.path.join(tmpdir, "citellus.html"), os.R_OK)
        assert maguiresults

        # Remove tmp folder
        shutil.rmtree(tmpdir)
        shutil.rmtree(tmpdir2)

        # Process plugin output from multiple plugins
        new_dict = []
        out_dict = []
        for item in results:
            rc = results[item]["result"]["rc"]
            if rc not in sorted({okay, failed, skipped, info}):
                print(results[item])
            assert rc in sorted({okay, failed, skipped, info})
            if rc == failed or rc == skipped:
                print(results[item])
                assert results[item]["result"]["err"] != ""
            new_dict.append(rc)
            if results[item]["result"]["out"] != "":
                print(results[item])
                assert results[item]["result"]["out"] == ""
            out_dict.append(results[item]["result"]["out"])

        for each in sorted(set(new_dict)):
            assert each in sorted({okay, failed, skipped, info})
    def test_all_plugins_snapshot(self):
        tmpdir = tempfile.mkdtemp(prefix='citellus-tmp')
        tmpdir2 = tempfile.mkdtemp(prefix='citellus-tmp')

        # Setup folder for all tests
        testtype = 'pass'
        for test in uttest:
            subprocess.call([test['plugin'], test['plugin'], testtype, tmpdir])
            subprocess.call([test['plugin'], test['plugin'], testtype, tmpdir2])

        # Run citellus once against them
        results = citellus.docitellus(path=tmpdir, plugins=citplugs, okay=okay, failed=failed, skipped=skipped, web=True)
        maguiresults = magui.domagui(sosreports=[tmpdir, tmpdir2], citellusplugins=citplugs)

        # Check that citellus.html has been copied
        assert os.access(os.path.join(tmpdir, 'citellus.json'), os.R_OK)
        assert os.access(os.path.join(tmpdir, 'citellus.html'), os.R_OK)
        assert maguiresults

        # Remove tmp folder
        shutil.rmtree(tmpdir)
        shutil.rmtree(tmpdir2)

        # Process plugin output from multiple plugins
        new_dict = []
        out_dict = []
        for item in results:
            rc = results[item]['result']['rc']
            if rc not in sorted({okay, failed, skipped}):
                print(results[item])
            assert rc in sorted({okay, failed, skipped})
            if rc == failed or rc == skipped:
                print(results[item])
                assert results[item]['result']['err'] != ""
            new_dict.append(rc)
            if results[item]['result']['out'] != "":
                print(results[item])
                assert results[item]['result']['out'] == ""
            out_dict.append(results[item]['result']['out'])

        assert sorted(set(new_dict)) == sorted({okay, failed, skipped})