File: VmTest.pm

package info (click to toggle)
pgbackrest 2.58.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,056 kB
  • sloc: ansic: 128,636; xml: 19,653; perl: 11,498; pascal: 3,279; sh: 91; sql: 32; makefile: 23
file content (355 lines) | stat: -rw-r--r-- 11,508 bytes parent folder | download
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
####################################################################################################################################
# VmTest.pm - Vm constants and data
####################################################################################################################################
package pgBackRestTest::Common::VmTest;

####################################################################################################################################
# Perl includes
####################################################################################################################################
use strict;
use warnings FATAL => qw(all);
use Carp qw(confess);

use Exporter qw(import);
    our @EXPORT = qw();

use pgBackRestDoc::Common::Exception;
use pgBackRestDoc::Common::Log;
use pgBackRestDoc::Common::String;

use pgBackRestTest::Common::DbVersion;

####################################################################################################################################
# VM hash keywords
####################################################################################################################################
use constant VM_DB                                                  => 'db';
    push @EXPORT, qw(VM_DB);
use constant VM_DB_TEST                                             => 'db-test';
    push @EXPORT, qw(VM_DB_TEST);
# Will coverage testing be run for C?
use constant VMDEF_COVERAGE_C                                       => 'coverage-c';
use constant VM_DEPRECATED                                          => 'deprecated';
    push @EXPORT, qw(VM_DEPRECATED);
use constant VM_IMAGE                                               => 'image';
    push @EXPORT, qw(VM_IMAGE);
use constant VM_OS_BASE                                             => 'os-base';
    push @EXPORT, qw(VM_OS_BASE);
use constant VMDEF_PG_REPO                                          => 'pg-repo';
use constant VMDEF_PGSQL_BIN                                        => 'psql-bin';
    push @EXPORT, qw(VMDEF_PGSQL_BIN);

####################################################################################################################################
# Valid OS base List
####################################################################################################################################
use constant VM_OS_BASE_ALPINE                                      => 'alpine';
    push @EXPORT, qw(VM_OS_BASE_ALPINE);
use constant VM_OS_BASE_DEBIAN                                      => 'debian';
    push @EXPORT, qw(VM_OS_BASE_DEBIAN);
use constant VM_OS_BASE_RHEL                                        => 'rhel';
    push @EXPORT, qw(VM_OS_BASE_RHEL);

####################################################################################################################################
# Valid architecture list
####################################################################################################################################
use constant VM_ARCH_AARCH64                                        => 'aarch64';
    push @EXPORT, qw(VM_ARCH_AARCH64);
use constant VM_ARCH_I386                                           => 'i386';
    push @EXPORT, qw(VM_ARCH_I386);
use constant VM_ARCH_X86_64                                         => 'x86_64';
    push @EXPORT, qw(VM_ARCH_X86_64);

####################################################################################################################################
# Valid VM list
####################################################################################################################################
use constant VM_ALL                                                 => 'all';
    push @EXPORT, qw(VM_ALL);

use constant VM_NONE                                                => 'none';
    push @EXPORT, qw(VM_NONE);

use constant VM_A321                                                 => 'a321';
    push @EXPORT, qw(VM_A321);
use constant VM_D11                                                 => 'd11';
    push @EXPORT, qw(VM_D11);
use constant VM_RH8                                                 => 'rh8';
    push @EXPORT, qw(VM_RH8);
use constant VM_F42                                                 => 'f42';
    push @EXPORT, qw(VM_F42);
use constant VM_U22                                                 => 'u22';
    push @EXPORT, qw(VM_U22);

# List of default test VMs
use constant VM_LIST                                                => (VM_D11, VM_RH8, VM_U22);
    push @EXPORT, qw(VM_LIST);

my $oyVm =
{
    # None
    &VM_NONE =>
    {
        &VM_OS_BASE => VM_OS_BASE_DEBIAN,
        &VMDEF_COVERAGE_C => true,
        &VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',

        &VM_DB =>
        [
            PG_VERSION_10,
        ],

        &VM_DB_TEST =>
        [
            PG_VERSION_10,
        ],
    },

    # Alpine 3.21
    &VM_A321 =>
    {
        &VM_OS_BASE => VM_OS_BASE_ALPINE,
        &VM_IMAGE => 'alpine:3.21',
        &VMDEF_PG_REPO => false,
        &VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',

        &VM_DB =>
        [
            PG_VERSION_17,
        ],

        &VM_DB_TEST =>
        [
            PG_VERSION_17,
        ],
    },

    # Debian 11
    &VM_D11 =>
    {
        &VM_OS_BASE => VM_OS_BASE_DEBIAN,
        &VM_IMAGE => 'debian:11',
        &VMDEF_PG_REPO => false,
        &VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',

        &VM_DB =>
        [
            PG_VERSION_13,
        ],

        &VM_DB_TEST =>
        [
            PG_VERSION_13,
        ],
    },

    # RHEL 8
    &VM_RH8 =>
    {
        &VM_OS_BASE => VM_OS_BASE_RHEL,
        &VM_IMAGE => 'rockylinux/rockylinux:8',
        &VMDEF_PGSQL_BIN => '/usr/pgsql-{[version]}/bin',

        &VM_DB =>
        [
            PG_VERSION_14,
            PG_VERSION_15,
            PG_VERSION_16,
            PG_VERSION_17,
        ],

        &VM_DB_TEST =>
        [
            PG_VERSION_14,
            PG_VERSION_15,
            PG_VERSION_16,
            PG_VERSION_17,
        ],
    },

    # Fedora 42
    &VM_F42 =>
    {
        &VM_OS_BASE => VM_OS_BASE_RHEL,
        &VM_IMAGE => 'fedora:42',
        &VMDEF_PGSQL_BIN => '/usr/pgsql-{[version]}/bin',
        &VMDEF_COVERAGE_C => true,

        &VM_DB =>
        [
            PG_VERSION_13,
            PG_VERSION_14,
            PG_VERSION_15,
            PG_VERSION_16,
            PG_VERSION_17,
        ],

        &VM_DB_TEST =>
        [
            PG_VERSION_15,
        ],
    },

    # Ubuntu 22.04
    &VM_U22 =>
    {
        &VM_OS_BASE => VM_OS_BASE_DEBIAN,
        &VM_IMAGE => 'ubuntu:22.04',
        &VMDEF_COVERAGE_C => true,
        &VMDEF_PGSQL_BIN => '/usr/lib/postgresql/{[version]}/bin',

        &VM_DB =>
        [
            PG_VERSION_96,
            PG_VERSION_10,
            PG_VERSION_11,
            PG_VERSION_12,
            PG_VERSION_13,
            PG_VERSION_14,
            PG_VERSION_15,
            PG_VERSION_16,
            PG_VERSION_17,
            PG_VERSION_18,
        ],

        &VM_DB_TEST =>
        [
            PG_VERSION_96,
            PG_VERSION_10,
            PG_VERSION_11,
            PG_VERSION_12,
            PG_VERSION_18,
        ],
    },
};

####################################################################################################################################
# Set VM_DB_TEST to VM_DB if it is not defined so it doesn't have to be checked everywhere
####################################################################################################################################
foreach my $strVm (sort(keys(%{$oyVm})))
{
    if (!defined($oyVm->{$strVm}{&VM_DB_TEST}))
    {
        $oyVm->{$strVm}{&VM_DB_TEST} = $oyVm->{$strVm}{&VM_DB};
    }
}

####################################################################################################################################
# Verify that each version of PostgreSQL is represented in one and only one default VM
####################################################################################################################################
foreach my $strPgVersion (versionSupport())
{
    my $strVmPgVersionRun;
    my $bVmCoverageC = false;

    foreach my $strVm (VM_LIST)
    {
        if (vmCoverageC($strVm))
        {
            $bVmCoverageC = true;
        }

        foreach my $strVmPgVersion (@{$oyVm->{$strVm}{&VM_DB_TEST}})
        {
            if ($strPgVersion eq $strVmPgVersion)
            {
                if (defined($strVmPgVersionRun))
                {
                    confess &log(ASSERT, "PostgreSQL $strPgVersion is already configured to run on default vm $strVm");
                }

                $strVmPgVersionRun = $strVm;
            }
        }
    }

    my $strErrorSuffix = 'is not configured to run on a default vm';

    if (!$bVmCoverageC)
    {
        confess &log(ASSERT, "C coverage ${strErrorSuffix}");
    }

    if (!defined($strVmPgVersionRun))
    {
        confess &log(ASSERT, "PostgreSQL ${strPgVersion} ${strErrorSuffix}");
    }
}

####################################################################################################################################
# vmValid
####################################################################################################################################
sub vmValid
{
    my $strVm = shift;

    if (!defined($oyVm->{$strVm}))
    {
        confess &log(ERROR, "no definition for vm '${strVm}'");
    }
}

push @EXPORT, qw(vmValid);

####################################################################################################################################
# vmPgRepo
####################################################################################################################################
sub vmPgRepo
{
    my $strVm = shift;

    vmValid($strVm);

    if (!defined($oyVm->{$strVm}{&VMDEF_PG_REPO}))
    {
        return true;
    }

    return $oyVm->{$strVm}{&VMDEF_PG_REPO};
}

push @EXPORT, qw(vmPgRepo);

####################################################################################################################################
# vmGet
####################################################################################################################################
sub vmGet
{
    return $oyVm;
}

push @EXPORT, qw(vmGet);

####################################################################################################################################
# vmCoverageC
####################################################################################################################################
sub vmCoverageC
{
    my $strVm = shift;

    return $oyVm->{$strVm}{&VMDEF_COVERAGE_C} ? true : false;
}

push @EXPORT, qw(vmCoverageC);

####################################################################################################################################
# Get host architecture
####################################################################################################################################
my $strHostArch = undef;

sub hostArch
{
    if (!defined($strHostArch))
    {
        $strHostArch = trim(`uname -m`);

        # Mac M1 reports arm64 but we generally need aarch64 (which Linux reports)
        if ($strHostArch eq 'arm64')
        {
            $strHostArch = VM_ARCH_AARCH64;
        }
    }

    return $strHostArch;
}

push @EXPORT, qw(hostArch);

1;