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#")
def test_report_with_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="success", noop=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#")
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#')
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#')
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#')
def __init__(self, api, node, hash_, start, end, received, version, format_, agent_version, transaction, status=None, metrics={}, logs={}, environment=None, noop=False, code_id=None, catalog_uuid=None, cached_catalog_status=None): self.node = node self.hash_ = hash_ self.start = json_to_datetime(start) self.end = json_to_datetime(end) self.received = json_to_datetime(received) self.version = version self.format_ = format_ self.agent_version = agent_version self.run_time = self.end - self.start self.transaction = transaction self.environment = environment self.status = 'noop' if noop else status self.metrics = metrics self.logs = logs self.code_id = code_id self.catalog_uuid = catalog_uuid self.cached_catalog_status = cached_catalog_status self.__string = '{0}'.format(self.hash_) self.__api = api
def __init__(self, api, node, hash_, start, end, received, version, format_, agent_version, transaction, status=None, metrics={}, logs={}, environment=None, noop=False, code_id=None, catalog_uuid=None, cached_catalog_status=None): self.node = node self.hash_ = hash_ self.start = json_to_datetime(start) self.end = json_to_datetime(end) self.received = json_to_datetime(received) self.version = version self.format_ = format_ self.agent_version = agent_version self.run_time = self.end - self.start self.transaction = transaction self.environment = environment self.status = 'noop' if noop else status self.metrics = metrics self.logs = logs self.code_id = code_id self.catalog_uuid = catalog_uuid self.cached_catalog_status = cached_catalog_status self.__string = '{0}'.format(self.hash_) self.__api = api self.__query_scope = '["=", "report", "{0}"]'.format(self.hash_)
def test_report_with_event(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', events=[{ "status": "success", "timestamp": '2015-08-31T21:09:00.000Z', "old_value": "file", "resource_title": "/etc/httpd/conf.d/README", "containment_path": [ "Stage['main']", "Apache", "File[/etc/httpd/conf.d/README]" ], "file": None, "new_value": "absent", "message": "removed", "property": "ensure", "line": None, "resource_type": "File", "containing_class": "Apache"}]) 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 len(report.events) == 1
def test_report_with_none_noop_pending_status_unchanged(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, '3.8.1', 'af9f16e3-75f6-4f90-acc6-f83d6524a6f3', status='unchanged', noop=False, metrics=[ {"name": "failure", "value": 1, "category": "events"}, {"name": "noop", "value": 1, "category": "events"}, {"name": "success", "value": 0, "category": "events"}]) 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 == '3.8.1' assert report.run_time == report.end - report.start assert report.transaction == 'af9f16e3-75f6-4f90-acc6-f83d6524a6f3' assert report.status == 'unchanged' assert str(report) == str('hash#') assert unicode(report) == unicode('hash#') assert repr(report) == str('Report: hash#')
def __init__(self, api, name, deactivated=None, report_timestamp=None, catalog_timestamp=None, facts_timestamp=None, status=None, events=None, unreported_time=None): self.name = name self.status = status self.events = events self.unreported_time = unreported_time if deactivated is not None: self.deactivated = json_to_datetime(deactivated) else: self.deactivated = False if report_timestamp is not None: self.report_timestamp = json_to_datetime(report_timestamp) else: self.report_timestamp = report_timestamp if facts_timestamp is not None: self.facts_timestamp = json_to_datetime(facts_timestamp) else: self.facts_timestamp = facts_timestamp if catalog_timestamp is not None: self.catalog_timestamp = json_to_datetime(catalog_timestamp) else: self.catalog_timestamp = catalog_timestamp self.__api = api self.__query_scope = '["=", "certname", "{0}"]'.format(self.name) self.__string = self.name
def test_apiv4_with_unchanged_status(self): node = Node( '_', 'node', status='unchanged', report_environment='development', catalog_environment='development', facts_environment='development', report_timestamp='2013-08-01T09:57:00.000Z', catalog_timestamp='2013-08-01T09:57:00.000Z', facts_timestamp='2013-08-01T09:57:00.000Z', ) assert node.name == 'node' assert node.deactivated is False assert node.expired is False assert node.report_environment == 'development' assert node.catalog_environment == 'development' assert node.facts_environment == 'development' assert node.report_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.facts_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.catalog_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.status == 'unchanged' assert str(node) == str('node') assert unicode(node) == unicode('node') assert repr(node) == str('<Node: node>')
def test_with_status_unreported(self): node = Node( '_', 'node', report_timestamp='2013-08-01T09:57:00.000Z', catalog_timestamp='2013-08-01T09:57:00.000Z', facts_timestamp='2013-08-01T09:57:00.000Z', status='unreported', unreported_time='0d 5h 20m', ) assert node.name == 'node' assert node.deactivated is False assert node.expired is False assert node.report_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.facts_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.catalog_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.status is 'unreported' assert node.unreported_time is '0d 5h 20m' assert str(node) == str('node') assert unicode(node) == unicode('node') assert repr(node) == str('<Node: node>')
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#')
def test_apiv4_with_failed_noop_status(self): node = Node( '_', 'node', status_report='failed', noop=True, noop_pending=False, report_environment='development', catalog_environment='development', facts_environment='development', report_timestamp='2013-08-01T09:57:00.000Z', catalog_timestamp='2013-08-01T09:57:00.000Z', facts_timestamp='2013-08-01T09:57:00.000Z', ) assert node.name == 'node' assert node.deactivated is False assert node.expired is False assert node.report_environment == 'development' assert node.catalog_environment == 'development' assert node.facts_environment == 'development' assert node.report_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.facts_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.catalog_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.status == 'failed' assert str(node) == str('node') assert str(node) == str('node') assert repr(node) == str('<Node: node>')
def test_apiv4_with_failed_noop_status(self): node = Node('_', 'node', status_report='failed', noop=True, noop_pending=False, report_environment='development', catalog_environment='development', facts_environment='development', report_timestamp='2013-08-01T09:57:00.000Z', catalog_timestamp='2013-08-01T09:57:00.000Z', facts_timestamp='2013-08-01T09:57:00.000Z', ) assert node.name == 'node' assert node.deactivated is False assert node.expired is False assert node.report_environment == 'development' assert node.catalog_environment == 'development' assert node.facts_environment == 'development' assert node.report_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.facts_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.catalog_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.status == 'failed' assert str(node) == str('node') assert unicode(node) == unicode('node') assert repr(node) == str('<Node: node>')
def __init__(self, api, name, deactivated=None, expired=None, report_timestamp=None, catalog_timestamp=None, facts_timestamp=None, status=None, noop=False, noop_pending=False, events=None, unreported_time=None, report_environment='production', catalog_environment='production', facts_environment='production', latest_report_hash=None, cached_catalog_status=None): self.name = name self.status = 'noop' if noop and noop_pending else status self.events = events self.unreported_time = unreported_time self.report_timestamp = report_timestamp self.catalog_timestamp = catalog_timestamp self.facts_timestamp = facts_timestamp self.report_environment = report_environment self.catalog_environment = catalog_environment self.facts_environment = facts_environment self.latest_report_hash = latest_report_hash self.cached_catalog_status = cached_catalog_status if deactivated is not None: self.deactivated = json_to_datetime(deactivated) else: self.deactivated = False if expired is not None: self.expired = json_to_datetime(expired) else: self.expired = False if report_timestamp is not None: self.report_timestamp = json_to_datetime(report_timestamp) else: self.report_timestamp = report_timestamp if facts_timestamp is not None: self.facts_timestamp = json_to_datetime(facts_timestamp) else: self.facts_timestamp = facts_timestamp if catalog_timestamp is not None: self.catalog_timestamp = json_to_datetime(catalog_timestamp) else: self.catalog_timestamp = catalog_timestamp self.__api = api self.__string = self.name
def __init__(self, node, hash_, start, end, received, version, format_, agent_version, transaction): self.node = node self.hash_ = hash_ self.start = json_to_datetime(start) self.end = json_to_datetime(end) self.received = json_to_datetime(received) self.version = version self.format_ = format_ self.agent_version = agent_version self.run_time = self.end - self.start self.transaction = transaction self.__string = "{0}".format(self.hash_)
def __init__(self, api, name, deactivated=None, expired=None, report_timestamp=None, catalog_timestamp=None, facts_timestamp=None, status_report=None, noop=False, noop_pending=False, report=None, unreported=False, unreported_time=None, report_environment='production', catalog_environment='production', facts_environment='production', latest_report_hash=None, cached_catalog_status=None): self.name = name self.report = report self.unreported_time = unreported_time self.report_timestamp = report_timestamp self.catalog_timestamp = catalog_timestamp self.facts_timestamp = facts_timestamp self.report_environment = report_environment self.catalog_environment = catalog_environment self.facts_environment = facts_environment self.latest_report_hash = latest_report_hash self.cached_catalog_status = cached_catalog_status if unreported: self.status = 'unreported' elif noop and noop_pending: self.status = 'noop' else: self.status = status_report if deactivated is not None: self.deactivated = json_to_datetime(deactivated) else: self.deactivated = False if expired is not None: self.expired = json_to_datetime(expired) else: self.expired = False if report_timestamp is not None: self.report_timestamp = json_to_datetime(report_timestamp) else: self.report_timestamp = report_timestamp if facts_timestamp is not None: self.facts_timestamp = json_to_datetime(facts_timestamp) else: self.facts_timestamp = facts_timestamp if catalog_timestamp is not None: self.catalog_timestamp = json_to_datetime(catalog_timestamp) else: self.catalog_timestamp = catalog_timestamp self.__api = api self.__string = self.name
def __init__(self, node, hash_, start, end, received, version, format_, agent_version, transaction): self.node = node self.hash_ = hash_ self.start = json_to_datetime(start) self.end = json_to_datetime(end) self.received = json_to_datetime(received) self.version = version self.format_ = format_ self.agent_version = agent_version self.run_time = self.end - self.start self.transaction = transaction self.__string = '{0}'.format(self.hash_)
def test_report(): 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') 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'
def test_event(self): event = Event( "node", "failure", "2013-08-01T10:57:00.000Z", "hash#", "/etc/ssh/sshd_config", "ensure", "Nothing to say", "present", "absent", "file", "Ssh::Server", ["Stage[main]", "Ssh::Server", "File[/etc/ssh/sshd_config]"], "/etc/puppet/modules/ssh/manifests/server.pp", 80, ) assert event.node == "node" assert event.status == "failure" assert event.failed is True assert event.timestamp == json_to_datetime("2013-08-01T10:57:00.000Z") assert event.hash_ == "hash#" assert event.item["title"] == "/etc/ssh/sshd_config" assert event.item["type"] == "file" assert event.item["property"] == "ensure" assert event.item["message"] == "Nothing to say" assert event.item["old"] == "absent" assert event.item["new"] == "present" assert str(event) == str("file[/etc/ssh/sshd_config]/hash#") assert unicode(event) == unicode("file[/etc/ssh/sshd_config]/hash#") assert repr(event) == str("Event: file[/etc/ssh/sshd_config]/hash#")
def test_expired(self): node = Node("_", "node", expired="2013-08-01T09:57:00.000Z") assert node.name == "node" assert node.expired == json_to_datetime("2013-08-01T09:57:00.000Z") assert str(node) == str("node") assert unicode(node) == unicode("node") assert repr(node) == str("<Node: node>")
def __init__(self, node, status, timestamp, hash_, title, property_, message, new_value, old_value, type_, class_, execution_path, source_file, line_number): self.node = node self.status = status if self.status == 'failure': self.failed = True else: self.failed = False self.timestamp = json_to_datetime(timestamp) self.hash_ = hash_ self.item = {} self.item['title'] = title self.item['type'] = type_ self.item['property'] = property_ self.item['message'] = message self.item['old'] = old_value self.item['new'] = new_value self.item['class'] = class_ self.item['execution_path'] = execution_path self.item['source_file'] = source_file self.item['line_number'] = line_number self.__string = '{0}[{1}]/{2}'.format(self.item['type'], self.item['title'], self.hash_)
def __init__(self, node, time, environment, facts, trusted): self.node = node self.time = json_to_datetime(time) self.environment = environment self.facts = facts self.trusted = trusted self.__string = self.node
def __init__(self, node, status, timestamp, hash_, title, property_, message, new_value, old_value, type_, class_, execution_path, source_file, line_number): self.node = node self.status = status if self.status == 'failure': self.failed = True else: self.failed = False self.timestamp = json_to_datetime(timestamp) self.hash_ = hash_ self.item = { 'title': title, 'type': type_, 'property': property_, 'message': message, 'old': old_value, 'new': new_value, 'class': class_, 'execution_path': execution_path, 'source_file': source_file, 'line_number': line_number } self.__string = '{0}[{1}]/{2}'.format(self.item['type'], self.item['title'], self.hash_)
def test_expired(self): node = Node('_', 'node', expired='2013-08-01T09:57:00.000Z',) assert node.name == 'node' assert node.expired == json_to_datetime('2013-08-01T09:57:00.000Z') assert str(node) == str('node') assert unicode(node) == unicode('node') assert repr(node) == str('<Node: node>')
def test_json_to_datetime(): json_datetime = '2013-08-01T09:57:00.000Z' python_datetime = json_to_datetime(json_datetime) assert python_datetime.dst() == datetime.timedelta(0) assert python_datetime.date() == datetime.date(2013, 8, 1) assert python_datetime.tzname() == 'UTC' assert python_datetime.utcoffset() == datetime.timedelta(0) assert python_datetime.dst() == datetime.timedelta(0)
def test_without_status(self): node = Node('_', 'node', report_timestamp='2013-08-01T09:57:00.000Z', catalog_timestamp='2013-08-01T09:57:00.000Z', facts_timestamp='2013-08-01T09:57:00.000Z',) assert node.name == 'node' assert node.deactivated is False assert node.expired is False assert node.report_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.facts_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.catalog_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert str(node) == str('node') assert unicode(node) == unicode('node') assert repr(node) == str('<Node: node>')
def test_without_status(self): node = Node( "_", "node", report_timestamp="2013-08-01T09:57:00.000Z", catalog_timestamp="2013-08-01T09:57:00.000Z", facts_timestamp="2013-08-01T09:57:00.000Z", ) assert node.name == "node" assert node.deactivated is False assert node.expired is False assert node.report_timestamp == json_to_datetime("2013-08-01T09:57:00.000Z") assert node.facts_timestamp == json_to_datetime("2013-08-01T09:57:00.000Z") assert node.catalog_timestamp == json_to_datetime("2013-08-01T09:57:00.000Z") assert str(node) == str("node") assert unicode(node) == unicode("node") assert repr(node) == str("<Node: node>")
def test_expired(self): node = Node( '_', 'node', expired='2013-08-01T09:57:00.000Z', ) assert node.name == 'node' assert node.expired == json_to_datetime('2013-08-01T09:57:00.000Z') assert str(node) == str('node') assert unicode(node) == unicode('node') assert repr(node) == str('<Node: node>')
def test_deactivated(self): node = Node( '_', 'node', deactivated='2013-08-01T09:57:00.000Z', ) assert node.name == 'node' assert node.deactivated == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert str(node) == str('node') assert str(node) == str('node') assert repr(node) == str('<Node: node>')
def test_without_status(self): node = Node( '_', 'node', report_timestamp='2013-08-01T09:57:00.000Z', catalog_timestamp='2013-08-01T09:57:00.000Z', facts_timestamp='2013-08-01T09:57:00.000Z', ) assert node.name == 'node' assert node.deactivated is False assert node.expired is False assert node.report_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.facts_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.catalog_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert str(node) == str('node') assert unicode(node) == unicode('node') assert repr(node) == str('<Node: node>')
def test_with_status_unreported(self): node = Node('_', 'node', report_timestamp='2013-08-01T09:57:00.000Z', catalog_timestamp='2013-08-01T09:57:00.000Z', facts_timestamp='2013-08-01T09:57:00.000Z', status='unreported', unreported_time='0d 5h 20m',) assert node.name == 'node' assert node.deactivated is False assert node.expired is False assert node.report_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.facts_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.catalog_timestamp == \ json_to_datetime('2013-08-01T09:57:00.000Z') assert node.status is 'unreported' assert node.unreported_time is '0d 5h 20m' assert str(node) == str('node') assert unicode(node) == unicode('node') assert repr(node) == str('<Node: node>')
def test_with_status_unreported(self): node = Node( "_", "node", report_timestamp="2013-08-01T09:57:00.000Z", catalog_timestamp="2013-08-01T09:57:00.000Z", facts_timestamp="2013-08-01T09:57:00.000Z", status="unreported", unreported_time="0d 5h 20m", ) assert node.name == "node" assert node.deactivated is False assert node.expired is False assert node.report_timestamp == json_to_datetime("2013-08-01T09:57:00.000Z") assert node.facts_timestamp == json_to_datetime("2013-08-01T09:57:00.000Z") assert node.catalog_timestamp == json_to_datetime("2013-08-01T09:57:00.000Z") assert node.status is "unreported" assert node.unreported_time is "0d 5h 20m" assert str(node) == str("node") assert unicode(node) == unicode("node") assert repr(node) == str("<Node: node>")
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 unicode(report) == unicode('hash#') assert repr(report) == str('Report: hash#')
def __init__(self, api, node, hash_, start, end, received, version, format_, agent_version, transaction, status=None, metrics=[], logs={}, environment=None, noop=None, noop_pending=None, code_id=None, catalog_uuid=None, cached_catalog_status=None, producer=None): self.node = node self.hash_ = hash_ self.start = json_to_datetime(start) self.end = json_to_datetime(end) self.received = json_to_datetime(received) self.version = version self.format_ = format_ self.agent_version = agent_version self.run_time = self.end - self.start self.transaction = transaction self.environment = environment self.status = 'noop' if noop and noop_pending else status self.metrics = metrics self.logs = logs self.code_id = code_id self.catalog_uuid = catalog_uuid self.cached_catalog_status = cached_catalog_status self.producer = producer self.__string = '{0}'.format(self.hash_) self.metrics_dict = None self.__api = api if status == 'unchanged' and noop_pending is None: if ( self.metric('events', 'noop') and not self.metric('events', 'success') and not self.metric('events', 'failure') ): self.status = 'noop'
def test_event(): event = Event('node1.puppet.board', 'failure', '2013-08-01T10:57:00.000Z', 'hash#', '/etc/ssh/sshd_config', 'ensure', 'Nothing to say', 'present', 'absent', 'file') assert event.node == 'node1.puppet.board' assert event.status == 'failure' assert event.failed is True assert event.timestamp == json_to_datetime('2013-08-01T10:57:00.000Z') assert event.hash_ == 'hash#' assert event.item['title'] == '/etc/ssh/sshd_config' assert event.item['type'] == 'file' assert event.item['property'] == 'ensure' assert event.item['message'] == 'Nothing to say' assert event.item['old'] == 'absent' assert event.item['new'] == 'present'
def test_event(): event = Event('node1.puppet.board', 'failure', '2013-08-01T10:57:00.000Z', 'hash#', '/etc/ssh/sshd_config', 'ensure', 'Nothing to say', 'present', 'absent', 'file') assert event.node == 'node1.puppet.board' assert event.status == 'failure' assert event.failed is True assert event.timestamp == json_to_datetime('2013-08-01T10:57:00.000Z') assert event.hash_ == 'hash#' assert event.item['title'] == '/etc/ssh/sshd_config' assert event.item['type'] == 'file' assert event.item['property'] == 'ensure' assert event.item['message'] == 'Nothing to say' assert event.item['old'] == 'absent' assert event.item['new'] == 'present' assert str(event) == str('file[/etc/ssh/sshd_config]/hash#') assert repr(event) == str('Event: file[/etc/ssh/sshd_config]/hash#')
def test_event(self): event = Event('node', 'failure', '2013-08-01T10:57:00.000Z', 'hash#', '/etc/ssh/sshd_config', 'ensure', 'Nothing to say', 'present', 'absent', 'file') assert event.node == 'node' assert event.status == 'failure' assert event.failed is True assert event.timestamp == json_to_datetime('2013-08-01T10:57:00.000Z') assert event.hash_ == 'hash#' assert event.item['title'] == '/etc/ssh/sshd_config' assert event.item['type'] == 'file' assert event.item['property'] == 'ensure' assert event.item['message'] == 'Nothing to say' assert event.item['old'] == 'absent' assert event.item['new'] == 'present' assert str(event) == str('file[/etc/ssh/sshd_config]/hash#') assert unicode(event) == unicode('file[/etc/ssh/sshd_config]/hash#') assert repr(event) == str('Event: file[/etc/ssh/sshd_config]/hash#')
def __init__(self, node, status, timestamp, hash_, title, property_, message, new_value, old_value, type_): self.node = node self.status = status if self.status == 'failure': self.failed = True else: self.failed = False self.timestamp = json_to_datetime(timestamp) self.hash_ = hash_ self.item = {} self.item['title'] = title self.item['type'] = type_ self.item['property'] = property_ self.item['message'] = message self.item['old'] = old_value self.item['new'] = new_value self.__string = '{0}[{1}]/{2}'.format(self.item['type'], self.item['title'], self.hash_)
def test_event(self): event = Event( 'node', 'failure', '2013-08-01T10:57:00.000Z', 'hash#', '/etc/ssh/sshd_config', 'ensure', 'Nothing to say', 'present', 'absent', 'file', 'Ssh::Server', ['Stage[main]', 'Ssh::Server', 'File[/etc/ssh/sshd_config]'], '/etc/puppet/modules/ssh/manifests/server.pp', 80) assert event.node == 'node' assert event.status == 'failure' assert event.failed is True assert event.timestamp == json_to_datetime('2013-08-01T10:57:00.000Z') assert event.hash_ == 'hash#' assert event.item['title'] == '/etc/ssh/sshd_config' assert event.item['type'] == 'file' assert event.item['property'] == 'ensure' assert event.item['message'] == 'Nothing to say' assert event.item['old'] == 'absent' assert event.item['new'] == 'present' assert str(event) == str('file[/etc/ssh/sshd_config]/hash#') assert unicode(event) == unicode('file[/etc/ssh/sshd_config]/hash#') assert repr(event) == str('Event: file[/etc/ssh/sshd_config]/hash#')
def __init__( self, node, status, timestamp, hash_, title, property_, message, new_value, old_value, type_, class_, execution_path, source_file, line_number, ): self.node = node self.status = status if self.status == "failure": self.failed = True else: self.failed = False self.timestamp = json_to_datetime(timestamp) self.hash_ = hash_ self.item = {} self.item["title"] = title self.item["type"] = type_ self.item["property"] = property_ self.item["message"] = message self.item["old"] = old_value self.item["new"] = new_value self.item["class"] = class_ self.item["execution_path"] = execution_path self.item["source_file"] = source_file self.item["line_number"] = line_number self.__string = "{0}[{1}]/{2}".format(self.item["type"], self.item["title"], self.hash_)
def test_inventory(self): inv = Inventory(node="test1.test.com", environment="production", time='2016-08-18T21:00:00.000Z', facts={ "hostname": "test1.test.com", "domain": "test.com", "puppetversion": "4.6.0" }, trusted={ "authenticated": "remote", "domain": "test.com", "certname": "test1.test.com", "extensions": {}, "hostname": "test1" }) assert inv.node == "test1.test.com" assert inv.environment == "production" assert inv.time == json_to_datetime('2016-08-18T21:00:00.000Z') assert inv.facts == { "hostname": "test1.test.com", "domain": "test.com", "puppetversion": "4.6.0" } assert inv.trusted == { "authenticated": "remote", "domain": "test.com", "certname": "test1.test.com", "extensions": {}, "hostname": "test1" } assert str(inv) == str("test1.test.com") assert str(inv) == str("test1.test.com") assert repr(inv) == str("<Inventory: test1.test.com>")
def test_inventory(self): inv = Inventory(node="test1.test.com", environment="production", time='2016-08-18T21:00:00.000Z', facts={ "hostname": "test1.test.com", "domain": "test.com", "puppetversion": "4.6.0" }, trusted={ "authenticated": "remote", "domain": "test.com", "certname": "test1.test.com", "extensions": {}, "hostname": "test1" }) assert inv.node == "test1.test.com" assert inv.environment == "production" assert inv.time == json_to_datetime('2016-08-18T21:00:00.000Z') assert inv.facts == { "hostname": "test1.test.com", "domain": "test.com", "puppetversion": "4.6.0" } assert inv.trusted == { "authenticated": "remote", "domain": "test.com", "certname": "test1.test.com", "extensions": {}, "hostname": "test1" } assert str(inv) == str("test1.test.com") assert unicode(inv) == unicode("test1.test.com") assert repr(inv) == str("<Inventory: test1.test.com>")
def nodes(self, unreported=2, with_status=False, **kwargs): nodes = self._query('nodes', **kwargs) now = datetime.utcnow() # If we happen to only get one node back it # won't be inside a list so iterating over it # goes boom. Therefor we wrap a list around it. if type(nodes) == dict: nodes = [ nodes, ] if with_status: latest_events = self.event_counts(query=EqualsOperator( "latest_report?", True), summarize_by='certname') for node in nodes: node['status_report'] = None node['events'] = None if with_status: status = [ s for s in latest_events if s['subject']['title'] == node['certname'] ] try: node['status_report'] = node['latest_report_status'] if status: node['events'] = status[0] except KeyError: if status: node['events'] = status = status[0] if status['successes'] > 0: node['status_report'] = 'changed' if status['noops'] > 0: node['status_report'] = 'noop' if status['failures'] > 0: node['status_report'] = 'failed' else: node['status_report'] = 'unchanged' # node report age if node['report_timestamp'] is not None: try: last_report = json_to_datetime( node['report_timestamp']) last_report = last_report.replace(tzinfo=None) unreported_border = now - timedelta(hours=unreported) if last_report < unreported_border: delta = (now - last_report) node['unreported'] = True node['unreported_time'] = '{0}d {1}h {2}m'.format( delta.days, int(delta.seconds / 3600), int((delta.seconds % 3600) / 60)) except AttributeError: node['unreported'] = True if not node['report_timestamp']: node['unreported'] = True yield CortexPuppetNode( self, name=node['certname'], deactivated=node['deactivated'], expired=node['expired'], report_timestamp=node['report_timestamp'], catalog_timestamp=node['catalog_timestamp'], facts_timestamp=node['facts_timestamp'], status_report=node['status_report'], noop=node.get('latest_report_noop'), noop_pending=node.get('latest_report_noop_pending'), events=node['events'], unreported=node.get('unreported'), unreported_time=node.get('unreported_time'), report_environment=node['report_environment'], catalog_environment=node['catalog_environment'], facts_environment=node['facts_environment'], latest_report_hash=node.get('latest_report_hash'), cached_catalog_status=node.get('cached_catalog_status'))
def nodes(self, unreported=2, with_status=False, **kwargs): """Query for nodes by either name or query. If both aren't provided this will return a list of all nodes. This method also fetches the nodes status and event counts of the latest report from puppetdb. :param with_status: (optional) include the node status in the\ returned nodes :type with_status: :bool: :param unreported: (optional) amount of hours when a node gets marked as unreported :type unreported: :obj:`None` or integer :param \*\*kwargs: The rest of the keyword arguments are passed to the _query function :returns: A generator yieling Nodes. :rtype: :class:`pypuppetdb.types.Node` """ nodes = self._query('nodes', **kwargs) now = datetime.datetime.utcnow() # If we happen to only get one node back it # won't be inside a list so iterating over it # goes boom. Therefor we wrap a list around it. if type(nodes) == dict: nodes = [ nodes, ] if with_status: latest_events = self.event_counts(query=EqualsOperator( "latest_report?", True), summarize_by='certname') for node in nodes: node['status_report'] = None node['events'] = None if with_status: status = [ s for s in latest_events if s['subject']['title'] == node['certname'] ] try: node['status_report'] = node['latest_report_status'] if status: node['events'] = status[0] except KeyError: if status: node['events'] = status = status[0] if status['successes'] > 0: node['status_report'] = 'changed' if status['noops'] > 0: node['status_report'] = 'noop' if status['failures'] > 0: node['status_report'] = 'failed' else: node['status_report'] = 'unchanged' # node report age if node['report_timestamp'] is not None: try: last_report = json_to_datetime( node['report_timestamp']) last_report = last_report.replace(tzinfo=None) unreported_border = now - timedelta(hours=unreported) if last_report < unreported_border: delta = (now - last_report) node['unreported'] = True node['unreported_time'] = '{0}d {1}h {2}m'.format( delta.days, int(delta.seconds / 3600), int((delta.seconds % 3600) / 60)) except AttributeError: node['unreported'] = True if not node['report_timestamp']: node['unreported'] = True yield Node(self, name=node['certname'], deactivated=node['deactivated'], expired=node['expired'], report_timestamp=node['report_timestamp'], catalog_timestamp=node['catalog_timestamp'], facts_timestamp=node['facts_timestamp'], status_report=node['status_report'], noop=node.get('latest_report_noop'), noop_pending=node.get('latest_report_noop_pending'), events=node['events'], unreported=node.get('unreported'), unreported_time=node.get('unreported_time'), report_environment=node['report_environment'], catalog_environment=node['catalog_environment'], facts_environment=node['facts_environment'], latest_report_hash=node.get('latest_report_hash'), cached_catalog_status=node.get('cached_catalog_status'))
def nodes(self, name=None, query=None, unreported=2, with_status=False): """Query for nodes by either name or query. If both aren't provided this will return a list of all nodes. This method also fetches the nodes status and event counts of the latest report from puppetdb. :param name: (optional) :type name: :obj:`None` or :obj:`string` :param query: (optional) :type query: :obj:`None` or :obj:`string` :param with_status: (optional) include the node status in the\ returned nodes :type with_status: :bool: :param unreported: (optional) amount of hours when anode gets marked as unreported :type unreported: :obj:`None` or integer :returns: A generator yieling Nodes. :rtype: :class:`pypuppetdb.types.Node` """ nodes = self._query('nodes', path=name, query=query) # If we happen to only get one node back it # won't be inside a list so iterating over it # goes boom. Therefor we wrap a list around it. if type(nodes) == dict: nodes = [ nodes, ] if with_status: latest_events = self._query('event-counts', query='["=","latest-report?",true]', summarize_by='certname') for node in nodes: node['unreported_time'] = None node['status'] = None if with_status: status = [ s for s in latest_events if s['subject']['title'] == node['name'] ] # node status from events if with_status and status: node['events'] = status = status[0] if status['successes'] > 0: node['status'] = 'changed' if status['failures'] > 0: node['status'] = 'failed' else: node['status'] = 'unchanged' node['events'] = None # node report age if with_status and node['report_timestamp'] is not None: try: last_report = json_to_datetime(node['report_timestamp']) last_report = last_report.replace(tzinfo=None) now = datetime.utcnow() unreported_border = now - timedelta(hours=unreported) if last_report < unreported_border: delta = (datetime.utcnow() - last_report) node['status'] = 'unreported' node['unreported_time'] = '{0}d {1}h {2}m'.format( delta.days, int(delta.seconds / 3600), int((delta.seconds % 3600) / 60)) except AttributeError: node['status'] = 'unreported' if not node['report_timestamp']: node['status'] = 'unreported' yield Node(self, node['name'], deactivated=node['deactivated'], report_timestamp=node['report_timestamp'], catalog_timestamp=node['catalog_timestamp'], facts_timestamp=node['facts_timestamp'], status=node['status'], events=node['events'], unreported_time=node['unreported_time'])
def test_json_to_datetime_invalid(): with pytest.raises(ValueError): json_to_datetime('2013-08-0109:57:00.000Z')
def nodes(self, name=None, query=None, unreported=2, with_status=False): """Query for nodes by either name or query. If both aren't provided this will return a list of all nodes. This method also fetches the nodes status and event counts of the latest report from puppetdb. :param name: (optional) :type name: :obj:`None` or :obj:`string` :param query: (optional) :type query: :obj:`None` or :obj:`string` :param with_status: (optional) include the node status in the\ returned nodes :type with_status: :bool: :param unreported: (optional) amount of hours when a node gets marked as unreported :type unreported: :obj:`None` or integer :returns: A generator yieling Nodes. :rtype: :class:`pypuppetdb.types.Node` """ nodes = self._query('nodes', path=name, query=query) # If we happen to only get one node back it # won't be inside a list so iterating over it # goes boom. Therefor we wrap a list around it. if type(nodes) == dict: nodes = [nodes, ] if with_status: latest_events = self._query( 'event-counts', query='["=","latest-report?",true]', summarize_by='certname') for node in nodes: node['unreported_time'] = None node['status'] = None if with_status: status = [s for s in latest_events if s['subject']['title'] == node['name']] # node status from events if with_status and status: node['events'] = status = status[0] if status['successes'] > 0: node['status'] = 'changed' if status['failures'] > 0: node['status'] = 'failed' else: if with_status: node['status'] = 'unchanged' node['events'] = None # node report age if with_status and node['report_timestamp'] is not None: try: last_report = json_to_datetime(node['report_timestamp']) last_report = last_report.replace(tzinfo=None) now = datetime.utcnow() unreported_border = now-timedelta(hours=unreported) if last_report < unreported_border: delta = (datetime.utcnow()-last_report) node['status'] = 'unreported' node['unreported_time'] = '{0}d {1}h {2}m'.format( delta.days, int(delta.seconds/3600), int((delta.seconds % 3600)/60) ) except AttributeError: node['status'] = 'unreported' if not node['report_timestamp'] and with_status: node['status'] = 'unreported' yield Node(self, node['name'], deactivated=node['deactivated'], report_timestamp=node['report_timestamp'], catalog_timestamp=node['catalog_timestamp'], facts_timestamp=node['facts_timestamp'], status=node['status'], events=node['events'], unreported_time=node['unreported_time'] )
def create_from_dict(query_api, node, with_status, with_event_numbers, latest_events, now, unreported): node['status_report'] = None node['events'] = None if with_status: if with_event_numbers: status = [ s for s in latest_events if s['subject']['title'] == node['certname'] ] try: node['status_report'] = node['latest_report_status'] if status: node['events'] = status[0] except KeyError: if status: node['events'] = status = status[0] if status['successes'] > 0: node['status_report'] = 'changed' if status['noops'] > 0: node['status_report'] = 'noop' if status['failures'] > 0: node['status_report'] = 'failed' else: node['status_report'] = 'unchanged' else: node['status_report'] = node['latest_report_status'] node['events'] = { 'successes': 0, 'failures': 0, 'noops': 0, } if node['status_report'] == 'changed': node['events']['successes'] = 'some' elif node['status_report'] == 'noop': node['events']['noops'] = 'some' elif node['status_report'] == 'failed': node['events']['failures'] = 'some' # node report age if node['report_timestamp'] is not None: try: last_report = json_to_datetime(node['report_timestamp']) last_report = last_report.replace(tzinfo=None) unreported_border = now - timedelta(hours=unreported) if last_report < unreported_border: delta = (now - last_report) node['unreported'] = True node['unreported_time'] = '{0}d {1}h {2}m'.format( delta.days, int(delta.seconds / 3600), int((delta.seconds % 3600) / 60)) except AttributeError: node['unreported'] = True if not node['report_timestamp']: node['unreported'] = True return Node(query_api, name=node['certname'], deactivated=node['deactivated'], expired=node['expired'], report_timestamp=node['report_timestamp'], catalog_timestamp=node['catalog_timestamp'], facts_timestamp=node['facts_timestamp'], status_report=node['status_report'], noop=node.get('latest_report_noop'), noop_pending=node.get('latest_report_noop_pending'), events=node['events'], unreported=node.get('unreported'), unreported_time=node.get('unreported_time'), report_environment=node['report_environment'], catalog_environment=node['catalog_environment'], facts_environment=node['facts_environment'], latest_report_hash=node.get('latest_report_hash'), cached_catalog_status=node.get('cached_catalog_status'))