Nested Run Keywords Statement In Robot Framework - if-statement

I have to execute a nested run keyword Statement and I am following below code in a function:
${value}= Run keyword And Return Status Dictionary Should Contain Key ${details} edit
Run Keyword If '${value}'=='True'
... Run Keywords
... Run Keyword If '&{details}[edit]'=='Block1' Log Block1 Call
... AND Run Keyword If '&{details}[edit]'=='Block2' Log Block2 Call
... AND Run Keyword If '&{details}[edit]'=='Block3' Log Block3 Call
... AND Run Keyword If '&{details}[edit]'=='Block4'
... Run Keywords
... Log Block4 1 Call
... AND Log Block4 2 Call
... AND Log Block4 3 Call
... AND Run Keyword If '&{details}[edit]'=='Block5'
... Run Keywords
... Log Block5 1 Call
... AND Log Block5 2 Call
... AND Log Block5 3 Call
When I am passing the value as Block2, It returns:
Block2 Call
Block4 2 Call
Block4 3 Call
Also, it does not return correct response with values 'Block4' and 'Block5'
I have tried this with ELSE If Statements also, but still this does not work.
Does Run Keyword does not support the Nested Statements? Or Is there any other which by which this can be accomplished?

Solved this by putting all the conditions in a separate method:
${value}= Run keyword And Return Status Dictionary Should Contain Key ${details} edit
Run Keyword If '${value}'=='True' Run_Conditions &{details}
Run_Conditions
[Arguments] &{details}
Run Keyword If '&{details}[edit]'=='Block1' Log Block1 Call
Run Keyword If '&{details}[edit]'=='Block2' Log Block2 Call
Run Keyword If '&{details}[edit]'=='Block3' Log Block3 Call
Run Keyword If '&{details}[edit]'=='Block4'
... Run Keywords
... Log Block4 1 Call
... AND Log Block4 2 Call
... AND Log Block4 3 Call
Run Keyword If '&{details}[edit]'=='Block5'
... Run Keywords
... Log Block5 1 Call
... AND Log Block5 2 Call
... AND Log Block5 3 Call

Related

Unknown action hi in contract error while deploying smart contract on testnet

I am tring to deploy contract on testnet http://api.kylin.alohaeos.com. I have following hello2.cpp program
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;
class suniltestacc : public contract {
public:
using contract::contract;
[[eosio::action]]
void hi( name user ) {
//require_auth( user );
//print( "Hello, ", name{user} );
print( "Hello, ", user);
}
};
EOSIO_DISPATCH(suniltestacc, (hi))
I compiled this program using eosio-cpp -o hello2.wasm hello2.cpp --abigen. It gives me two warnings which I ignored.
Warning, empty ricardian clause file
Warning, empty ricardian clause file
Then I execute cleos -u http://api.kylin.alohaeos.com set contract suniltestacc /home/varsha/Varsha/contracts/hello2
This runs successfully, after that I am trying this command
cleos -u https://api.kylin.alohaeos.com push action suniltestacc hi '["bobmarley"]' -p suniltestacc#active
It is giving me error
error 2019-01-22T08:10:35.520 thread-0 main.cpp:3449 main ] Failed with error: Assert Exception (10)
!action_type.empty(): Unknown action hi in contract suniltestacc.
Can somebody help me with this.
There is nothing wrong with this, Its all working fine.
Below is the result when i called your function.
cleos -u https://api.kylin.alohaeos.com push action suniltestacc hi '["bobmarley"]' -p doslnjslongd#active
executed transaction: 8faa9669ed143c979afa842489dafdfc610e0c6ad4f2831039a170448f867835 104 bytes 134 us
suniltestacc <= suniltestacc::hi {"user":"bobmarley"}
warning: transaction executed locally, but may not be confirmed by the network yet ]
Let me know if i can help you further.

Implementing a 'for loop' within user_data provisioner file

I am currently using a template_file to provision user_data into an aws_launch_configuration, like so:
resource "aws_launch_configuration" "launch_config" {
...
user_data = "${data.template_file.init.rendered}"
}
data "template_file" "init" {
template = "${file("router-init.sh.tpl")}"
vars {
hub_ip_addresses = "${join(",", aws_instance.gridHub.*.private_ip)}"
}
}
I am feeding in a variable (i.e. hub_ip_addresses) into the router-init.sh.tpl file, and in this file I am making use of the argument like so:
`#!/bin/sh
...
IFS=',' read -r -a array <<< "$hub_ip_addresses"
for element in "${array[#]}"
do
#do stuff with $element
done
Basically, I am splitting the string based on a delimiter, and then looping through each ip address in the array.
This bash script works fine when I run it on my local machine -- however, when terraform executes it, it throws a error:
* data.template_file.init: data.template_file.init: failed to render : parse error at 13:25: expected expression but found invalid sequence "#"
I'm supposing the '#' symbol is causing an issue. Is there a reason why this is so? Do I need to escape it with a '\' ?
EDIT: Not sure if related to this issue, but in the preceeding line in the bash script, IFS=',' read -r -a array <<< "$hub_ip_addresses", the <<< seems to be causing everything else that follows to look as if they are inside a comment (i.e. greyed out as if it was within a quotation mark ').)
You need to escape the $ characters in your template by doubling them up or Terraform will attempt to interpolate them as the input variables to the template.
The template docs cover this briefly although the example given is for inline templates rather than for all templates, including those that are loaded with the file() function.
So something like:
#!/bin/sh
...
IFS=',' read -r -a array <<< "$hub_ip_addresses"
for element in "$${array[#]}"
do
#do stuff with $$element
done

How to unit test an Erlang function?

get_ue_supported_srvcc([]) ->
?SRVCC_3GPP_NONE_SUPPORT;
get_ue_supported_srvcc([#sip_contactV{extensionsP = EP} | T]) ->
case b2bLib:support_tags_to_value(EP) of
?SRVCC_3GPP_NONE_SUPPORT ->
get_ue_supported_srvcc(T);
Flag ->
Flag
end.
I want create a unit test for this function,
Here is my unit test case:
get_ue_supported_srvcc_test() ->
Contact =
[#sip_contactV{extensionsP =
[{"+sip.instance",
{quoted_string,"<urn:gsma:imei:35502406-005233-0>"}},
{"+g.3gpp.icsi-ref",
{quoted_string,"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel"}},
"+g.3gpp.mid-call",
"+g.3gpp.srvcc-alerting",
"+g.3gpp.ps2cs-srvcc-orig-pre-alerting",
"video"]}],
?assertEqual(7, b2bAtcfLib:get_ue_supported_srvcc(Contact)).
But when I run it, I get this error:
======================== EUnit ========================
module 'b2bAtcfLib'
b2bAtcfLib_tests: get_ue_supported_srvcc_test (module 'b2bAtcfLib_tests')...*failed*
in function b2bLib:support_tags_to_value/1
called as support_tags_to_value([{"+sip.instance",{quoted_string,"<urn:gsma:imei:35502406-005233-0>"}},
{"+g.3gpp.icsi-ref",
{quoted_string,"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel"}},
"+g.3gpp.mid-call","+g.3gpp.srvcc-alerting",
"+g.3gpp.ps2cs-srvcc-orig-pre-alerting","video"])
in call from b2bAtcfLib:get_ue_supported_srvcc/1 (src/b2bAtcfLib.erl, line 1735)
in call from b2bAtcfLib_tests:'-get_ue_supported_srvcc_test/0-fun-0-'/1 (test/unit/b2bAtcfLib_tests.erl, line 49)
in call from b2bAtcfLib_tests:get_ue_supported_srvcc_test/0
**error:undef
output:<<"">>
[done in 0.008 s]
=======================================================
The error means b2bLib:support_tags_to_value/1 is undef.
The define for this function b2bLib:support_tags_to_value:
support_tags_to_value(FieldStr) ->
lists:sum([Val || {Tag, Val} <- ?TAGLIST, lists:member(Tag, FieldStr)]).
The error is:
**error:undef
That means that the test is calling a function that's not defined. Either the module couldn't be found, or the module in question doesn't define a function with that name and arity.
The whole error message is a bit confusing. Now that we know that we got a "function undefined" error, we should be looking at this line:
in function b2bLib:support_tags_to_value/1
Even though it says that the error occurred "in" this function, this is the function that's undefined.
So either the test is run in such a way that it doesn't find the b2bLib module, or that module doesn't define a function called support_tags_to_value taking one argument. If it's the former, add -pa path/to/ebin to the Erlang command line in order to add the right directory to the code path.

Comment out/delete blocks in large amount of files

I'm attempting to write something that can process Nagios config files containing a block of text, and either add # to the start of each line, or delete the block. (To function as a kind of mass check removal in Nagios itself).
Ex:
define service {
service_description Service 1
use Template 1
host_name Host 1
check_command Command A
}
define service {
service_description Service 2
use Template 1
host_name Host 1
check_command Command B
}
define service {
service_description Service 3
use Template 1
host_name Host 1
check_command Command C
}
Would need to change to this (or equivalent):
define service {
service_description Service 1
use Template 1
host_name Host 1
check_command Command A
}
#define service {
# service_description Service 2
# use Template 1
# host_name Host 1
# check_command Command B
#}
define service {
service_description Service 3
use Template 1
host_name Host 1
check_command Command C
}
Is there a way to regex match the block between "define service {" and "}", and containing either "Service 2" or "Command "B", and append/delete the block via sed/awk/perl, etc?
Thanks.
sed '
# take each paragraph one by one
/define service {/,/}/{
# inside paragraphe, add each line (one at a time) in buffer
H
# if not the end of paragraphe, delete the line (from output) (and cycle to next line)
/}/!d
# empty current line (the last of paragraphe) and swap with the whole buffer
s/.*//;x
# if it contain Service2 (and Command B on next line) goto to label comm
/Service2/ b comm
/Command B/ b comm
# goto label head (so no Service2 nor command b in paragraphe)
b head
:comm
# comment each line of paragraphe (multiline with \n as new line)
s/\n/&#/g
: head
# remove first character (a new line due to use of H and not h on first line)
s/.//
}
# default behaviour that print the content
' YourFile
Self commented
Here's a regex that creates the match you want:
/define service\s\{.*(Service 2|Command B).*\}/s
You can test it here. I have no experience with sed, awk or perl, so I will not make any attempt to create a replacement.
sed -n '/define service {/,/}/{:1;N;/\}/!b 1;/Command B\|Service 2/{s/\n/\n#/g;s/^/#/g;p;d;b 1};p;d;b 1}' file_name
This is how it works
picks the block within braces;keeps appending to pattern space till a closing brace is found;searches the patter space for the two key words; if found then appends a # in front of every new line in pattern space and prints the content. Clears the pattern space and repeats the provess

How do I make command line arguments with a hyphen (-) show up as non-optional in python v2.7?

I have the following python script
parser = argparse.ArgumentParser(description='Process controller.py arguments')
parser.add_argument("-b", help='Build number, e.g., 1234')
args = vars(parser.parse_args())
When I run it I get...
$ python CommandLineParser.py -h
usage: CommandLineParser.py [-h] [-b B]
Process controller.py arguments
optional arguments:
-h, --help show this help message and exit
-b B Build number, e.g., 1234
How do I make the "-b" show up as a "non-optional" argument (because it's NOT!). As an added bonus, how do I rid of the uppercase "B" after it? Thanks!
You need to set required to True and metavar (it's responsible for B) to '':
parser.add_argument("-b", help='Build number, e.g., 1234', required=True, metavar='')
Actually, you will still see your required argument as optional if run your script in a help mode. This is because of a bug: argparse required arguments displayed under "optional arguments":
The argparse module lists required args as optional in the default
help message.
There are also some workarounds suggested, but I like this one more: add your own required arguments group:
required_group = parser.add_argument_group('required arguments')
required_group.add_argument("-b", help='Build number, e.g., 1234', required=True, metavar='')
Then, you will see this on a command-line:
$ python test.py -h
usage: test.py [-h] -b
Process controller.py arguments
optional arguments:
-h, --help show this help message and exit
required arguments:
-b Build number, e.g., 1234
Please use the required keyword when adding it to the argparse: http://docs.python.org/2/library/argparse.html#sub-commands
parser.add_argument("-b", help='Build number, e.g., 1234', required=True)