How to use the testinfra.utils.cached_property function in testinfra

To help you get started, we’ve selected a few testinfra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github philpep / testinfra / testinfra / modules / blockdevice.py View on Github external
    @cached_property
    def _data(self):
        header = ['RO', 'RA', 'SSZ', 'BSZ', 'StartSec', 'Size', 'Device']
        command = 'blockdev  --report %s'
        blockdev = self.run(command % self.device)
        if blockdev.rc != 0 or blockdev.stderr:
            raise RuntimeError("Failed to gather data: %s" % blockdev.stderr)
        output = blockdev.stdout.splitlines()
        if len(output) < 2:
            raise RuntimeError("No data from %s" % self.device)
        if output[0].split() != header:
            raise RuntimeError('Unknown output of blockdev: %s' % output[0])
        fields = output[1].split()
        return {
            'rw_mode': str(fields[0]),
            'read_ahead': int(fields[1]),
            'sector_size': int(fields[2]),
github philpep / testinfra / testinfra / modules / socket.py View on Github external
    @cached_property
    def _command(self):
        return self.find_command('netstat')
github philpep / testinfra / testinfra / modules / sysctl.py View on Github external
    @cached_property
    def _sysctl_command(self):
        return self.find_command('sysctl')
github philpep / testinfra / testinfra / utils / ansible_runner.py View on Github external
    @cached_property
    def inventory(self):
        return get_ansible_inventory(self.ansible_config, self.inventory_file)
github philpep / testinfra / testinfra / backend / paramiko.py View on Github external
    @cached_property
    def client(self):
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.WarningPolicy())
        cfg = {
            "hostname": self.host.name,
            "port": int(self.host.port) if self.host.port else 22,
            "username": self.host.user,
            "timeout": self.timeout,
        }
        if self.ssh_config:
            with open(self.ssh_config) as f:
                ssh_config = paramiko.SSHConfig()
                ssh_config.parse(f)
                self._load_ssh_config(client, cfg, ssh_config)
        else:
            # fallback reading ~/.ssh/config
github philpep / testinfra / testinfra / utils / ansible_runner.py View on Github external
    @cached_property
    def ansible_config(self):
        return get_ansible_config()
github philpep / testinfra / testinfra / modules / service.py View on Github external
    @cached_property
    def _service_command(self):
        return self.find_command("rc-service")
github philpep / testinfra / testinfra / modules / interface.py View on Github external
    @cached_property
    def _ip(self):
        return self.find_command('ip')
github philpep / testinfra / testinfra / modules / systeminfo.py View on Github external
    @cached_property
    def sysinfo(self):
        sysinfo = {
            "type": None,
            "distribution": None,
            "codename": None,
            "release": None,
        }
        uname = self.run_expect([0, 1], 'uname -s')
        if uname.rc == 1:
            # FIXME: find a better way to detect windows here
            sysinfo.update(**self._get_windows_sysinfo())
            return sysinfo
        sysinfo["type"] = uname.stdout.rstrip("\r\n").lower()
        if sysinfo["type"] == "linux":
            sysinfo.update(**self._get_linux_sysinfo())
        elif sysinfo["type"] == "darwin":