Merge lp:~rvb/maas-test/update-proxy into lp:maas-test

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: 154
Merged at revision: 154
Proposed branch: lp:~rvb/maas-test/update-proxy
Merge into: lp:maas-test
Prerequisite: lp:~rvb/maas-test/only-one-arch
Diff against target: 99 lines (+30/-24)
2 files modified
maastest/kvmfixture.py (+13/-8)
maastest/tests/test_kvmfixture.py (+17/-16)
To merge this branch: bzr merge lp:~rvb/maas-test/update-proxy
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+217332@code.launchpad.net

Commit message

Always run `apt-get update` before installing packages to avoid (as much as possible) races when the content of the archive changes. Also: Use the defined proxy when running `apt-get update`.

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

 review: approve
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlNdqvIACgkQWhGlTF8G/Hf2TgCfZuuTiJ4ZBcG5RxjXSXQUd3km
BIwAoKOnx9OulLzTzu0uEJdOZsnwg4Ni
=dwak
-----END PGP SIGNATURE-----

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'maastest/kvmfixture.py'
2--- maastest/kvmfixture.py 2014-04-10 05:15:23 +0000
3+++ maastest/kvmfixture.py 2014-04-26 08:40:07 +0000
4@@ -304,14 +304,14 @@
5 self.architecture)
6
7 def configure_archives(self):
8- """Add repositories to the VM and update the list of packages."""
9+ """Add repositories to the VM."""
10 if self.archives is not None:
11 for archive in self.archives:
12 self.run_command(
13 ["sudo", "add-apt-repository", "-y", archive],
14 check_call=True)
15- self.run_command(
16- ["sudo", "apt-get", "update"], check_call=True)
17+ # No need to update the list of packages, it's done before
18+ # any package installation to avoid, as much as possible, races.
19
20 def configure_network(self):
21 """Configure the virtual machine network.
22@@ -381,11 +381,16 @@
23 """Install the given packages on the virtual machine."""
24 return [
25 'sudo',
26- 'http_proxy=%s' % self.proxy_url,
27- 'https_proxy=%s' % self.proxy_url,
28- 'DEBIAN_FRONTEND=noninteractive',
29- 'apt-get', 'install', '-y'
30- ] + list(packages)
31+ 'sh', '-c',
32+ 'export http_proxy=%s; '
33+ 'export https_proxy=%s; '
34+ 'export DEBIAN_FRONTEND=noninteractive; '
35+ 'apt-get update; '
36+ 'apt-get install -y %s' % (
37+ self.proxy_url,
38+ self.proxy_url,
39+ ' '.join(list(packages)))
40+ ]
41
42 def install_packages(self, packages):
43 """Install the given packages on the virtual machine."""
44
45=== modified file 'maastest/tests/test_kvmfixture.py'
46--- maastest/tests/test_kvmfixture.py 2014-04-10 05:14:35 +0000
47+++ maastest/tests/test_kvmfixture.py 2014-04-26 08:40:07 +0000
48@@ -502,27 +502,11 @@
49 add_archive_cmds = [
50 ["sudo", "add-apt-repository", "-y", archives[0]],
51 ["sudo", "add-apt-repository", "-y", archives[1]],
52- ["sudo", "apt-get", "update"],
53 ]
54 self.assertEqual(
55 [mock.call(cmd, check_call=True) for cmd in add_archive_cmds],
56 run_command_mock.mock_calls)
57
58- def test_configure_archives_always_updates(self):
59- mock_identity = mock.MagicMock()
60- mock_identity.return_value = "ubuntu@test"
61- self.patch(kvmfixture.KVMFixture, 'identity', mock_identity)
62- run_command_mock = mock.MagicMock(return_value=(0, '', ''))
63- self.patch(kvmfixture.KVMFixture, 'run_command', run_command_mock)
64- fixture = self.make_KVMFixture(
65- 'series', 'architecture', archives=None)
66-
67- fixture.configure_archives()
68-
69- self.assertEqual(
70- [mock.call(["sudo", "apt-get", "update"], check_call=True)],
71- run_command_mock.mock_calls)
72-
73 def test_configure_network_configures_network(self):
74 series = "test-series"
75 architecture = "test-arch"
76@@ -563,6 +547,23 @@
77 check_call=True),
78 fake_run_command.mock_calls[-1])
79
80+ def test_make_apt_get_install_command_returns_command(self):
81+ fixture = self.make_KVMFixture('series', 'architecture')
82+ packages = [self.getUniqueString(), self.getUniqueString()]
83+ command = fixture._make_apt_get_install_command(packages)
84+ self.assertEqual(
85+ [
86+ "sudo", "sh", "-c",
87+ "export http_proxy=%s; export https_proxy=%s; "
88+ "export DEBIAN_FRONTEND=noninteractive; "
89+ "apt-get update; apt-get install -y %s" % (
90+ self.proxy_url,
91+ self.proxy_url,
92+ ' '.join(packages),
93+ )
94+ ],
95+ command)
96+
97 def test_install_packages_runs_apt_get_noninteractively_with_check(self):
98 self.patch_run_command()
99 packages = ['foo', 'bar']

Subscribers

People subscribed via source and target branches