Discussion:
[pve-devel] [PATCH qemu-server 2/3] t/cmd2cfg: mock iscsi initiator name
Wolfgang Bumiller
2018-12-07 09:31:18 UTC
Permalink
Signed-off-by: Wolfgang Bumiller <***@proxmox.com>
---
test/cfg2cmd/minimal-defaults.conf.cmd | 2 +-
test/cfg2cmd/simple1.conf.cmd | 2 +-
test/run_config2command_tests.pl | 3 +++
3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/test/cfg2cmd/minimal-defaults.conf.cmd b/test/cfg2cmd/minimal-defaults.conf.cmd
index 6c1f9d6..ec81ab5 100644
--- a/test/cfg2cmd/minimal-defaults.conf.cmd
+++ b/test/cfg2cmd/minimal-defaults.conf.cmd
@@ -20,5 +20,5 @@
-device 'usb-tablet,id=tablet,bus=uhci.0,port=1' \
-device 'VGA,id=vga,bus=pci.0,addr=0x2' \
-device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
- -iscsi 'initiator-name=iqn.1993-08.org.debian:01:a1d15f6610fd' \
+ -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
-machine 'type=pc'
diff --git a/test/cfg2cmd/simple1.conf.cmd b/test/cfg2cmd/simple1.conf.cmd
index f202ea8..07a1d2e 100644
--- a/test/cfg2cmd/simple1.conf.cmd
+++ b/test/cfg2cmd/simple1.conf.cmd
@@ -21,7 +21,7 @@
-device 'usb-tablet,id=tablet,bus=uhci.0,port=1' \
-device 'VGA,id=vga,bus=pci.0,addr=0x2' \
-device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
- -iscsi 'initiator-name=iqn.1993-08.org.debian:01:a1d15f6610fd' \
+ -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
-drive 'if=none,id=drive-ide2,media=cdrom,aio=threads' \
-device 'ide-cd,bus=ide.1,unit=0,drive=drive-ide2,id=ide2,bootindex=200' \
-device 'virtio-scsi-pci,id=scsihw0,bus=pci.0,addr=0x5' \
diff --git a/test/run_config2command_tests.pl b/test/run_config2command_tests.pl
index 00dbcbb..3fe4855 100755
--- a/test/run_config2command_tests.pl
+++ b/test/run_config2command_tests.pl
@@ -110,6 +110,9 @@ $qemu_server_module->mock(
get_host_arch => sub() {
return $current_test->{host_arch} // 'x86_64';
},
+ get_initiator_name => sub {
+ return 'iqn.1993-08.org.debian:01:aabbccddeeff';
+ }
);

my $qemu_server_config;
--
2.11.0
Wolfgang Bumiller
2018-12-07 09:31:19 UTC
Permalink
(The diff() sub is copied from our pve-common's network
interfaces test scripts)

Signed-off-by: Wolfgang Bumiller <***@proxmox.com>
---
test/run_config2command_tests.pl | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/test/run_config2command_tests.pl b/test/run_config2command_tests.pl
index 3fe4855..0e37c17 100755
--- a/test/run_config2command_tests.pl
+++ b/test/run_config2command_tests.pl
@@ -125,6 +125,38 @@ $qemu_server_config->mock(
},
);

+sub diff($$) {
+ my ($a, $b) = @_;
+ return if $a eq $b;
+
+ my ($ra, $wa) = POSIX::pipe();
+ my ($rb, $wb) = POSIX::pipe();
+ my $ha = IO::Handle->new_from_fd($wa, 'w');
+ my $hb = IO::Handle->new_from_fd($wb, 'w');
+
+ open my $diffproc, '-|', 'diff', '-up', "/dev/fd/$ra", "/dev/fd/$rb"
+ or die "failed to run program 'diff': $!";
+ POSIX::close($ra);
+ POSIX::close($rb);
+
+ open my $f1, '<', \$a;
+ open my $f2, '<', \$b;
+ my ($line1, $line2);
+ do {
+ $ha->print($line1) if defined($line1 = <$f1>);
+ $hb->print($line2) if defined($line2 = <$f2>);
+ } while (defined($line1 // $line2));
+ close $f1;
+ close $f2;
+ close $ha;
+ close $hb;
+
+ local $/ = undef;
+ my $diff = <$diffproc>;
+ close $diffproc;
+ die "files differ:\n$diff";
+}
+
sub do_test($) {
my ($config_fn) = @_;

@@ -156,7 +188,9 @@ sub do_test($) {
# comment out for easier debugging
#file_set_contents("$cmd_fn.tmp", $cmdline);

- is_deeply($cmd, $cmd_expected, "$testname")
+ my $exp = join("\n", @$cmd_expected);
+ my $got = join("\n", @$cmd);
+ diff($exp, $got);
} else {
file_set_contents($cmd_fn, $cmdline);
}
--
2.11.0
Loading...