System tests for aptly publish snapshot.

This commit is contained in:
Andrey Smirnov
2014-01-31 19:04:44 +04:00
parent 5bd0546fb7
commit 59d72c8112
20 changed files with 408 additions and 5 deletions

View File

@@ -80,7 +80,9 @@ class BaseTest(object):
def run_cmd(self, command, expected_code=0):
try:
proc = subprocess.Popen(shlex.split(command), stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
if not hasattr(command, "__iter__"):
command = shlex.split(command)
proc = subprocess.Popen(command, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
output, _ = proc.communicate()
if proc.returncode != expected_code:
raise Exception("exit code %d != %d (output: %s)" % (proc.returncode, expected_code, output))
@@ -107,6 +109,23 @@ class BaseTest(object):
def check_cmd_output(self, command, gold_name, match_prepare=None, expected_code=0):
self.verify_match(self.get_gold(gold_name), self.run_cmd(command, expected_code=expected_code), match_prepare)
def read_file(self, path):
with open(os.path.join(os.environ["HOME"], ".aptly", path), "r") as f:
return f.read()
def check_file(self, path, gold_name, match_prepare=None):
contents = self.read_file(path)
self.verify_match(self.get_gold(gold_name), contents, match_prepare=match_prepare)
def check_exists(self, path):
if not os.path.exists(os.path.join(os.environ["HOME"], ".aptly", path)):
raise Exception("path %s doesn't exist" % (path, ))
def check_not_exists(self, path):
if os.path.exists(os.path.join(os.environ["HOME"], ".aptly", path)):
raise Exception("path %s exists" % (path, ))
def verify_match(self, a, b, match_prepare=None):
if match_prepare is not None:
a = match_prepare(a)
@@ -117,9 +136,6 @@ class BaseTest(object):
raise Exception("content doesn't match:\n" + diff + "\n")
def check_file(self):
self.verify_match(self.get_gold(), open(self.checkedFile, "r").read())
check = check_output
def prepare(self):

View File

@@ -19,7 +19,7 @@ def run(include_long_tests=False):
"""
Run system test.
"""
tests = glob.glob("t*_*")
tests = ["t06_publish"]#glob.glob("t*_*")
fails = []
numTests = numFailed = numSkipped = 0

View File

@@ -0,0 +1 @@
ERROR: unable to publish: invalid prefix ppa/pool/la

View File

@@ -0,0 +1 @@
ERROR: unable to publish: invalid prefix ../la

View File

@@ -0,0 +1 @@
ERROR: unable to publish: snapshot with name snap12 not found

View File

@@ -0,0 +1,10 @@
Signing file '${HOME}/.aptly/public/dists/maverick/Release' with gpg, please enter your passphrase when prompted:
Clearsigning file '${HOME}/.aptly/public/dists/maverick/Release' with gpg, please enter your passphrase when prompted:
Snapshot snap1 has been successfully published.
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
deb http://your-server/ maverick main
Don't forget to add your GPG key to apt with apt-key.
You can also use `aptly serve` to publish your repositories over HTTP quickly.

View File

@@ -0,0 +1,10 @@
Origin: . maverick
Label: . maverick
Codename: maverick
Date: Fri, 31 Jan 2014 14:18:52 UTC
Architectures: amd64 i386
Components: main
Description: Generated by aptly
MD5Sum:
SHA1:
SHA256:

View File

@@ -0,0 +1,10 @@
Signing file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
Clearsigning file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
Snapshot snap2 has been successfully published.
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
deb http://your-server/ squeeze main
Don't forget to add your GPG key to apt with apt-key.
You can also use `aptly serve` to publish your repositories over HTTP quickly.

View File

@@ -0,0 +1,9 @@
Origin: . squeeze
Label: . squeeze
Codename: squeeze
Architectures: amd64 i386
Components: main
Description: Generated by aptly
MD5Sum:
SHA1:
SHA256:

View File

@@ -0,0 +1,10 @@
Signing file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
Clearsigning file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
Snapshot snap3 has been successfully published.
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
deb http://your-server/ squeeze contrib
Don't forget to add your GPG key to apt with apt-key.
You can also use `aptly serve` to publish your repositories over HTTP quickly.

View File

@@ -0,0 +1,9 @@
Origin: . squeeze
Label: . squeeze
Codename: squeeze
Architectures: amd64 i386
Components: contrib
Description: Generated by aptly
MD5Sum:
SHA1:
SHA256:

View File

@@ -0,0 +1,10 @@
Signing file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
Clearsigning file '${HOME}/.aptly/public/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
Snapshot snap4 has been successfully published.
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
deb http://your-server/ squeeze main
Don't forget to add your GPG key to apt with apt-key.
You can also use `aptly serve` to publish your repositories over HTTP quickly.

View File

@@ -0,0 +1,9 @@
Origin: . squeeze
Label: . squeeze
Codename: squeeze
Architectures: i386
Components: main
Description: Generated by aptly
MD5Sum:
SHA1:
SHA256:

View File

@@ -0,0 +1,10 @@
Signing file '${HOME}/.aptly/public/ppa/smira/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
Clearsigning file '${HOME}/.aptly/public/ppa/smira/dists/squeeze/Release' with gpg, please enter your passphrase when prompted:
Snapshot snap5 has been successfully published.
Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing.
Now you can add following line to apt sources:
deb http://your-server/ppa/smira/ squeeze main
Don't forget to add your GPG key to apt with apt-key.
You can also use `aptly serve` to publish your repositories over HTTP quickly.

View File

@@ -0,0 +1 @@
ERROR: unable to guess distribution name, please specify explicitly

View File

@@ -0,0 +1 @@
ERROR: prefix/distribution already used by another published repo: ./maverick (main) [amd64, i386] publishes [snap7]: Snapshot from mirror [gnuplot-maverick]: http://ppa.launchpad.net/gladky-anton/gnuplot/ubuntu/ maverick

View File

@@ -0,0 +1 @@
ERROR: prefix/distribution already used by another published repo: ppa/maverick (main) [amd64, i386] publishes [snap8]: Snapshot from mirror [gnuplot-maverick]: http://ppa.launchpad.net/gladky-anton/gnuplot/ubuntu/ maverick

View File

@@ -0,0 +1 @@
ERROR: unable to publish: invalid prefix ppa/dists/la

View File

@@ -0,0 +1,7 @@
"""
Testing publishing snapshots
"""
from .snapshot import *
#from .list import *
#from .drop import *

View File

@@ -0,0 +1,286 @@
import os
import hashlib
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:')])
class PublishSnapshot1Test(BaseTest):
"""
publish snapshot: defaults
"""
fixtureDB = True
fixturePool = True
fixtureCmds = [
"aptly snapshot create snap1 from mirror gnuplot-maverick",
]
runCmd = "aptly publish snapshot 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/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/pool/main/g/gnuplot/gnuplot-doc_4.6.1-1~maverick2_all.deb')
# verify contents except of sums
self.check_file('public/dists/maverick/Release', 'release', match_prepare=strip_processor)
# verify signatures
self.run_cmd(["gpg", "--verify", os.path.join(os.environ["HOME"], ".aptly", 'public/dists/maverick/InRelease')])
self.run_cmd(["gpg", "--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']):
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 -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('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 -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('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 -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('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 -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 merge snap6 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 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 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