Merge lp:~rvb/maas-test/bmc-params-2 into lp:maas-test

Proposed by Raphaël Badin
Status: Merged
Merged at revision: 49
Proposed branch: lp:~rvb/maas-test/bmc-params-2
Merge into: lp:maas-test
Prerequisite: lp:~rvb/maas-test/bmc-params-1
Diff against target: 150 lines (+33/-32)
4 files modified
maastest/kvmfixture.py (+11/-0)
maastest/maasfixture.py (+6/-18)
maastest/tests/test_kvmfixture.py (+14/-0)
maastest/tests/test_maasfixture.py (+2/-14)
To merge this branch: bzr merge lp:~rvb/maas-test/bmc-params-2
Reviewer Review Type Date Requested Status
Graham Binns (community) Approve
Review via email: mp+196108@code.launchpad.net

Commit message

Move install_package into kvm fixture.

Description of the change

This is a pure refactoring branch. install_package really belongs to KVMFixture and not MAASFixture. It has nothing that is MAAS-specific. I'm doing this because I'll need to install packages from KVMFixture in the next branch.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve
lp:~rvb/maas-test/bmc-params-2 updated
49. By Raphaël Badin

Merged bmc-params into bmc-params-2.

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 2013-11-20 11:53:52 +0000
+++ maastest/kvmfixture.py 2013-11-21 14:40:34 +0000
@@ -51,6 +51,12 @@
51# https://lists.ubuntu.com/archives/ubuntu-devel/2013-June/037195.html51# https://lists.ubuntu.com/archives/ubuntu-devel/2013-June/037195.html
52VM_LOCALE = "en_US.UTF-8"52VM_LOCALE = "en_US.UTF-8"
5353
54# Standard, non-interactive, "apt-get install" line.
55APT_GET_INSTALL = [
56 'sudo', 'DEBIAN_FRONTEND=noninteractive',
57 'apt-get', 'install', '-y',
58 ]
59
5460
55class KVMFixture(Fixture):61class KVMFixture(Fixture):
56 """A fixture for a Kernel-based Virtual Machine.62 """A fixture for a Kernel-based Virtual Machine.
@@ -299,6 +305,11 @@
299 remote_command_line,305 remote_command_line,
300 ]306 ]
301307
308 def install_packages(self, packages):
309 """Install the given packages on the virtual machine."""
310 self.run_command(
311 APT_GET_INSTALL + list(packages), check_call=True)
312
302 def run_command(self, args, input=None, check_call=False):313 def run_command(self, args, input=None, check_call=False):
303 """Run the given command in the VM."""314 """Run the given command in the VM."""
304 args = self._make_ssh_command(args)315 args = self._make_ssh_command(args)
305316
=== modified file 'maastest/maasfixture.py'
--- maastest/maasfixture.py 2013-11-18 16:03:32 +0000
+++ maastest/maasfixture.py 2013-11-21 14:40:34 +0000
@@ -40,13 +40,6 @@
40MAAS_ADMIN_USER = 'admin'40MAAS_ADMIN_USER = 'admin'
4141
4242
43# Standard, non-interactive, "apt-get install" line.
44APT_GET_INSTALL = [
45 'sudo', 'DEBIAN_FRONTEND=noninteractive',
46 'apt-get', 'install', '-y',
47 ]
48
49
50def compose_rewrite_for_default_maas_url(config_file, default_maas_url):43def compose_rewrite_for_default_maas_url(config_file, default_maas_url):
51 """Return a shell command to rewrite `DEFAULT_MAAS_URL` in config."""44 """Return a shell command to rewrite `DEFAULT_MAAS_URL` in config."""
52 # Comment out existing DEFAULT_MAAS_URL, and add new one.45 # Comment out existing DEFAULT_MAAS_URL, and add new one.
@@ -75,11 +68,6 @@
75 """68 """
76 self.kvm_fixture = kvmfixture69 self.kvm_fixture = kvmfixture
7770
78 def install_packages(self, packages):
79 """Install the given packages on the virtual machine."""
80 self.kvm_fixture.run_command(
81 APT_GET_INSTALL + list(packages), check_call=True)
82
83 def install_maas(self):71 def install_maas(self):
84 """Install and configure MAAS in the virtual machine."""72 """Install and configure MAAS in the virtual machine."""
85 # Install the English language pack first. If this is not done73 # Install the English language pack first. If this is not done
@@ -88,9 +76,9 @@
88 # TODO: Is there no better way to ensure this, e.g. through a76 # TODO: Is there no better way to ensure this, e.g. through a
89 # dependency?77 # dependency?
90 logging.info("Installing MAAS...")78 logging.info("Installing MAAS...")
91 self.install_packages(['language-pack-en'])79 self.kvm_fixture.install_packages(['language-pack-en'])
92 # Now we can install maas (which also installs postgres).80 # Now we can install maas (which also installs postgres).
93 self.install_packages(['maas', 'maas-dhcp', 'maas-dns'])81 self.kvm_fixture.install_packages(['maas', 'maas-dhcp', 'maas-dns'])
94 logging.info("Done installing MAAS.")82 logging.info("Done installing MAAS.")
9583
96 def configure_default_maas_url(self):84 def configure_default_maas_url(self):
@@ -156,10 +144,10 @@
156 # TODO: ARCHES and RELEASES should come from command-line144 # TODO: ARCHES and RELEASES should come from command-line
157 # parameters.145 # parameters.
158 self.kvm_fixture.run_command([146 self.kvm_fixture.run_command([
159 u'sudo',147 'sudo',
160 u'RELEASES=precise',148 'RELEASES=precise',
161 u'ARCHES=amd64/generic i386/generic',149 'ARCHES=amd64/generic i386/generic',
162 u'maas-import-pxe-files',150 'maas-import-pxe-files',
163 ],151 ],
164 check_call=True)152 check_call=True)
165 logging.info("Done importing MAAS PXE Files.")153 logging.info("Done importing MAAS PXE Files.")
166154
=== modified file 'maastest/tests/test_kvmfixture.py'
--- maastest/tests/test_kvmfixture.py 2013-11-20 09:48:51 +0000
+++ maastest/tests/test_kvmfixture.py 2013-11-21 14:40:34 +0000
@@ -488,6 +488,20 @@
488 check_call=True),488 check_call=True),
489 fake_run_command.mock_calls[-1])489 fake_run_command.mock_calls[-1])
490490
491 def test_install_packages_runs_apt_get_noninteractively_with_check(self):
492 self.patch_run_command()
493 packages = ['foo', 'bar']
494 fixture = self.make_KVMFixture('series', 'architecture')
495 kvm_run_command = mock.MagicMock(return_value=(0, '', ''))
496 self.patch(kvmfixture.KVMFixture, 'run_command', kvm_run_command)
497
498 fixture.install_packages(packages)
499
500 self.assertEqual(
501 [mock.call(
502 kvmfixture.APT_GET_INSTALL + packages, check_call=True)],
503 kvm_run_command.mock_calls)
504
491 def test_run_command_runs_command_remotely(self):505 def test_run_command_runs_command_remotely(self):
492 fake_run_command = self.patch_run_command()506 fake_run_command = self.patch_run_command()
493 series = "test-series"507 series = "test-series"
494508
=== modified file 'maastest/tests/test_maasfixture.py'
--- maastest/tests/test_maasfixture.py 2013-11-18 16:03:32 +0000
+++ maastest/tests/test_maasfixture.py 2013-11-21 14:40:34 +0000
@@ -221,18 +221,6 @@
221 client = maas_fixture.get_maas_api_client(actual_api_key)221 client = maas_fixture.get_maas_api_client(actual_api_key)
222 self.assertIsInstance(client, MAASClient)222 self.assertIsInstance(client, MAASClient)
223223
224 def test_install_packages_runs_apt_get_noninteractively_with_check(self):
225 fixture = self.make_kvm_fixture()
226 packages = ['foo', 'bar']
227 maas_fixture = maasfixture.MAASFixture(fixture)
228
229 maas_fixture.install_packages(packages)
230
231 self.assertEqual(
232 [mock.call(
233 maasfixture.APT_GET_INSTALL + packages, check_call=True)],
234 fixture.run_command.mock_calls)
235
236 def test_install_maas_installs_integrates_with_install_packages(self):224 def test_install_maas_installs_integrates_with_install_packages(self):
237 fixture = self.make_kvm_fixture()225 fixture = self.make_kvm_fixture()
238 maas_fixture = maasfixture.MAASFixture(fixture)226 maas_fixture = maasfixture.MAASFixture(fixture)
@@ -241,7 +229,7 @@
241229
242 fixture.run_command.assert_has_call(230 fixture.run_command.assert_has_call(
243 mock.call(231 mock.call(
244 maasfixture.APT_GET_INSTALL + ['language-pack-en'],232 kvmfixture.APT_GET_INSTALL + ['language-pack-en'],
245 check_call=True),233 check_call=True),
246 )234 )
247235
@@ -251,7 +239,7 @@
251 fixture = self.make_kvm_fixture()239 fixture = self.make_kvm_fixture()
252 fake_install = mock.MagicMock()240 fake_install = mock.MagicMock()
253 maas_fixture = maasfixture.MAASFixture(fixture)241 maas_fixture = maasfixture.MAASFixture(fixture)
254 self.patch(maas_fixture, 'install_packages', fake_install)242 self.patch(fixture, 'install_packages', fake_install)
255243
256 maas_fixture.install_maas()244 maas_fixture.install_maas()
257245

Subscribers

People subscribed via source and target branches