예제 #1
0
 def version(self):
     """
     Print version information (NVR) and exit.
     """
     from insights import get_nvr
     print(get_nvr())
     sys.exit()
예제 #2
0
def status():
    if "versions" not in stats:
        versions = stats["versions"] = {}
        versions["insights-core"] = {
            "version": insights.get_nvr(),
            "commit": insights.package_info["COMMIT"]
        }
        versions["insights-web"] = {
            "version": get_nvr(),
            "commit": package_info["COMMIT"]
        }
        versions.update(insights.RULES_STATUS)
    stats["uptime"] = format_seconds(time.time() - stats["start_time"])
    return jsonify(stats)
예제 #3
0
    def _support_diag_dump(self):
        '''
        Collect log info for debug
        '''
        # check insights config
        cfg_block = []

        pconn = InsightsConnection(self.config)
        logger.info('Insights version: %s', get_nvr())

        reg_check = registration_check(pconn)
        cfg_block.append('Registration check:')
        if pconn.config.legacy_upload:
            for key in reg_check:
                cfg_block.append(key + ': ' + str(reg_check[key]))
        else:
            cfg_block.append("status: " + str(reg_check))

        lastupload = 'never'
        if os.path.isfile(constants.lastupload_file):
            with open(constants.lastupload_file) as upl_file:
                lastupload = upl_file.readline().strip()
        cfg_block.append('\nLast successful upload was ' + lastupload)

        cfg_block.append('auto_config: ' + str(self.config.auto_config))
        if self.config.proxy:
            obfuscated_proxy = re.sub(r'(.*)(:)(.*)(@.*)', r'\1\2********\4',
                                      self.config.proxy)
        else:
            obfuscated_proxy = 'None'
        cfg_block.append('proxy: ' + obfuscated_proxy)

        logger.info('\n'.join(cfg_block))
        logger.info('python-requests: %s', requests.__version__)

        succ = pconn.test_connection()
        if succ == 0:
            logger.info('Connection test: PASS\n')
        else:
            logger.info('Connection test: FAIL\n')

        # run commands
        commands = [
            'uname -a', 'cat /etc/redhat-release', 'env', 'sestatus',
            'subscription-manager identity',
            'systemctl cat insights-client.timer',
            'systemctl cat insights-client.service',
            'systemctl status insights-client.timer',
            'systemctl status insights-client.service'
        ]
        for cmd in commands:
            logger.info("Running command: %s", cmd)
            try:
                proc = Popen(shlex.split(cmd),
                             shell=False,
                             stdout=PIPE,
                             stderr=STDOUT,
                             close_fds=True)
                stdout, stderr = proc.communicate()
            except OSError as o:
                if 'systemctl' not in cmd:
                    # suppress output for systemctl cmd failures
                    logger.info('Error running command "%s": %s', cmd, o)
            except Exception as e:
                # unknown error
                logger.info("Process failed: %s", e)
            logger.info("Process output: \n%s", stdout)
        # check available disk space for /var/tmp
        tmp_dir = '/var/tmp'
        dest_dir_stat = os.statvfs(tmp_dir)
        dest_dir_size = (dest_dir_stat.f_bavail * dest_dir_stat.f_frsize)
        logger.info(
            'Available space in %s:\t%s bytes\t%.1f 1K-blocks\t%.1f MB',
            tmp_dir, dest_dir_size, dest_dir_size / 1024.0,
            (dest_dir_size / 1024.0) / 1024.0)
예제 #4
0
import sys
from insights import get_nvr
from insights.command_parser import InsightsCli
import pytest
from mock import patch

VERSION_OUT = get_nvr() + '\n'


def test_insights_cli_version(capsys):
    test_args_list = [
        ["insights", "version"],
        ["insights", "--version"],
        ["insights", "cat", "--version"],
        ["insights", "collect", "--version"],
        ["insights", "inspect", "--version"],
        ["insights", "info", "--version"],
        ["insights", "ocpshell", "--version"],
        ["insights", "run", "--version"]
    ]
    for args in test_args_list:
        with patch.object(sys, 'argv', args):
            with pytest.raises(SystemExit):
                InsightsCli()
            out, err = capsys.readouterr()
            assert err == ''
            assert out == VERSION_OUT


def test_insights_cli_version_bad_arg(capsys):
    test_args = ["insights", "-v"]