示例#1
0
    def path(self):
        if self.fs_path:  # pylint: disable=W0125
            path = os.path.join(HotSOSConfig.DATA_ROOT, self.fs_path)
            if (HotSOSConfig.USE_ALL_LOGS and not
                    self.options['disable-all-logs']):
                path = "{}*".format(path)

            return path

        if self.command:  # pylint: disable=W0125
            if self.cmd_tmp_path:
                return self.cmd_tmp_path

            args_callback = self.options['args-callback']
            if args_callback:
                args, kwargs = self.get_method(args_callback)
            else:
                args = self.options['args']
                kwargs = self.options['kwargs']

            # get command output
            out = getattr(CLIHelper(), self.command)(*args, **kwargs)
            # store in temp file to make it searchable
            # NOTE: we dont need to delete this at the the end since they are
            # created in the plugun tmp dir which is wiped at the end of the
            # plugin run.
            if type(out) == list:
                out = ''.join(out)
            elif type(out) == dict:
                out = str(out)

            self.cmd_tmp_path = mktemp_dump(out)
            return self.cmd_tmp_path

        log.debug("no input provided")
示例#2
0
    def udev_bcache_devs(self):
        """ If bcache devices exist fetch information and return as a list. """
        if self._bcache_devs:
            return self._bcache_devs

        udevadm_info = self.cli.udevadm_info_exportdb()
        if not udevadm_info:
            return self._bcache_devs

        s = FileSearcher()
        sdef = SequenceSearchDef(start=SearchDef(r"^P: .+/(bcache\S+)"),
                                 body=SearchDef(r"^S: disk/by-uuid/(\S+)"),
                                 tag="bcacheinfo")
        s.add_search_term(sdef, utils.mktemp_dump('\n'.join(udevadm_info)))
        results = s.search()
        devs = []
        for section in results.find_sequence_sections(sdef).values():
            dev = {}
            for r in section:
                if r.tag == sdef.start_tag:
                    dev["name"] = r.get(1)
                else:
                    dev["by-uuid"] = r.get(1)

            devs.append(dev)

        self._bcache_devs = devs
        return self._bcache_devs
示例#3
0
 def __init__(self, daemon_type):
     self.daemon_type = daemon_type
     self.cli = host_helpers.CLIHelper()
     self.date_in_secs = self.get_date_secs()
     self._version_info = None
     self._etime = None
     self._rss = None
     # create file-based caches of useful commands so they can be searched.
     self.cli_cache = {'ps': self.cli.ps()}
     for cmd, output in self.cli_cache.items():
         self.cli_cache[cmd] = utils.mktemp_dump('\n'.join(output))
示例#4
0
 def __init__(self):
     self._property_cache = {}
     # save to file so we can search it later
     cli = host_helpers.CLIHelper()
     self._f_report = mktemp_dump(''.join(cli.rabbitmqctl_report()))
     searcher = FileSearcher()
     searcher.add_search_term(self.connections_searchdef, self._f_report)
     searcher.add_search_term(self.memory_searchdef, self._f_report)
     searcher.add_search_term(self.cluster_partition_handling_searchdef,
                              self._f_report)
     searcher.add_search_term(self.queues_searchdef, self._f_report)
     self.results = searcher.search()
示例#5
0
    def stats(self):
        """ Get ip link info for the interface. """
        counters = self.cache_load()
        if counters:
            return counters

        s = FileSearcher()
        seqdef = SequenceSearchDef(
                    # match start of interface
                    start=SearchDef(IP_IFACE_NAME_TEMPLATE.format(self.name)),
                    # match body of interface
                    body=SearchDef(r".+"),
                    # match next interface or EOF
                    end=SearchDef([IP_IFACE_NAME, IP_EOF]),
                    tag="ifaces")
        f_ip_link_show = mktemp_dump(''.join(self.cli_helper.ip_link()))
        s.add_search_term(seqdef, path=f_ip_link_show)
        results = s.search()
        os.unlink(f_ip_link_show)
        stats_raw = []
        for section in results.find_sequence_sections(seqdef).values():
            for result in section:
                if result.tag == seqdef.body_tag:
                    stats_raw.append(result.get(0))

        if not stats_raw:
            return {}

        # NOTE: we only expect one match
        counters = {}
        for i, line in enumerate(stats_raw):
            ret = re.compile(r"\s+([RT]X):\s+.+").findall(line)
            if ret:
                rxtx = ret[0].lower()
                ret = re.compile(r"\s*([a-z]+)\s*").findall(line)
                if ret:
                    for j, column in enumerate(ret):
                        value = int(stats_raw[i + 1].split()[j])
                        if column in ['packets', 'dropped', 'errors',
                                      'overrun']:
                            if rxtx not in counters:
                                counters[rxtx] = {}

                            counters[rxtx][column] = value

        if counters:
            self.cache_save(counters)
            return counters

        return {}
示例#6
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.ceph_config = CephConfig()
     self.bcache = BcacheBase()
     self._local_osds = None
     self.apt_check = host_helpers.APTPackageChecksBase(
         core_pkgs=CEPH_PKGS_CORE, other_pkgs=CEPH_PKGS_OTHER)
     self.cluster = CephCluster()
     self.cli = host_helpers.CLIHelper()
     # create file-based caches of useful commands so they can be searched.
     self.cli_cache = {
         'ceph_volume_lvm_list': self.cli.ceph_volume_lvm_list()
     }
     for cmd, output in self.cli_cache.items():
         self.cli_cache[cmd] = utils.mktemp_dump('\n'.join(output))
示例#7
0
    def __init__(self):
        self.cli = host_helpers.CLIHelper()
        # create file-based caches of useful commands so they can be searched.
        self.cli_cache = {'ceph_versions': self.cli.ceph_versions()}
        for cmd, output in self.cli_cache.items():
            self.cli_cache[cmd] = utils.mktemp_dump('\n'.join(output))

        self.crush_map = CephCrushMap()
        self._large_omap_pgs = {}
        self._bad_meta_osds = []
        self._cluster_osds = []
        self._cluster_mons = []
        self._mon_dump = None
        self._osd_dump = None
        self._pg_dump = None
        self._osd_df_tree = None
        self._osds_pgs = {}
示例#8
0
    def config(self):
        if not self.cfg:
            path = glob.glob(os.path.join(self.juju_lib_path,
                                          "agents/machine-*/agent.conf"))
            if not path:
                return self.cfg

            # NOTE: we only expect one of these to exist
            path = path[0]
            # filter out 'sanitised' lines since they will not be valid yaml
            if os.path.exists(path):
                ftmp = utils.mktemp_dump("")
                with open(ftmp, 'w') as fdtmp:
                    expr = re.compile(r"\*\*\*\*\*\*\*\*\*")
                    with open(path) as fd:
                        for line in fd.readlines():
                            if not expr.search(line):
                                fdtmp.write(line)

                self.cfg = yaml.safe_load(open(ftmp))
                os.remove(ftmp)

        return self.cfg
示例#9
0
    def _get_interfaces(self, namespaces=False):
        """
        Get all interfaces in ip address show.

        @param namespaces: if set to True will get interfaces from all
        namespaces on the host.
        @return: list of NetworkPort objects for each interface found.
        """
        interfaces = []

        interfaces_raw = self.cache_load(namespaces=namespaces)
        if interfaces_raw:
            for iface in interfaces_raw:
                interfaces.append(NetworkPort(**iface))

            return interfaces

        interfaces_raw = []
        seq = SequenceSearchDef(start=SearchDef(IP_IFACE_NAME),
                                body=SearchDef([IP_IFACE_V4_ADDR,
                                                IP_IFACE_V6_ADDR,
                                                IP_IFACE_HW_ADDR,
                                                IP_IFACE_VXLAN_INFO]),
                                tag='ip_addr_show')
        search_obj = FileSearcher()
        if namespaces:
            for ns in self.cli.ip_netns():
                ns_name = ns.partition(" ")[0]
                ip_addr = self.cli.ns_ip_addr(namespace=ns_name)
                path = mktemp_dump('\n'.join(ip_addr))
                search_obj.add_search_term(seq, path)
        else:
            path = mktemp_dump('\n'.join(self.cli.ip_addr()))
            search_obj.add_search_term(seq, path)

        if not search_obj.paths:
            log.debug("no network info found (namespaces=%s)", namespaces)
            return []

        r = search_obj.search()
        for path in search_obj.paths:
            # we no longer need this file so can delete it
            os.unlink(path)
            sections = r.find_sequence_sections(seq, path).values()
            for section in sections:
                addrs = []
                encap_info = None
                hwaddr = None
                name = None
                state = None
                for result in section:
                    if result.tag == seq.start_tag:
                        name = result.get(1)
                        state = result.get(2)
                    elif result.tag == seq.body_tag:
                        if result.get(1) in ['inet', 'inet6']:
                            addrs.append(result.get(2))
                        elif result.get(1) in ['vxlan']:
                            encap_info = {result.get(1): {
                                              'id': result.get(2),
                                              'local_ip': result.get(3),
                                              'dev': result.get(4)}}
                        else:
                            hwaddr = result.get(2)

                interfaces_raw.append({'name': name, 'addresses': addrs,
                                       'hwaddr': hwaddr, 'state': state,
                                       'encap_info': encap_info})

        self.cache_save(interfaces_raw, namespaces=namespaces)
        for iface in interfaces_raw:
            interfaces.append(NetworkPort(**iface))

        return interfaces