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
1=== modified file 'maastest/kvmfixture.py'
2--- maastest/kvmfixture.py 2013-11-20 11:53:52 +0000
3+++ maastest/kvmfixture.py 2013-11-21 14:40:34 +0000
4@@ -51,6 +51,12 @@
5 # https://lists.ubuntu.com/archives/ubuntu-devel/2013-June/037195.html
6 VM_LOCALE = "en_US.UTF-8"
7
8+# Standard, non-interactive, "apt-get install" line.
9+APT_GET_INSTALL = [
10+ 'sudo', 'DEBIAN_FRONTEND=noninteractive',
11+ 'apt-get', 'install', '-y',
12+ ]
13+
14
15 class KVMFixture(Fixture):
16 """A fixture for a Kernel-based Virtual Machine.
17@@ -299,6 +305,11 @@
18 remote_command_line,
19 ]
20
21+ def install_packages(self, packages):
22+ """Install the given packages on the virtual machine."""
23+ self.run_command(
24+ APT_GET_INSTALL + list(packages), check_call=True)
25+
26 def run_command(self, args, input=None, check_call=False):
27 """Run the given command in the VM."""
28 args = self._make_ssh_command(args)
29
30=== modified file 'maastest/maasfixture.py'
31--- maastest/maasfixture.py 2013-11-18 16:03:32 +0000
32+++ maastest/maasfixture.py 2013-11-21 14:40:34 +0000
33@@ -40,13 +40,6 @@
34 MAAS_ADMIN_USER = 'admin'
35
36
37-# Standard, non-interactive, "apt-get install" line.
38-APT_GET_INSTALL = [
39- 'sudo', 'DEBIAN_FRONTEND=noninteractive',
40- 'apt-get', 'install', '-y',
41- ]
42-
43-
44 def compose_rewrite_for_default_maas_url(config_file, default_maas_url):
45 """Return a shell command to rewrite `DEFAULT_MAAS_URL` in config."""
46 # Comment out existing DEFAULT_MAAS_URL, and add new one.
47@@ -75,11 +68,6 @@
48 """
49 self.kvm_fixture = kvmfixture
50
51- def install_packages(self, packages):
52- """Install the given packages on the virtual machine."""
53- self.kvm_fixture.run_command(
54- APT_GET_INSTALL + list(packages), check_call=True)
55-
56 def install_maas(self):
57 """Install and configure MAAS in the virtual machine."""
58 # Install the English language pack first. If this is not done
59@@ -88,9 +76,9 @@
60 # TODO: Is there no better way to ensure this, e.g. through a
61 # dependency?
62 logging.info("Installing MAAS...")
63- self.install_packages(['language-pack-en'])
64+ self.kvm_fixture.install_packages(['language-pack-en'])
65 # Now we can install maas (which also installs postgres).
66- self.install_packages(['maas', 'maas-dhcp', 'maas-dns'])
67+ self.kvm_fixture.install_packages(['maas', 'maas-dhcp', 'maas-dns'])
68 logging.info("Done installing MAAS.")
69
70 def configure_default_maas_url(self):
71@@ -156,10 +144,10 @@
72 # TODO: ARCHES and RELEASES should come from command-line
73 # parameters.
74 self.kvm_fixture.run_command([
75- u'sudo',
76- u'RELEASES=precise',
77- u'ARCHES=amd64/generic i386/generic',
78- u'maas-import-pxe-files',
79+ 'sudo',
80+ 'RELEASES=precise',
81+ 'ARCHES=amd64/generic i386/generic',
82+ 'maas-import-pxe-files',
83 ],
84 check_call=True)
85 logging.info("Done importing MAAS PXE Files.")
86
87=== modified file 'maastest/tests/test_kvmfixture.py'
88--- maastest/tests/test_kvmfixture.py 2013-11-20 09:48:51 +0000
89+++ maastest/tests/test_kvmfixture.py 2013-11-21 14:40:34 +0000
90@@ -488,6 +488,20 @@
91 check_call=True),
92 fake_run_command.mock_calls[-1])
93
94+ def test_install_packages_runs_apt_get_noninteractively_with_check(self):
95+ self.patch_run_command()
96+ packages = ['foo', 'bar']
97+ fixture = self.make_KVMFixture('series', 'architecture')
98+ kvm_run_command = mock.MagicMock(return_value=(0, '', ''))
99+ self.patch(kvmfixture.KVMFixture, 'run_command', kvm_run_command)
100+
101+ fixture.install_packages(packages)
102+
103+ self.assertEqual(
104+ [mock.call(
105+ kvmfixture.APT_GET_INSTALL + packages, check_call=True)],
106+ kvm_run_command.mock_calls)
107+
108 def test_run_command_runs_command_remotely(self):
109 fake_run_command = self.patch_run_command()
110 series = "test-series"
111
112=== modified file 'maastest/tests/test_maasfixture.py'
113--- maastest/tests/test_maasfixture.py 2013-11-18 16:03:32 +0000
114+++ maastest/tests/test_maasfixture.py 2013-11-21 14:40:34 +0000
115@@ -221,18 +221,6 @@
116 client = maas_fixture.get_maas_api_client(actual_api_key)
117 self.assertIsInstance(client, MAASClient)
118
119- def test_install_packages_runs_apt_get_noninteractively_with_check(self):
120- fixture = self.make_kvm_fixture()
121- packages = ['foo', 'bar']
122- maas_fixture = maasfixture.MAASFixture(fixture)
123-
124- maas_fixture.install_packages(packages)
125-
126- self.assertEqual(
127- [mock.call(
128- maasfixture.APT_GET_INSTALL + packages, check_call=True)],
129- fixture.run_command.mock_calls)
130-
131 def test_install_maas_installs_integrates_with_install_packages(self):
132 fixture = self.make_kvm_fixture()
133 maas_fixture = maasfixture.MAASFixture(fixture)
134@@ -241,7 +229,7 @@
135
136 fixture.run_command.assert_has_call(
137 mock.call(
138- maasfixture.APT_GET_INSTALL + ['language-pack-en'],
139+ kvmfixture.APT_GET_INSTALL + ['language-pack-en'],
140 check_call=True),
141 )
142
143@@ -251,7 +239,7 @@
144 fixture = self.make_kvm_fixture()
145 fake_install = mock.MagicMock()
146 maas_fixture = maasfixture.MAASFixture(fixture)
147- self.patch(maas_fixture, 'install_packages', fake_install)
148+ self.patch(fixture, 'install_packages', fake_install)
149
150 maas_fixture.install_maas()
151

Subscribers

People subscribed via source and target branches