summaryrefslogtreecommitdiffstats
path: root/config-db/t/12-system.t
diff options
context:
space:
mode:
Diffstat (limited to 'config-db/t/12-system.t')
-rw-r--r--config-db/t/12-system.t215
1 files changed, 190 insertions, 25 deletions
diff --git a/config-db/t/12-system.t b/config-db/t/12-system.t
index ee908dba..7a3e5e1e 100644
--- a/config-db/t/12-system.t
+++ b/config-db/t/12-system.t
@@ -1,5 +1,8 @@
use Test::More qw(no_plan);
+use strict;
+use warnings;
+
use lib '/opt/openslx/lib';
# basic init
@@ -35,6 +38,11 @@ my $inSystem1 = {
'name' => 'sys-1',
'export_id' => 1,
'comment' => '',
+ 'attrs' => {
+ 'ramfs_fsmods' => 'squashfs',
+ 'ramfs_nicmods' => 'e1000 forcedeth r8169',
+ 'start_sshd' => 'yes',
+ },
};
is(
my $system1ID = $configDB->addSystem($inSystem1), 1,
@@ -55,10 +63,43 @@ my $fullSystem = {
'label' => 'BlingBling System - really kuul!',
'kernel_params' => 'debug=3 console=ttyS1',
'hidden' => '1',
- 'attr_ramfs_nicmods' => 'e1000 forcedeth',
- 'attr_ramfs_fsmods' => 'squashfs',
- 'attr_ramfs_miscmods' => 'tpm',
- 'attr_ramfs_screen' => '1024x768',
+ 'attrs' => {
+ 'automnt_dir' => 'a',
+ 'automnt_src' => 'b',
+ 'country' => 'c',
+ 'dm_allow_shutdown' => 'd',
+ 'hw_graphic' => 'e',
+ 'hw_monitor' => 'f',
+ 'hw_mouse' => 'g',
+ 'late_dm' => 'h',
+ 'netbios_workgroup' => 'i',
+ 'nis_domain' => 'j',
+ 'nis_servers' => 'k',
+ 'ramfs_fsmods' => 'l',
+ 'ramfs_miscmods' => 'm',
+ 'ramfs_nicmods' => 'n',
+ 'ramfs_screen' => 'o',
+ 'sane_scanner' => 'p',
+ 'scratch' => 'q',
+ 'slxgrp' => 'r',
+ 'start_alsasound' => 's',
+ 'start_atd' => 't',
+ 'start_cron' => 'u',
+ 'start_dreshal' => 'v',
+ 'start_ntp' => 'w',
+ 'start_nfsv4' => 'x',
+ 'start_printer' => 'y',
+ 'start_samba' => 'z',
+ 'start_snmp' => 'A',
+ 'start_sshd' => 'B',
+ 'start_syslog' => 'C',
+ 'start_x' => 'D',
+ 'start_xdmcp' => 'E',
+ 'tex_enable' => 'F',
+ 'timezone' => 'G',
+ 'tvout' => 'H',
+ 'vmware' => 'I',
+ },
};
ok(
my ($system2ID, $system3ID) = $configDB->addSystem([
@@ -79,39 +120,72 @@ is($system3->{comment}, 'nuff said', 'system 3 - comment
is($system3->{label}, 'BlingBling System - really kuul!', 'system 3 - label');
is($system3->{kernel_params}, 'debug=3 console=ttyS1', 'system 3 - kernel_params');
is($system3->{hidden}, '1', 'system 3 - hidden');
-is($system3->{attr_ramfs_nicmods}, 'e1000 forcedeth', 'system 3 - attr_ramfs_nicmods');
-is($system3->{attr_ramfs_fsmods}, 'squashfs', 'system 3 - attr_ramfs_fsmods');
-is($system3->{attr_ramfs_miscmods}, 'tpm', 'system 3 - attr_ramfs_miscmods');
-is($system3->{attr_ramfs_screen}, '1024x768', 'system 3 - attr_ramfs_screen');
+is($system3->{attrs}->{automnt_dir}, 'a', 'system 3 - attr automnt_dir');
+is($system3->{attrs}->{automnt_src}, 'b', 'system 3 - attr automnt_src');
+is($system3->{attrs}->{country}, 'c', 'system 3 - attr country');
+is($system3->{attrs}->{dm_allow_shutdown}, 'd', 'system 3 - attr dm_allow_shutdown');
+is($system3->{attrs}->{hw_graphic}, 'e', 'system 3 - attr hw_graphic');
+is($system3->{attrs}->{hw_monitor}, 'f', 'system 3 - attr hw_monitor');
+is($system3->{attrs}->{hw_mouse}, 'g', 'system 3 - attr hw_mouse');
+is($system3->{attrs}->{late_dm}, 'h', 'system 3 - attr late_dm');
+is($system3->{attrs}->{netbios_workgroup}, 'i', 'system 3 - attr netbios_workgroup');
+is($system3->{attrs}->{nis_domain}, 'j', 'system 3 - attr nis_domain');
+is($system3->{attrs}->{nis_servers}, 'k', 'system 3 - attr nis_servers');
+is($system3->{attrs}->{ramfs_fsmods}, 'l', 'system 3 - attr ramfs_fsmods');
+is($system3->{attrs}->{ramfs_miscmods}, 'm', 'system 3 - attr ramfs_miscmods');
+is($system3->{attrs}->{ramfs_nicmods}, 'n', 'system 3 - attr ramfs_nicmods');
+is($system3->{attrs}->{ramfs_screen}, 'o', 'system 3 - attr ramfs_screen');
+is($system3->{attrs}->{sane_scanner}, 'p', 'system 3 - attr sane_scanner');
+is($system3->{attrs}->{scratch}, 'q', 'system 3 - attr scratch');
+is($system3->{attrs}->{slxgrp}, 'r', 'system 3 - attr slxgrp');
+is($system3->{attrs}->{start_alsasound}, 's', 'system 3 - attr start_alsasound');
+is($system3->{attrs}->{start_atd}, 't', 'system 3 - attr start_atd');
+is($system3->{attrs}->{start_cron}, 'u', 'system 3 - attr start_cron');
+is($system3->{attrs}->{start_dreshal}, 'v', 'system 3 - attr start_dreshal');
+is($system3->{attrs}->{start_ntp}, 'w', 'system 3 - attr start_ftp');
+is($system3->{attrs}->{start_nfsv4}, 'x', 'system 3 - attr start_nfsv4');
+is($system3->{attrs}->{start_printer}, 'y', 'system 3 - attr start_printer');
+is($system3->{attrs}->{start_samba}, 'z', 'system 3 - attr start_samba');
+is($system3->{attrs}->{start_snmp}, 'A', 'system 3 - attr start_snmp');
+is($system3->{attrs}->{start_sshd}, 'B', 'system 3 - attr start_sshd');
+is($system3->{attrs}->{start_syslog}, 'C', 'system 3 - attr start_syslog');
+is($system3->{attrs}->{start_x}, 'D', 'system 3 - attr start_x');
+is($system3->{attrs}->{start_xdmcp}, 'E', 'system 3 - attr start_xdmcp');
+is($system3->{attrs}->{tex_enable}, 'F', 'system 3 - attr tex_enable');
+is($system3->{attrs}->{timezone}, 'G', 'system 3 - attr timezone');
+is($system3->{attrs}->{tvout}, 'H', 'system 3 - attr tvout');
+is($system3->{attrs}->{vmware}, 'I', 'system 3 - attr vmware');
+is(keys %{$system3->{attrs}}, 35, 'system 3 - attribute count');
# fetch system 2 by a filter on id and check all values
ok(
my $system2 = $configDB->fetchSystemByFilter({ id => 2 }),
'fetch system 2 by filter on id'
);
-is($system2->{id}, 2, 'system 2 - id');
-is($system2->{name}, 'sys-2.0', 'system 2 - name');
-is($system2->{kernel}, 'vmlinuz', 'system 2 - kernel');
-is($system2->{export_id}, '1', 'system 2 - export_id');
-is($system2->{comment}, undef, 'system 2 - comment');
+is($system2->{id}, 2, 'system 2 - id');
+is($system2->{name}, 'sys-2.0', 'system 2 - name');
+is($system2->{kernel}, 'vmlinuz', 'system 2 - kernel');
+is($system2->{export_id}, '1', 'system 2 - export_id');
+is($system2->{comment}, undef, 'system 2 - comment');
+is(keys %{$system2->{attrs}}, 0, 'system 2 - attribute count');
# fetch system 1 by filter on name and check all values
ok(
my $system1 = $configDB->fetchSystemByFilter({ name => 'sys-1' }),
'fetch system 1 by filter on name'
);
-is($system1->{id}, 1, 'system 1 - id');
-is($system1->{name}, 'sys-1', 'system 1 - name');
-is($system1->{export_id}, '1', 'system 1 - export_id');
-is($system1->{kernel}, 'vmlinuz', 'system 1 - kernel');
-is($system1->{comment}, '', 'system 1 - comment');
-is($system1->{label}, 'sys-1', 'system 1 - label');
-is($system1->{kernel_params}, undef, 'system 1 - kernel_params');
-is($system1->{hidden}, undef, 'system 1 - hidden');
-is($system1->{attr_ramfs_nicmods}, undef, 'system 1 - attr_ramfs_nicmods');
-is($system1->{attr_ramfs_fsmods}, undef, 'system 1 - attr_ramfs_fsmods');
-is($system1->{attr_ramfs_miscmods}, undef, 'system 1 - attr_ramfs_miscmods');
-is($system1->{attr_ramfs_screen}, undef, 'system 1 - attr_ramfs_screen');
+is($system1->{id}, 1, 'system 1 - id');
+is($system1->{name}, 'sys-1', 'system 1 - name');
+is($system1->{export_id}, '1', 'system 1 - export_id');
+is($system1->{kernel}, 'vmlinuz', 'system 1 - kernel');
+is($system1->{comment}, '', 'system 1 - comment');
+is($system1->{label}, 'sys-1', 'system 1 - label');
+is($system1->{kernel_params}, undef, 'system 1 - kernel_params');
+is($system1->{hidden}, undef, 'system 1 - hidden');
+is(keys %{$system1->{attrs}}, 3, 'system 1 - attribute count');
+is($system1->{attrs}->{ramfs_fsmods}, 'squashfs', 'system 1 - attr ramfs_fsmods');
+is($system1->{attrs}->{ramfs_nicmods}, 'e1000 forcedeth r8169', 'system 1 - attr ramfs_nicmods');
+is($system1->{attrs}->{start_sshd}, 'yes', 'system 1 - attr start_sshd');
# fetch systems 3 & 1 by id
ok(
@@ -148,6 +222,17 @@ is(@systems1And2, 2, 'should have got 2 systems');
is($systems1And2[0]->{id}, 1, 'first id should be 1');
is($systems1And2[1]->{id}, 2, 'second id should be 2');
+# fetch systems 1 & 2 by filter on hidden being undef'd
+ok(
+ @systems1And2 = $configDB->fetchSystemByFilter({ hidden => undef }),
+ 'fetch systems 1 & 2 by filter on hidden being undefined'
+);
+is(@systems1And2, 2, 'should have got 2 systems');
+# now sort by ID and check if we have really got 1 and 2
+@systems1And2 = sort { $a->{id} cmp $b->{id} } @systems1And2;
+is($systems1And2[0]->{id}, 1, 'first id should be 1');
+is($systems1And2[1]->{id}, 2, 'second id should be 2');
+
# try to fetch with multi-column filter
ok(
($system2, $system3)
@@ -169,6 +254,83 @@ is(@systems1And3, 2, 'should have got 2 systems');
is($systems1And3[0]->{id}, 1, 'first id should be 1');
is($systems1And3[1]->{id}, 3, 'second id should be 3');
+# filter systems by different attributes & values in combination
+ok(
+ my @system1Only = $configDB->fetchSystemByFilter( {}, undef, {
+ ramfs_nicmods => 'e1000 forcedeth r8169'
+ } ),
+ 'fetch system 1 by filter on attribute ramfs_nicmods'
+);
+
+is(@system1Only, 1, 'should have got 1 system');
+is($system1Only[0]->{id}, 1, 'first id should be 1');
+
+ok(
+ @system1Only = $configDB->fetchSystemByFilter( undef, 'id', {
+ ramfs_nicmods => 'e1000 forcedeth r8169',
+ slxgrp => undef,
+ } ),
+ 'fetch system 1 by filter on attribute ramfs_nicmods'
+);
+is(@system1Only, 1, 'should have got 1 system');
+is($system1Only[0]->{id}, 1, 'first id should be 1');
+
+ok(
+ @system1Only = $configDB->fetchSystemByFilter( {
+ export_id => 1,
+ hidden => undef,
+ }, 'id', {
+ ramfs_nicmods => 'e1000 forcedeth r8169',
+ slxgrp => undef,
+ } ),
+ 'fetch system 1 by multiple filter on values and attributes'
+);
+is(@system1Only, 1, 'should have got 1 system');
+is($system1Only[0]->{id}, 1, 'first id should be 1');
+
+is(
+ $configDB->fetchSystemByFilter( {
+ export_id => 2,
+ }, 'id', {
+ ramfs_nicmods => 'e1000 forcedeth r8169',
+ slxgrp => undef,
+ } ),
+ undef,
+ 'mismatch system 1 by filter with incorrect value'
+);
+is(
+ $configDB->fetchSystemByFilter( {
+ export_id => 1,
+ }, 'id', {
+ ramfs_nicmods => 'xxxx',
+ slxgrp => undef,
+ } ),
+ undef,
+ 'mismatch system 1 by filter with incorrect attribute value'
+);
+is(
+ $configDB->fetchSystemByFilter( {
+ name => 'sys-1',
+ }, 'id', {
+ start_sshd => undef,
+ } ),
+ undef,
+ 'mismatch system 1 by filter with attribute not being empty'
+);
+
+# fetch systems 1 & 2 by filter on attribute start_samba not existing
+ok(
+ @systems1And2 = $configDB->fetchSystemByFilter( {}, undef, {
+ start_samba => undef,
+ } ),
+ 'fetch systems 1 & 2 by filter on attribute start_samba not existing'
+);
+is(@systems1And2, 2, 'should have got 2 systems');
+# now sort by ID and check if we have really got 1 and 2
+@systems1And2 = sort { $a->{id} cmp $b->{id} } @systems1And2;
+is($systems1And2[0]->{id}, 1, 'first id should be 1');
+is($systems1And2[1]->{id}, 2, 'second id should be 2');
+
# try to fetch a couple of non-existing systems by id
is(
$configDB->fetchSystemByID(-1), undef,
@@ -203,6 +365,9 @@ ok(
is($system1->{id}, 1, 'really got system number 1');
is($system1->{name}, q{SYS-'1'}, q{really got system named "SYS-'1'"});
+# changing nothing at all should succeed
+ok($configDB->changeSystem(1), 'changing nothing at all in system 1');
+
# changing a non-existing column should fail
ok(
! eval { $configDB->changeSystem(1, { xname => "xx" }) },