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_edge(self):
resource_a = Resource('node', '/etc/ssh/sshd_config', 'file',
['class', 'ssh'], False,
'/ssh/manifests/init.pp', 15, 'production',
parameters={})
resource_b = Resource('node', 'sshd', 'service',
['class', 'ssh'], False,
'/ssh/manifests/init.pp', 30, 'production',
parameters={})
edge = Edge(resource_a, resource_b, 'notify')
assert edge.source == resource_a
assert edge.target == resource_b
assert edge.relationship == 'notify'
assert str(edge) == str(
'file[/etc/ssh/sshd_config] - notify - service[sshd]')
assert str(edge) == str(
'file[/etc/ssh/sshd_config] - notify - service[sshd]')
assert repr(edge) == str(
'')
def test_resource(self):
resource = Resource('node', '/etc/ssh/sshd_config', 'file',
['class', 'ssh'], False, '/ssh/manifests/init.pp',
15, 'production', parameters={
'ensure': 'present',
'owner': 'root',
'group': 'root',
'mode': '0600',
})
assert resource.node == 'node'
assert resource.name == '/etc/ssh/sshd_config'
assert resource.type_ == 'file'
assert resource.tags == ['class', 'ssh']
assert resource.exported is False
assert resource.sourcefile == '/ssh/manifests/init.pp'
assert resource.sourceline == 15
assert resource.environment == 'production'
def test_edge(self):
resource_a = Resource('node', '/etc/ssh/sshd_config', 'file',
['class', 'ssh'], False,
'/ssh/manifests/init.pp', 15, 'production',
parameters={})
resource_b = Resource('node', 'sshd', 'service',
['class', 'ssh'], False,
'/ssh/manifests/init.pp', 30, 'production',
parameters={})
edge = Edge(resource_a, resource_b, 'notify')
assert edge.source == resource_a
assert edge.target == resource_b
assert edge.relationship == 'notify'
assert str(edge) == str(
'file[/etc/ssh/sshd_config] - notify - service[sshd]')
self.node = node
self.version = version
self.transaction_uuid = transaction_uuid
self.environment = environment
self.code_id = code_id
self.catalog_uuid = catalog_uuid
self.producer = producer
self.resources = dict()
for resource in resources:
if 'file' not in resource:
resource['file'] = None
if 'line' not in resource:
resource['line'] = None
identifier = resource['type'] + '[' + resource['title'] + ']'
res = Resource(node=node, name=resource['title'],
type_=resource['type'], tags=resource['tags'],
exported=resource['exported'],
sourcefile=resource['file'],
sourceline=resource['line'],
parameters=resource['parameters'],
environment=self.environment)
self.resources[identifier] = res
self.edges = []
for edge in edges:
identifier_source = edge['source_type'] + \
'[' + edge['source_title'] + ']'
identifier_target = edge['target_type'] + \
'[' + edge['target_title'] + ']'
e = Edge(source=self.resources[identifier_source],
target=self.resources[identifier_target],
if type_ is not None:
type_ = self._normalize_resource_type(type_)
if title is not None:
path = '{0}/{1}'.format(type_, title)
elif title is None:
path = type_
elif query is None:
log.debug('Going to query for all resources. This is usually a '
'bad idea as it might return enormous amounts of '
'resources.')
resources = self._query('resources', path=path, query=query)
for resource in resources:
yield Resource(
resource['certname'],
resource['title'],
resource['type'],
resource['tags'],
resource['exported'],
resource['file'],
resource['line'],
resource['parameters'],
)
:returns: A generator yielding Resources
:rtype: :class:`pypuppetdb.types.Resource`
"""
path = None
if type_ is not None:
type_ = self._normalize_resource_type(type_)
if title is not None:
path = '{0}/{1}'.format(type_, title)
elif title is None:
path = type_
resources = self._query('resources', path=path, **kwargs)
for resource in resources:
yield Resource(
node=resource['certname'],
name=resource['title'],
type_=resource['type'],
tags=resource['tags'],
exported=resource['exported'],
sourcefile=resource['file'],
sourceline=resource['line'],
parameters=resource['parameters'],
environment=resource['environment'],
)
type_ = self._normalize_resource_type(type_)
if title is not None:
path = '{0}/{1}'.format(type_, title)
elif title is None:
path = type_
else:
log.debug('Going to query for all resources. This is usually a '
'bad idea as it might return enormous amounts of '
'resources.')
query = ''
path = None
resources = self._query('resources', path=path, query=query)
for resource in resources:
yield Resource(
resource['certname'],
resource['title'],
resource['type'],
resource['tags'],
resource['exported'],
resource['sourcefile'],
resource['sourceline'],
resource['parameters'],
)
:rtype: :class:`pypuppetdb.types.Resource`
"""
path = None
if type_ is not None:
type_ = self._normalize_resource_type(type_)
if title is not None:
path = '{0}/{1}'.format(type_, title)
elif title is None:
path = type_
resources = self._query('resources', path=path, **kwargs)
for resource in resources:
yield Resource(
node=resource['certname'],
name=resource['title'],
type_=resource['type'],
tags=resource['tags'],
exported=resource['exported'],
sourcefile=resource['file'],
sourceline=resource['line'],
parameters=resource['parameters'],
environment=resource['environment'],
)