Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into livepatch-motd
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Jul 22, 2022
2 parents 4674c17 + f1f4e7f commit 41be417
Show file tree
Hide file tree
Showing 41 changed files with 473 additions and 455 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
- name: setup
run: |
sudo apt-get update
sudo apt-get install autopkgtest git-buildpackage
sudo snap install lxd --channel=3.0/stable
sudo apt-get install distro-info autopkgtest git-buildpackage
sudo snap install lxd --channel=stable
sudo usermod --append --groups lxd $(whoami)
sudo lxd init --auto
sudo autopkgtest-build-lxd ubuntu-daily:groovy
sudo autopkgtest-build-lxd ubuntu:$(distro-info --stable)
- name: build source
run: gbp buildpackage -us -uc -S -d -nc --git-ignore-branch --git-prebuild=
- name: autopkgtest
# skipping tests is ok
run: sudo autopkgtest -U ../build-area/*.dsc -- lxd autopkgtest/ubuntu/groovy/amd64 || [ $? == 2 ]
run: sudo autopkgtest -U ../build-area/*.dsc -- lxd autopkgtest/ubuntu/$(distro-info --stable)/amd64 || [ $? == 2 ]
4 changes: 3 additions & 1 deletion HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Running tests

Please run:

$ make -C test
$ PYTHONPATH=. python3 -m unittest

Or

$ PYTHONPATH=. python3 -m pytest
20 changes: 19 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
unattended-upgrades (2.9) UNRELEASED; urgency=medium
unattended-upgrades (2.10) UNRELEASED; urgency=medium

[ Brian Murray ]
* kernel/postinst.d/unattended-upgrades: check to see if canonical-livepatch
is installed and enabled. In the event that it is and it says a reboot is
required do not update reboot-required files so that only one reboot
message appears in the message of the day.

-- Brian Murray <[email protected]> Mon, 17 Jan 2022 09:52:04 -0800

unattended-upgrades (2.9.1) unstable; urgency=medium

[ Jean-Pierre Giraud ]
* French translation updates (Closes: #989635)

[ Balint Reczey ]
* debian/tests/common-functions: Skip test if debootstrapping fails
* debian/control: Remove myself from Uploaders

[Michael Vogt]
* github: fix action to use current lts as base for autopkgtest
* github: move to latest lxd instead of hardcoding it
* github: move action to use stable (impish) for tests

-- Balint Reczey <[email protected]> Thu, 21 Jul 2022 14:25:14 +0200
>>>>>>> origin/master

unattended-upgrades (2.8) unstable; urgency=medium

[ Lucas Moura ]
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Build-Depends-Indep: python3-dev,
python3-distro-info,
pycodestyle | pep8,
# powermgmt-base, (tests disable on_ac_power checks)
pyflakes3,
flake8,
python3-apt (>= 1.9.6~),
python3-mock,
lsb-release
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ override_dh_auto_build:
$(PYTHON) setup.py build

override_dh_auto_test:
$(MAKE) -C test
$(PYTHON) setup.py test

override_dh_auto_install:
$(PYTHON) setup.py install \
Expand Down
5 changes: 5 additions & 0 deletions debian/tests/common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ do_debootstrap() {
chroot_dir="$2"
mirror="$3"

if [ $(systemd-detect-virt) = "lxc" ]; then
echo "mkdnod fails in lxc, skipping debootstrap"
exit 77
fi

ret=0
for i in $(seq 5); do
debootstrap --include eatmydata,time "$@" 2>&1 && break || ret=$?
Expand Down
6 changes: 3 additions & 3 deletions debian/tests/control
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Tests: run-tests test-systemd.py
Depends: @, @builddeps@, apt
Restrictions: needs-root, isolation-container, needs-reboot
Restrictions: needs-root, isolation-container, needs-reboot, allow-stderr

Tests: upgrade-all-security
Depends: @, @builddeps@, apt, debootstrap, distro-info
Restrictions: needs-root, build-needed, skippable
Restrictions: needs-root, build-needed, skippable, allow-stderr

Tests: upgrade-between-snapshots
Restrictions: needs-root, build-needed, flaky, skippable
Restrictions: needs-root, build-needed, flaky, skippable, allow-stderr
Depends: @, @builddeps@, apt, debootstrap

Tests: kernel-patterns
Expand Down
4 changes: 3 additions & 1 deletion debian/tests/kernel-patterns
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

test/autopkgtest_kernel_patterns.py
set -ex

PYTHONPATH=. test/autopkgtest_kernel_patterns.py
6 changes: 4 additions & 2 deletions debian/tests/run-tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh

cd test
make
set -ex

python3 -m unittest

2 changes: 1 addition & 1 deletion debian/tests/upgrade-all-security
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Also test if packages can be upgraded to -updates and -proposed, but failures
# in -proposed are ignored since those can be issues in the packages.

set -e
set -ex

chroot_dir=$AUTOPKGTEST_TMP/chroot

Expand Down
2 changes: 1 addition & 1 deletion debian/tests/upgrade-between-snapshots
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

set -e
set -ex

chroot_dir=$AUTOPKGTEST_TMP/chroot
start_date=20200309T000000Z
Expand Down
13 changes: 2 additions & 11 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@ test-packages:
$(MAKE) -C packages

check: test-packages
set -e; \
find . -name 'test_*.py' | \
while read file; do \
if [ -x $$file ]; then \
echo "Running $$file with python3"; \
python3 $$file 2>&1; \
echo "Running $$file with python3-coverage"; \
python3 -m coverage run -a $$file 2>&1; \
fi \
done
#PYTHONPATH=.. python3 -m unittest
PYTHONPATH=.. python3 -m coverage run -a -m unittest

clean:
$(MAKE) -C packages clean
Expand All @@ -25,5 +17,4 @@ clean:
find .. -type d -name __pycache__ | xargs rm -rf

coverage-html:
echo "output in htmlcov/
python3 -m coverage html
47 changes: 21 additions & 26 deletions test/test_against_real_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,31 @@
network access, and it fails in some situations (unclear which).
"""

import apt_pkg
apt_pkg.config.set("Dir", "./aptroot")
import apt
import glob
import logging
import os
import re
import unittest

import unattended_upgrade

import apt_pkg

apt_pkg.config.set("APT::Architecture", "amd64")
apt_pkg.config.set("Dir", os.path.join(os.path.dirname(__file__), "aptroot"))
import apt

import unattended_upgrade
from test.test_base import TestBase, MockOptions

class MockOptions():
def __init__(self, debug=True, dry_run=False):
self.debug = debug
self.dry_run = dry_run
self.apt_debug = False
self.minimal_upgrade_steps = True
self.verbose = False

apt_pkg.config.set("APT::Architecture", "amd64")

class TestAgainstRealArchive(unittest.TestCase):

# FIXME: port to something more recent than lucid(!)
class TestAgainstRealArchive(TestBase):
@unittest.skip("FIXME: test needs porting")
@unittest.skipIf(os.getuid() != 0, "must run as root")
def setUp(self):
for g in ["./aptroot/var/log/apt/*",
"./aptroot/var/log/*"]:
TestBase.setUp(self)
for g in ["./aptroot/var/log/apt/*", "./aptroot/var/log/*"]:
for f in glob.glob(g):
if os.path.isfile(f):
os.remove(f)
Expand Down Expand Up @@ -65,29 +61,28 @@ def test_against_real_archive(self):
# check that stuff worked
self.assertFalse(" ERROR " in log, log)
# check if we actually have the expected ugprade in it
self.assertTrue(
re.search("INFO Packages that will be upgraded:.*awstats", log))
self.assertTrue(re.search("INFO Packages that will be upgraded:.*awstats", log))
# apt-doc has a higher version in -updates than in -security
# and no other dependencies so its a perfect test
self.assertTrue(
re.search("INFO Packages that will be upgraded:.*apt-doc", log))
self.assertTrue(re.search("INFO Packages that will be upgraded:.*apt-doc", log))
self.assertFalse(
re.search("INFO Packages that will be upgraded:.*ant-doc", log))
self.assertTrue(
re.search("DEBUG skipping blacklisted package 'ant-doc'", log))
re.search("INFO Packages that will be upgraded:.*ant-doc", log)
)
self.assertTrue(re.search("DEBUG skipping blacklisted package 'ant-doc'", log))
# test dpkg install log
#term_log = open("aptroot/var/log/apt/term.log").read()
# term_log = open("aptroot/var/log/apt/term.log").read()
# FIXME: when we redirect STDIN the below test will break - however
# we need to redirect it as otherwise we may hang forever
# - this is actually a bug in apt that uses "tcgetattr(0, &tt)"
# on FD=0 instead of FD=1
#print term_log
#self.assertTrue(
# print term_log
# self.assertTrue(
# re.search(
# "fake-dpkg: --status-fd .* --configure.*awstats", term_log))


if __name__ == "__main__":
import locale

locale.setlocale(locale.LC_ALL, "C")
unittest.main()
59 changes: 59 additions & 0 deletions test/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/python3

import logging
import os
import os.path
import shutil
import subprocess
import tempfile
import unittest

import apt

import unattended_upgrade


class MockOptions(object):
debug = True
verbose = False
download_only = False
dry_run = False
apt_debug = False
minimal_upgrade_steps = True


class TestBase(unittest.TestCase):
@classmethod
def setUpClass(cls):
# XXX: find a more elegant way
pkgdir = os.path.join(os.path.dirname(__file__), "packages")
subprocess.check_call(["make", "-C", pkgdir])

def setUp(self):
super(TestBase, self).setUp()
self.tempdir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.tempdir)
self.testdir = os.path.dirname(__file__)
# ensure custom logging gets reset (XXX: does this work?)
self.addCleanup(logging.shutdown)
logging.root.handlers = []
# XXX: workaround for most tests assuming to run inside the "test"
# dir
os.chdir(self.testdir)
# fake the lock file
unattended_upgrade.LOCK_FILE = os.path.join(self.tempdir, "u-u.lock")
# XXX: some test monkey patch this without reset
unattended_upgrade.init_distro_info()
# reset apt config
apt.apt_pkg.init_config()
# must be last
self._saved_apt_conf = {}
for k in apt.apt_pkg.config.keys():
if not k.endswith("::"):
self._saved_apt_conf[k] = apt.apt_pkg.config.get(k)
self.addCleanup(self.enforce_apt_config_reset)

def enforce_apt_config_reset(self):
for k in self._saved_apt_conf:
v = self._saved_apt_conf[k]
apt.apt_pkg.config.set(k, v)
3 changes: 2 additions & 1 deletion test/test_blacklisted_wrong_origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
from mock import (
Mock,
)
from test.test_base import TestBase

from unattended_upgrade import calculate_upgradable_pkgs


class TestBlacklistedWrongOrigin(unittest.TestCase):
class TestBlacklistedWrongOrigin(TestBase):

@unittest.skipIf(sys.version_info[0] != 3, "only works on py3")
def test_if_origin_does_not_match_then_blacklist_is_not_checked(self):
Expand Down
13 changes: 7 additions & 6 deletions test/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@


import os
import shutil
import tempfile
import os.path
import unittest

import apt_pkg
apt_pkg.config.set("Dir", "./aptroot")
apt_pkg.config.set("Dir", os.path.join(os.path.dirname(__file__), "aptroot"))
import apt
import unattended_upgrade

Expand All @@ -17,6 +16,8 @@
except ImportError:
pass

from test.test_base import TestBase


class MockFetcher:
items = [] # type: List[MockAcquireItem]
Expand All @@ -27,15 +28,15 @@ def __init__(self, destfile):
self.destfile = destfile


class TestClean(unittest.TestCase):
class TestClean(TestBase):

def setUp(self):
self.tempdir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.tempdir)
TestBase.setUp(self)
os.chdir(self.tempdir)

def test_clean(self):
apt.apt_pkg.config.set("dir::cache::archives", self.tempdir)
self.addCleanup(apt.apt_pkg.config.clear, "dir::cache::archives")
os.makedirs("dir")
with open("file1", "w"):
pass
Expand Down
Loading

0 comments on commit 41be417

Please sign in to comment.