* Fixed a bug in Words->parse_banged_string() Where the flattened string wasn't being used for the variable substitutions.

* This resolves issue #23.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent 1081645893
commit 3f04c9031b
  1. 4
      Anvil/Tools/Words.pm
  2. 44
      tools/test.pl

@ -399,10 +399,10 @@ sub parse_banged_string
# Some variable values will be multi-line strings. We need to replace the new-lines in those
# multi-line values into '##br##' so that we can do a proper variable insertion. We can't simply
# replace all new-lines, however, as it's normal to have multiple keys, each on their own line.
my $new_string = "";
if ($key_string =~ /\n/gs)
{
my $in_value = 0;
my $new_string = "";
foreach my $line (split/\n/, $key_string)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
@ -449,7 +449,7 @@ sub parse_banged_string
}
# There might be multiple keys, split by newlines.
foreach my $message (split/\n/, $key_string)
foreach my $message (split/\n/, $new_string)
{
# If we've looped, there will be data in 'out_string" already so append a newline to separate
# this key from the previous one.

@ -26,10 +26,44 @@ $anvil->Get->switches;
$anvil->Database->connect({debug => 3});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"});
my ($free_minor, $free_port) = $anvil->DRBD->get_next_resource({debug => 2, anvil_uuid => "1aded871-fcb1-4473-9b97-6e9c246fc568"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
free_minor => $free_minor,
free_port => $free_port,
}});
my $key_string = 'scan_drbd_message_0007,!!resource_name!srv00-sql1!!,!!resource_state!#!string!scan_drbd_unit_0004!#!!,!!resource_xml!<resource name="srv00-sql1" conf-file-line="/etc/drbd.d/srv00-sql1.res:2">] from key string: [scan_drbd_message_0007,!!resource_name!srv00-sql1!!,!!resource_state!#!string!scan_drbd_unit_0004!#!!,!!resource_xml!<resource name="srv00-sql1" conf-file-line="/etc/drbd.d/srv00-sql1.res:2">
<host name="mk-a02n01">
<volume vnr="0">
<device minor="0">/dev/drbd_srv00-sql1_0</device>
<disk>/dev/mk-a02n01_ssd0/srv00-sql1_0</disk>
<meta-disk>internal</meta-disk>
</volume>
<address family="(null)" port="(null)">(null)</address>
</host>
<host name="mk-a02n02">
<volume vnr="0">
<device minor="0">/dev/drbd_srv00-sql1_0</device>
<disk>/dev/mk-a02n02_ssd0/srv00-sql1_0</disk>
<meta-disk>internal</meta-disk>
</volume>
<address family="(null)" port="(null)">(null)</address>
</host>
<connection>
<host name="mk-a02n01"><address family="ipv4" port="7788">10.101.12.1</address></host>
<host name="mk-a02n02"><address family="ipv4" port="7788">10.101.12.2</address></host>
<section name="net">
<option name="protocol" value="C"/>
<option name="fencing" value="resource-and-stonith"/>
</section>
<section name="disk">
<option name="c-max-rate" value="500M"/>
</section>
</connection>
</resource>!!';
my $out_string = $anvil->Words->parse_banged_string({
debug => 2,
key_string => $key_string,
});
print "Got:
====
".$out_string."
====
";
$anvil->nice_exit({exit_code => 0});

Loading…
Cancel
Save