/
snapshot.py
928 lines (757 loc) · 39.8 KB
/
snapshot.py
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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
import os
import hashlib
import inspect
from lib import BaseTest
def strip_processor(output):
return "\n".join([l for l in output.split("\n") if not l.startswith(' ') and not l.startswith('Date:')])
def sorted_processor(output):
return "\n".join(sorted(output.split("\n")))
class PublishSnapshot1Test(BaseTest):
"""
publish snapshot: defaults
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap1 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap1"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot1Test, self).check()
self.check_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
self.check_exists('public/dists/maverick/Release.gpg')
self.check_exists('public/dists/maverick/main/binary-i386/Release')
self.check_exists('public/dists/maverick/main/binary-i386/Packages')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.bz2')
self.check_exists('public/dists/maverick/main/binary-amd64/Release')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.bz2')
self.check_not_exists('public/dists/maverick/main/debian-installer/binary-i386/Packages')
self.check_not_exists('public/dists/maverick/main/debian-installer/binary-amd64/Packages')
self.check_exists('public/pool/main/g/gnuplot/gnuplot-doc_4.6.1-1~maverick2_all.deb')
# verify contents except of sums
self.check_file_contents('public/dists/maverick/Release', 'release', match_prepare=strip_processor)
self.check_file_contents('public/dists/maverick/main/binary-i386/Release', 'release_i386')
self.check_file_contents('public/dists/maverick/main/binary-amd64/Release', 'release_amd64')
self.check_file_contents('public/dists/maverick/main/binary-i386/Packages', 'packages_i386', match_prepare=sorted_processor)
self.check_file_contents('public/dists/maverick/main/binary-amd64/Packages', 'packages_amd64', match_prepare=sorted_processor)
# verify signatures
self.run_cmd(["gpg", "--no-auto-check-trustdb", "--keyring", os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files", "aptly.pub"),
"--verify", os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/InRelease')])
self.run_cmd(["gpg", "--no-auto-check-trustdb", "--keyring", os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files", "aptly.pub"),
"--verify", os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/Release.gpg'),
os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/Release')])
# verify sums
release = self.read_file('public/dists/maverick/Release').split("\n")
release = [l for l in release if l.startswith(" ")]
pathsSeen = set()
for l in release:
fileHash, fileSize, path = l.split()
pathsSeen.add(path)
fileSize = int(fileSize)
st = os.stat(os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/', path))
if fileSize != st.st_size:
raise Exception("file size doesn't match for %s: %d != %d" % (path, fileSize, st.st_size))
if len(fileHash) == 32:
h = hashlib.md5()
elif len(fileHash) == 40:
h = hashlib.sha1()
else:
h = hashlib.sha256()
h.update(self.read_file(os.path.join('public/dists/maverick', path)))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (path, fileHash, h.hexdigest()))
if pathsSeen != set(['main/binary-amd64/Packages', 'main/binary-i386/Packages', 'main/binary-i386/Packages.gz',
'main/binary-amd64/Packages.gz', 'main/binary-amd64/Packages.bz2', 'main/binary-i386/Packages.bz2',
'main/binary-amd64/Release', 'main/binary-i386/Release']):
raise Exception("path seen wrong: %r" % (pathsSeen, ))
class PublishSnapshot2Test(BaseTest):
"""
publish snapshot: different distribution
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap2 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=squeeze snap2"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot2Test, self).check()
self.check_exists('public/dists/squeeze/InRelease')
self.check_exists('public/dists/squeeze/Release')
self.check_exists('public/dists/squeeze/Release.gpg')
self.check_exists('public/dists/squeeze/main/binary-i386/Packages')
self.check_exists('public/dists/squeeze/main/binary-i386/Packages.gz')
self.check_exists('public/dists/squeeze/main/binary-i386/Packages.bz2')
self.check_exists('public/dists/squeeze/main/binary-amd64/Packages')
self.check_exists('public/dists/squeeze/main/binary-amd64/Packages.gz')
self.check_exists('public/dists/squeeze/main/binary-amd64/Packages.bz2')
self.check_exists('public/pool/main/g/gnuplot/gnuplot-doc_4.6.1-1~maverick2_all.deb')
# verify contents except of sums
self.check_file_contents('public/dists/squeeze/Release', 'release', match_prepare=strip_processor)
class PublishSnapshot3Test(BaseTest):
"""
publish snapshot: different distribution and component
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap3 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=squeeze -component=contrib snap3"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot3Test, self).check()
self.check_exists('public/dists/squeeze/InRelease')
self.check_exists('public/dists/squeeze/Release')
self.check_exists('public/dists/squeeze/Release.gpg')
self.check_exists('public/dists/squeeze/contrib/binary-i386/Packages')
self.check_exists('public/dists/squeeze/contrib/binary-i386/Packages.gz')
self.check_exists('public/dists/squeeze/contrib/binary-i386/Packages.bz2')
self.check_exists('public/dists/squeeze/contrib/binary-amd64/Packages')
self.check_exists('public/dists/squeeze/contrib/binary-amd64/Packages.gz')
self.check_exists('public/dists/squeeze/contrib/binary-amd64/Packages.bz2')
self.check_exists('public/pool/contrib/g/gnuplot/gnuplot-doc_4.6.1-1~maverick2_all.deb')
# verify contents except of sums
self.check_file_contents('public/dists/squeeze/Release', 'release', match_prepare=strip_processor)
class PublishSnapshot4Test(BaseTest):
"""
publish snapshot: limit architectures
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap4 from mirror gnuplot-maverick",
]
runCmd = "aptly -architectures=i386 publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=squeeze snap4"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot4Test, self).check()
self.check_exists('public/dists/squeeze/InRelease')
self.check_exists('public/dists/squeeze/Release')
self.check_exists('public/dists/squeeze/Release.gpg')
self.check_exists('public/dists/squeeze/main/binary-i386/Packages')
self.check_exists('public/dists/squeeze/main/binary-i386/Packages.gz')
self.check_exists('public/dists/squeeze/main/binary-i386/Packages.bz2')
self.check_not_exists('public/dists/squeeze/main/binary-amd64/Packages')
self.check_not_exists('public/dists/squeeze/main/binary-amd64/Packages.gz')
self.check_not_exists('public/dists/squeeze/main/binary-amd64/Packages.bz2')
self.check_exists('public/pool/main/g/gnuplot/gnuplot-doc_4.6.1-1~maverick2_all.deb')
# verify contents except of sums
self.check_file_contents('public/dists/squeeze/Release', 'release', match_prepare=strip_processor)
class PublishSnapshot5Test(BaseTest):
"""
publish snapshot: under prefix
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap5 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=squeeze snap5 ppa/smira"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot5Test, self).check()
self.check_exists('public/ppa/smira/dists/squeeze/InRelease')
self.check_exists('public/ppa/smira/dists/squeeze/Release')
self.check_exists('public/ppa/smira/dists/squeeze/Release.gpg')
self.check_exists('public/ppa/smira/dists/squeeze/main/binary-i386/Packages')
self.check_exists('public/ppa/smira/dists/squeeze/main/binary-i386/Packages.gz')
self.check_exists('public/ppa/smira/dists/squeeze/main/binary-i386/Packages.bz2')
self.check_exists('public/ppa/smira/dists/squeeze/main/binary-amd64/Packages')
self.check_exists('public/ppa/smira/dists/squeeze/main/binary-amd64/Packages.gz')
self.check_exists('public/ppa/smira/dists/squeeze/main/binary-amd64/Packages.bz2')
self.check_exists('public/ppa/smira/pool/main/g/gnuplot/gnuplot-doc_4.6.1-1~maverick2_all.deb')
class PublishSnapshot6Test(BaseTest):
"""
publish snapshot: specify distribution
"""
fixtureDB = True
fixtureCmds = [
"aptly snapshot create snap from mirror gnuplot-maverick",
"aptly snapshot create snap2 from mirror wheezy-main",
"aptly snapshot merge snap6 snap2 snap"
]
runCmd = "aptly publish snapshot snap6"
expectedCode = 1
class PublishSnapshot7Test(BaseTest):
"""
publish snapshot: double publish under root
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap7 from mirror gnuplot-maverick",
"aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap7",
]
runCmd = "aptly publish snapshot snap7"
expectedCode = 1
class PublishSnapshot8Test(BaseTest):
"""
publish snapshot: double publish under prefix
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap8 from mirror gnuplot-maverick",
"aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap8 ./ppa",
]
runCmd = "aptly publish snapshot snap8 ppa"
expectedCode = 1
class PublishSnapshot9Test(BaseTest):
"""
publish snapshot: wrong prefix
"""
fixtureDB = True
fixtureCmds = [
"aptly snapshot create snap9 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot snap9 ppa/dists/la"
expectedCode = 1
class PublishSnapshot10Test(BaseTest):
"""
publish snapshot: wrong prefix
"""
fixtureDB = True
fixtureCmds = [
"aptly snapshot create snap10 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot snap10 ppa/pool/la"
expectedCode = 1
class PublishSnapshot11Test(BaseTest):
"""
publish snapshot: wrong prefix
"""
fixtureDB = True
fixtureCmds = [
"aptly snapshot create snap11 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot snap11 ../la"
expectedCode = 1
class PublishSnapshot12Test(BaseTest):
"""
publish snapshot: no snapshot
"""
fixtureDB = True
runCmd = "aptly publish snapshot snap12"
expectedCode = 1
class PublishSnapshot13Test(BaseTest):
"""
publish snapshot: -skip-signing
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap13 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot -skip-signing snap13"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot13Test, self).check()
self.check_not_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
self.check_not_exists('public/dists/maverick/Release.gpg')
self.check_exists('public/dists/maverick/main/binary-i386/Packages')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.bz2')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.bz2')
# verify contents except of sums
self.check_file_contents('public/dists/maverick/Release', 'release', match_prepare=strip_processor)
class PublishSnapshot14Test(BaseTest):
"""
publish snapshot: empty snapshot is not publishable w/o architectures list
"""
fixtureDB = True
fixtureCmds = [
"aptly snapshot create snap14 empty",
]
runCmd = "aptly publish snapshot --distribution=mars --skip-signing snap14"
expectedCode = 1
class PublishSnapshot15Test(BaseTest):
"""
publish snapshot: skip signing via config
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap15 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot snap15"
configOverride = {"gpgDisableSign": True}
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot15Test, self).check()
self.check_not_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
self.check_not_exists('public/dists/maverick/Release.gpg')
self.check_exists('public/dists/maverick/main/binary-i386/Packages')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.bz2')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.bz2')
# verify contents except of sums
self.check_file_contents('public/dists/maverick/Release', 'release', match_prepare=strip_processor)
class PublishSnapshot16Test(BaseTest):
"""
publish snapshot: with sources
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap16 from mirror gnuplot-maverick-src",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap16"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot16Test, self).check()
self.check_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
self.check_exists('public/dists/maverick/Release.gpg')
self.check_exists('public/dists/maverick/main/binary-i386/Packages')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.bz2')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.bz2')
self.check_exists('public/dists/maverick/main/source/Sources')
self.check_exists('public/dists/maverick/main/source/Sources.gz')
self.check_exists('public/dists/maverick/main/source/Sources.bz2')
self.check_exists('public/pool/main/g/gnuplot/gnuplot-doc_4.6.1-1~maverick2_all.deb')
self.check_exists('public/pool/main/g/gnuplot/gnuplot_4.6.1-1~maverick2.debian.tar.gz')
self.check_exists('public/pool/main/g/gnuplot/gnuplot_4.6.1-1~maverick2.dsc')
self.check_exists('public/pool/main/g/gnuplot/gnuplot_4.6.1.orig.tar.gz')
# verify contents except of sums
self.check_file_contents('public/dists/maverick/Release', 'release', match_prepare=strip_processor)
self.check_file_contents('public/dists/maverick/main/source/Sources', 'sources', match_prepare=lambda s: "\n".join(sorted(s.split("\n"))))
# verify signatures
self.run_cmd(["gpg", "--no-auto-check-trustdb", "--keyring", os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files", "aptly.pub"),
"--verify", os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/InRelease')])
self.run_cmd(["gpg", "--no-auto-check-trustdb", "--keyring", os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files", "aptly.pub"),
"--verify", os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/Release.gpg'),
os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/Release')])
class PublishSnapshot17Test(BaseTest):
"""
publish snapshot: from local repo
"""
fixtureCmds = [
"aptly repo create local-repo",
"aptly repo add local-repo ${files}",
"aptly snapshot create snap17 from repo local-repo",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=maverick snap17"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot17Test, self).check()
self.check_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
self.check_exists('public/dists/maverick/Release.gpg')
self.check_exists('public/dists/maverick/main/binary-i386/Packages')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.bz2')
self.check_exists('public/dists/maverick/main/source/Sources')
self.check_exists('public/dists/maverick/main/source/Sources.gz')
self.check_exists('public/dists/maverick/main/source/Sources.bz2')
self.check_exists('public/pool/main/p/pyspi/pyspi_0.6.1-1.3.dsc')
self.check_exists('public/pool/main/p/pyspi/pyspi_0.6.1-1.3.diff.gz')
self.check_exists('public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz')
self.check_exists('public/pool/main/p/pyspi/pyspi-0.6.1-1.3.stripped.dsc')
self.check_exists('public/pool/main/b/boost-defaults/libboost-program-options-dev_1.49.0.1_i386.deb')
# verify contents except of sums
self.check_file_contents('public/dists/maverick/Release', 'release', match_prepare=strip_processor)
self.check_file_contents('public/dists/maverick/main/source/Sources', 'sources', match_prepare=lambda s: "\n".join(sorted(s.split("\n"))))
self.check_file_contents('public/dists/maverick/main/binary-i386/Packages', 'binary', match_prepare=lambda s: "\n".join(sorted(s.split("\n"))))
# verify signatures
self.run_cmd(["gpg", "--no-auto-check-trustdb", "--keyring", os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files", "aptly.pub"),
"--verify", os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/InRelease')])
self.run_cmd(["gpg", "--no-auto-check-trustdb", "--keyring", os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files", "aptly.pub"),
"--verify", os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/Release.gpg'),
os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/Release')])
class PublishSnapshot18Test(BaseTest):
"""
publish snapshot: specify distribution from local repo
"""
fixtureCmds = [
"aptly repo create repo1",
"aptly repo add repo1 ${files}",
"aptly snapshot create snap1 from repo repo1",
]
runCmd = "aptly publish snapshot snap1"
expectedCode = 1
class PublishSnapshot19Test(BaseTest):
"""
publish snapshot: guess distribution from long chain
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap1 from mirror gnuplot-maverick",
"aptly snapshot create snap2 from mirror gnuplot-maverick",
"aptly snapshot create snap3 from mirror gnuplot-maverick",
"aptly snapshot merge snap4 snap1 snap2",
"aptly snapshot pull snap4 snap1 snap5 gnuplot",
]
runCmd = "aptly publish snapshot -skip-signing snap5"
gold_processor = BaseTest.expand_environ
class PublishSnapshot20Test(BaseTest):
"""
publish snapshot: guess distribution from long chain including local repo
"""
fixtureDB = True
fixturePoolCopy = True
fixtureCmds = [
"aptly snapshot create snap1 from mirror gnuplot-maverick",
"aptly repo create -distribution=maverick local-repo",
"aptly repo add local-repo ${files}",
"aptly snapshot create snap2 from repo local-repo",
"aptly snapshot merge snap3 snap1 snap2",
]
runCmd = "aptly publish snapshot -skip-signing snap3"
gold_processor = BaseTest.expand_environ
class PublishSnapshot21Test(BaseTest):
"""
publish snapshot: conflict in distributions
"""
fixtureDB = True
fixturePoolCopy = True
fixtureCmds = [
"aptly snapshot create snap1 from mirror gnuplot-maverick",
"aptly repo create -distribution=squeeze local-repo",
"aptly repo add local-repo ${files}",
"aptly snapshot create snap2 from repo local-repo",
"aptly snapshot merge snap3 snap1 snap2",
]
runCmd = "aptly publish snapshot -skip-signing snap3"
gold_processor = BaseTest.expand_environ
expectedCode = 1
class PublishSnapshot22Test(BaseTest):
"""
publish snapshot: conflict in components
"""
fixtureDB = True
fixturePoolCopy = True
fixtureCmds = [
"aptly snapshot create snap1 from mirror gnuplot-maverick",
"aptly repo create -component=contrib -distribution=maverick local-repo",
"aptly repo add local-repo ${files}",
"aptly snapshot create snap2 from repo local-repo",
"aptly snapshot merge snap3 snap1 snap2",
]
runCmd = "aptly publish snapshot -skip-signing snap3"
gold_processor = BaseTest.expand_environ
class PublishSnapshot23Test(BaseTest):
"""
publish snapshot: distribution empty plus distribution maverick
"""
fixtureDB = True
fixturePoolCopy = True
fixtureCmds = [
"aptly snapshot create snap1 from mirror gnuplot-maverick",
"aptly repo create local-repo",
"aptly repo add local-repo ${files}",
"aptly snapshot create snap2 from repo local-repo",
"aptly snapshot merge snap3 snap1 snap2",
]
runCmd = "aptly publish snapshot -skip-signing snap3"
gold_processor = BaseTest.expand_environ
class PublishSnapshot24Test(BaseTest):
"""
publish snapshot: custom origin
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap24 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=squeeze -origin=aptly24 snap24"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot24Test, self).check()
# verify contents except of sums
self.check_file_contents('public/dists/squeeze/Release', 'release', match_prepare=strip_processor)
class PublishSnapshot25Test(BaseTest):
"""
publish snapshot: empty snapshot is publishable with architectures list
"""
fixtureDB = True
fixtureCmds = [
"aptly snapshot create snap25 empty",
]
runCmd = "aptly publish snapshot -architectures=amd64 --distribution=maverick -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec snap25"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot25Test, self).check()
self.check_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
self.check_exists('public/dists/maverick/Release.gpg')
self.check_not_exists('public/dists/maverick/main/binary-i386/Packages')
self.check_not_exists('public/dists/maverick/main/binary-i386/Packages.gz')
self.check_not_exists('public/dists/maverick/main/binary-i386/Packages.bz2')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.bz2')
class PublishSnapshot26Test(BaseTest):
"""
publish snapshot: multiple component
"""
fixtureDB = True
fixturePoolCopy = True
fixtureCmds = [
"aptly snapshot create snap26.1 from mirror gnuplot-maverick",
"aptly repo create local-repo",
"aptly repo add local-repo ${files}",
"aptly snapshot create snap26.2 from repo local-repo",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -component=main,contrib snap26.1 snap26.2"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot26Test, self).check()
self.check_exists('public/dists/maverick/InRelease')
self.check_exists('public/dists/maverick/Release')
self.check_exists('public/dists/maverick/Release.gpg')
self.check_exists('public/dists/maverick/main/binary-i386/Packages')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-i386/Packages.bz2')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.gz')
self.check_exists('public/dists/maverick/main/binary-amd64/Packages.bz2')
self.check_exists('public/dists/maverick/main/source/Sources')
self.check_exists('public/dists/maverick/main/source/Sources.gz')
self.check_exists('public/dists/maverick/main/source/Sources.bz2')
self.check_exists('public/dists/maverick/contrib/binary-i386/Packages')
self.check_exists('public/dists/maverick/contrib/binary-i386/Packages.gz')
self.check_exists('public/dists/maverick/contrib/binary-i386/Packages.bz2')
self.check_exists('public/dists/maverick/contrib/binary-amd64/Packages')
self.check_exists('public/dists/maverick/contrib/binary-amd64/Packages.gz')
self.check_exists('public/dists/maverick/contrib/binary-amd64/Packages.bz2')
self.check_exists('public/dists/maverick/contrib/source/Sources')
self.check_exists('public/dists/maverick/contrib/source/Sources.gz')
self.check_exists('public/dists/maverick/contrib/source/Sources.bz2')
self.check_exists('public/pool/main/g/gnuplot/gnuplot-doc_4.6.1-1~maverick2_all.deb')
self.check_exists('public/pool/contrib/p/pyspi/pyspi_0.6.1-1.3.dsc')
self.check_exists('public/pool/contrib/p/pyspi/pyspi_0.6.1-1.3.diff.gz')
self.check_exists('public/pool/contrib/p/pyspi/pyspi_0.6.1.orig.tar.gz')
self.check_exists('public/pool/contrib/p/pyspi/pyspi-0.6.1-1.3.stripped.dsc')
self.check_exists('public/pool/contrib/b/boost-defaults/libboost-program-options-dev_1.49.0.1_i386.deb')
# verify contents except of sums
self.check_file_contents('public/dists/maverick/Release', 'release', match_prepare=strip_processor)
# verify signatures
self.run_cmd(["gpg", "--no-auto-check-trustdb", "--keyring", os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files", "aptly.pub"),
"--verify", os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/InRelease')])
self.run_cmd(["gpg", "--no-auto-check-trustdb", "--keyring", os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files", "aptly.pub"),
"--verify", os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/Release.gpg'),
os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/Release')])
# verify sums
release = self.read_file('public/dists/maverick/Release').split("\n")
release = [l for l in release if l.startswith(" ")]
pathsSeen = set()
for l in release:
fileHash, fileSize, path = l.split()
pathsSeen.add(path)
fileSize = int(fileSize)
st = os.stat(os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/', path))
if fileSize != st.st_size:
raise Exception("file size doesn't match for %s: %d != %d" % (path, fileSize, st.st_size))
if len(fileHash) == 32:
h = hashlib.md5()
elif len(fileHash) == 40:
h = hashlib.sha1()
else:
h = hashlib.sha256()
h.update(self.read_file(os.path.join('public/dists/maverick', path)))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (path, fileHash, h.hexdigest()))
if pathsSeen != set(['main/binary-amd64/Packages', 'main/binary-i386/Packages', 'main/binary-i386/Packages.gz',
'main/binary-amd64/Packages.gz', 'main/binary-amd64/Packages.bz2', 'main/binary-i386/Packages.bz2',
'main/source/Sources', 'main/source/Sources.gz', 'main/source/Sources.bz2',
'contrib/binary-amd64/Packages', 'contrib/binary-i386/Packages', 'contrib/binary-i386/Packages.gz',
'contrib/binary-amd64/Packages.gz', 'contrib/binary-amd64/Packages.bz2', 'contrib/binary-i386/Packages.bz2',
'contrib/source/Sources', 'contrib/source/Sources.gz', 'contrib/source/Sources.bz2',
'main/binary-amd64/Release', 'main/binary-i386/Release', 'main/source/Release',
'contrib/binary-amd64/Release', 'contrib/binary-i386/Release', 'contrib/source/Release']):
raise Exception("path seen wrong: %r" % (pathsSeen, ))
class PublishSnapshot27Test(BaseTest):
"""
publish snapshot: multiple component, guessing component names
"""
fixtureDB = True
fixturePoolCopy = True
fixtureCmds = [
"aptly snapshot create snap27.1 from mirror gnuplot-maverick",
"aptly repo create -component=contrib local-repo",
"aptly repo add local-repo ${files}",
"aptly snapshot create snap27.2 from repo local-repo",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -component=, snap27.1 snap27.2"
gold_processor = BaseTest.expand_environ
class PublishSnapshot28Test(BaseTest):
"""
publish snapshot: duplicate component name (guessed)
"""
fixtureDB = True
fixtureCmds = [
"aptly snapshot create snap28.1 from mirror gnuplot-maverick",
"aptly repo create local-repo",
"aptly repo add local-repo ${files}",
"aptly snapshot create snap28.2 from repo local-repo",
]
runCmd = "aptly publish snapshot -component=, snap28.1 snap28.2"
expectedCode = 1
class PublishSnapshot29Test(BaseTest):
"""
publish snapshot: duplicate component name (manual)
"""
fixtureCmds = [
"aptly snapshot create snap29.1 empty",
"aptly snapshot create snap29.2 empty",
]
runCmd = "aptly publish snapshot -component=b,b snap29.1 snap29.2"
expectedCode = 1
class PublishSnapshot30Test(BaseTest):
"""
publish snapshot: distribution conflict
"""
fixtureDB = True
fixtureCmds = [
"aptly snapshot create snap30.1 from mirror gnuplot-maverick",
"aptly repo create -distribution=squeeze local-repo",
"aptly repo add local-repo ${files}",
"aptly snapshot create snap30.2 from repo local-repo",
]
runCmd = "aptly publish snapshot -component=main,contrib snap30.1 snap30.2"
expectedCode = 1
class PublishSnapshot31Test(BaseTest):
"""
publish snapshot: no such snapshot
"""
fixtureCmds = [
"aptly snapshot create snap31.1 empty",
]
runCmd = "aptly publish snapshot -component=main,contrib snap31.1 snap31.2"
expectedCode = 1
class PublishSnapshot32Test(BaseTest):
"""
publish snapshot: mismatch in count
"""
fixtureCmds = [
"aptly snapshot create snap32.1 empty",
]
runCmd = "aptly publish snapshot -component=main,contrib snap32.1"
expectedCode = 2
outputMatchPrepare = lambda _, s: "\n".join([l for l in s.split("\n") if l.startswith("ERROR")])
class PublishSnapshot33Test(BaseTest):
"""
publish snapshot: conflicting files in the snapshot
"""
fixtureCmds = [
"aptly repo create local-repo1",
"aptly repo add local-repo1 ${files}",
"aptly snapshot create snap1 from repo local-repo1",
"aptly repo create local-repo2",
"aptly repo add local-repo2 ${testfiles}",
"aptly snapshot create snap2 from repo local-repo2",
"aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=maverick snap1",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=squeeze snap2"
expectedCode = 1
gold_processor = BaseTest.expand_environ
class PublishSnapshot34Test(BaseTest):
"""
publish snapshot: -force-overwrite
"""
fixtureCmds = [
"aptly repo create local-repo1",
"aptly repo add local-repo1 ${files}",
"aptly snapshot create snap1 from repo local-repo1",
"aptly repo create local-repo2",
"aptly repo add local-repo2 ${testfiles}",
"aptly snapshot create snap2 from repo local-repo2",
"aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=maverick snap1",
]
runCmd = "aptly publish snapshot -force-overwrite -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=squeeze snap2"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot34Test, self).check()
self.check_file_contents("public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz", "file")
class PublishSnapshot35Test(BaseTest):
"""
publish snapshot: mirror with udebs
"""
fixtureGpg = True
fixtureCmds = [
"aptly -architectures=i386,amd64 mirror create -keyring=aptlytest.gpg -filter='$$Source (dmraid)' -with-udebs squeeze http://mirror.yandex.ru/debian/ squeeze main non-free",
"aptly mirror update -keyring=aptlytest.gpg squeeze",
"aptly snapshot create squeeze from mirror squeeze",
]
runCmd = "aptly publish snapshot -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec squeeze"
gold_processor = BaseTest.expand_environ
def check(self):
super(PublishSnapshot35Test, self).check()
self.check_exists('public/dists/squeeze/InRelease')
self.check_exists('public/dists/squeeze/Release')
self.check_exists('public/dists/squeeze/Release.gpg')
self.check_exists('public/dists/squeeze/main/binary-i386/Release')
self.check_exists('public/dists/squeeze/main/binary-i386/Packages')
self.check_exists('public/dists/squeeze/main/binary-i386/Packages.gz')
self.check_exists('public/dists/squeeze/main/binary-i386/Packages.bz2')
self.check_exists('public/dists/squeeze/main/debian-installer/binary-i386/Release')
self.check_exists('public/dists/squeeze/main/debian-installer/binary-i386/Packages')
self.check_exists('public/dists/squeeze/main/debian-installer/binary-i386/Packages.gz')
self.check_exists('public/dists/squeeze/main/debian-installer/binary-i386/Packages.bz2')
self.check_exists('public/dists/squeeze/main/binary-amd64/Release')
self.check_exists('public/dists/squeeze/main/binary-amd64/Packages')
self.check_exists('public/dists/squeeze/main/binary-amd64/Packages.gz')
self.check_exists('public/dists/squeeze/main/binary-amd64/Packages.bz2')
self.check_exists('public/dists/squeeze/main/debian-installer/binary-amd64/Release')
self.check_exists('public/dists/squeeze/main/debian-installer/binary-amd64/Packages')
self.check_exists('public/dists/squeeze/main/debian-installer/binary-amd64/Packages.gz')
self.check_exists('public/dists/squeeze/main/debian-installer/binary-amd64/Packages.bz2')
self.check_not_exists('public/dists/squeeze/main/source/Sources')
self.check_not_exists('public/dists/squeeze/main/source/Sources.gz')
self.check_not_exists('public/dists/squeeze/main/source/Sources.bz2')
self.check_exists('public/pool/main/d/dmraid/dmraid-udeb_1.0.0.rc16-4.1_amd64.udeb')
self.check_exists('public/pool/main/d/dmraid/dmraid-udeb_1.0.0.rc16-4.1_i386.udeb')
self.check_exists('public/pool/main/d/dmraid/dmraid_1.0.0.rc16-4.1_amd64.deb')
self.check_exists('public/pool/main/d/dmraid/dmraid_1.0.0.rc16-4.1_i386.deb')
self.check_file_contents('public/dists/squeeze/main/binary-i386/Packages', 'packages_i386', match_prepare=sorted_processor)
self.check_file_contents('public/dists/squeeze/main/debian-installer/binary-i386/Packages', 'packages_udeb_i386', match_prepare=sorted_processor)
self.check_file_contents('public/dists/squeeze/main/binary-amd64/Packages', 'packages_amd64', match_prepare=sorted_processor)
self.check_file_contents('public/dists/squeeze/main/debian-installer/binary-amd64/Packages', 'packages_udeb_amd64', match_prepare=sorted_processor)
# verify contents except of sums
self.check_file_contents('public/dists/squeeze/Release', 'release', match_prepare=strip_processor)
self.check_file_contents('public/dists/squeeze/main/debian-installer/binary-i386/Release', 'release_udeb_i386', match_prepare=strip_processor)
# verify sums
release = self.read_file('public/dists/squeeze/Release').split("\n")
release = [l for l in release if l.startswith(" ")]
pathsSeen = set()
for l in release:
fileHash, fileSize, path = l.split()
pathsSeen.add(path)
fileSize = int(fileSize)
st = os.stat(os.path.join(os.environ["HOME"], ".aptly", 'public/dists/squeeze/', path))
if fileSize != st.st_size:
raise Exception("file size doesn't match for %s: %d != %d" % (path, fileSize, st.st_size))
if len(fileHash) == 32:
h = hashlib.md5()
elif len(fileHash) == 40:
h = hashlib.sha1()
else:
h = hashlib.sha256()
h.update(self.read_file(os.path.join('public/dists/squeeze', path)))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (path, fileHash, h.hexdigest()))
pathsExepcted = set()
for arch in ("i386", "amd64"):
for udeb in ("", "debian-installer/"):
for ext in ("", ".gz", ".bz2"):
pathsExepcted.add("main/%sbinary-%s/Packages%s" % (udeb, arch, ext))
pathsExepcted.add("main/%sbinary-%s/Release" % (udeb, arch))
if pathsSeen != pathsExepcted:
raise Exception("path seen wrong: %r != %r" % (pathsSeen, pathsExepcted))