Пример #1
0
    def test_report_with_cataloguuid_codeid(self):
        report = Report('_',
                        'node2.puppet.board',
                        'hash#',
                        '2015-08-31T21:07:00.000Z',
                        '2015-08-31T21:09:00.000Z',
                        '2015-08-31T21:10:00.000Z',
                        '1482347613',
                        4,
                        '4.2.1',
                        'af9f16e3-75f6-4f90-acc6-f83d6524a6f3',
                        code_id=None,
                        catalog_uuid="0b3a4943-a164-4cea-bbf0-91d0ee931326",
                        cached_catalog_status="not_used")

        assert report.node == 'node2.puppet.board'
        assert report.hash_ == 'hash#'
        assert report.start == json_to_datetime('2015-08-31T21:07:00.000Z')
        assert report.end == json_to_datetime('2015-08-31T21:09:00.000Z')
        assert report.received == json_to_datetime('2015-08-31T21:10:00.000Z')
        assert report.version == '1482347613'
        assert report.format_ == 4
        assert report.agent_version == '4.2.1'
        assert report.run_time == report.end - report.start
        assert report.transaction == 'af9f16e3-75f6-4f90-acc6-f83d6524a6f3'
        assert report.catalog_uuid == "0b3a4943-a164-4cea-bbf0-91d0ee931326"
        assert report.cached_catalog_status == "not_used"
        assert str(report) == str('hash#')
        assert unicode(report) == unicode('hash#')
        assert repr(report) == str('Report: hash#')
Пример #2
0
    def reports(self, **kwargs):
        """Get reports for our infrastructure. It is strongly recommended
        to include query and/or paging parameters for this endpoint to
        prevent large result sets and potential PuppetDB performance
        bottlenecks.

        :param \*\*kwargs: The rest of the keyword arguments are passed
                           to the _query function

        :returns: A generating yielding Reports
        :rtype: :class:`pypuppetdb.types.Report`
        """
        reports = self._query('reports', **kwargs)
        for report in reports:
            yield Report(
                api=self,
                node=report['certname'],
                hash_=report['hash'],
                start=report['start_time'],
                end=report['end_time'],
                received=report['receive_time'],
                version=report['configuration_version'],
                format_=report['report_format'],
                agent_version=report['puppet_version'],
                transaction=report['transaction_uuid'],
                environment=report['environment'],
                status=report['status'],
                noop=report.get('noop'),
                noop_pending=report.get('noop_pending'),
                metrics=report['metrics']['data'],
                logs=report['logs']['data'],
                code_id=report.get('code_id'),
                catalog_uuid=report.get('catalog_uuid'),
                cached_catalog_status=report.get('cached_catalog_status'))
Пример #3
0
    def test_report_with_pending_noop(self):
        report = Report('_',
                        'node2.puppet.board',
                        'hash#',
                        '2015-08-31T21:07:00.000Z',
                        '2015-08-31T21:09:00.000Z',
                        '2015-08-31T21:10:00.000Z',
                        '1482347613',
                        4,
                        '4.2.1',
                        'af9f16e3-75f6-4f90-acc6-f83d6524a6f3',
                        status='unchanged',
                        noop=True,
                        noop_pending=True)

        assert report.node == 'node2.puppet.board'
        assert report.hash_ == 'hash#'
        assert report.start == json_to_datetime('2015-08-31T21:07:00.000Z')
        assert report.end == json_to_datetime('2015-08-31T21:09:00.000Z')
        assert report.received == json_to_datetime('2015-08-31T21:10:00.000Z')
        assert report.version == '1482347613'
        assert report.format_ == 4
        assert report.agent_version == '4.2.1'
        assert report.run_time == report.end - report.start
        assert report.transaction == 'af9f16e3-75f6-4f90-acc6-f83d6524a6f3'
        assert report.status == 'noop'
        assert str(report) == str('hash#')
        assert unicode(report) == unicode('hash#')
        assert repr(report) == str('Report: hash#')
Пример #4
0
    def test_report(self):
        report = Report('_',
                        'node1.puppet.board',
                        'hash#',
                        '2013-08-01T09:57:00.000Z',
                        '2013-08-01T10:57:00.000Z',
                        '2013-08-01T10:58:00.000Z',
                        '1351535883',
                        3,
                        '3.2.1',
                        'af9f16e3-75f6-4f90-acc6-f83d6524a6f3',
                        status='success')

        assert report.node == 'node1.puppet.board'
        assert report.hash_ == 'hash#'
        assert report.start == json_to_datetime('2013-08-01T09:57:00.000Z')
        assert report.end == json_to_datetime('2013-08-01T10:57:00.000Z')
        assert report.received == json_to_datetime('2013-08-01T10:58:00.000Z')
        assert report.version == '1351535883'
        assert report.format_ == 3
        assert report.agent_version == '3.2.1'
        assert report.run_time == report.end - report.start
        assert report.transaction == 'af9f16e3-75f6-4f90-acc6-f83d6524a6f3'
        assert report.status == 'success'
        assert str(report) == str('hash#')
        assert unicode(report) == unicode('hash#')
        assert repr(report) == str('Report: hash#')
Пример #5
0
    def test_report_with_producer(self):
        report = Report('_',
                        "test.test.com",
                        "hash#",
                        '2015-08-31T21:07:00.000Z',
                        '2015-08-31T21:09:00.000Z',
                        '2015-08-31T21:10:00.000Z',
                        '1482347613',
                        4,
                        '4.2.1',
                        'af9f16e3-75f6-4f90-acc6-f83d6524a6f3',
                        producer="puppet01.test.com")

        assert report.node == "test.test.com"
        assert report.hash_ == 'hash#'
        assert report.start == json_to_datetime('2015-08-31T21:07:00.000Z')
        assert report.end == json_to_datetime('2015-08-31T21:09:00.000Z')
        assert report.received == json_to_datetime('2015-08-31T21:10:00.000Z')
        assert report.version == '1482347613'
        assert report.format_ == 4
        assert report.agent_version == '4.2.1'
        assert report.run_time == report.end - report.start
        assert report.producer == "puppet01.test.com"
        assert str(report) == str('hash#')
        assert str(report) == str('hash#')
        assert repr(report) == str('Report: hash#')
Пример #6
0
    def reports(self, query):
        """Get reports for our infrastructure. Currently reports can only
        be filtered through a query which requests a specific certname.
        If not it will return all reports.

        This yields a Report object for every returned report."""
        reports = self._query('reports', query=query)
        for report in reports:
            yield Report(report['certname'], report['hash'],
                         report['start-time'], report['end-time'],
                         report['receive-time'],
                         report['configuration-version'],
                         report['report-format'], report['puppet-version'],
                         report['transaction-uuid'])
Пример #7
0
    def reports(self, **kwargs):
        """Get reports for our infrastructure. It is strongly recommended
        to include query and/or paging parameters for this endpoint to
        prevent large result sets and potential PuppetDB performance
        bottlenecks.

        :param \*\*kwargs: The rest of the keyword arguments are passed
                           to the _query function

        :returns: A generating yielding Reports
        :rtype: :class:`pypuppetdb.types.Report`
        """
        reports = self._query('reports', **kwargs)
        for report in reports:
            yield Report.create_from_dict(self, report)
Пример #8
0
def mock_puppetdb_default_nodes(mocker):
    timestamp = '2013-08-01T09:57:00.000Z'
    report_hash = '1234567'
    transaction = '7890'
    version = '3.8.5'
    node_list = [
        Node('_',
             'node-%s' % status,
             report_timestamp=timestamp,
             latest_report_hash=report_hash,
             catalog_timestamp=timestamp,
             facts_timestamp=timestamp,
             status_report=status,
             report=Report('_', 'node-%s', report_hash, timestamp, timestamp,
                           timestamp, version, '6', version, transaction))
        for status in ['failed', 'changed', 'unchanged', 'noop', 'unreported']
    ]

    return mocker.patch.object(app.puppetdb,
                               'nodes',
                               return_value=iter(node_list))
Пример #9
0
    def pql(self,
            pql,
            with_status=False,
            unreported=2,
            with_event_numbers=True):
        """Makes a PQL (Puppet Query Language) and tries to cast results
        to a rich type. If it won't work, returns plain dicts.

        :param pql: PQL query
        :type pql: :obj:`string`

        :param with_status: (optional, only for queries for nodes) include
                           the node status in the returned nodes
        :type with_status: :bool:
        :param unreported: (optional, only for queries for nodes) amount
                           of hours when a node gets marked as unreported
        :type unreported: :obj:`None` or integer
        :param with_event_numbers: (optional, only for queries for nodes)
                           include the exact number of
                           changed/unchanged/failed/noop events when
                           with_status is set to True. If set to False
                           only "some" string is provided if there are
                           resources with such status in the last report.
                           This provides performance benefits as potentially
                           slow event-counts query is omitted completely.
        :type with_event_numbers: :bool:

        :returns: A generator yielding elements of a rich type or plain dicts
        """

        type_class = self._get_type_from_query(pql)

        if type_class == Node and (with_status or unreported != 2
                                   or not with_event_numbers):
            log.error(
                "with_status, unreported and with_event_numbers are used only"
                " for queries for nodes!")
            raise APIError

        for element in self._pql(pql=pql):
            if type_class == Node:

                # TODO: deduplicate this - see QueryAPI.nodes()

                now = datetime.utcnow()

                latest_events = None
                if with_status and with_event_numbers:
                    latest_events = self._query(
                        'event-counts',
                        query=EqualsOperator("latest_report?", True),
                        summarize_by='certname',
                    )

                yield Node.create_from_dict(self, element, with_status,
                                            with_event_numbers, latest_events,
                                            now, unreported)

            elif type_class == Report:
                yield Report.create_from_dict(self, element)
            elif type_class:
                yield type_class.create_from_dict(element)
            else:
                yield element