Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
3532356
Prepare for futurize pass: fix "except" clause
ydirson Jul 28, 2022
3ee5615
Futurize: first pass, using -wn1
ydirson Aug 11, 2022
8ef7288
Futurize fixes: drop now-duplicated test
ydirson Jul 28, 2022
ddf7ba6
Futurize fixes: fix broken indentations
ydirson Jul 12, 2022
d97f4aa
Futurize fixes: use "raise" not "raise_" when not reraising
ydirson Jul 12, 2022
d05898a
Un-futurize: replace future.utils.raise_ with six.raise_from
ydirson Jul 15, 2022
459f5ef
Futurize fixes: remove now-unused imports
ydirson Jul 12, 2022
6505b3f
Futurize pylint complements: "print" continuation indentations, line …
ydirson Jul 15, 2022
7ae43d5
Futurize pylint complements: whitespace in expressions
ydirson Jul 15, 2022
a88ceb5
Migrate tests from StringIO.StringIO to io.StringIO
ydirson Jul 15, 2022
4d3681c
cpiofile: drop CpioFileCompat.write()
ydirson Jul 29, 2022
8a29168
Switch integer division to py3-compatible "//"
ydirson Jul 15, 2022
c410bab
xcp.accessor: upgrade urllib usage (futurize)
ydirson Jul 18, 2022
60ecacd
xcp.accessor: more urllib upgrading
ydirson Jul 18, 2022
422993d
Use new-style classes even in python2 (2to3)
ydirson Jul 18, 2022
764fc9b
futurize: deal with xrange()
ydirson Jul 18, 2022
4728f42
python3: remove casts from "int" to "long"
ydirson Jul 18, 2022
05e65da
python3: change float cast from "long" to "int"
ydirson Jul 18, 2022
bd10129
2to3: rename "next" methods to "__next__", use six.Iterator for porta…
ydirson Jul 18, 2022
1b54918
futurize: convert "iteritems()" to "items()", all negligible perf impact
ydirson Jul 18, 2022
48f6d6b
Apply fixes from `2to3 -f map` that are useful even when suboptimal
ydirson Jul 18, 2022
e67cf34
Apply all fixes from `2to3 -f filter` that are useful even when subop…
ydirson Jul 18, 2022
eede266
Futurize fixes: use generator comprehensions when list ones are not n…
ydirson Jul 18, 2022
610144a
Futurize cleanups: use list comprehension not `list(map())` or `list(…
ydirson Jul 18, 2022
7b03e6a
Futurize cleanups: xcp.net.ifrename.logic: simplify nested comprehens…
ydirson Jul 18, 2022
62bb70a
Futurize cleanups: line-wrapping fixes
ydirson Jul 18, 2022
1a33f75
Futurize cleanups: cleanup duplicated imports
ydirson Jul 18, 2022
e3dd1cc
Futurize pylint complements: xcp.accessor: bring consistency to "open…
ydirson Jul 20, 2022
60f35c5
Futurize pylint complements: disable warnings triggered by "import fu…
ydirson Jul 20, 2022
b12aa7c
Futurize pylint complements: test_cpio: mark unused import as expected
ydirson Jul 20, 2022
6d14ba8
Futurize pylint complements: xcp.accessor: avoid redefining "file" bu…
ydirson Jul 20, 2022
a78340c
Futurize pylint complements: Avoid useless ".keys()" when enumerating…
ydirson Jul 20, 2022
5da778b
Futurize pylint complements: xcp.repository: honor singleton-comparis…
ydirson Jul 20, 2022
e6b3689
Futurize pylint complements: xcp.repository: locally disable too-few-…
ydirson Jul 20, 2022
3d35879
Futurize pylint complements: "print" continuation indentations, line …
ydirson Jul 15, 2022
84a013f
Futurize pylint complements: whitespace in expressions
ydirson Jul 15, 2022
4cd6d2b
xcp.cpiofile: fix bad indentation
ydirson Aug 8, 2022
0ccda70
xcp: get rid of useless blackslash line continuations
ydirson Aug 8, 2022
9060d4b
test_cpio: always use hashlib, came with python 2.5
ydirson Jul 18, 2022
9a5bb61
test_cpio: use context manager to avoid forgetting to close some files
ydirson Jul 18, 2022
ce2af04
test_cpio: use context manager for other "open" calls for consistency
ydirson Jul 18, 2022
49bf476
tests: avoid useless try/except
ydirson Jul 27, 2022
8437deb
tests: use TestCase.assertRaises as context manager
ydirson Jul 27, 2022
c445fd8
Mark bytes literals and streams as such
ydirson Jul 18, 2022
1b6345c
test_cpio: add some docstrings
ydirson Jul 19, 2022
0d5d52a
test_cpio: generate reproducible archives
ydirson Jul 19, 2022
33c559c
test_cpio: avoid overwriting original archives with "archiveCreate()"
ydirson Jul 19, 2022
67394aa
test_cpio: improve test readability
ydirson Jul 19, 2022
225541b
test_cpio: expect different xz flags depending on python version
ydirson Jul 19, 2022
ccf5cc9
test_cpio: check xz magic, not just the flags
ydirson Jul 19, 2022
8466dbd
cpio: fix check for xz file magic ignoring the 6th byte
ydirson Jul 19, 2022
cb25e3c
test_cpio: remove unused import (pylint on python3)
ydirson Aug 8, 2022
39d23a9
cpiofile: revert unnecessary deviations from original tarfile.py
ydirson Aug 10, 2022
268f84f
cpiofile: revert overeager tar->cpio substitution on "target"
ydirson Aug 10, 2022
8439094
cpiofile: catch use of non-binary streams early
ydirson Aug 31, 2022
1902174
cpiofile: hack support for text IO to archive member
ydirson Aug 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ diff_cover
mock
pytest
pytest-cov
# dependencies also in setup.py until they can be used
six
future
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@
],
requires=[
'branding',
'six',
'future',
],
)
82 changes: 48 additions & 34 deletions tests/test_cpio.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
from __future__ import print_function
from hashlib import md5
import os
import sys
import shutil
import subprocess
import unittest
import warnings

from xcp.cpiofile import CpioFile, CpioInfo, CpioFileCompat, CPIO_PLAIN, CPIO_GZIPPED
from xcp.cpiofile import CpioFile, CpioFileCompat, CPIO_PLAIN, CPIO_GZIPPED

try:
from hashlib import md5
except:
from md5 import md5

def writeRandomFile(fn, size, start='', add='a'):
f = open(fn, 'wb')
m = md5()
m.update(start)
assert(len(add) != 0)
while size > 0:
d = m.digest()
if size < len(d):
d=d[:size]
f.write(d)
size -= len(d)
m.update(add)
f.close()
def writeRandomFile(fn, size, start=b'', add=b'a'):
"Create a pseudo-random reproducible file from seeds `start` amd `add`"
with open(fn, 'wb') as f:
m = md5()
m.update(start)
assert(len(add) != 0)
while size > 0:
d = m.digest()
if size < len(d):
d=d[:size]
f.write(d)
size -= len(d)
m.update(add)


def check_call(cmd):
Expand All @@ -40,20 +38,27 @@ def setUp(self):
shutil.rmtree('archive', True)
os.mkdir('archive')
writeRandomFile('archive/data', 10491)
self.md5data = md5(open('archive/data').read()).hexdigest()
check_call("find archive | cpio -o -H newc > archive.cpio")
with open('archive/data', 'rb') as fd:
self.md5data = md5(fd.read()).hexdigest()
# fixed timestamps for cpio reproducibility
os.utime('archive/data', (0, 0))
os.utime('archive', (0, 0))

check_call(
"find archive | cpio --reproducible -o -H newc > archive.cpio")
check_call("gzip -c < archive.cpio > archive.cpio.gz")
check_call("bzip2 -c < archive.cpio > archive.cpio.bz2")
try:
import lzma
self.doXZ = subprocess.call("xz --check=crc32 --lzma2=dict=1MiB < archive.cpio > archive.cpio.xz", shell=True) == 0
import lzma # pylint: disable=unused-variable
self.doXZ = subprocess.call("xz --check=crc32 --lzma2=dict=1MiB"
" < archive.cpio > archive.cpio.xz", shell=True) == 0
except Exception as ex:
# FIXME will issue warning even if test_xz is not requested
warnings.warn("will not test cpio.xz: %s" % ex)
self.doXZ = False

def tearDown(self):
check_call("rm -rf archive archive.cpio* archive2")
check_call("rm -rf archive archive.cpio* archive2 archive2.cpio*")

# TODO check with file (like 'r:*')
# TODO use cat to check properly for pipes
Expand All @@ -77,10 +82,12 @@ def archiveExtract(self, fn, fmt='r|*'):
arc.close()

def archiveCreate(self, fn, fmt='w'):
os.unlink(fn)
if os.path.exists(fn):
os.unlink(fn)
arc = CpioFile.open(fn, fmt)
f = arc.getcpioinfo('archive/data')
arc.addfile(f, open('archive/data'))
with open('archive/data', 'rb') as fd:
arc.addfile(f, fd)
# test recursively add "."
os.chdir('archive')
arc.add(".")
Expand All @@ -89,17 +96,24 @@ def archiveCreate(self, fn, fmt='w'):
arc.close()
# special case for XZ, test check type (crc32)
if fmt.endswith('xz'):
f = open(fn, 'rb')
f.seek(6)
self.assertEqual(f.read(2), '\x00\x01')
f.close()
with open(fn, 'rb') as f:
# check xz magic
self.assertEqual(f.read(6), b"\xfd7zXZ\0")
# check stream flags
if sys.version_info < (3, 0):
expected_flags = b'\x00\x01' # pylzma defaults to CRC32
else:
expected_flags = b'\x00\x04' # python3 defaults to CRC64
self.assertEqual(f.read(2), expected_flags)
self.archiveExtract(fn)

def doArchive(self, fn, fmt=None):
self.archiveExtract(fn)
self.archiveCreate(fn, fmt is None and 'w' or 'w|%s' % fmt )
if not fmt is None:
self.archiveExtract(fn, 'r|%s' % fmt)
fn2 = "archive2" + fn[len("archive"):]
print("creating %s" % fn2)
self.archiveCreate(fn2, fmt is None and 'w' or 'w|%s' % fmt)
if fmt is not None:
self.archiveExtract(fn2, 'r|%s' % fmt)

def test_plain(self):
self.doArchive('archive.cpio')
Expand All @@ -113,7 +127,7 @@ def test_bz2(self):
def test_xz(self):
if not self.doXZ:
raise unittest.SkipTest("lzma package or xz tool not available")
print 'Running test for XZ'
print('Running test for XZ')
self.doArchive('archive.cpio.xz', 'xz')

# CpioFileCompat testing
Expand Down
27 changes: 11 additions & 16 deletions tests/test_ifrename_dynamic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from __future__ import unicode_literals
import json
import logging
import unittest
from copy import deepcopy

try:
import cStringIO as StringIO
except ImportError:
import StringIO
from io import StringIO

from xcp.net.ifrename.dynamic import DynamicRules
from xcp.net.ifrename.macpci import MACPCI
Expand All @@ -16,7 +14,7 @@
class TestLoadAndParse(unittest.TestCase):

def setUp(self):
self.logbuf = StringIO.StringIO()
self.logbuf = StringIO()
openLog(self.logbuf, logging.NOTSET)

def tearDown(self):
Expand All @@ -26,7 +24,7 @@ def tearDown(self):

def test_null(self):

fd = StringIO.StringIO("")
fd = StringIO("")
dr = DynamicRules(fd=fd)

self.assertTrue(dr.load_and_parse())
Expand All @@ -36,7 +34,7 @@ def test_null(self):

def test_empty(self):

fd = StringIO.StringIO(
fd = StringIO(
'{"lastboot":[],"old":[]}'
)
dr = DynamicRules(fd=fd)
Expand All @@ -48,7 +46,7 @@ def test_empty(self):

def test_one_invalid(self):

fd = StringIO.StringIO(
fd = StringIO(
'{"lastboot":[["","",""]],"old":[]}'
)
dr = DynamicRules(fd=fd)
Expand All @@ -60,7 +58,7 @@ def test_one_invalid(self):

def test_one_valid_lastboot(self):

fd = StringIO.StringIO(
fd = StringIO(
'{"lastboot":[["01:23:45:67:89:0a","00:10.2","eth2"]],"old":[]}'
)
dr = DynamicRules(fd=fd)
Expand All @@ -74,7 +72,7 @@ def test_one_valid_lastboot(self):

def test_one_valid_lastboot2(self):

fd = StringIO.StringIO(
fd = StringIO(
'{"lastboot":[],"old":[["01:23:45:67:89:0a","00:10.2","eth2"]]}'
)
dr = DynamicRules(fd=fd)
Expand All @@ -88,7 +86,7 @@ def test_one_valid_lastboot2(self):
class TestGenerate(unittest.TestCase):

def setUp(self):
self.logbuf = StringIO.StringIO()
self.logbuf = StringIO()
openLog(self.logbuf, logging.NOTSET)

def tearDown(self):
Expand Down Expand Up @@ -149,7 +147,7 @@ def test_pci_missing(self):
class TestSave(unittest.TestCase):

def setUp(self):
self.logbuf = StringIO.StringIO()
self.logbuf = StringIO()
openLog(self.logbuf, logging.NOTSET)

def tearDown(self):
Expand All @@ -162,10 +160,7 @@ def test_one_invalid_lastboot(self):
dr = DynamicRules()
dr.lastboot = [["foo", "bar", "baz"]]

try:
json.loads(dr.write(False))
except Exception:
self.fail()
json.loads(dr.write(False))

def test_one_ibft_lastboot(self):

Expand Down
Loading