Puppet Spec and Test kitchen - puppet

How can I override log format of serverspec and extract in a separate file?
I am able to to do this but not able to extract in separate file.
My code snippet is :
RSpec.configure do |c|
c.output_stream = File.open('serverspec-result.json', 'w')
end
when i am running kitchen test, it giving me following warning :
RSpec's reporter has already been initialized with
#<IO:<STDOUT>> as the output stream,
so your change to `output_stream` will be ignored.
You should configure it earlier for it to take effect.

Related

Coverage appears to load coveragerc file, but all configuration remains default

I may be missing something obvious here, but I don't seem to be able to get coverage to load configuration data from a .coveragerc file when being used as an imported module, although it does seem to be checking that the configuration file is present. First, here is the full contents of my .coveragerc:
[Run]
branch = True
[Report]
show_missing = True
skip_covered = True
More specifically, this snippet of code confirms that it does see the file, as it prints out ['.coveragerc'], as expected.
cov = coverage.Coverage(config_file='.coveragerc')
print(cov.config.config_files)
When the config file name is changed to a file that does not exist (such as .notcoveragerc), I get this exception that seems to confirm that the code above is successfully loading a file, or at least verifying its existence.
coverage.misc.CoverageException: Couldn't read '.notcoveragerc' as a config file
However, if I check any of the other values that I expect to be changed from their defaults based on the contents of my .coveragerc, I can see that they have not been changed.
cov = coverage.Coverage(config_file='.coveragerc')
print(cov.config.config_files)
print(cov.config.branch)
print(cov.config.show_missing)
print(cov.config.skip_covered)
The above code outputs the following:
['.testcoveragerc']
False
False
False
Am I missing something obvious in the documentation or is this something I should file a bug report for?
Your section names should be lowercase: [run], not [Run].
I encountered the exact same issue.
I was able to resolve it by moving .coveragerc into the same folder as manage.py.

Puppet : How to load file from agent - Part 3

Using the functions in my earlier queries (see reference below), I am able to pull the file from the agent and perform the necessary tasks. However, this is affecting all the users on the system as it throws an exception stating that the file is not found. Is there anyway I can add some logic like unless file_exists .... to this ruby function ?
My hierarchy is shown below. I am not following why it affects other users who are not even in "mymodules".
Root
modules
mymodules
lib
facter
ruby_function1.rb
ruby_function2.rb
modules_by_userxx1
modules_by_userxx2
modules_by_userxx3
....
Reference :
Puppet : How to load file from agent
Puppet : How to load file from agent - Part 2
As requested by Dominic, adding reference code :
# module_name/lib/facter/master_hash.rb
require 'json'
Facter.add(:master_hash) do
setcode do
# return content of foo as a string
f = File.read('/path/to/some_file.json')
master_hash = JSON.parse(f)
master_hash
end
end
I'll assume you're talking about the custom fact from the previous answers rather than a Ruby function, in which case, add a File.exist? conditional:
# module_name/lib/facter/master_hash.rb
require 'json'
Facter.add(:master_hash) do
setcode do
if File.exist?('/path/to/some_file.json')
# return content of foo as a string
f = File.read('/path/to/some_file.json')
master_hash = JSON.parse(f)
master_hash
end
end
end
Please include the full error message (with the filename/line number it provides) and the source code when asking questions.
Custom facts are shipped within modules, but are all synced to agents as they're used to discover data.
Facts are synced and run on agents before the node is classified because they can be used to make classification and catalog decisions, e.g. based on hostname or OS. Because facts run before classification, it isn't yet possible to know which classes (and perhaps modules) are going to be applied, so should be safe to run on every node in the environment.

Puppet : How to load file from agent

I have written a manifest that performs a number of tasks. The very first task is that it loads the contents of a file into a variable. The file will exist on the target node ( or managed node or the one running the Puppet agent).
However, when I triggered the manifest via a puppet run, I realized that it was expecting to find the file on the master, not the agent!
$some_var = file("path_to_file")
How do I fix this so that it loads the file from the agent?
Indeed functions execute only on the master. Therefore, you need either an external or custom fact for this to execute on the node. Here is a custom fact ready to go for this purpose of returning the contents of a file foo:
# module_name/lib/facter/foo_content.rb
Facter.add(:foo_content) do
setcode do
# return content of foo as a string
File.read('/path/to/foo')
end
end
You can then use this thusly:
# facter 3
$some_var = $facts['foo_content']
# facter 2
$some_var = $::foo_content
Note this solution assumes foo is not some extremely enormous file.
https://docs.puppet.com/facter/3.6/custom_facts.html

py.test : logging the number of failures

Can I catch the failures found by py.test ? I would like to build a log where I will write the numbers of failures and also the OS tested.
You can log a machine readable result file for this purpose using:
py.test --resultlog=path
Documentation is available here. This file is what many other tools use to inspect the output of a py.test run and, for example, compare results between different runs.
Apart from --resultlog which #srowland showed, you can also use --junitxml to write a JUnit XML file, or write your own plugin to log in a custom format.

How to read a txt file, get a data and store it as variable in Custom Properties of SOAPUI using Groovy?

i started to use Soapui this week and i did some tests like sending a request POST and save the response as txt file ina folder.
What i'm trying to do is to read this txt file, copy a sepcific data and store it in Custom Properties.
Because i want to use this object in the nest Request POST which is depending of the first request.
I want to do it in Groovy.
i have only the Open source SOAPUI version 5.0.0
Thank you
You've to add a groovy test step in your test case and do it similar as you would in java, check groovy documentation.
Only as a reference SOAPUI 5.2.0 has the groovy 2.1.7 version (check the dependency in pom.xml) so in groovy scripts which runs on SOAPUI you can use the java standard api included in the jre, the SOAPUI classes, the groovy 2.1.7 API among some others, additionally you can include other jars in SOAPUI\bin\ext in order to use them in groovy script.
Finally you're asking about to read some data from a file and write it to a custom property, so for example you can do it as follows:
// read the file from path
def file = new File('/path/yourFile')
// for example read line by line
def yourData = file.eachLine { line ->
// check if the line contains your data
if(line.contains('mySpecifiyData=')){
return line
}
}
// put the line in a custom property in the testCase
testRunner.testCase.setPropertyValue('yourProp',yourData)
Since your problem it's not clear I show you a possible sample showing how to read a file looking for specific content and saving this content in a custom property in the testCase.
Note that in groovy scripts the are a global objects which you can use: testRunner, context and log, in this sample I use testRunner to access testCase and its properties, in the same way you can go thought testRunner to access testSuites, project, testSteps etc... check the documentation:
http://www.soapui.org/Scripting-Properties/tips-a-tricks.html
http://www.soapui.org/Functional-Testing/working-with-scripts.html
Hope this helps,

Resources