aptly mirror create system tests.

This commit is contained in:
Andrey Smirnov
2014-01-21 14:21:22 +04:00
parent 7ec27ad88c
commit e1ca459329
13 changed files with 153 additions and 8 deletions

View File

@@ -33,13 +33,17 @@ class BaseTest(object):
f.close()
def run(self):
self.output = self.run_cmd(self.runCmd, self.expectedCode)
def run_cmd(self, command, expected_code=0):
try:
proc = subprocess.Popen(self.runCmd.split(" "), stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
self.output, _ = proc.communicate()
if proc.returncode != self.expectedCode:
raise Exception("exit code %d != %d" % (proc.returncode, self.expectedCode))
proc = subprocess.Popen(command.split(" "), stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
output, _ = proc.communicate()
if proc.returncode != expected_code:
raise Exception("exit code %d != %d" % (proc.returncode, expected_code))
return output
except Exception, e:
raise Exception("Running command %s failed: %s" % (self.runCmd, str(e)))
raise Exception("Running command %s failed: %s" % (command, str(e)))
def gold_processor(self, gold):
return gold
@@ -47,13 +51,16 @@ class BaseTest(object):
def expand_environ(self, gold):
return string.Template(gold).substitute(os.environ)
def get_gold(self):
gold = os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)), self.__class__.__name__ + "_gold")
def get_gold(self, gold_name="gold"):
gold = os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)), self.__class__.__name__ + "_" + gold_name)
return self.gold_processor(open(gold, "r").read())
def check_output(self):
self.verify_match(self.get_gold(), self.output)
def check_cmd_output(self, command, gold_name):
self.verify_match(self.get_gold(gold_name), self.run_cmd(command))
def verify_match(self, a, b):
if a != b:
diff = "".join(difflib.unified_diff([l + "\n" for l in a.split("\n")], [l + "\n" for l in b.split("\n")]))

View File

@@ -38,7 +38,7 @@ def run():
except BaseException, e:
numFailed += 1
fails.append((test, t, e, testModule))
sys.stdout.write("FAIL\n")
sys.stdout.write(colored("FAIL\n", color="red"))
else:
sys.stdout.write(colored("OK\n", color="green"))

View File

@@ -0,0 +1,4 @@
Downloading http://mirror.yandex.ru/debian/dists/wheezy/Release...
Mirror [mirror1]: http://mirror.yandex.ru/debian/ wheezy successfully added.
You can run 'aptly mirror update mirror1' to download repository contents.

View File

@@ -0,0 +1,18 @@
Name: mirror1
Archive Root URL: http://mirror.yandex.ru/debian/
Distribution: wheezy
Components: main, contrib, non-free
Architectures: amd64, armel, armhf, i386, ia64, kfreebsd-amd64, kfreebsd-i386, mips, mipsel, powerpc, s390, s390x, sparc
Last update: never
Information from release file:
Architectures: amd64 armel armhf i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 s390x sparc
Codename: wheezy
Components: main contrib non-free
Date: Sat, 14 Dec 2013 10:51:30 UTC
Description: Debian 7.3 Released 14 December 2013
Label: Debian
Origin: Debian
Suite: stable
Version: 7.3

View File

@@ -0,0 +1,4 @@
Downloading http://mirror.yandex.ru/debian/dists/wheezy/Release...
Mirror [mirror2]: http://mirror.yandex.ru/debian/ wheezy successfully added.
You can run 'aptly mirror update mirror2' to download repository contents.

View File

@@ -0,0 +1,18 @@
Name: mirror2
Archive Root URL: http://mirror.yandex.ru/debian/
Distribution: wheezy
Components: main
Architectures: amd64, armel, armhf, i386, ia64, kfreebsd-amd64, kfreebsd-i386, mips, mipsel, powerpc, s390, s390x, sparc
Last update: never
Information from release file:
Architectures: amd64 armel armhf i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 s390x sparc
Codename: wheezy
Components: main contrib non-free
Date: Sat, 14 Dec 2013 10:51:30 UTC
Description: Debian 7.3 Released 14 December 2013
Label: Debian
Origin: Debian
Suite: stable
Version: 7.3

View File

@@ -0,0 +1,4 @@
Downloading http://mirror.yandex.ru/debian/dists/wheezy/Release...
Mirror [mirror3]: http://mirror.yandex.ru/debian/ wheezy successfully added.
You can run 'aptly mirror update mirror3' to download repository contents.

View File

@@ -0,0 +1,18 @@
Name: mirror3
Archive Root URL: http://mirror.yandex.ru/debian/
Distribution: wheezy
Components: main, contrib
Architectures: i386, amd64
Last update: never
Information from release file:
Architectures: amd64 armel armhf i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 s390x sparc
Codename: wheezy
Components: main contrib non-free
Date: Sat, 14 Dec 2013 10:51:30 UTC
Description: Debian 7.3 Released 14 December 2013
Label: Debian
Origin: Debian
Suite: stable
Version: 7.3

View File

@@ -0,0 +1,2 @@
Downloading http://mirror.yandex.ru/debian/dists/wheezy/Release...
ERROR: unable to fetch mirror: component life not available in repo [mirror4]: http://mirror.yandex.ru/debian/ wheezy

View File

@@ -0,0 +1,2 @@
Downloading http://mirror.yandex.ru/debian/dists/wheezy/Release...
ERROR: unable to fetch mirror: architecture nano68 not available in repo [mirror5]: http://mirror.yandex.ru/debian/ wheezy

View File

@@ -0,0 +1,2 @@
Downloading http://mirror.yandex.ru/debian/dists/suslik/Release...
ERROR: unable to fetch mirror: HTTP code 404 while fetching http://mirror.yandex.ru/debian/dists/suslik/Release

View File

@@ -0,0 +1,5 @@
"""
Testing mirror management
"""
from .create import *

View File

@@ -0,0 +1,61 @@
from lib import BaseTest
class CreateMirror1Test(BaseTest):
"""
create mirror: all architectures + all components
"""
runCmd = "aptly mirror create mirror1 http://mirror.yandex.ru/debian/ wheezy"
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 mirror2 http://mirror.yandex.ru/debian/ wheezy 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 mirror3 http://mirror.yandex.ru/debian/ wheezy 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 mirror4 http://mirror.yandex.ru/debian/ wheezy life"
class CreateMirror5Test(BaseTest):
"""
create mirror: missing architecture
"""
expectedCode = 1
runCmd = "aptly -architectures=i386,nano68 mirror create mirror5 http://mirror.yandex.ru/debian/ wheezy"
class CreateMirror6Test(BaseTest):
"""
create mirror: missing release
"""
expectedCode = 1
runCmd = "aptly mirror create mirror6 http://mirror.yandex.ru/debian/ suslik"