#! /usr/bin/env perl
##**************************************************************
##
## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
##
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
##
##    http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************

use CondorTest;
use CondorUtils;
use Check::SimpleJob;
use CheckOutputFormats;
use strict;
use warnings;

#testreq: personal
my $config = <<CONDOR_TESTREQ_CONFIG;
NEGOTIATOR_INTERVAL = 5
NUM_CPUS = 32
STARTD_DEBUG = D_ALWAYS:2 D_COMMAND:1
CONDOR_TESTREQ_CONFIG
#endtestreq

my $testname = "cmd_status-transform";

# needs to specify every time before a check
my $command_arg;
my $ClusterId;
my $pid;
my $executable;
if (CondorUtils::is_windows()) {
	$executable = "sleep.exe";
} else {
	$executable = "x_sleep.pl";
}
my $arguments;
my $submit_content;
my $submitfile;

# other variables, updated through each check
my %Attr_old;
my %Attr_new;
my @fields;
my @machine_info;
my @summary;
my %cnt_num;
my $option;
my %table1;
my %table2;
my $table1_ref;
my $table2_ref;
my @content;

# elements of the format file
my $format_file;
my $format_content;
my $rules_file;
my $rules_content;
my $orig_ads;
my $new_ads;

my $sel0;
my $sel1;
my $sel2;
my $sel3;

print "############################################################################\n";
$option = "to_multi_platform";
$ClusterId = 100;
$pid = $$;
$arguments = 600;
$orig_ads = "$testname"."_orig.ads";
$new_ads = "$testname"."_new.ads";
$submit_content =
"executable = $executable
arguments = $arguments
queue";
$submitfile = "$testname$pid.sub";
emit_dag_files($testname,$submit_content,$pid);

$rules_content = 
"NAME Simulate multiple STARTD platforms
REQUIREMENTS SlotId

EVALMACRO SLOT = splitslotname(Name)[0]
INDEX = \$(ROW)+1

SET UidDomain = \"\$(DOMAIN:cs.wisc.edu)\"
SET Machine = \"exec\$INT(INDEX,%02d).\$(MY.UidDomain)\"
if defined SLOT
  SET  Name = \"\$(SLOT)@\$(My.Machine)\"
else
  COPY Machine Name
endif
COPY Machine PrivateNetworkName

if \$(SharedFileSystem)
  COPY UidDomain FileSystemDomain
else
  COPY Machine FileSystemDomain
endif

SET Arch           = \"\$(ARCH)\"
SET OpSys          = \"\$(OS)\"
SET OpSysAndVer    = \"\$(OSAndVer)\"
SET OpSysVer       = \"\$(OSVer)\"
SET OpSysName      = \"\$(OSName)\"
SET OpSysMajorVer  = \"\$(OSMajor)\"
SET OpSysShortName = \"\$(OSShort)\"
SET OpSysLegacy    = \"\$(OSLegacy)\"

TRANSFORM Arch,OS,OSAndVer,OSVer,OSName,OSMajor,OSShort,OSLegacy from (
  X86_64 LINUX   Debian7      700 Debian       7 Debian  LINUX
  X86_64 LINUX   Debian8      800 Debian       8 Debian  LINUX
  X86_64 LINUX   SL6          602 SL           6 SL      LINUX
  X86_64 LINUX   SL7          702 SL           7 SL      LINUX
  X86_64 LINUX   RedHat6      607 RedHat       6 RedHat  LINUX
  X86_64 LINUX   RedHat6      607 RedHat       6 RedHat  LINUX
  INTEL  LINUX   RedHat6      607 RedHat       6 RedHat  LINUX
  X86_64 LINUX   RedHat7      702 RedHat       7 RedHat  LINUX
  X86_64 WINDOWS WINDOWS601   601 Windows7   601 Win7    WINNT61
  X86_64 WINDOWS WINDOWS602   602 Windows8   602 Win8    WINNT62
  X86_64 WINDOWS WINDOWS1000 1000 Windows10 1000 Win10   WINNT100
  X86_64 OSX     MacOSX7      705 Lion         7 MacOSX  OSX
  X86_64 OSX     MacOSX8      805 MountainLion 8 MacOSX  OSX
  X86_64 OSX     MacOSX10    1001 ElCapitan   10 MacOSX  OSX
  X86_64 OSX     MacOSX10    1005 ElCapitan   10 MacOSX  OSX
  X86_64 LINUX   Ubuntu12    1204 Ubuntu      12 Ubuntu  LINUX
  X86_64 LINUX   Ubuntu14    1404 Ubuntu      14 Ubuntu  LINUX
  X86_64 LINUX   Fedora23    2300 Fedora      23 Fedora  LINUX
  X86_64 LINUX   Fedora24    2200 Fedora      22 Fedora  LINUX
  X86_64 FREEBSD FreeBSD10   1003 FreeBSD     10 FreeBSD FREEBSD
)";
$rules_file = "$option.rules";
open(FH,">$rules_file") || print "FAILED opening file $rules_file\n";
print FH $rules_content;
close(FH);

`condor_submit $submitfile`;
my $counter = 100;
while ($counter ne 0){
	if ($counter == 0){
		print "Took too long!\n";
		exit(1);
	} else {
		`condor_status -limit 2 -l > $orig_ads`;
		%Attr_old = read_attr($orig_ads);
		if (scalar keys %Attr_old == 0){
			sleep(1);
		} else {
			last;
		}
		$counter --;
	}
}
`condor_status -long > $orig_ads`;
%Attr_old = read_attr($orig_ads);
`condor_transform_ads -rules $rules_file -out $new_ads $orig_ads`;
`condor_rm -all`;

@content = `condor_status -ads $new_ads -sort Name`;
%Attr_new = read_attr($new_ads);
print @content;
($table1_ref,$table2_ref) = read_status_output(\@content);
%table1 = %{$table1_ref};
%table2 = %{$table2_ref};

@machine_info = split_fields(\%table1);
@summary = split_fields(\%table2);
if (check_heading('status_machine',\%table1) && check_heading('status_summary',\%table2)){
	RegisterResult(check_status(\@machine_info,\@summary,$option,\%Attr_old,\%Attr_new,20),check_name =>$option,test_name =>$testname);
} else {
	RegisterResult(0, check_name => $option, test_name => $testname);
}

print "############################################################################\n";
$option = "states";
$rules_content = 
"NAME Simulate multiple STARTD platforms
REQUIREMENTS SlotId

EVALMACRO SLOT = splitslotname(Name)[0]
INDEX = \$(ROW)+1

SET UidDomain = \"\$(DOMAIN:cs.wisc.edu)\"
SET Machine = \"exec\$INT(INDEX,%02d).\$(MY.UidDomain)\"
if defined SLOT
  SET  Name = \"\$(SLOT)@\$(My.Machine)\"
else
  COPY Machine Name
endif
COPY Machine PrivateNetworkName

if \$(SharedFileSystem)
  COPY UidDomain FileSystemDomain
else
  COPY Machine FileSystemDomain
endif

SET State =  \"\$(STATE)\"
SET Activity = \"\$(ACTIVITY)\"
TRANSFORM STATE,ACTIVITY from (
Unclaimed Idle
Claimed Retiring
Matched Busy
Preempting Busy
Owner Idle
)";
$rules_file = "$option.rules";
open(FH,">$rules_file") || print "FAILED opening file $rules_file\n";
print FH $rules_content;
close(FH);

`condor_transform_ads -rules $rules_file -out $new_ads $orig_ads`;

@content = `condor_status -ads $new_ads -sort Name`;
%Attr_new = read_attr($new_ads);
print @content;
($table1_ref,$table2_ref) = read_status_output(\@content);
%table1 = %{$table1_ref};
%table2 = %{$table2_ref};

@machine_info = split_fields(\%table1);
@summary = split_fields(\%table2);
if (check_heading('status_machine',\%table1) && check_heading('status_summary',\%table2)){
	RegisterResult(check_status(\@machine_info,\@summary,$option,\%Attr_old,\%Attr_new),check_name =>$option,test_name =>$testname);
} else {
	RegisterResult(0, check_name => $option, test_name => $testname);
}

print "############################################################################\n";
$option = "avail";
$rules_content = 
"NAME Simulate multiple STARTD platforms
REQUIREMENTS SlotId

EVALMACRO SLOT = splitslotname(Name)[0]
INDEX = \$(ROW)+1

SET UidDomain = \"\$(DOMAIN:cs.wisc.edu)\"
SET Machine = \"exec\$INT(INDEX,%02d).\$(MY.UidDomain)\"
if defined SLOT
  SET  Name = \"\$(SLOT)@\$(My.Machine)\"
else
  COPY Machine Name
endif
COPY Machine PrivateNetworkName

if \$(SharedFileSystem)
  COPY UidDomain FileSystemDomain
else
  COPY Machine FileSystemDomain
endif

SET State \"\$(STATE)\"
TRANSFORM STATE from (
Unclaimed
Claimed
Matched
Preempting
Owner
Unclaimed
)";
$rules_file = "$option.rules";
open(FH,">$rules_file") || print "FAILED opening file $rules_file\n";
print FH $rules_content;
close(FH);

`condor_transform_ads -rules $rules_file -out $new_ads $orig_ads`;

@content = `condor_status -ads $new_ads -avail -sort Name`;
%Attr_new = read_attr($new_ads);
print @content;
($table1_ref,$table2_ref) = read_status_output(\@content);
%table1 = %{$table1_ref};
%table2 = %{$table2_ref};

@machine_info = split_fields(\%table1);
@summary = split_fields(\%table2);
if (check_heading('status_machine',\%table1) && check_heading('status_summary',\%table2)){
	RegisterResult(check_status(\@machine_info,\@summary,$option,\%Attr_old,\%Attr_new),check_name =>$option,test_name =>$testname);
} else {
	RegisterResult(0, check_name => $option, test_name => $testname);
}

print "############################################################################\n";
$option = "claimed";
$rules_content = 
"NAME Simulate multiple STARTD platforms
REQUIREMENTS SlotId

EVALMACRO SLOT = splitslotname(Name)[0]
INDEX = \$(ROW)+1

SET UidDomain = \"\$(DOMAIN:cs.wisc.edu)\"
SET Machine = \"exec\$INT(INDEX,%02d).\$(MY.UidDomain)\"
if defined SLOT
  SET  Name = \"\$(SLOT)@\$(My.Machine)\"
else
  COPY Machine Name
endif
COPY Machine PrivateNetworkName

if \$(SharedFileSystem)
  COPY UidDomain FileSystemDomain
else
  COPY Machine FileSystemDomain
endif

SET State \"\$(STATE)\"
SET RemoteUser \"\$(REMOTEUSER)\"
COPY RemoteUser RemoteOwner
COPY Machine ClientMachine
SET Activity \"Busy\"
SET OpSys = \"\$(OS)\"
SET Arch = \"\$(ARCH)\"
TRANSFORM STATE, REMOTEUSER, OS, ARCH from (
Unclaimed foo\@cs.wisc.edu LINUX, X86_64
Claimed foo\@cs.wisc.edu LINUX, X86_64
Matched foo\@cs.wisc.edu LINUX, X86_64
Preempting foo\@cs.wisc.edu LINUX, X86_64
Owner foo\@cs.wisc.edu LINUX, X86_64
Unclaimed foo\@cs.wisc.edu LINUX, X86_64
)";
$rules_file = "$option.rules";
open(FH,">$rules_file") || print "FAILED opening file $rules_file\n";
print FH $rules_content;
close(FH);

`condor_transform_ads -rules $rules_file -out $new_ads $orig_ads`;

@content = `condor_status -ads $new_ads -claimed -sort Name`;
%Attr_new = read_attr($new_ads);
print @content;
($table1_ref,$table2_ref) = read_status_output(\@content);
%table1 = %{$table1_ref};
%table2 = %{$table2_ref};

@machine_info = split_fields(\%table1);
@summary = split_fields(\%table2);
if (check_heading('status_claimed_machine',\%table1) && check_heading('status_claimed_summary',\%table2)){
	RegisterResult(check_status(\@machine_info,\@summary,$option,\%Attr_old,\%Attr_new),check_name =>$option,test_name =>$testname);
} else {
	RegisterResult(0, check_name => $option, test_name => $testname);
}

print "############################################################################\n";
$option = "constraint";
$rules_content = 
"NAME Simulate multiple STARTD platforms
REQUIREMENTS SlotId

EVALMACRO SLOT = splitslotname(Name)[0]
INDEX = \$(ROW)+1

SET UidDomain = \"\$(DOMAIN:cs.wisc.edu)\"
SET Machine = \"exec\$INT(INDEX,%02d).\$(MY.UidDomain)\"
if defined SLOT
  SET  Name = \"\$(SLOT)@\$(My.Machine)\"
else
  COPY Machine Name
endif
COPY Machine PrivateNetworkName

if \$(SharedFileSystem)
  COPY UidDomain FileSystemDomain
else
  COPY Machine FileSystemDomain
endif

SET State =  \"\$(STATE)\"
SET Activity = \"\$(ACTIVITY)\"

TRANSFORM STATE,ACTIVITY from (
Unclaimed Idle
Claimed Retiring
Matched Busy
Preempting Busy
Owner Idle
)";

$rules_file = "$option.rules";
open(FH,">$rules_file") || print "FAILED opening file $rules_file\n";
print FH $rules_content;
close(FH);

`condor_transform_ads -rules $rules_file -out $new_ads $orig_ads`;

my $act="\\"."\""."Busy"."\\"."\"";
@content = `condor_status -ads $new_ads -constraint Activity==$act -sort Name`;
%Attr_new = read_attr($new_ads);
print @content;
($table1_ref,$table2_ref) = read_status_output(\@content);
%table1 = %{$table1_ref};
%table2 = %{$table2_ref};

@machine_info = split_fields(\%table1);
@summary = split_fields(\%table2);
if (check_heading('status_machine',\%table1) && check_heading('status_summary',\%table2)){
	RegisterResult(check_status(\@machine_info,\@summary,$option,\%Attr_old,\%Attr_new),check_name =>$option,test_name =>$testname);
} else {
	RegisterResult(0, check_name => $option, test_name => $testname);
}

print "############################################################################\n";
$option = "sort";
$rules_content = 
"NAME Simulate multiple STARTD platforms
REQUIREMENTS SlotId

EVALMACRO SLOT = splitslotname(Name)[0]
INDEX = \$(ROW)+1

SET UidDomain = \"\$(DOMAIN:cs.wisc.edu)\"
SET Machine = \"exec\$INT(INDEX,%02d).\$(MY.UidDomain)\"
if defined SLOT
  SET  Name = \"\$(SLOT)@\$(My.Machine)\"
else
  COPY Machine Name
endif
COPY Machine PrivateNetworkName

if \$(SharedFileSystem)
  COPY UidDomain FileSystemDomain
else
  COPY Machine FileSystemDomain
endif

SET State =  \"\$(STATE)\"
SET Activity = \"\$(ACTIVITY)\"

TRANSFORM STATE,ACTIVITY from (
Unclaimed Idle
Claimed Retiring
Matched Busy
Preempting Busy
Owner Idle
)";

$rules_file = "$option.rules";
open(FH,">$rules_file") || print "FAILED opening file $rules_file\n";
print FH $rules_content;
close(FH);

`condor_transform_ads -rules $rules_file -out $new_ads $orig_ads`;

@content = `condor_status -ads $new_ads -sort State`;
%Attr_new = read_attr($new_ads);
print @content;
($table1_ref,$table2_ref) = read_status_output(\@content);
%table1 = %{$table1_ref};
%table2 = %{$table2_ref};

@machine_info = split_fields(\%table1);
@summary = split_fields(\%table2);
if (check_heading('status_machine',\%table1) && check_heading('status_summary',\%table2)){
	RegisterResult(check_status(\@machine_info,\@summary,$option,\%Attr_old,\%Attr_new),check_name =>$option,test_name =>$testname);
} else {
	RegisterResult(0, check_name => $option, test_name => $testname);
}

print "############################################################################\n";
$option = "total";
$rules_content = 
"NAME Simulate multiple STARTD platforms
REQUIREMENTS SlotId

EVALMACRO SLOT = splitslotname(Name)[0]
INDEX = \$(ROW)+1

SET UidDomain = \"\$(DOMAIN:cs.wisc.edu)\"
SET Machine = \"exec\$INT(INDEX,%02d).\$(MY.UidDomain)\"
if defined SLOT
  SET  Name = \"\$(SLOT)@\$(My.Machine)\"
else
  COPY Machine Name
endif
COPY Machine PrivateNetworkName

if \$(SharedFileSystem)
  COPY UidDomain FileSystemDomain
else
  COPY Machine FileSystemDomain
endif

SET State =  \"\$(STATE)\"
SET Activity = \"\$(ACTIVITY)\"

TRANSFORM STATE,ACTIVITY from (
Unclaimed Idle
Claimed Retiring
Matched Busy
Preempting Busy
Owner Idle
)";

$rules_file = "$option.rules";
open(FH,">$rules_file") || print "FAILED opening file $rules_file\n";
print FH $rules_content;
close(FH);

`condor_transform_ads -rules $rules_file -out $new_ads $orig_ads`;
`condor_rm -all`;

@content = `condor_status -ads $new_ads -total`;
%Attr_new = read_attr($new_ads);
print @content;
my %table11;
my $index = 0;
for my $i (0..scalar @content -1){
	if ($content[$i] =~ /\S/){
		$table11{$index} = $content[$i];
		$index++;
	}
}
%table1 = %table11;
@summary = split_fields(\%table1);
if (check_heading('status_summary',\%table1)){
	RegisterResult(check_status(\@machine_info,\@summary,$option,\%Attr_old,\%Attr_new),check_name =>$option,test_name =>$testname);
} else {
	RegisterResult(0, check_name => $option, test_name => $testname);
}

print "############################################################################\n";
$option = "xml";
$rules_content = 
"NAME Simulate multiple STARTD platforms
REQUIREMENTS SlotId

EVALMACRO SLOT = splitslotname(Name)[0]
INDEX = \$(ROW)+1

SET UidDomain = \"\$(DOMAIN:cs.wisc.edu)\"
SET Machine = \"exec\$INT(INDEX,%02d).\$(MY.UidDomain)\"
if defined SLOT
  SET  Name = \"\$(SLOT)@\$(My.Machine)\"
else
  COPY Machine Name
endif
COPY Machine PrivateNetworkName

if \$(SharedFileSystem)
  COPY UidDomain FileSystemDomain
else
  COPY Machine FileSystemDomain
endif

SET Arch           = \"\$(ARCH)\"
SET OpSys          = \"\$(OS)\"
SET OpSysAndVer    = \"\$(OSAndVer)\"
SET OpSysVer       = \"\$(OSVer)\"
SET OpSysName      = \"\$(OSName)\"
SET OpSysMajorVer  = \"\$(OSMajor)\"
SET OpSysShortName = \"\$(OSShort)\"
SET OpSysLegacy    = \"\$(OSLegacy)\"

TRANSFORM Arch,OS,OSAndVer,OSVer,OSName,OSMajor,OSShort,OSLegacy,State from (
  X86_64 LINUX   Debian7      700 Debian       7 Debian  LINUX    Unclaimed
  X86_64 LINUX   Debian8      800 Debian       8 Debian  LINUX    Unclaimed
  X86_64 LINUX   SL6          602 SL           6 SL      LINUX    Unclaimed
  X86_64 LINUX   SL7          702 SL           7 SL      LINUX    Unclaimed
  X86_64 LINUX   RedHat6      607 RedHat       6 RedHat  LINUX    Unclaimed
  X86_64 LINUX   RedHat6      607 RedHat       6 RedHat  LINUX    Unclaimed
  INTEL  LINUX   RedHat6      607 RedHat       6 RedHat  LINUX    Unclaimed
  X86_64 LINUX   RedHat7      702 RedHat       7 RedHat  LINUX    Unclaimed
  X86_64 WINDOWS WINDOWS601   601 Windows7   601 Win7    WINNT61  Unclaimed
  X86_64 WINDOWS WINDOWS602   602 Windows8   602 Win8    WINNT62  Unclaimed
  X86_64 WINDOWS WINDOWS1000 1000 Windows10 1000 Win10   WINNT100 Unclaimed
  X86_64 OSX     MacOSX7      705 Lion         7 MacOSX  OSX      Unclaimed
  X86_64 OSX     MacOSX8      805 MountainLion 8 MacOSX  OSX      Unclaimed
  X86_64 OSX     MacOSX10    1001 ElCapitan   10 MacOSX  OSX      Unclaimed
  X86_64 OSX     MacOSX10    1005 ElCapitan   10 MacOSX  OSX      Unclaimed
  X86_64 LINUX   Ubuntu12    1204 Ubuntu      12 Ubuntu  LINUX    Unclaimed
  X86_64 LINUX   Ubuntu14    1404 Ubuntu      14 Ubuntu  LINUX    Unclaimed
  X86_64 LINUX   Fedora23    2300 Fedora      23 Fedora  LINUX    Unclaimed
  X86_64 LINUX   Fedora24    2200 Fedora      22 Fedora  LINUX    Unclaimed
  X86_64 FREEBSD FreeBSD10   1003 FreeBSD     10 FreeBSD FREEBSD  Unclaimed
)";
$rules_file = "$option.rules";
open(FH,">$rules_file") || print "FAILED opening file $rules_file\n";
print FH $rules_content;
close(FH);

my $status_ads_xml_orig = "$testname"."_xml_orig.ads";
my $status_ads_xml_new = "$testname"."_xml_new.ads";
`condor_status -ads:long $orig_ads -xml > $status_ads_xml_orig`;
`condor_transform_ads -rules $rules_file -out:xml $status_ads_xml_new $status_ads_xml_orig`;
my $convert = "temp.txt";
open(FH,">$convert") || print "FAILED opening file $convert\n";
print FH "TRANSFORM";
close(FH);
`condor_transform_ads -rules $convert -out:long $new_ads -in $status_ads_xml_new`;

@content = `condor_status -ads:xml $status_ads_xml_new -sort Name`;
%Attr_new = read_attr($new_ads);
print @content;
($table1_ref,$table2_ref) = read_status_output(\@content);
%table1 = %{$table1_ref};
%table2 = %{$table2_ref};

@machine_info = split_fields(\%table1);
@summary = split_fields(\%table2);
if (check_heading('status_machine',\%table1) && check_heading('status_summary',\%table2)){
	RegisterResult(check_status(\@machine_info,\@summary,$option,\%Attr_old,\%Attr_new),check_name =>$option,test_name =>$testname);
} else {
	RegisterResult(0, check_name => $option, test_name => $testname);
}

print "############################################################################\n";
$option = "json";
$rules_content = 
"NAME Simulate multiple STARTD platforms
REQUIREMENTS SlotId

EVALMACRO SLOT = splitslotname(Name)[0]
INDEX = \$(ROW)+1

SET UidDomain = \"\$(DOMAIN:cs.wisc.edu)\"
SET Machine = \"exec\$INT(INDEX,%02d).\$(MY.UidDomain)\"
if defined SLOT
  SET  Name = \"\$(SLOT)@\$(My.Machine)\"
else
  COPY Machine Name
endif
COPY Machine PrivateNetworkName

if \$(SharedFileSystem)
  COPY UidDomain FileSystemDomain
else
  COPY Machine FileSystemDomain
endif

SET Arch           = \"\$(ARCH)\"
SET OpSys          = \"\$(OS)\"
SET OpSysAndVer    = \"\$(OSAndVer)\"
SET OpSysVer       = \"\$(OSVer)\"
SET OpSysName      = \"\$(OSName)\"
SET OpSysMajorVer  = \"\$(OSMajor)\"
SET OpSysShortName = \"\$(OSShort)\"
SET OpSysLegacy    = \"\$(OSLegacy)\"

TRANSFORM Arch,OS,OSAndVer,OSVer,OSName,OSMajor,OSShort,OSLegacy,State from (
  X86_64 LINUX   Debian7      700 Debian       7 Debian  LINUX    Unclaimed
  X86_64 LINUX   Debian8      800 Debian       8 Debian  LINUX    Unclaimed
  X86_64 LINUX   SL6          602 SL           6 SL      LINUX    Unclaimed
  X86_64 LINUX   SL7          702 SL           7 SL      LINUX    Unclaimed
  X86_64 LINUX   RedHat6      607 RedHat       6 RedHat  LINUX    Unclaimed
  X86_64 LINUX   RedHat6      607 RedHat       6 RedHat  LINUX    Unclaimed
  INTEL  LINUX   RedHat6      607 RedHat       6 RedHat  LINUX    Unclaimed
  X86_64 LINUX   RedHat7      702 RedHat       7 RedHat  LINUX    Unclaimed
  X86_64 WINDOWS WINDOWS601   601 Windows7   601 Win7    WINNT61  Unclaimed
  X86_64 WINDOWS WINDOWS602   602 Windows8   602 Win8    WINNT62  Unclaimed
  X86_64 WINDOWS WINDOWS1000 1000 Windows10 1000 Win10   WINNT100 Unclaimed
  X86_64 OSX     MacOSX7      705 Lion         7 MacOSX  OSX      Unclaimed
  X86_64 OSX     MacOSX8      805 MountainLion 8 MacOSX  OSX      Unclaimed
  X86_64 OSX     MacOSX10    1001 ElCapitan   10 MacOSX  OSX      Unclaimed
  X86_64 OSX     MacOSX10    1005 ElCapitan   10 MacOSX  OSX      Unclaimed
  X86_64 LINUX   Ubuntu12    1204 Ubuntu      12 Ubuntu  LINUX    Unclaimed
  X86_64 LINUX   Ubuntu14    1404 Ubuntu      14 Ubuntu  LINUX    Unclaimed
  X86_64 LINUX   Fedora23    2300 Fedora      23 Fedora  LINUX    Unclaimed
  X86_64 LINUX   Fedora24    2200 Fedora      22 Fedora  LINUX    Unclaimed
  X86_64 FREEBSD FreeBSD10   1003 FreeBSD     10 FreeBSD FREEBSD  Unclaimed
)";
$rules_file = "$option.rules";
open(FH,">$rules_file") || print "FAILED opening file $rules_file\n";
print FH $rules_content;
close(FH);

my $status_ads_json_orig = "$testname"."_json_orig.ads";
my $status_ads_json_new = "$testname"."_json_new.ads";
`condor_status -ads:long $orig_ads -json > $status_ads_json_orig`;
`condor_transform_ads -rules $rules_file -out:json $status_ads_json_new $status_ads_json_orig`;
`condor_transform_ads -rules $convert -out:long $new_ads -in $status_ads_json_new`;

@content = `condor_status -ads:json $status_ads_json_new -sort Name`;
%Attr_new = read_attr($new_ads);
print @content;
($table1_ref,$table2_ref) = read_status_output(\@content);
%table1 = %{$table1_ref};
%table2 = %{$table2_ref};

@machine_info = split_fields(\%table1);
@summary = split_fields(\%table2);
if (check_heading('status_machine',\%table1) && check_heading('status_summary',\%table2)){
	RegisterResult(check_status(\@machine_info,\@summary,$option,\%Attr_old,\%Attr_new),check_name =>$option,test_name =>$testname);
} else {
	RegisterResult(0, check_name => $option, test_name => $testname);
}

CondorTest::EndTest();
exit(0);
