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($$$);
#
# Parse an rspec into nice perl things.
#
sub new($$)
sub new($$;$)
{
my ($class, $rspecfile) = @_;
my ($class, $rspecfile, $permissive) = @_;
my %namespaces = ();
my $rspec;
......@@ -84,6 +84,7 @@ sub new($$)
"tour" => undef,
"namespaces" => \%namespaces,
"bscounter" => 0,
"permissive" => (defined($permissive) ? $permissive : 0),
};
bless($self, $class);
......@@ -102,9 +103,9 @@ sub new($$)
/^description$/i && do {
my $type = GeniXML::FindAttr("type", $child);
my $text = $child->textContent();
# Trim for rtecheck.
$text =~ s/^\s+//;
# Kill terminating newline for rtecheck
chomp($text);
$text =~ s/\s+$//g;
$text =~ s/\"/\\"/g;
$tour->{'description'} = {
"text" => $text,
......@@ -115,9 +116,9 @@ sub new($$)
/^instructions$/i && do {
my $type = GeniXML::FindAttr("type", $child);
my $text = $child->textContent();
# Trim for rtecheck.
$text =~ s/^\s+//;
# Kill terminating newline for rtecheck
chomp($text);
$text =~ s/\s+$//g;
# This happens a lot.
if ($text ne "") {
$text =~ s/\"/\\"/g;
......@@ -173,8 +174,8 @@ sub new($$)
SWITCH: for (lc($name)) {
/^password$/i && do {
my $name = GetTextOrFail("name", $ref);
APT_Rspec::Attribute->new($self, $name, {"name" => $name});
my $passname = GetTextOrFail("name", $ref);
APT_Rspec::Attribute->new($self, $name, $passname);
last SWITCH;
};
/^routable_pool$/i && do {
......@@ -244,6 +245,7 @@ sub new($$)
};
(/^(\w+:)?password$/i ||
/^(\w+:)?routable_pool$/i ||
/^(\w+:)?packing_strategy$/i ||
/^(\w+:)?collocate_factor$/i ||
/^(\w+:)?routing_style$/i ||
/^(\w+:)?delay_image$/i) && do {
......@@ -251,11 +253,13 @@ sub new($$)
last SWITCH;
};
/^(\w+:)?data_set$/i && do {
fatal("data_set element is not supported");
fatal("data_set element is not supported")
if (!$self->permissive());
last SWITCH;
};
/^(\w+:)?profile_parameters$/i && do {
fatal("profile_parameters element is not supported");
fatal("profile_parameters element is not supported")
if (!$self->permissive());
last SWITCH;
};
/^#(comment|text)$/i && do {
......@@ -287,6 +291,7 @@ sub ifaces($) { return $_[0]->{'ifaces'}; }
sub tour($) { return $_[0]->{'tour'}; }
sub attributes($) { return $_[0]->{'toplevel_elements'}; }
sub toplevel_elements($) { return $_[0]->attributes(); }
sub permissive($) { return $_[0]->{'permissive'}; }
sub description($)
{
......@@ -476,7 +481,7 @@ sub CompareLists($$$)
my @l1 = @{$l1};
my @l2 = @{$l2};
#print "CompareLists: $text\n";
#print STDERR "CompareLists: $text\n";
if (scalar(@l1) != scalar(@l2)) {
print STDERR "$text: rspec one has a different count then rspec two\n";
......@@ -552,7 +557,7 @@ sub Compare($$)
if (APT_Rspec::CompareHashes($key, $val1, $val2));
last SWITCH;
};
/^(bscounter|namespaces|nodelist|linklist)$/i && do {
/^(bscounter|namespaces|nodelist|linklist|permissive)$/i && do {
last SWITCH;
};
print STDERR "Rspec:Compare: Unknown attribute: $key\n";
......@@ -772,6 +777,16 @@ sub new($$$$$)
{
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 = {
"client_id" => $client_id,
"type" => $type,
......@@ -793,7 +808,7 @@ sub new($$$$$)
"pipes" => {},
"use_type_default_image"=> undef,
"routable_control_ip" => undef,
"tag" => "node" . scalar(keys(%{$rspec->nodes()})),
"tag" => $tag,
};
bless($self, $class);
return $self;
......@@ -909,6 +924,10 @@ sub addNode($$$)
$node->{'component_manager_id'} = $val;
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");
}
}
......@@ -1092,6 +1111,11 @@ sub addNode($$$)
$node->{"hardware_type"} = $hardware;
last SWITCH;
};
/^adb_target$/i && do {
my $hardware = GetTextOrFail("target_id", $child);
$node->{"adb_target"} = $hardware;
last SWITCH;
};
/^site$/i && do {
my $site = GetTextOrFail("id", $child);
$node->{"jacks_site"} = $site;
......@@ -1176,6 +1200,7 @@ sub Compare($$)
};
(/^(component_id|component_manager_id|disk_image)$/i ||
/^(hardware_type|jacks_site|xen_ptype|instantiate_on)$/i ||
/^(adb_target)$/i ||
/^(use_type_default_image|routable_control_ip)$/i) && do {
return 1
if (APT_Rspec::CompareValues("Node: $client_id: $key",
......@@ -1299,6 +1324,16 @@ sub new($$$$)
{
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 = {
"client_id" => $client_id,
"type" => $type,
......@@ -1322,7 +1357,7 @@ sub new($$$$)
"component_managers" => [],
"jacks_site" => undef,
"statements" => [],
"tag" => "link" . scalar(keys(%{$rspec->links()})),
"tag" => $tag,
};
bless($self, $class);
return $self;
......@@ -1929,6 +1964,7 @@ sub Compare($$)
package APT_Rspec::Service;
use Carp;
use English;
use Data::Dumper;
use HTML::Entities;
use GeniXML;
......@@ -2037,6 +2073,7 @@ sub new($$$$)
"readonly" => undef,
"dataset" => undef,
"placement" => undef,
"rwclone" => undef,
"tag" => $tag,
};
......@@ -2072,6 +2109,10 @@ sub new($$$$)
$self->{'size'} = $val;
last SWITCH;
};
/^rwclone$/i && do {
$self->{'rwclone'} = (lc($val) eq "true" ? 1 : 0);
last SWITCH;
};
fatal("Unknown attribute for blockstore $bsname: $key,$val");
}
}
......
......@@ -44,17 +44,20 @@ sub usage()
print STDERR " -s : Print rspec before and after\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 " -p : Permissive mode, ignore unsupported stuff\n";
exit(-1);
}
my $optlist = "dargscx:tG";
my $optlist = "dargscx:tGXp";
my $debug = 0;
my $all = 0;
my $regress = 0;
my $compare = 0;
my $doscript = 0;
my $norspec = 0;
my $printgl = 0;
my $printrspec = 0;
my $rtecheck = 0;
my $permissive = 0;
my $clause = "";
my $profile;
......@@ -122,6 +125,9 @@ if (defined($options{"g"})) {
if (defined($options{"G"})) {
$doscript = 1;
}
if (defined($options{"p"})) {
$permissive = 1;
}
if (defined($options{"s"})) {
$printrspec = 1;
}
......@@ -131,6 +137,9 @@ if (defined($options{"t"})) {
if (defined($options{"x"})) {
$clause = "where rspec like '%" . $options{"x"} . "%'";
}
if (defined($options{"X"})) {
$norspec = 1;
}
usage()
if (!$all && @ARGV != 1);
......@@ -161,6 +170,8 @@ else {
if (!defined($profile));
next
if (defined($profile->script()) && !$doscript);
next
if (!defined($profile->script()) && $norspec);
print "Converting $profile\n";
$count++;
......@@ -194,7 +205,8 @@ sub CheckProfile($)
if ($printrspec) {
system("$XMLLINT --format $filename");
}
my $output = emutil::ExecQuiet("$CONVERTER -t $filename");
my $opts = "-t " . ($permissive ? "-p" : "");
my $output = emutil::ExecQuiet("$CONVERTER $opts $filename");
if ($?) {
#print STDERR $profile->rspec() . "\n";
print STDERR $output;
......@@ -226,13 +238,13 @@ sub CheckProfile($)
print $output;
}
if ($compare) {
my $rspec1 = eval { APT_Rspec->new($profile->rspec()) };
my $rspec1 = eval { APT_Rspec->new($profile->rspec(),$permissive) };
if ($@) {
print STDERR $@;
print STDERR "*** Could not parse profile rspec into object\n";
goto bad;
}
my $rspec2 = eval { APT_Rspec->new($output) };
my $rspec2 = eval { APT_Rspec->new($output, $permissive) };
if ($@) {
print STDERR $@;
print STDERR "*** Could not parse output rspec into object\n";
......@@ -283,19 +295,20 @@ sub CheckScriptProfile($)
}
if ($printrspec) {
print $output . "\n";
print $profile->rspec() . "\n";
}
if ($regress) {
if ($compare) {
#
# 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 ($@) {
print STDERR $@;
print STDERR "*** Could not parse profile rspec into object\n";
goto bad;
}
my $rspec2 = eval { APT_Rspec->new($output) };
my $rspec2 = eval { APT_Rspec->new($output, $permissive) };
if ($@) {
print STDERR $@;
print STDERR "*** Could not parse output rspec into object\n";
......
......@@ -44,12 +44,14 @@ sub usage()
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 " -t - Do not add stub docstring (for regression)\n";
print STDERR " -p - Permissive mode, ignore unsupported stuff\n";
exit(-1);
}
my $optlist = "do:rs:t";
my $optlist = "do:rs:tp";
my $debug = 0;
my $regress = 0;
my $nodocstr = 0;
my $permissive = 0;
my $ofile;
my $rfile;
......@@ -109,6 +111,9 @@ if (defined($options{"t"})) {
if (defined($options{"o"})) {
$ofile = $options{"o"};
}
if (defined($options{"p"})) {
$permissive = 1;
}
if (defined($options{"r"})) {
$regress = 1;
$nodocstr = 1;
......@@ -136,7 +141,7 @@ if ($?) {
print STDERR $xmlerrors;
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")
if (!defined($rspec));
......@@ -267,6 +272,10 @@ sub GenerateNodeStatements($)
my $name = $node->{'disk_image'};
$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'})) {
my $site = $node->{'jacks_site'};
$node->addTagStatement("Site('$site')");
......@@ -378,6 +387,7 @@ sub GenerateNodeStatements($)
my $readonly = $blockstore->{'readonly'};
my $size = $blockstore->{'size'};
my $placement = $blockstore->{'placement'};
my $rwclone = $blockstore->{'rwclone'};
my $dataset = $blockstore->{'dataset'};
if (defined($readonly) && $readonly) {
......@@ -393,6 +403,10 @@ sub GenerateNodeStatements($)
if (defined($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