Merge lp:~abentley/juju-release-tools/no-debs-error into lp:juju-release-tools

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 284
Proposed branch: lp:~abentley/juju-release-tools/no-debs-error
Merge into: lp:juju-release-tools
Diff against target: 100 lines (+63/-9)
2 files modified
generate_agents.py (+21/-9)
tests/test_generate_agents.py (+42/-0)
To merge this branch: bzr merge lp:~abentley/juju-release-tools/no-debs-error
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+290225@code.launchpad.net

Commit message

Error when no debs are found.

Description of the change

This branch updates generate_agents to error when no debs are found.

In circumstances where the package isn't available as expected (e.g. wrong upatch), the release-juju-update-unsigned job does error, but does so quite late in the process, and not intentionally.
http://juju-ci.vapour.ws:8080/job/release-juju-update-unsigned/30/console

This branch updates generate_agents to fail immediately if it was unable to download any debs.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'generate_agents.py'
2--- generate_agents.py 2016-03-02 17:58:51 +0000
3+++ generate_agents.py 2016-03-28 16:45:58 +0000
4@@ -27,12 +27,32 @@
5 from utils import temp_dir
6
7
8+class NoDebsFound(Exception):
9+ """Raised when no .deb files could be found."""
10+
11+
12 # These are the archives that are searched for matching releases.
13 UBUNTU_ARCH = "http://archive.ubuntu.com/ubuntu/pool/universe/j/juju-core/"
14 ARM_ARCH = "http://ports.ubuntu.com/pool/universe/j/juju-core/"
15 PUBLIC_ARCHIVES = [UBUNTU_ARCH, ARM_ARCH]
16
17
18+def move_debs(dest_debs):
19+ juju_core_dir = os.path.join(dest_debs, 'juju2')
20+ if not os.path.isdir(juju_core_dir):
21+ # The juju2 package was not found, try the juju-core package.
22+ juju_core_dir = os.path.join(dest_debs, 'juju-core')
23+ if os.path.isdir(juju_core_dir):
24+ debs = glob.glob(os.path.join(juju_core_dir, '*deb'))
25+ else:
26+ debs = []
27+ if len(debs) == 0:
28+ raise NoDebsFound('No deb files found.')
29+ for deb in debs:
30+ shutil.move(deb, dest_debs)
31+ shutil.rmtree(juju_core_dir)
32+
33+
34 def retrieve_packages(release, upatch, archives, dest_debs, s3_config):
35 # Retrieve the packages that contain a jujud for this version.
36 print("Retrieving juju-core packages from archives")
37@@ -47,15 +67,7 @@
38 'lftp', '-c', 'mirror', '-i',
39 "(juju2|juju-core).*{}.*\.{}~juj.*\.deb".format(release, upatch),
40 archive], cwd=dest_debs)
41- juju_core_dir = os.path.join(dest_debs, 'juju2')
42- if not os.path.isdir(juju_core_dir):
43- # The juju2 package was not found, try the juju-core package.
44- juju_core_dir = os.path.join(dest_debs, 'juju-core')
45- if os.path.isdir(juju_core_dir):
46- debs = glob.glob(os.path.join(juju_core_dir, '*deb'))
47- for deb in debs:
48- shutil.move(deb, dest_debs)
49- shutil.rmtree(juju_core_dir)
50+ move_debs(dest_debs)
51 if os.path.exists(s3_config):
52 print(
53 'checking s3://juju-qa-data/agent-archive for'
54
55=== added file 'tests/test_generate_agents.py'
56--- tests/test_generate_agents.py 1970-01-01 00:00:00 +0000
57+++ tests/test_generate_agents.py 2016-03-28 16:45:58 +0000
58@@ -0,0 +1,42 @@
59+import os
60+from unittest import TestCase
61+
62+from generate_agents import (
63+ move_debs,
64+ NoDebsFound,
65+ )
66+from utils import temp_dir
67+
68+
69+class TestMoveDebs(TestCase):
70+
71+ def test_juju2(self):
72+ with temp_dir() as dest_debs:
73+ parent = os.path.join(dest_debs, 'juju2')
74+ os.mkdir(parent)
75+ open(os.path.join(parent, 'foo.deb'), 'w').close()
76+ move_debs(dest_debs)
77+ self.assertTrue(os.path.exists(os.path.join(dest_debs, 'foo.deb')))
78+
79+ def test_juju_core(self):
80+ with temp_dir() as dest_debs:
81+ parent = os.path.join(dest_debs, 'juju-core')
82+ os.mkdir(parent)
83+ open(os.path.join(parent, 'foo.deb'), 'w').close()
84+ move_debs(dest_debs)
85+ self.assertTrue(os.path.exists(os.path.join(dest_debs, 'foo.deb')))
86+
87+ def test_none(self):
88+ with temp_dir() as dest_debs:
89+ parent = os.path.join(dest_debs, 'juju-core')
90+ os.mkdir(parent)
91+ with self.assertRaisesRegexp(NoDebsFound, 'No deb files found.'):
92+ move_debs(dest_debs)
93+
94+ def test_wrong_dir(self):
95+ with temp_dir() as dest_debs:
96+ parent = os.path.join(dest_debs, 'wrong-dir')
97+ os.mkdir(parent)
98+ open(os.path.join(parent, 'foo.deb'), 'w').close()
99+ with self.assertRaisesRegexp(NoDebsFound, 'No deb files found.'):
100+ move_debs(dest_debs)

Subscribers

People subscribed via source and target branches