Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 str(report) == str('hash#')
assert repr(report) == str('Report: hash#')
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('')
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 str(report) == str('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 str(report) == str('hash#')
assert repr(report) == str('Report: hash#')
def test_report_with_failed_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='failed',
noop=True,
noop_pending=False)
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 == 'failed'
assert str(report) == str('hash#')
assert str(report) == str('hash#')
assert repr(report) == str('Report: 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 str(event) == str('file[/etc/ssh/sshd_config]/hash#')
assert repr(event) == str('Event: file[/etc/ssh/sshd_config]/hash#')
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_report='unchanged',
unreported=True,
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 == 'unreported'
assert node.unreported_time is '0d 5h 20m'
assert str(node) == str('node')
assert str(node) == str('node')
assert repr(node) == str('')
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 str(report) == str('hash#')
assert repr(report) == str('Report: 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
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