Merge pull request #27 from ClusterLabs/string_bugs

* Fixed a bug in Words->parse_banged_string() Where the flattened str…
main
Digimer 4 years ago committed by GitHub
commit 42dc688d04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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 # 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 # 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. # 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) if ($key_string =~ /\n/gs)
{ {
my $in_value = 0; my $in_value = 0;
my $new_string = "";
foreach my $line (split/\n/, $key_string) foreach my $line (split/\n/, $key_string)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); $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. # 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 # If we've looped, there will be data in 'out_string" already so append a newline to separate
# this key from the previous one. # this key from the previous one.

@ -26,10 +26,44 @@ $anvil->Get->switches;
$anvil->Database->connect({debug => 3}); $anvil->Database->connect({debug => 3});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"}); $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"}); 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">
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { <host name="mk-a02n01">
free_minor => $free_minor, <volume vnr="0">
free_port => $free_port, <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}); $anvil->nice_exit({exit_code => 0});

Loading…
Cancel
Save