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_with_latest_report_hash(self):
node = Node('_', 'node',
latest_report_hash='hash#1')
assert node.name == 'node'
assert node.latest_report_hash == 'hash#1'
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_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')
def test_with_status_unreported_from_failed(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_report='failed',
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')
def mock_puppetdb_default_nodes(mocker):
node_list = [
Node('_', 'node-unreported',
report_timestamp='2013-08-01T09:57:00.000Z',
latest_report_hash='1234567',
catalog_timestamp='2013-08-01T09:57:00.000Z',
facts_timestamp='2013-08-01T09:57:00.000Z',
status_report='unreported'),
Node('_', 'node-changed',
report_timestamp='2013-08-01T09:57:00.000Z',
latest_report_hash='1234567',
catalog_timestamp='2013-08-01T09:57:00.000Z',
facts_timestamp='2013-08-01T09:57:00.000Z',
status_report='changed'),
Node('_', 'node-failed',
report_timestamp='2013-08-01T09:57:00.000Z',
latest_report_hash='1234567',
catalog_timestamp='2013-08-01T09:57:00.000Z',
facts_timestamp='2013-08-01T09:57:00.000Z',
def test_with_cached_catalog_status(self):
node1 = Node('_', 'node', cached_catalog_status='explicitly_requested')
node2 = Node('_', 'node', cached_catalog_status='on_failure')
node3 = Node('_', 'node', cached_catalog_status='not_used')
assert node1.name == 'node'
assert node1.cached_catalog_status == 'explicitly_requested'
assert node2.name == 'node'
assert node2.cached_catalog_status == 'on_failure'
assert node3.name == 'node'
assert node3.cached_catalog_status == 'not_used'
def test_apiv4_with_pending_noop_status(self):
node = Node('_', 'node',
status_report='unchanged',
noop=True,
noop_pending=True,
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'
def mock_puppetdb_default_nodes(mocker):
node_list = [
Node('_', 'node-unreported',
report_timestamp='2013-08-01T09:57:00.000Z',
latest_report_hash='1234567',
catalog_timestamp='2013-08-01T09:57:00.000Z',
facts_timestamp='2013-08-01T09:57:00.000Z',
status_report='unreported'),
Node('_', 'node-changed',
report_timestamp='2013-08-01T09:57:00.000Z',
latest_report_hash='1234567',
catalog_timestamp='2013-08-01T09:57:00.000Z',
facts_timestamp='2013-08-01T09:57:00.000Z',
status_report='changed'),
Node('_', 'node-failed',
report_timestamp='2013-08-01T09:57:00.000Z',
latest_report_hash='1234567',
catalog_timestamp='2013-08-01T09:57:00.000Z',
facts_timestamp='2013-08-01T09:57:00.000Z',
status_report='failed'),
Node('_', 'node-noop',
report_timestamp='2013-08-01T09:57:00.000Z',
latest_report_hash='1234567',
catalog_timestamp='2013-08-01T09:57:00.000Z',
facts_timestamp='2013-08-01T09:57:00.000Z',
status_report='noop'),
Node('_', 'node-unchanged',
report_timestamp='2013-08-01T09:57:00.000Z',
latest_report_hash='1234567',
catalog_timestamp='2013-08-01T09:57:00.000Z',
facts_timestamp='2013-08-01T09:57:00.000Z',
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']
)
:type query: :obj:`None` or :obj:`string`
: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:
log.debug("Request returned a single node.")
nodes = [nodes, ]
for node in nodes:
yield Node(self,
node['name'],
deactivated=node['deactivated'],
report_timestamp=node['report_timestamp'],
catalog_timestamp=node['catalog_timestamp'],
facts_timestamp=node['facts_timestamp'],
)
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,
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=node['status'],
events=node['events'],
unreported_time=node['unreported_time'],
report_environment=node['report_environment'],
catalog_environment=node['catalog_environment'],
facts_environment=node['facts_environment']
)