ConfigParser.MissingSectionHeaderError: File contains no section headers - configparser

I am trying to fetch data from a .cfg (configuration file) in python but I am always getting the error
ConfigParser.MissingSectionHeaderError: File contains no section headers.
The screenshot of the problem
Here is the link for the .cfg file:
http://www.mediafire.com/file/66k9m7trxo7krx9/a.cfg/file

Most probably you have parameters without section, e.g.:
name1 = value1
name2 = value2
According documentation there should be a section.
I may suggest the following solutions:
Add section explicitly
Add section in ini file, e.g:
[default]
name1 = value1
name2 = value2
Add section implicitly
from configparser import ConfigParser
parser = ConfigParser()
with open('config.ini') as stream:
parser.read_string('[default]\n' + stream.read())
# now you can use it for parameters without section
print(parser.get('default', 'name1'))

The ConfigParser module assumes that config files have section headers. Section headers are used to keep configurations of one type together. Write [Default] in the first line of your configuration file. This will tell ConfigParser that there is only one header and that is the default.

You are adding JSON file instead of config file in format:
[OPTIONS]
option1 = foo
option2 = bar

Related

How to declare and use map var in yaml file?

I try to write a map in y yaml file and want to use it in yaml file itself with a key. for example ->
in my yaml file I wrote -
pod_env_map:
pod1: "env1"
pod2: "env2"
pod3: "env3"
and in this yaml file itself I'm getting a var $pod_name.
So now i want to write stages with some command for all pod and correspond env.
So instead of putting multiple checks of $pod_name == 'pod1'....
I want to use above dict somehow in code like pod_env_map[$pod_name], please help me to know what should be the syntax for this? I tried to find but didn't get relavent info anywhere.

Want to insert a text in a file beforealine using lineinfile in ansible playbook

I need to add a text before the end of a parameter in file. I need to insert my text just before </abc>. I am using lineinfile and it enters the text before <abc> and not </abc>.
My current text file :
<domain-log-broadcast-filter>MultiDataSourceLogFilter</domain-log-broadcast-filter>
<abc>Info is already here. i just need to append the text at end of this parameter. new values to be inserted here</abc>
My Playbook :
- lineinfile:
path: /tmp/tochange.xml
insertbefore: '\<\/abc\>'
line: "Tisisthelinetobeinsertedbyme"
state: present
My Output for this is :
<domain-log-broadcast-filter>MultiDataSourceLogFilter</domain-log-broadcast-filter>
Thisisthelinetobeinsertedbyme
<abc>Info is already here. i just need to append the text at end of this parameter. new values to be inserted here</abc>
Now i have 2 requirements :
I want to insert my text just before </abc>
I have 4 </abc> parameters in my file. I want to ignore the first </abc> and the line is to be inserted before other 3 </abc> parameters.
Please sugest me a best way to do it, all i need is this work to be done, with any modules any script in the playbook. Thanks in advance.
Q: "... with any modules any script in the playbook."
A: Ansible file modules are not able to do it. You'll need the module command or shell to run file editing tools like sed or awk.
Module lineinfile is not able not to fulfill the requirements. This module modifies single lines in a file. It's not possible to change 3 out of 4 lines that match regexp. Neither replace nor blockinfile modules will help you either, I'm afraid. The module template modifies whole files. The next option might be the module patch.
Quoting from lineinfile:
"... For other cases, see the copy or template modules."

How to set Fileinput directory value from properties?

If my flow is File Input -> Compute Node -> File Output, how can I set the File Input directory value based on a User Defined Property? I will have a different file drop directory for dev, qa and prod and don’t want this hard coded anywhere. If it cannot be done using my User Defined Properties, how else can I accomplish this?
Create configurable properties per environment and define the input directory there.
Properties for dev:
# File: yourapp-dev.properties
yourflow#File Input.inputDirectory = ./yourapp/dev/in
Properties for qa:
# File: yourapp-qa.properties
yourflow#File Input.inputDirectory = ./yourapp/qa/in
Apply the properties per environment. For dev it would be:
mqsiapplybaroverride -b yourapp.bar -p yourapp-dev.properties -r
Now you can deploy yourapp.bar to the dev environment.

Read multiple CSV files automatically from a directory inside a ForEach Controller with JMeter

Im trying to read multiple CSV files from a special directory inside a While Controller to convert the data in the files to a specific JMeter property/variable. But I always get an error:
ERROR - jmeter.threads.JMeterThread: Test failed! java.lang.IllegalArgumentException: File ${CURRENTACTIONATTRIBUTEFILE} must exist and be readable
Is it possible that the variable isn't evaluated at this moment? (__V doesn't change anything).I really have no idea why this isn't working.
When I place a Debug Sampler between the ForEach and the While Controller it shows me the JMeterVariable CURRENTACTIONATTRIBUTEFILE has the correct path and file name (when I paste this string hardcoded in the CSV data set config filename it works):
CURRENTACTIONATTRIBUTEFILE=C:/#JMeter/Plans/PRODUCT/61_RISK2VALUE/61_RISK2VALUE - Resources/ModelingData/ActionAttributes/ActionAttributes_AM2.csv
This is what my Testplan Setup looks like:
CREATE file variables: groovy sampler, which checks a special directory and creates numbered vars with the file path + name + extension and a var with the count of the files found in the directory
ForEach Controller
While Controller
CSV Data Set Config (Filename: ${CURRENTACTIONATTRIBUTEFILE)
CREATE variables: groovy sampler, which creates properties/vars to a special convention I need
"CREATE file variables" - sampler code:
String actionAttributeFilePath = "${PATHPLAN}${PATHMODELINGDATA}ActionAttributes/";
File modelingDataDirectory = new File(actionAttributeFilePath);
File[] files = modelingDataDirectory.listFiles();
int fileCounter = 1;
for (File file : files) {
if(file)
{
String actionAttributeFile = actionAttributeFilePath + file.getName();
vars.put("ACTIONATTRIBUTEFILE_" + fileCounter, actionAttributeFile);
fileCounter++;
}
}
vars.put("ACTIONATTRIBUTEFILE_COUNT", Integer.toString(fileCounter-1))
"CREATE variables" - sampler code (not relevant for my problem):
All variables names used below, come from the CSV data set config.
if ("${ATTRIBUTEDEFINITIONID}" != "<EOF>")
{
def variableName = sprintf('ATTRIBUTE%2$sDEFINITIONID_%1$s',["${ATTRIBUTEFORMULANAME}", "${ATTRIBUTETYPE}"])
props.put(variableName,"${ATTRIBUTEDEFINITIONID}");
}
You won't be able to use a JMeter Variable as a CSV Data Set Config filename as CSV Data Set Config is being initialized before any variables.
The only way to make this dynamic is using JMeter Property instead of JMeter Variable
Substitute your ${CURRENTACTIONATTRIBUTEFILE} variable reference with JMeter Property using __P() function as ${__P(CURRENTACTIONATTRIBUTEFILE,)}
Provide the property value via -J command line argument like:
jmeter -JCURRENTACTIONATTRIBUTEFILE="C:/#JMeter/Plans/PRODUCT/61_RISK2VALUE/61_RISK2VALUE - Resources/ModelingData/ActionAttributes/ActionAttributes_AM2.csv"
Another way of setting the property is defining it in user.properties file like:
CURRENTACTIONATTRIBUTEFILE="C:/#JMeter/Plans/PRODUCT/61_RISK2VALUE/61_RISK2VALUE - Resources/ModelingData/ActionAttributes/ActionAttributes_AM2.csv"
References:
Configuring JMeter
Apache JMeter Properties Customization Guide
The CSV Data Set Config element has a field called Filename where you need to specify the file name of your CSV along with its' path.
By default JMeter starts to look for data files in the JMeter root/home folder (\apache-jmeter-x. xx\bin) or the same folder where the JMeter script (.jmx file) resides.
So you can have your CSV files together in the same directory than the .jmx.

Make configuration file point to an existing file

qrouter [-c < config_name>] [options] < basename>
where <basename> is without an extension.
File <basename>.def is assumed to exist
and to define cell placement and netlist
information. File <config_name> is
assumed to exist and contains basic
routing parameters, or points to a LEF
file containing detailed routing parameters.
If this option is not specified, then the
default configuration file name of "route.cfg"
is used.
How to write a .cfg file that points to an existing file?
The commend is used to run an open source VLSI routing tool called Qrouter, an example .cfg file can be like below:
lef /usr/lib/ibm01.lef

Resources