summaryrefslogtreecommitdiffstats
path: root/config-db/t/25-attributes.t
blob: 35c9d53721b1731be50620a796bf300860ba4241 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use Test::More qw(no_plan);

use lib '/opt/openslx/lib';

# basic init
use OpenSLX::ConfigDB;

my $configDB = OpenSLX::ConfigDB->new;
$configDB->connect();

my $defaultAttrs = {	# mostly copied from DBSchema
	'attr_ramfs_fsmods' => '',
	'attr_ramfs_miscmods' => '',
	'attr_ramfs_nicmods' => 'forcedeth e1000 e100 tg3 via-rhine r8169 pcnet32',
	'attr_ramfs_screen' => '',

	'attr_automnt_dir' => '',
	'attr_automnt_src' => '',
	'attr_country' => 'de',
	'attr_dm_allow_shutdown' => 'user',
	'attr_hw_graphic' => '',
	'attr_hw_monitor' => '',
	'attr_hw_mouse' => '',
	'attr_late_dm' => 'no',
	'attr_netbios_workgroup' => 'slx-network',
	'attr_nis_domain' => '',
	'attr_nis_servers' => '',
	'attr_sane_scanner' => '',
	'attr_scratch' => '',
	'attr_slxgrp' => '',
	'attr_start_alsasound' => 'yes',
	'attr_start_atd' => 'no',
	'attr_start_cron' => 'no',
	'attr_start_dreshal' => 'yes',
	'attr_start_ntp' => 'initial',
	'attr_start_nfsv4' => 'no',
	'attr_start_printer' => 'no',
	'attr_start_samba' => 'may',
	'attr_start_snmp' => 'no',
	'attr_start_sshd' => 'yes',
	'attr_start_syslog' => 'yes',
	'attr_start_x' => 'yes',
	'attr_start_xdmcp' => 'kdm',
	'attr_tex_enable' => 'no',
	'attr_timezone' => 'Europe/Berlin',
	'attr_tvout' => 'no',
	'attr_vmware' => 'no',
};
ok(
	$configDB->changeSystem(0, $defaultAttrs),
	'attributes of default system have been set'
);
my $defaultSystem = $configDB->fetchSystemByID(0);

my $system1 = $configDB->fetchSystemByID(1);
my $sys1Attrs = {
	'attr_ramfs_fsmods' => 'squashfs',
	'attr_ramfs_nicmods' => 'forcedeth e1000 r8169',
	'attr_start_x' => 'no',
	'attr_start_xdmcp' => '',
};
ok(
	$configDB->changeSystem(1, $sys1Attrs),
	'attributes of system 1 have been set'
);
my $changedSystem1 = $configDB->fetchSystemByID(1);
foreach my $key (keys %$changedSystem1) {
	is(
		$changedSystem1->{$key},
		exists $sys1Attrs->{$key} ? $sys1Attrs->{$key} : $system1->{$key},
		"checking value for $key of system 1"
	);
}

my $system3 = $configDB->fetchSystemByID(3);
my $sys3Attrs = {
	'attr_automnt_dir' => '1',
	'attr_automnt_src' => '2',
	'attr_country' => '3',
	'attr_dm_allow_shutdown' => '4',
	'attr_hw_graphic' => '5',
	'attr_hw_monitor' => '6',
	'attr_hw_mouse' => '7',
	'attr_late_dm' => '8',
	'attr_netbios_workgroup' => '9',
	'attr_nis_domain' => '10',
	'attr_nis_servers' => '11',
	'attr_sane_scanner' => '12',
	'attr_scratch' => '13',
	'attr_slxgrp' => '14',
	'attr_start_alsasound' => '15',
	'attr_start_atd' => '16',
	'attr_start_cron' => '17',
	'attr_start_dreshal' => '18',
	'attr_start_ntp' => '19',
	'attr_start_nfsv4' => '20',
	'attr_start_printer' => '21',
	'attr_start_samba' => '22',
	'attr_start_snmp' => '23',
	'attr_start_sshd' => '24',
	'attr_start_syslog' => '25',
	'attr_start_x' => '26',
	'attr_start_xdmcp' => '27',
	'attr_tex_enable' => '28',
	'attr_timezone' => '29',
	'attr_tvout' => '30',
	'attr_vmware' => '31',
};
ok(
	$configDB->changeSystem(3, $sys3Attrs),
	'attributes of system 3 have been set'
);
my $changedSystem3 = $configDB->fetchSystemByID(3);
foreach my $key (keys %$changedSystem3) {
	is(
		$changedSystem3->{$key},
		exists $sys3Attrs->{$key} ? $sys3Attrs->{$key} : $system3->{$key},
		"checking value for $key of system 3"
	);
}

my $defaultClient = $configDB->fetchClientByID(0);
my $defaultClientAttrs = {
	# pretend the whole computer centre has been warped to London ;-)
	'attr_timezone' => 'Europe/London',
};
ok(
	$configDB->changeClient(0, $defaultClientAttrs),
	'attributes of default client have been set'
);
my $changedDefaultClient = $configDB->fetchClientByID(0);
foreach my $key (keys %$changedDefaultClient) {
	is(
		$changedDefaultClient->{$key},
		exists $defaultClientAttrs->{$key} 
			? $defaultClientAttrs->{$key} 
			: $defaultClient->{$key},
		"checking value for $key of default client"
	);
}

# check merging of default attributes, the order should be:
# default system attributes overruled by system attributes overruled by
# default client attributes
$system1 = $changedSystem1;
$system3 = $changedSystem3;
$defaultClient = $changedDefaultClient;
my $shouldBeAttrs1 = { %$defaultSystem };
foreach my $key (keys %$system1) {
	next if !$configDB->isAttribute($key);
	if (defined $system1->{$key} && length($system1->{$key})) {
		$shouldBeAttrs1->{$key} = $system1->{$key};
	}
}
foreach my $key (keys %$defaultClient) {
	next if !$configDB->isAttribute($key);
	if (defined $defaultClient->{$key} && length($defaultClient->{$key})) {
		$shouldBeAttrs1->{$key} = $defaultClient->{$key};
	}
}

my $mergedSystem1 =  $configDB->fetchSystemByID(1);
ok(
	$configDB->mergeAttributes($mergedSystem1), 
	'merging default attributes for system 1'
);
is_deeply(
	$mergedSystem1, $shouldBeAttrs1, 
	'checking merged attributes for system 1'
);

$configDB->disconnect();