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
=== modified file 'maastest/kvmfixture.py'
--- maastest/kvmfixture.py 2014-04-10 05:15:23 +0000
+++ maastest/kvmfixture.py 2014-04-26 08:40:07 +0000
@@ -304,14 +304,14 @@
304 self.architecture)304 self.architecture)
305305
306 def configure_archives(self):306 def configure_archives(self):
307 """Add repositories to the VM and update the list of packages."""307 """Add repositories to the VM."""
308 if self.archives is not None:308 if self.archives is not None:
309 for archive in self.archives:309 for archive in self.archives:
310 self.run_command(310 self.run_command(
311 ["sudo", "add-apt-repository", "-y", archive],311 ["sudo", "add-apt-repository", "-y", archive],
312 check_call=True)312 check_call=True)
313 self.run_command(313 # No need to update the list of packages, it's done before
314 ["sudo", "apt-get", "update"], check_call=True)314 # any package installation to avoid, as much as possible, races.
315315
316 def configure_network(self):316 def configure_network(self):
317 """Configure the virtual machine network.317 """Configure the virtual machine network.
@@ -381,11 +381,16 @@
381 """Install the given packages on the virtual machine."""381 """Install the given packages on the virtual machine."""
382 return [382 return [
383 'sudo',383 'sudo',
384 'http_proxy=%s' % self.proxy_url,384 'sh', '-c',
385 'https_proxy=%s' % self.proxy_url,385 'export http_proxy=%s; '
386 'DEBIAN_FRONTEND=noninteractive',386 'export https_proxy=%s; '
387 'apt-get', 'install', '-y'387 'export DEBIAN_FRONTEND=noninteractive; '
388 ] + list(packages)388 'apt-get update; '
389 'apt-get install -y %s' % (
390 self.proxy_url,
391 self.proxy_url,
392 ' '.join(list(packages)))
393 ]
389394
390 def install_packages(self, packages):395 def install_packages(self, packages):
391 """Install the given packages on the virtual machine."""396 """Install the given packages on the virtual machine."""
392397
=== modified file 'maastest/tests/test_kvmfixture.py'
--- maastest/tests/test_kvmfixture.py 2014-04-10 05:14:35 +0000
+++ maastest/tests/test_kvmfixture.py 2014-04-26 08:40:07 +0000
@@ -502,27 +502,11 @@
502 add_archive_cmds = [502 add_archive_cmds = [
503 ["sudo", "add-apt-repository", "-y", archives[0]],503 ["sudo", "add-apt-repository", "-y", archives[0]],
504 ["sudo", "add-apt-repository", "-y", archives[1]],504 ["sudo", "add-apt-repository", "-y", archives[1]],
505 ["sudo", "apt-get", "update"],
506 ]505 ]
507 self.assertEqual(506 self.assertEqual(
508 [mock.call(cmd, check_call=True) for cmd in add_archive_cmds],507 [mock.call(cmd, check_call=True) for cmd in add_archive_cmds],
509 run_command_mock.mock_calls)508 run_command_mock.mock_calls)
510509
511 def test_configure_archives_always_updates(self):
512 mock_identity = mock.MagicMock()
513 mock_identity.return_value = "ubuntu@test"
514 self.patch(kvmfixture.KVMFixture, 'identity', mock_identity)
515 run_command_mock = mock.MagicMock(return_value=(0, '', ''))
516 self.patch(kvmfixture.KVMFixture, 'run_command', run_command_mock)
517 fixture = self.make_KVMFixture(
518 'series', 'architecture', archives=None)
519
520 fixture.configure_archives()
521
522 self.assertEqual(
523 [mock.call(["sudo", "apt-get", "update"], check_call=True)],
524 run_command_mock.mock_calls)
525
526 def test_configure_network_configures_network(self):510 def test_configure_network_configures_network(self):
527 series = "test-series"511 series = "test-series"
528 architecture = "test-arch"512 architecture = "test-arch"
@@ -563,6 +547,23 @@
563 check_call=True),547 check_call=True),
564 fake_run_command.mock_calls[-1])548 fake_run_command.mock_calls[-1])
565549
550 def test_make_apt_get_install_command_returns_command(self):
551 fixture = self.make_KVMFixture('series', 'architecture')
552 packages = [self.getUniqueString(), self.getUniqueString()]
553 command = fixture._make_apt_get_install_command(packages)
554 self.assertEqual(
555 [
556 "sudo", "sh", "-c",
557 "export http_proxy=%s; export https_proxy=%s; "
558 "export DEBIAN_FRONTEND=noninteractive; "
559 "apt-get update; apt-get install -y %s" % (
560 self.proxy_url,
561 self.proxy_url,
562 ' '.join(packages),
563 )
564 ],
565 command)
566
566 def test_install_packages_runs_apt_get_noninteractively_with_check(self):567 def test_install_packages_runs_apt_get_noninteractively_with_check(self):
567 self.patch_run_command()568 self.patch_run_command()
568 packages = ['foo', 'bar']569 packages = ['foo', 'bar']

Subscribers

People subscribed via source and target branches