File: create.py

package info (click to toggle)
aptly 1.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 49,928 kB
  • sloc: python: 10,398; sh: 252; makefile: 184
file content (535 lines) | stat: -rw-r--r-- 20,238 bytes parent folder | download | duplicates (2)
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
from pathlib import Path
import re
import os

from lib import BaseTest


class CreateMirror1Test(BaseTest):
    """
    create mirror: all architectures + all components
    """
    runCmd = "aptly mirror create --ignore-signatures mirror1 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror1", "mirror_show")


class CreateMirror2Test(BaseTest):
    """
    create mirror: all architectures and 1 component
    """
    runCmd = "aptly mirror create --ignore-signatures mirror2  http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch main"

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror2", "mirror_show")


class CreateMirror3Test(BaseTest):
    """
    create mirror: some architectures and 2 components
    """
    runCmd = "aptly -architectures=i386,amd64 mirror create --ignore-signatures mirror3 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch main contrib"

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror3", "mirror_show")


class CreateMirror4Test(BaseTest):
    """
    create mirror: missing component
    """
    expectedCode = 1

    runCmd = "aptly -architectures=i386,amd64 mirror create --ignore-signatures mirror4 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch life"


class CreateMirror5Test(BaseTest):
    """
    create mirror: missing architecture
    """
    expectedCode = 1

    runCmd = "aptly -architectures=i386,nano68 mirror create --ignore-signatures mirror5 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"


class CreateMirror6Test(BaseTest):
    """
    create mirror: missing release
    """
    expectedCode = 1
    requiresGPG2 = True

    configOverride = {"max-tries": 1}
    runCmd = "aptly mirror create --keyring=aptlytest.gpg mirror6 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ suslik"


class CreateMirror7Test(BaseTest):
    """
    create mirror: architectures fixed via config file
    """
    runCmd = "aptly mirror create --ignore-signatures mirror7 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch main contrib"
    configOverride = {"architectures": ["i386", "amd64"]}

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror7", "mirror_show")


class CreateMirror8Test(BaseTest):
    """
    create mirror: already exists
    """
    fixtureCmds = [
        "aptly mirror create --ignore-signatures mirror8 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch main contrib"
    ]
    runCmd = "aptly mirror create --ignore-signatures mirror8 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch main contrib"
    expectedCode = 1


class CreateMirror9Test(BaseTest):
    """
    create mirror: repo with InRelease verification
    """
    runCmd = "aptly mirror create --keyring=aptlytest.gpg mirror9 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch-backports"
    fixtureGpg = True
    requiresGPG2 = True

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using|Warning: using insecure memory!\n', '', s)

    def check(self):
        def removeDates(s):
            return re.sub(r"(Date|Valid-Until): [,0-9:+A-Za-z -]+\n", "", s)

        self.check_output()
        self.check_cmd_output("aptly mirror show mirror9",
                              "mirror_show", match_prepare=removeDates)


class CreateMirror10Test(BaseTest):
    """
    create mirror: repo with InRelease verification, failure
    """
    runCmd = "aptly mirror create --keyring=aptlytest.gpg mirror10 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch-backports"
    fixtureGpg = False
    gold_processor = BaseTest.expand_environ
    expectedCode = 1

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using|gpgv: keyblock resource .*$|gpgv: Can\'t check signature: .*$', '', s, flags=re.MULTILINE)


class CreateMirror11Test(BaseTest):
    """
    create mirror: repo with Release + Release.gpg verification
    """
    configOverride = {"max-tries": 1}
    runCmd = "aptly mirror create --keyring=aptlytest.gpg mirror11 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"
    fixtureGpg = True

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using', '', s)

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror11", "mirror_show")


class CreateMirror12Test(BaseTest):
    """
    create mirror: repo with Release+Release.gpg verification, failure
    """
    configOverride = {"max-tries": 1}
    runCmd = "aptly mirror create --keyring=aptlytest.gpg mirror12 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"
    fixtureGpg = False
    gold_processor = BaseTest.expand_environ
    expectedCode = 1

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using|gpgv: keyblock resource .*$|gpgv: Can\'t check signature: .*$', '', s, flags=re.MULTILINE)


class CreateMirror13Test(BaseTest):
    """
    create mirror: skip verification using config file
    """
    runCmd = "aptly mirror create mirror13 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"
    configOverride = {"gpgDisableVerify": True}

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror13", "mirror_show")


class CreateMirror14Test(BaseTest):
    """
    create mirror: flat repository
    """
    runCmd = "aptly mirror create -keyring=aptlytest.gpg mirror14  http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/debian bullseye-cran40/"
    fixtureGpg = True

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using', '', s)

    def check(self):
        def removeDates(s):
            return re.sub(r"(Date|Valid-Until): [,0-9:+A-Za-z -]+\n", "", s)

        self.check_output()
        self.check_cmd_output("aptly mirror show mirror14",
                              "mirror_show", match_prepare=removeDates)


class CreateMirror15Test(BaseTest):
    """
    create mirror: flat repository + components
    """
    runCmd = "aptly mirror create -keyring=aptlytest.gpg mirror14  http://repo.aptly.info/system-tests/cloud.r-project.org/bin/linux/debian bullseye-cran40/ main"
    expectedCode = 1


class CreateMirror16Test(BaseTest):
    """
    create mirror: there's no "source" architecture
    """
    expectedCode = 1

    runCmd = "aptly -architectures=source mirror create -ignore-signatures mirror16 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"


class CreateMirror17Test(BaseTest):
    """
    create mirror: mirror with sources enabled
    """
    runCmd = "aptly -architectures=i386 mirror create -ignore-signatures -with-sources mirror17 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror17", "mirror_show")


class CreateMirror18Test(BaseTest):
    """
    create mirror: mirror with ppa URL
    """
    fixtureGpg = True
    configOverride = {
        "max-tries": 1,
        "ppaDistributorID": "ubuntu",
        "ppaCodename": "maverick",
    }

    fixtureCmds = [
        "gpg --no-default-keyring --keyring=ppa.gpg --keyserver=hkp://keyserver.ubuntu.com:80 --recv-keys 5BFCD481D86D5824470E469F9000B1C3A01F726C 02219381E9161C78A46CB2BFA5279A973B1F56C0",
        f"chmod 400 {os.path.join(os.environ['HOME'], '.gnupg/ppa.gpg')}"
    ]
    runCmd = "aptly mirror create -keyring=ppa.gpg mirror18 ppa:gladky-anton/gnuplot"

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using', '', s)

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror18", "mirror_show")


class CreateMirror19Test(BaseTest):
    """
    create mirror: mirror with / in distribution
    """
    fixtureGpg = True

    runCmd = "aptly -architectures='i386' mirror create -keyring=aptlytest.gpg -with-sources mirror19 http://repo.aptly.info/system-tests/archive.debian.org/debian-security/ stretch/updates main"

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using', '', s)

    def check(self):
        def removeDates(s):
            return re.sub(r"(Date|Valid-Until): [,0-9:+A-Za-z -]+\n", "", s)

        self.check_output()
        self.check_cmd_output("aptly mirror show mirror19",
                              "mirror_show", match_prepare=removeDates)


class CreateMirror20Test(BaseTest):
    """
    create mirror: using failing HTTP_PROXY
    """
    fixtureGpg = True
    configOverride = {"max-tries": 1}

    runCmd = "aptly -architectures='i386' mirror create -keyring=aptlytest.gpg -with-sources mirror20 http://repo.aptly.info/system-tests/archive.debian.org/debian-security/ stretch/updates main"
    environmentOverride = {"HTTP_PROXY": "127.0.0.1:3137"}
    expectedCode = 1

    def outputMatchPrepare(self, s):
        return s.replace(
            'getsockopt: ', ''
        ).replace(
            'connect: ', ''
        ).replace(
            'proxyconnect tcp', 'http: error connecting to proxy http://127.0.0.1:3137'
        ).replace(
            'Get http://repo.aptly.info/system-tests/archive.debian.org/debian-security/dists/stretch/updates/Release:',
            'Get "http://repo.aptly.info/system-tests/archive.debian.org/debian-security/dists/stretch/updates/Release":'
        )


class CreateMirror21Test(BaseTest):
    """
    create mirror: flat repository in subdir
    """
    configOverride = {"max-tries": 1}
    runCmd = "aptly mirror create -keyring=aptlytest.gpg mirror21 http://repo.aptly.info/system-tests/pkg.jenkins.io/debian-stable binary/"
    fixtureGpg = True

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using', '', s)

    def check(self):
        def removeSHA512(s):
            return re.sub(r"SHA512: .+\n", "", s)

        def removeDates(s):
            return re.sub(r"(Date|Valid-Until): [,0-9:+A-Za-z -]+\n", "", s)

        self.check_output()
        self.check_cmd_output("aptly mirror show mirror21", "mirror_show",
                              match_prepare=lambda s: removeSHA512(removeDates(s)))


class CreateMirror22Test(BaseTest):
    """
    create mirror: mirror with filter
    """
    runCmd = "aptly mirror create -ignore-signatures -filter='nginx | Priority (required)' mirror22 http://repo.aptly.info/system-tests/archive.debian.org/debian-security/ stretch/updates main"

    def check(self):
        def removeDates(s):
            return re.sub(r"(Date|Valid-Until): [,0-9:+A-Za-z -]+\n", "", s)

        self.check_output()
        self.check_cmd_output("aptly mirror show mirror22",
                              "mirror_show", match_prepare=removeDates)


class CreateMirror23Test(BaseTest):
    """
    create mirror: mirror with wrong filter
    """
    runCmd = "aptly mirror create -ignore-signatures -filter='nginx | ' mirror23 http://repo.aptly.info/system-tests/archive.debian.org/debian-security/ stretch/updates main"
    expectedCode = 1


class CreateMirror24Test(BaseTest):
    """
    create mirror: disable config value with option
    """
    runCmd = "aptly mirror create -ignore-signatures=false -keyring=aptlytest.gpg mirror24 http://repo.aptly.info/system-tests/archive.debian.org/debian-security/ stretch/updates main"
    fixtureGpg = True

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using', '', s)

    configOverride = {
        "gpgDisableVerify": True
    }


class CreateMirror25Test(BaseTest):
    """
    create mirror: mirror with udebs enabled
    """
    runCmd = "aptly -architectures=i386 mirror create -ignore-signatures -with-udebs mirror25 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror25", "mirror_show")


class CreateMirror26Test(BaseTest):
    """
    create mirror: flat mirror with udebs
    """
    runCmd = "aptly mirror create -keyring=aptlytest.gpg -with-udebs mirror26 http://repo.aptly.info/system-tests/pkg.jenkins.io/debian-stable binary/"
    fixtureGpg = True
    expectedCode = 1


class CreateMirror27Test(BaseTest):
    """
    create mirror: component with slashes, no stripping
    """
    runCmd = "aptly mirror create --ignore-signatures mirror27 http://repo.aptly.info/system-tests/mirror.chpc.utah.edu/pub/linux.dell.com/repo/community/ubuntu wheezy openmanage/740"

    def outputMatchPrepare(self, s):
        return self.strip_retry_lines(s)

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror27", "mirror_show")


class CreateMirror29Test(BaseTest):
    """
    create mirror: repo with InRelease verification (internal GPG implementation)
    """
    fixtureCmds = ["gpg --no-default-keyring --keyring aptlytest.gpg --export-options export-minimal --export -o " + os.path.join(
                     os.environ["HOME"], ".gnupg/aptlytest-gpg1.gpg")]
    runCmd = "aptly mirror create --keyring=aptlytest-gpg1.gpg mirror9 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch-backports"
    configOverride = {"gpgProvider": "internal"}
    fixtureGpg = True

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using', '', s)

    def teardown(self):
        self.run_cmd(["rm", "-f", os.path.join(os.environ["HOME"], ".gnupg/aptlytest-gpg1.gpg")])


class CreateMirror30Test(BaseTest):
    """
    create mirror: repo with InRelease verification, failure  (internal GPG implementation)
    """
    runCmd = "aptly mirror create --keyring=aptlytest.gpg mirror10 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"
    configOverride = {"gpgProvider": "internal", "max-tries": 1}
    gold_processor = BaseTest.expand_environ
    fixtureGpg = False
    expectedCode = 1

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using', '', s)


class CreateMirror31Test(BaseTest):
    """
    create mirror: repo with Release + Release.gpg verification (internal GPG implementation)
    """
    fixtureCmds = ["gpg --no-default-keyring --keyring aptlytest.gpg --export-options export-minimal --export -o " + os.path.join(
                     os.environ["HOME"], ".gnupg/aptlytest-gpg1.gpg")]
    runCmd = "aptly mirror create --keyring=aptlytest-gpg1.gpg mirror11 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"
    configOverride = {"gpgProvider": "internal", "max-tries": 1}
    fixtureGpg = True
    faketime = True

    def outputMatchPrepare(self, s):
        return re.sub(r'Signature made .* using', '', s)

    def teardown(self):
        self.run_cmd(["rm", "-f", os.path.join(os.environ["HOME"], ".gnupg/aptlytest-gpg1.gpg")])


class CreateMirror32Test(BaseTest):
    """
    create mirror: repo with Release + Release.gpg verification (gpg2)
    """
    configOverride = {"max-tries": 1}
    runCmd = "aptly mirror create --keyring=aptlytest.gpg mirror32 http://repo.aptly.info/system-tests/archive.debian.org/debian-archive/debian/ stretch"
    fixtureGpg = True
    requiresGPG2 = True

    def outputMatchPrepare(self, s):
        return \
            re.sub(r'([A-F0-9]{8})[A-F0-9]{8}', r'\1',
                   re.sub(r'^gpgv: (Signature made .+|.+using RSA key.+)\n', '', s, flags=re.MULTILINE))

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror32", "mirror_show")


class CreateMirror33Test(BaseTest):
    """
    create mirror: repo with only InRelease file but no verification
    """
    configOverride = {"max-tries": 1}
    runCmd = "aptly mirror create -ignore-signatures mirror33 http://repo.aptly.info/system-tests/nvidia.github.io/libnvidia-container/stable/ubuntu16.04/amd64 ./"
    fixtureGpg = False
    requiresGPG2 = False

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror33", "mirror_show")


class CreateMirror34Test(BaseTest):
    """
    create mirror error: flat repo with filter but no architectures in InRelease file
    """
    configOverride = {"max-tries": 1}
    runCmd = "aptly mirror create -ignore-signatures -filter \"cuda-12-6 (= 12.6.2-1)\" -filter-with-deps mirror34 http://repo.aptly.info/system-tests/developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ ./"


class CreateMirror35Test(BaseTest):
    """
    create mirror: flat repo with filter but no architectures in InRelease file
    """
    configOverride = {"max-tries": 1}
    fixtureCmds = [
        "aptly mirror create -architectures amd64 -ignore-signatures -filter \"cuda-12-6 (= 12.6.2-1)\" -filter-with-deps mirror35 "
        "http://repo.aptly.info/system-tests/developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ ./",
    ]
    runCmd = "aptly mirror update -ignore-signatures mirror35"

    # the downloading of the actual packages will return 404 since they don't exist. ignore the errors, the test verifies proper count of filtered packages

    def outputMatchPrepare(self, s):
        s = re.sub(r'Downloading: .*\n', '', s, flags=re.MULTILINE)
        s = re.sub(r'Download Error: .*\n', '', s, flags=re.MULTILINE)
        s = re.sub(r'Retrying .*\n', '', s, flags=re.MULTILINE)
        s = re.sub(r'Error \(retrying\): .*\n', '', s, flags=re.MULTILINE)
        s = re.sub(r'HTTP code 404 while fetching .*\n', '', s, flags=re.MULTILINE)
        s = re.sub(r'ERROR: unable to update: .*\n', '', s, flags=re.MULTILINE)
        return s

    def check(self):
        self.check_output()
        self.check_cmd_output("aptly mirror show mirror35", "mirror_show")


class CreateMirror36Test(BaseTest):
    """
    create mirror: mirror with filter read from file
    """
    filterFilePath = os.path.join(os.environ["HOME"], ".aptly-filter.tmp")
    fixtureCmds = [f"bash -c \"echo -n 'nginx | Priority (required)' > {filterFilePath}\""]
    runCmd = f"aptly mirror create -ignore-signatures -filter='@{filterFilePath}' mirror36 http://repo.aptly.info/system-tests/archive.debian.org/debian-security/ stretch/updates main"

    def check(self):
        def removeDates(s):
            return re.sub(r"(Date|Valid-Until): [,0-9:+A-Za-z -]+\n", "", s)

        self.check_output()
        self.check_cmd_output("aptly mirror show mirror36",
                              "mirror_show", match_prepare=removeDates)


class CreateMirror37Test(BaseTest):
    """
    create mirror: mirror with filter read from stdin
    """
    aptly_testing_bin = Path(__file__).parent.parent.parent / "aptly.test"
    # Hack: Normally the test system detects if runCmd is an aptly command and then
    # substitutes the aptly_testing_bin path and deletes the last three lines of output.
    # However, I need to run it in bash to control stdin, so I have to do it manually.
    runCmd = [
        "bash",
        "-c",
        f"echo -n 'nginx | Priority (required)' | {aptly_testing_bin} mirror create " +
        "-ignore-signatures -filter='@-' mirror37 http://repo.aptly.info/system-tests/archive.debian.org/debian-security/ stretch/updates main " +
        "| grep -vE '^(EXIT|PASS|coverage:)'"
    ]

    def check(self):
        def removeDates(s):
            return re.sub(r"(Date|Valid-Until): [,0-9:+A-Za-z -]+\n", "", s)

        self.check_output()
        self.check_cmd_output("aptly mirror show mirror37",
                              "mirror_show", match_prepare=removeDates)