Commit 668fd8de authored by Leigh Stoller's avatar Leigh Stoller

Various converter changes;

1. Add adb_target and rwclone support.

2. Name the link/node variables by the user client_id with dashes
   converted to underscore, and prefix with node_/link_ if the user name
   does not already start with node/link.

3. Add "permissive" mode to ignore profile_parameters, data_set, and the
   routable_control_ip attribute so that we can test more profiles.

4. Add options to run just the geni-lib based profiles through
   regression testing.
parent 295bcef4
...@@ -50,9 +50,9 @@ sub CompareLists($$$); ...@@ -50,9 +50,9 @@ sub CompareLists($$$);
# #
# Parse an rspec into nice perl things. # Parse an rspec into nice perl things.
# #
sub new($$) sub new($$;$)
{ {
my ($class, $rspecfile) = @_; my ($class, $rspecfile, $permissive) = @_;
my %namespaces = (); my %namespaces = ();
my $rspec; my $rspec;
...@@ -84,6 +84,7 @@ sub new($$) ...@@ -84,6 +84,7 @@ sub new($$)
"tour" => undef, "tour" => undef,
"namespaces" => \%namespaces, "namespaces" => \%namespaces,
"bscounter" => 0, "bscounter" => 0,
"permissive" => (defined($permissive) ? $permissive : 0),
}; };
bless($self, $class); bless($self, $class);
...@@ -102,9 +103,9 @@ sub new($$) ...@@ -102,9 +103,9 @@ sub new($$)
/^description$/i && do { /^description$/i && do {
my $type = GeniXML::FindAttr("type", $child); my $type = GeniXML::FindAttr("type", $child);
my $text = $child->textContent(); my $text = $child->textContent();
# Trim for rtecheck.
$text =~ s/^\s+//; $text =~ s/^\s+//;
# Kill terminating newline for rtecheck $text =~ s/\s+$//g;
chomp($text);
$text =~ s/\"/\\"/g; $text =~ s/\"/\\"/g;
$tour->{'description'} = { $tour->{'description'} = {
"text" => $text, "text" => $text,
...@@ -115,9 +116,9 @@ sub new($$) ...@@ -115,9 +116,9 @@ sub new($$)
/^instructions$/i && do { /^instructions$/i && do {
my $type = GeniXML::FindAttr("type", $child); my $type = GeniXML::FindAttr("type", $child);
my $text = $child->textContent(); my $text = $child->textContent();
# Trim for rtecheck.
$text =~ s/^\s+//; $text =~ s/^\s+//;
# Kill terminating newline for rtecheck $text =~ s/\s+$//g;
chomp($text);
# This happens a lot. # This happens a lot.
if ($text ne "") { if ($text ne "") {
$text =~ s/\"/\\"/g; $text =~ s/\"/\\"/g;
...@@ -173,8 +174,8 @@ sub new($$) ...@@ -173,8 +174,8 @@ sub new($$)
SWITCH: for (lc($name)) { SWITCH: for (lc($name)) {
/^password$/i && do { /^password$/i && do {
my $name = GetTextOrFail("name", $ref); my $passname = GetTextOrFail("name", $ref);
APT_Rspec::Attribute->new($self, $name, {"name" => $name}); APT_Rspec::Attribute->new($self, $name, $passname);
last SWITCH; last SWITCH;
}; };
/^routable_pool$/i && do { /^routable_pool$/i && do {
...@@ -244,6 +245,7 @@ sub new($$) ...@@ -244,6 +245,7 @@ sub new($$)
}; };
(/^(\w+:)?password$/i || (/^(\w+:)?password$/i ||
/^(\w+:)?routable_pool$/i || /^(\w+:)?routable_pool$/i ||
/^(\w+:)?packing_strategy$/i ||
/^(\w+:)?collocate_factor$/i || /^(\w+:)?collocate_factor$/i ||
/^(\w+:)?routing_style$/i || /^(\w+:)?routing_style$/i ||
/^(\w+:)?delay_image$/i) && do { /^(\w+:)?delay_image$/i) && do {
...@@ -251,11 +253,13 @@ sub new($$) ...@@ -251,11 +253,13 @@ sub new($$)
last SWITCH; last SWITCH;
}; };
/^(\w+:)?data_set$/i && do { /^(\w+:)?data_set$/i && do {
fatal("data_set element is not supported"); fatal("data_set element is not supported")
if (!$self->permissive());
last SWITCH; last SWITCH;
}; };
/^(\w+:)?profile_parameters$/i && do { /^(\w+:)?profile_parameters$/i && do {
fatal("profile_parameters element is not supported"); fatal("profile_parameters element is not supported")
if (!$self->permissive());
last SWITCH; last SWITCH;
}; };
/^#(comment|text)$/i && do { /^#(comment|text)$/i && do {
...@@ -287,6 +291,7 @@ sub ifaces($) { return $_[0]->{'ifaces'}; } ...@@ -287,6 +291,7 @@ sub ifaces($) { return $_[0]->{'ifaces'}; }
sub tour($) { return $_[0]->{'tour'}; } sub tour($) { return $_[0]->{'tour'}; }
sub attributes($) { return $_[0]->{'toplevel_elements'}; } sub attributes($) { return $_[0]->{'toplevel_elements'}; }
sub toplevel_elements($) { return $_[0]->attributes(); } sub toplevel_elements($) { return $_[0]->attributes(); }
sub permissive($) { return $_[0]->{'permissive'}; }
sub description($) sub description($)
{ {
...@@ -476,7 +481,7 @@ sub CompareLists($$$) ...@@ -476,7 +481,7 @@ sub CompareLists($$$)
my @l1 = @{$l1}; my @l1 = @{$l1};
my @l2 = @{$l2}; my @l2 = @{$l2};
#print "CompareLists: $text\n"; #print STDERR "CompareLists: $text\n";
if (scalar(@l1) != scalar(@l2)) { if (scalar(@l1) != scalar(@l2)) {
print STDERR "$text: rspec one has a different count then rspec two\n"; print STDERR "$text: rspec one has a different count then rspec two\n";
...@@ -552,7 +557,7 @@ sub Compare($$) ...@@ -552,7 +557,7 @@ sub Compare($$)
if (APT_Rspec::CompareHashes($key, $val1, $val2)); if (APT_Rspec::CompareHashes($key, $val1, $val2));
last SWITCH; last SWITCH;
}; };
/^(bscounter|namespaces|nodelist|linklist)$/i && do { /^(bscounter|namespaces|nodelist|linklist|permissive)$/i && do {
last SWITCH; last SWITCH;
}; };
print STDERR "Rspec:Compare: Unknown attribute: $key\n"; print STDERR "Rspec:Compare: Unknown attribute: $key\n";
...@@ -772,6 +777,16 @@ sub new($$$$$) ...@@ -772,6 +777,16 @@ sub new($$$$$)
{ {
my ($class, $rspec, $client_id, $type, $exclusive) = @_; my ($class, $rspec, $client_id, $type, $exclusive) = @_;
#
# Make up a tag (variable for the script) that makes some kind of sense.
#
my $tag = $client_id;
# Replace dashes with underscores.
$tag =~ s/\-/\_/g;
if ($tag !~ /^node/i) {
$tag = "node_${tag}";
}
my $self = { my $self = {
"client_id" => $client_id, "client_id" => $client_id,
"type" => $type, "type" => $type,
...@@ -793,7 +808,7 @@ sub new($$$$$) ...@@ -793,7 +808,7 @@ sub new($$$$$)
"pipes" => {}, "pipes" => {},
"use_type_default_image"=> undef, "use_type_default_image"=> undef,
"routable_control_ip" => undef, "routable_control_ip" => undef,
"tag" => "node" . scalar(keys(%{$rspec->nodes()})), "tag" => $tag,
}; };
bless($self, $class); bless($self, $class);
return $self; return $self;
...@@ -909,6 +924,10 @@ sub addNode($$$) ...@@ -909,6 +924,10 @@ sub addNode($$$)
$node->{'component_manager_id'} = $val; $node->{'component_manager_id'} = $val;
last SWITCH; last SWITCH;
}; };
/^(\w+:)?routable_control_ip$/i && $rspec->permissive() && do {
# Ignore, it would not work anyway.
last SWITCH;
};
fatal("Unknown attribute for node $client_id: $key,$val"); fatal("Unknown attribute for node $client_id: $key,$val");
} }
} }
...@@ -1092,6 +1111,11 @@ sub addNode($$$) ...@@ -1092,6 +1111,11 @@ sub addNode($$$)
$node->{"hardware_type"} = $hardware; $node->{"hardware_type"} = $hardware;
last SWITCH; last SWITCH;
}; };
/^adb_target$/i && do {
my $hardware = GetTextOrFail("target_id", $child);
$node->{"adb_target"} = $hardware;
last SWITCH;
};
/^site$/i && do { /^site$/i && do {
my $site = GetTextOrFail("id", $child); my $site = GetTextOrFail("id", $child);
$node->{"jacks_site"} = $site; $node->{"jacks_site"} = $site;
...@@ -1176,6 +1200,7 @@ sub Compare($$) ...@@ -1176,6 +1200,7 @@ sub Compare($$)
}; };
(/^(component_id|component_manager_id|disk_image)$/i || (/^(component_id|component_manager_id|disk_image)$/i ||
/^(hardware_type|jacks_site|xen_ptype|instantiate_on)$/i || /^(hardware_type|jacks_site|xen_ptype|instantiate_on)$/i ||
/^(adb_target)$/i ||
/^(use_type_default_image|routable_control_ip)$/i) && do { /^(use_type_default_image|routable_control_ip)$/i) && do {
return 1 return 1
if (APT_Rspec::CompareValues("Node: $client_id: $key", if (APT_Rspec::CompareValues("Node: $client_id: $key",
...@@ -1299,6 +1324,16 @@ sub new($$$$) ...@@ -1299,6 +1324,16 @@ sub new($$$$)
{ {
my ($class, $rspec, $client_id, $type) = @_; my ($class, $rspec, $client_id, $type) = @_;
#
# Make up a tag (variable for the script) that makes some kind of sense.
#
my $tag = $client_id;
# Replace dashes with underscores.
$tag =~ s/\-/\_/g;
if ($tag !~ /^link/i) {
$tag = "link_${tag}";
}
my $self = { my $self = {
"client_id" => $client_id, "client_id" => $client_id,
"type" => $type, "type" => $type,
...@@ -1322,7 +1357,7 @@ sub new($$$$) ...@@ -1322,7 +1357,7 @@ sub new($$$$)
"component_managers" => [], "component_managers" => [],
"jacks_site" => undef, "jacks_site" => undef,
"statements" => [], "statements" => [],
"tag" => "link" . scalar(keys(%{$rspec->links()})), "tag" => $tag,
}; };
bless($self, $class); bless($self, $class);
return $self; return $self;
...@@ -1929,6 +1964,7 @@ sub Compare($$) ...@@ -1929,6 +1964,7 @@ sub Compare($$)
package APT_Rspec::Service; package APT_Rspec::Service;
use Carp; use Carp;
use English; use English;
use Data::Dumper;
use HTML::Entities; use HTML::Entities;
use GeniXML; use GeniXML;
...@@ -2037,6 +2073,7 @@ sub new($$$$) ...@@ -2037,6 +2073,7 @@ sub new($$$$)
"readonly" => undef, "readonly" => undef,
"dataset" => undef, "dataset" => undef,
"placement" => undef, "placement" => undef,
"rwclone" => undef,
"tag" => $tag, "tag" => $tag,
}; };
...@@ -2072,6 +2109,10 @@ sub new($$$$) ...@@ -2072,6 +2109,10 @@ sub new($$$$)
$self->{'size'} = $val; $self->{'size'} = $val;
last SWITCH; last SWITCH;
}; };
/^rwclone$/i && do {
$self->{'rwclone'} = (lc($val) eq "true" ? 1 : 0);
last SWITCH;
};
fatal("Unknown attribute for blockstore $bsname: $key,$val"); fatal("Unknown attribute for blockstore $bsname: $key,$val");
} }
} }
......
...@@ -44,17 +44,20 @@ sub usage() ...@@ -44,17 +44,20 @@ sub usage()
print STDERR " -s : Print rspec before and after\n"; print STDERR " -s : Print rspec before and after\n";
print STDERR " -x : Only include rspecs with matching token\n"; print STDERR " -x : Only include rspecs with matching token\n";
print STDERR " -G : Also test script based profiles, no RTE of course\n"; print STDERR " -G : Also test script based profiles, no RTE of course\n";
print STDERR " -p : Permissive mode, ignore unsupported stuff\n";
exit(-1); exit(-1);
} }
my $optlist = "dargscx:tG"; my $optlist = "dargscx:tGXp";
my $debug = 0; my $debug = 0;
my $all = 0; my $all = 0;
my $regress = 0; my $regress = 0;
my $compare = 0; my $compare = 0;
my $doscript = 0; my $doscript = 0;
my $norspec = 0;
my $printgl = 0; my $printgl = 0;
my $printrspec = 0; my $printrspec = 0;
my $rtecheck = 0; my $rtecheck = 0;
my $permissive = 0;
my $clause = ""; my $clause = "";
my $profile; my $profile;
...@@ -122,6 +125,9 @@ if (defined($options{"g"})) { ...@@ -122,6 +125,9 @@ if (defined($options{"g"})) {
if (defined($options{"G"})) { if (defined($options{"G"})) {
$doscript = 1; $doscript = 1;
} }
if (defined($options{"p"})) {
$permissive = 1;
}
if (defined($options{"s"})) { if (defined($options{"s"})) {
$printrspec = 1; $printrspec = 1;
} }
...@@ -131,6 +137,9 @@ if (defined($options{"t"})) { ...@@ -131,6 +137,9 @@ if (defined($options{"t"})) {
if (defined($options{"x"})) { if (defined($options{"x"})) {
$clause = "where rspec like '%" . $options{"x"} . "%'"; $clause = "where rspec like '%" . $options{"x"} . "%'";
} }
if (defined($options{"X"})) {
$norspec = 1;
}
usage() usage()
if (!$all && @ARGV != 1); if (!$all && @ARGV != 1);
...@@ -161,6 +170,8 @@ else { ...@@ -161,6 +170,8 @@ else {
if (!defined($profile)); if (!defined($profile));
next next
if (defined($profile->script()) && !$doscript); if (defined($profile->script()) && !$doscript);
next
if (!defined($profile->script()) && $norspec);
print "Converting $profile\n"; print "Converting $profile\n";
$count++; $count++;
...@@ -194,7 +205,8 @@ sub CheckProfile($) ...@@ -194,7 +205,8 @@ sub CheckProfile($)
if ($printrspec) { if ($printrspec) {
system("$XMLLINT --format $filename"); system("$XMLLINT --format $filename");
} }
my $output = emutil::ExecQuiet("$CONVERTER -t $filename"); my $opts = "-t " . ($permissive ? "-p" : "");
my $output = emutil::ExecQuiet("$CONVERTER $opts $filename");
if ($?) { if ($?) {
#print STDERR $profile->rspec() . "\n"; #print STDERR $profile->rspec() . "\n";
print STDERR $output; print STDERR $output;
...@@ -226,13 +238,13 @@ sub CheckProfile($) ...@@ -226,13 +238,13 @@ sub CheckProfile($)
print $output; print $output;
} }
if ($compare) { if ($compare) {
my $rspec1 = eval { APT_Rspec->new($profile->rspec()) }; my $rspec1 = eval { APT_Rspec->new($profile->rspec(),$permissive) };
if ($@) { if ($@) {
print STDERR $@; print STDERR $@;
print STDERR "*** Could not parse profile rspec into object\n"; print STDERR "*** Could not parse profile rspec into object\n";
goto bad; goto bad;
} }
my $rspec2 = eval { APT_Rspec->new($output) }; my $rspec2 = eval { APT_Rspec->new($output, $permissive) };
if ($@) { if ($@) {
print STDERR $@; print STDERR $@;
print STDERR "*** Could not parse output rspec into object\n"; print STDERR "*** Could not parse output rspec into object\n";
...@@ -283,19 +295,20 @@ sub CheckScriptProfile($) ...@@ -283,19 +295,20 @@ sub CheckScriptProfile($)
} }
if ($printrspec) { if ($printrspec) {
print $output . "\n"; print $output . "\n";
print $profile->rspec() . "\n";
} }
if ($regress) { if ($regress) {
if ($compare) { if ($compare) {
# #
# Compare current rspec against newly generated rspec. # Compare current rspec against newly generated rspec.
# #
my $rspec1 = eval { APT_Rspec->new($profile->rspec()) }; my $rspec1 = eval { APT_Rspec->new($profile->rspec(), $permissive)};
if ($@) { if ($@) {
print STDERR $@; print STDERR $@;
print STDERR "*** Could not parse profile rspec into object\n"; print STDERR "*** Could not parse profile rspec into object\n";
goto bad; goto bad;
} }
my $rspec2 = eval { APT_Rspec->new($output) }; my $rspec2 = eval { APT_Rspec->new($output, $permissive) };
if ($@) { if ($@) {
print STDERR $@; print STDERR $@;
print STDERR "*** Could not parse output rspec into object\n"; print STDERR "*** Could not parse output rspec into object\n";
......
...@@ -44,12 +44,14 @@ sub usage() ...@@ -44,12 +44,14 @@ sub usage()
print STDERR " -s file - Specify output file for post geni-lib rspec\n"; print STDERR " -s file - Specify output file for post geni-lib rspec\n";
print STDERR " -r - Regression test; run geni-lib, compare rspecs\n"; print STDERR " -r - Regression test; run geni-lib, compare rspecs\n";
print STDERR " -t - Do not add stub docstring (for regression)\n"; print STDERR " -t - Do not add stub docstring (for regression)\n";
print STDERR " -p - Permissive mode, ignore unsupported stuff\n";
exit(-1); exit(-1);
} }
my $optlist = "do:rs:t"; my $optlist = "do:rs:tp";
my $debug = 0; my $debug = 0;
my $regress = 0; my $regress = 0;
my $nodocstr = 0; my $nodocstr = 0;
my $permissive = 0;
my $ofile; my $ofile;
my $rfile; my $rfile;
...@@ -109,6 +111,9 @@ if (defined($options{"t"})) { ...@@ -109,6 +111,9 @@ if (defined($options{"t"})) {
if (defined($options{"o"})) { if (defined($options{"o"})) {
$ofile = $options{"o"}; $ofile = $options{"o"};
} }
if (defined($options{"p"})) {
$permissive = 1;
}
if (defined($options{"r"})) { if (defined($options{"r"})) {
$regress = 1; $regress = 1;
$nodocstr = 1; $nodocstr = 1;
...@@ -136,7 +141,7 @@ if ($?) { ...@@ -136,7 +141,7 @@ if ($?) {
print STDERR $xmlerrors; print STDERR $xmlerrors;
fatal("rspec is not well formed"); fatal("rspec is not well formed");
} }
my $rspec = APT_Rspec->new($rspecfile); my $rspec = APT_Rspec->new($rspecfile, $permissive);
fatal("Could not create rspec object") fatal("Could not create rspec object")
if (!defined($rspec)); if (!defined($rspec));
...@@ -267,6 +272,10 @@ sub GenerateNodeStatements($) ...@@ -267,6 +272,10 @@ sub GenerateNodeStatements($)
my $name = $node->{'disk_image'}; my $name = $node->{'disk_image'};
$node->addTagStatement("disk_image = '$name'"); $node->addTagStatement("disk_image = '$name'");
} }
if (defined($node->{'adb_target'})) {
my $target_id = $node->{'adb_target'};
$node->addTagStatement("adb_target = '$target_id'");
}
if (defined($node->{'jacks_site'})) { if (defined($node->{'jacks_site'})) {
my $site = $node->{'jacks_site'}; my $site = $node->{'jacks_site'};
$node->addTagStatement("Site('$site')"); $node->addTagStatement("Site('$site')");
...@@ -378,6 +387,7 @@ sub GenerateNodeStatements($) ...@@ -378,6 +387,7 @@ sub GenerateNodeStatements($)
my $readonly = $blockstore->{'readonly'}; my $readonly = $blockstore->{'readonly'};
my $size = $blockstore->{'size'}; my $size = $blockstore->{'size'};
my $placement = $blockstore->{'placement'}; my $placement = $blockstore->{'placement'};
my $rwclone = $blockstore->{'rwclone'};
my $dataset = $blockstore->{'dataset'}; my $dataset = $blockstore->{'dataset'};
if (defined($readonly) && $readonly) { if (defined($readonly) && $readonly) {
...@@ -393,6 +403,10 @@ sub GenerateNodeStatements($) ...@@ -393,6 +403,10 @@ sub GenerateNodeStatements($)
if (defined($dataset)) { if (defined($dataset)) {
$node->addStatement("${btag}.dataset = '$dataset'"); $node->addStatement("${btag}.dataset = '$dataset'");
} }
# Do not not spit out default (false).
if (defined($rwclone) && $rwclone) {
$node->addStatement("${btag}.rwclone = True");
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment