Merge lp:~gmb/maas-test/import-images into lp:maas-test

Proposed by Graham Binns
Status: Merged
Merged at revision: 39
Proposed branch: lp:~gmb/maas-test/import-images
Merge into: lp:maas-test
Diff against target: 104 lines (+35/-3)
4 files modified
maastest/kvmfixture.py (+7/-0)
maastest/maasfixture.py (+13/-3)
maastest/tests/test_maasfixture.py (+14/-0)
packages.txt (+1/-0)
To merge this branch: bzr merge lp:~gmb/maas-test/import-images
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Gavin Panella (community) Approve
Review via email: mp+195550@code.launchpad.net

Description of the change

This branch makes importing PXE files a setup step for the MAAS fixture. It updates the import_pxe_files config directly rather than using `export` because the latter didn't persist across SSH sessions.

To post a comment you must log in.
lp:~gmb/maas-test/import-images updated
50. By Graham Binns

Added a todo.

Revision history for this message
Gavin Panella (allenap) wrote :

Nice. A few very minor comments.

[1]

+        # latter doesn't seem to work stick across SSH sessions. I don't

I assume "work stick" is a northern expression? :)

[2]

+        # know whether that's because # we're doing it over SSH and not

Extra #

[3]

+        expected_pxe_config_snippet = (
+            '\n'
+            'RELEASES="precise"\n'
+            'ARCHES="amd64/generic i386/generic"\n'
+            '\n')

This would be easier to read as:

        expected_pxe_config_snippet = dedent("""\

            RELEASES="precise"
            ARCHES="amd64/generic i386/generic"

            """

[4]

+        self.assertEqual(
+            expected_command, kvm_fixture.run_command.mock_calls[0])

I guess it's somewhat important that the config call is the first. Can
you note this here, so that this doesn't get changed to using
<mock>.assert_any_call()?

[5]

+        self.assertEqual(
+            mock.call([u'sudo', u'maas-import-pxe-files'], check_call=True),
+            kvm_fixture.run_command.mock_calls[-1])

Similar comment about ordering here.

review: Approve
Revision history for this message
Raphaël Badin (rvb) wrote :

Looks nice, but I've got a question, see [1].

[0]

32 === modified file 'maastest/maasfixture.py'
33 --- maastest/maasfixture.py 2013-11-15 14:14:29 +0000
34 +++ maastest/maasfixture.py 2013-11-18 09:48:39 +0000
[...]
39 - def import_maas_images(self, admin_user, api_key):
40 + def import_maas_images(self):

It's really fine to have 'RELEASES="precise" and 'ARCHES="amd64/generic i386/generic" hardcoded from now but it would be nice to have them hardcoded in maastest/main.py and passed to MAASFixture() (same as the parameters 'series' and 'architecture' used by KVMFixture). This way, when we will make them configurable, the change will be minimal. This is really just a detail but might be worth doing in a follow-up branch; this way, all the parameters (even those that are hardcoded for now) will be available at the highest level (i.e. in maastest/main.py) and we will have a nice list of all the config values in one place instead of hardcoded values scattered throughout the code.

[1]

50 + # Update the import_pxe_files config. The reason that we do this
51 + # rather than just `export`ing RELEASES and ARCHES is that the
52 + # latter doesn't seem to work stick across SSH sessions. I don't
53 + # know whether that's because # we're doing it over SSH and not
54 + # using shell=True on the Popen calls in run_command, but this,
55 + # on the other hand, definitely does work.

I'm a bit surprised by that, since we define "DEBIAN_FRONTEND=noninteractive" when we install packages in the VM (see maastest/maasfixture.py). Env variables are not carried over by sudo by default but how about defining the variables *inside* the command executed by sudo… something like:
sudo RELEASES="precise" ARCHES="amd64/generic i386/generic" maas-import-pxe-files
?

review: Needs Information
lp:~gmb/maas-test/import-images updated
51. By Graham Binns

Include config in command.

Revision history for this message
Graham Binns (gmb) wrote :

On 18 November 2013 13:19, Raphaël Badin <email address hidden> wrote:
>
> [0]
>
> 32 === modified file 'maastest/maasfixture.py'
> 33 --- maastest/maasfixture.py 2013-11-15 14:14:29 +0000
> 34 +++ maastest/maasfixture.py 2013-11-18 09:48:39 +0000
> [...]
> 39 - def import_maas_images(self, admin_user, api_key):
> 40 + def import_maas_images(self):
>
> It's really fine to have 'RELEASES="precise" and 'ARCHES="amd64/generic i386/generic" hardcoded from now but it would be nice to have them hardcoded in maastest/main.py and passed to MAASFixture() (same as the parameters 'series' and 'architecture' used by KVMFixture). This way, when we will make them configurable, the change will be minimal. This is really just a detail but might be worth doing in a follow-up branch; this way, all the parameters (even those that are hardcoded for now) will be available at the highest level (i.e. in maastest/main.py) and we will have a nice list of all the config values in one place instead of hardcoded values scattered throughout the code.

Agreeed. I'll do a follow-up.

> [1]
>
> 50 + # Update the import_pxe_files config. The reason that we do this
> 51 + # rather than just `export`ing RELEASES and ARCHES is that the
> 52 + # latter doesn't seem to work stick across SSH sessions. I don't
> 53 + # know whether that's because # we're doing it over SSH and not
> 54 + # using shell=True on the Popen calls in run_command, but this,
> 55 + # on the other hand, definitely does work.
>
> I'm a bit surprised by that, since we define "DEBIAN_FRONTEND=noninteractive" when we install packages in the VM (see maastest/maasfixture.py). Env variables are not carried over by sudo by default but how about defining the variables *inside* the command executed by sudo… something like:
> sudo RELEASES="precise" ARCHES="amd64/generic i386/generic" maas-import-pxe-files

WFM, I'll do that. It's not that defining the variables in the shell
doesn't work, it's that `export...` doesn't work — the DEBIAN_FRONTEND
variable is defined as part of the command executed by sudo, hence it
works fine.

Revision history for this message
Raphaël Badin (rvb) wrote :

> WFM, I'll do that. It's not that defining the variables in the shell
> doesn't work, it's that `export...` doesn't work — the DEBIAN_FRONTEND
> variable is defined as part of the command executed by sudo, hence it
> works fine.

Great, the code will be even simpler this way.

review: Approve
lp:~gmb/maas-test/import-images updated
52. By Graham Binns

Fixing quotes.

Revision history for this message
Raphaël Badin (rvb) wrote :

[2]

49 + logging.info("Importing MAAS PXE files.")

and

8 + logging.info(
9 + "Configuring network interface on virtual machine %s",
10 + self.name)

Btw, I've tried to put "..." at the end of the comments that indicate that an operation is being performed. Let's keep that convention here.

lp:~gmb/maas-test/import-images updated
53. By Graham Binns

Test fixes and shiznit.

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-15 15:48:07 +0000
3+++ maastest/kvmfixture.py 2013-11-18 16:04:03 +0000
4@@ -250,12 +250,18 @@
5 # Configure the bridged network if self.direct_interface is not
6 # None.
7 if self.direct_interface is not None:
8+ logging.info(
9+ "Configuring network interface on virtual machine %s...",
10+ self.name)
11 network_config_snippet = make_network_interface_config(
12 'eth1', self.direct_ip, self.direct_network)
13 self.run_command(
14 ["sudo", "tee", "-a", "/etc/network/interfaces"],
15 input=network_config_snippet, check_call=True)
16 self.run_command(["sudo", "ifup", "eth1"], check_call=True)
17+ logging.info(
18+ "Done configuring network interface on virtual machine %s",
19+ self.name)
20
21 def destroy(self):
22 """Destroy the virtual machine."""
23@@ -302,6 +308,7 @@
24 return retcode, stdout, stderr
25
26
27+
28 KVM_TEMPLATE = """
29 <domain type='kvm'>
30 <os>
31
32=== modified file 'maastest/maasfixture.py'
33--- maastest/maasfixture.py 2013-11-15 14:14:29 +0000
34+++ maastest/maasfixture.py 2013-11-18 16:04:03 +0000
35@@ -143,7 +143,7 @@
36
37 return username, password
38
39- def import_maas_images(self, admin_user, api_key):
40+ def import_maas_images(self):
41 """Import boot images into the MAAS instance.
42
43 This download gigabytes of data to the virtual machine's disk.
44@@ -152,7 +152,17 @@
45 :param admin_user: Login name for the MAAS admin user.
46 :param api_key: Admin user's API key.
47 """
48- # TODO: Actually implement.
49+ logging.info("Importing MAAS PXE files...")
50+ # TODO: ARCHES and RELEASES should come from command-line
51+ # parameters.
52+ self.kvm_fixture.run_command([
53+ u'sudo',
54+ u'RELEASES=precise',
55+ u'ARCHES=amd64/generic i386/generic',
56+ u'maas-import-pxe-files',
57+ ],
58+ check_call=True)
59+ logging.info("Done importing MAAS PXE Files.")
60
61 def setUp(self):
62 """Install and configure MAAS inside the virtual machine.
63@@ -174,7 +184,7 @@
64 self.admin_api_key = api_key
65 self.admin_maas_client = maas_client
66 # MAAS setup.
67- self.import_maas_images(admin_user, api_key)
68+ self.import_maas_images()
69 if self.kvm_fixture.direct_ip is not None:
70 self.check_cluster_connected()
71 self.configure_cluster()
72
73=== modified file 'maastest/tests/test_maasfixture.py'
74--- maastest/tests/test_maasfixture.py 2013-11-15 11:57:00 +0000
75+++ maastest/tests/test_maasfixture.py 2013-11-18 16:04:03 +0000
76@@ -430,3 +430,17 @@
77 maas_fixture.check_cluster_connected.mock_calls,
78 maas_fixture.configure_cluster.mock_calls,
79 ])
80+
81+ def test_import_mmas_images_imports_pxe_images(self):
82+ kvm_fixture = self.make_kvm_fixture()
83+ self.patch(kvm_fixture, 'run_command', mock.MagicMock())
84+ maas_fixture = maasfixture.MAASFixture(kvm_fixture)
85+ maas_fixture.import_maas_images()
86+ self.assertEqual(
87+ mock.call([
88+ u'sudo',
89+ u'RELEASES=precise',
90+ u'ARCHES=amd64/generic i386/generic',
91+ u'maas-import-pxe-files',
92+ ], check_call=True),
93+ kvm_fixture.run_command.mock_calls[-1])
94
95=== modified file 'packages.txt'
96--- packages.txt 2013-11-14 11:13:37 +0000
97+++ packages.txt 2013-11-18 16:04:03 +0000
98@@ -14,5 +14,6 @@
99 python3-six
100 python3-testresources
101 python3-testtools
102+qemu-kvm
103 uvtool
104 uvtool-libvirt

Subscribers

People subscribed via source and target branches