Merge lp:~jtv/maas-test/var-cache into lp:maas-test

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: 106
Merged at revision: 105
Proposed branch: lp:~jtv/maas-test/var-cache
Merge into: lp:maas-test
Diff against target: 273 lines (+35/-35)
8 files modified
docs/man/maas-test.8.rst (+6/-7)
maastest/kvmfixture.py (+7/-7)
maastest/proxyfixture.py (+1/-2)
maastest/report.py (+2/-3)
maastest/tests/test_kvmfixture.py (+6/-6)
maastest/utils.py (+7/-1)
man/maas-test.8 (+6/-7)
packages.txt (+0/-2)
To merge this branch: bzr merge lp:~jtv/maas-test/var-cache
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+200951@code.launchpad.net

Commit message

Move ~/.config/maas-test into /var/cache/.

Description of the change

As agreed with Julian. This is not the complete change: we also agreed to move the pidfiles for polipo into /run. It all follows from the fact that we now run maas-test in its entirety as root, instead of sudo'ing all over the place: maas-test's state is now effectively global system state. This also resolves the nastiness of having ~/.config/maas-test, in your own home directory, owned by root. As an added bonus, we no longer run the risk of test runs accidentally creating the directory.

What you see here is not the full story; we also agreed to move the pidfiles into /var/run. I'm leaving that for my next branch. Some of the other items might fit in better with /var/lib, but we'll ignore that for now — the important thing is that you can delete /var/cache/maas-test and start over without past runs coming back to haunt you.

Some of the changes you'll see in the diff are:
 * DEFAULT_STATE_DIR now provides a single shared, global default location.
 * xdg is no longer needed.
 * Documentation no longer says this stuff is in ~/.maas-test — we never updated that.
 * Generated man page has been re-generated. Don't bother reviewing that part.

Jeroen

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

Lovely, thank you. Minor gripes inline for things I thought of after
our call. Sorry ...

>
> === modified file 'docs/man/maas-test.8.rst' ---
> docs/man/maas-test.8.rst 2014-01-08 07:33:48 +0000 +++
> docs/man/maas-test.8.rst 2014-01-09 05:13:48 +0000 @@ -108,8 +108,8
> @@ developers, by filing a Launchpad bug which includes the test
> results as an attachment.
>
> -By defaults the results will also be written to timestamped log
> files -under `~/.maas-test/logs`. +By default, the results are also
> written to timestamped log files under
> +`/var/cache/maas-test/logs`.

We should put them in /var/log/ Sorry I neglected to mention this before.

>
>
> Options @@ -188,7 +188,7 @@ test runs, but also caches a large
> amount of data on the testing system's filesystem. The proxy
> software used is `polipo`. The cache will be stored under -
> `~/.maas-test`. + `/var/cache/maas-test`.
>
> .. _`reporting options`:
>
> @@ -199,7 +199,7 @@ --log-results-only Write test results to a
> file, but don't upload them to Launchpad. Results will be written
> to a timestamped log file under - ~/.maas-test/logs. +
> `/var/cache/maas-test/logs`.

/var/log/

> + :param ssh_key_dir: Optional directory in which to store
> the SSH keys + for connecting to this KVM instance.
> Defaults to the default state + directory.

This is a bit awkward. "Defaults to the default..." Can you be more
specific? I think it's ok to mention /var/cache.

> if log_dir is None: - log_dir = os.path.join( -
> BaseDirectory.save_config_path('maas-test'), 'logs') +
> log_dir = DEFAULT_STATE_DIR

/var/log/maas-test

Lastly, check the packaging branch, you might be able to remove
python-xdg as a dependency.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlLOODgACgkQWhGlTF8G/HdX2gCdHeAsEo+7rzLkZ1eMFoMTcbb/
zg8AnRUI4zs3807YNAhMdASSk3AFf1cp
=ZO+r
-----END PGP SIGNATURE-----

review: Approve
lp:~jtv/maas-test/var-cache updated
106. By Jeroen T. Vermeulen

Review change in docstring.

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

> > -By defaults the results will also be written to timestamped log
> > files -under `~/.maas-test/logs`. +By default, the results are also
> > written to timestamped log files under
> > +`/var/cache/maas-test/logs`.
>
> We should put them in /var/log/ Sorry I neglected to mention this before.

Told you /var/cache wasn't right for everything. :) I'll do that part in a separate branch because there will be testing repercussions. We don't want tests to try and create /var/log/maas-test (so it needs to be patched), and conversely we do want a production run to create it (so it needs to be tested).

> > + :param ssh_key_dir: Optional directory in which to store
> > the SSH keys + for connecting to this KVM instance.
> > Defaults to the default state + directory.
>
> This is a bit awkward. "Defaults to the default..." Can you be more
> specific? I think it's ok to mention /var/cache.

OK, done.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/man/maas-test.8.rst'
2--- docs/man/maas-test.8.rst 2014-01-08 07:33:48 +0000
3+++ docs/man/maas-test.8.rst 2014-01-09 05:58:44 +0000
4@@ -108,8 +108,8 @@
5 developers, by filing a Launchpad bug which includes the test results as an
6 attachment.
7
8-By defaults the results will also be written to timestamped log files
9-under `~/.maas-test/logs`.
10+By default, the results are also written to timestamped log files under
11+`/var/cache/maas-test/logs`.
12
13
14 Options
15@@ -188,7 +188,7 @@
16 test runs, but also caches a large amount of data on the testing system's
17 filesystem.
18 The proxy software used is `polipo`. The cache will be stored under
19- `~/.maas-test`.
20+ `/var/cache/maas-test`.
21
22 .. _`reporting options`:
23
24@@ -199,7 +199,7 @@
25 --log-results-only
26 Write test results to a file, but don't upload them to Launchpad.
27 Results will be written to a timestamped log file under
28- ~/.maas-test/logs.
29+ `/var/cache/maas-test/logs`.
30
31
32 Reporting bugs
33@@ -226,9 +226,8 @@
34 Files
35 =====
36
37-State and configuration for `maas-test` is stored in the user's home directory,
38-under `~/.maas-test`. This includes an ssh key pair for communicating with the
39-virtual machine.
40+State and configuration for `maas-test` is stored in `/var/cache/maas-test`.
41+This includes an ssh key pair for communicating with the virtual machine.
42
43 If you choose to run a local proxy, downloaded data will also be cached there.
44 It can quickly grow to gigabyte sizes.
45
46=== modified file 'maastest/kvmfixture.py'
47--- maastest/kvmfixture.py 2014-01-08 17:31:43 +0000
48+++ maastest/kvmfixture.py 2014-01-09 05:58:44 +0000
49@@ -26,6 +26,7 @@
50 from fixtures import Fixture
51 from lxml import etree
52 from maastest.utils import (
53+ DEFAULT_STATE_DIR,
54 extract_mac_ip_mapping,
55 retries,
56 run_command,
57@@ -33,7 +34,6 @@
58 import netaddr
59 from six import text_type
60 from testtools.content import text_content
61-from xdg import BaseDirectory
62
63 # Maximum wait for the virtual machine to complete its cloud-init
64 # initialization. It can take quite a while, because it performs an
65@@ -110,9 +110,9 @@
66 :param archives: An optional list of repository names. If provided,
67 each repository will be added onto the VM.
68 :type archives: list
69- :param ssh_key_dir: The directory in which to store the SSH keys
70- for connecting to this KVM instance. If None, this defaults
71- to the default XDG config directory.
72+ :param ssh_key_dir: Optional directory in which to store the SSH keys
73+ for connecting to this KVM instance. Defaults to
74+ `/var/cache/maas-test`.
75 :type ssh_key_dir: string.
76 """
77 super(KVMFixture, self).__init__()
78@@ -136,7 +136,7 @@
79 name = text_type(uuid1())
80 self.name = name
81 if ssh_key_dir is None:
82- ssh_key_dir = BaseDirectory.save_config_path('maas-test')
83+ ssh_key_dir = DEFAULT_STATE_DIR
84 self.ssh_private_key_file = os.path.join(
85 ssh_key_dir, 'vm_ssh_id_rsa')
86 self.running = False
87@@ -205,8 +205,8 @@
88 def generate_ssh_key(self):
89 """Set up an ssh key pair for accessing the virtual machine.
90
91- The key pair will be in a directory `~/.maas-test/`. If this did not
92- exist yet, it will be created.
93+ The key pair will be stored in the SSH key directory `ssh_key_dir`.
94+ If this did not exist yet, it will be created.
95 """
96 key_dir = os.path.dirname(self.ssh_private_key_file)
97 if not os.path.exists(key_dir):
98
99=== modified file 'maastest/proxyfixture.py'
100--- maastest/proxyfixture.py 2014-01-08 17:31:43 +0000
101+++ maastest/proxyfixture.py 2014-01-09 05:58:44 +0000
102@@ -23,7 +23,6 @@
103 from maastest import utils
104 from netaddr import IPNetwork
105 import netifaces
106-from xdg import BaseDirectory
107
108
109 DISK_CACHE_ROOT = '%(config_dir)s/proxy_cache/'
110@@ -75,7 +74,7 @@
111 super(LocalProxyFixture, self).__init__()
112 self.port = port
113 if config_dir is None:
114- config_dir = BaseDirectory.save_config_path('maas-test')
115+ config_dir = utils.DEFAULT_STATE_DIR
116 self.config_dir = config_dir
117 self.pid_file = os.path.join(self.config_dir, 'proxy.pid')
118 self._network_address = None
119
120=== modified file 'maastest/report.py'
121--- maastest/report.py 2014-01-08 10:56:59 +0000
122+++ maastest/report.py 2014-01-09 05:58:44 +0000
123@@ -28,7 +28,7 @@
124 )
125
126 from apiclient import multipart
127-from xdg import BaseDirectory
128+from maastest.utils import DEFAULT_STATE_DIR
129
130
131 # This is largely cargo-culted from apiclient.multipart because
132@@ -128,8 +128,7 @@
133 :param log_dir: The directory under which to create `log_file_name`.
134 """
135 if log_dir is None:
136- log_dir = os.path.join(
137- BaseDirectory.save_config_path('maas-test'), 'logs')
138+ log_dir = DEFAULT_STATE_DIR
139 if not os.path.exists(log_dir):
140 os.makedirs(log_dir)
141
142
143=== modified file 'maastest/tests/test_kvmfixture.py'
144--- maastest/tests/test_kvmfixture.py 2014-01-08 17:31:43 +0000
145+++ maastest/tests/test_kvmfixture.py 2014-01-09 05:58:44 +0000
146@@ -41,10 +41,10 @@
147 super(TestKVMFixture, self).setUp()
148 self.logger = self.useFixture(fixtures.FakeLogger())
149 self.patch(kvmfixture, 'sleep', mock.MagicMock())
150- # KVMFixture.generate_ssh_key() generates an ssh key in ~/.maas-test,
151- # creating that directory if necessary. Set up a fake home directory
152- # so it can do what it needs to.
153- self.home_dir = self.useFixture(fixtures.TempDir()).path
154+ # KVMFixture.generate_ssh_key() generates an ssh key in maas-test's
155+ # configuration directory, creating that directory if necessary. Set
156+ # up a temporary directory so it can do what it needs to.
157+ self.state_dir = self.useFixture(fixtures.TempDir()).path
158
159 def patch_run_command(self, return_value=0, stdout=b'', stderr=b''):
160 """Patch out `kvmfixture` calls to `run_command`.
161@@ -77,7 +77,7 @@
162 series, architecture, name=name,
163 direct_interface=direct_interface,
164 direct_network=direct_network, archives=archives,
165- proxy_url=proxy_url, ssh_key_dir=self.home_dir)
166+ proxy_url=proxy_url, ssh_key_dir=self.state_dir)
167 # Hack to get fixture.addDetail to work without actually calling
168 # fixture.setUp().
169 fixture._details = {}
170@@ -290,7 +290,7 @@
171 self.assertThat(fixture.ssh_private_key_file, FileExists())
172 self.assertThat(fixture.get_ssh_public_key_file(), FileExists())
173 self.assertThat(
174- fixture.ssh_private_key_file, StartsWith(self.home_dir + '/'))
175+ fixture.ssh_private_key_file, StartsWith(self.state_dir + '/'))
176
177 self.assertThat(
178 fixture.ssh_private_key_file,
179
180=== modified file 'maastest/utils.py'
181--- maastest/utils.py 2014-01-08 17:31:43 +0000
182+++ maastest/utils.py 2014-01-09 05:58:44 +0000
183@@ -1,4 +1,4 @@
184-# Copyright 2013 Canonical Ltd. This software is licensed under the
185+# Copyright 2013-2014 Canonical Ltd. This software is licensed under the
186 # GNU Affero General Public License version 3 (see the file LICENSE).
187
188 """maas-test utilities."""
189@@ -13,6 +13,7 @@
190 __all__ = [
191 "BINARY",
192 "binary_content",
193+ "DEFAULT_STATE_DIR",
194 "determine_vm_series",
195 "determine_vm_architecture",
196 "get_uri",
197@@ -45,6 +46,11 @@
198 from testtools.content_type import ContentType
199
200
201+# Default location for maas-test state, such as SSH keys for the virtual
202+# machine, and the http proxy cache.
203+DEFAULT_STATE_DIR = '/var/cache/maas-test'
204+
205+
206 def read_file(path):
207 """Return a given file's contents, as `bytes`."""
208 with open(path, "rb") as f:
209
210=== modified file 'man/maas-test.8'
211--- man/maas-test.8 2014-01-08 07:33:58 +0000
212+++ man/maas-test.8 2014-01-09 05:58:44 +0000
213@@ -121,8 +121,8 @@
214 developers, by filing a Launchpad bug which includes the test results as an
215 attachment.
216 .sp
217-By defaults the results will also be written to timestamped log files
218-under \fI~/.maas\-test/logs\fP\&.
219+By default, the results are also written to timestamped log files under
220+\fI/var/cache/maas\-test/logs\fP\&.
221 .SH OPTIONS
222 .INDENT 0.0
223 .TP
224@@ -199,7 +199,7 @@
225 test runs, but also caches a large amount of data on the testing system\(aqs
226 filesystem.
227 The proxy software used is \fIpolipo\fP\&. The cache will be stored under
228-\fI~/.maas\-test\fP\&.
229+\fI/var/cache/maas\-test\fP\&.
230 .UNINDENT
231 .INDENT 0.0
232 .TP
233@@ -210,7 +210,7 @@
234 .B \-\-log\-results\-only
235 Write test results to a file, but don\(aqt upload them to Launchpad.
236 Results will be written to a timestamped log file under
237-~/.maas\-test/logs.
238+\fI/var/cache/maas\-test/logs\fP\&.
239 .UNINDENT
240 .SH REPORTING BUGS
241 .sp
242@@ -228,9 +228,8 @@
243 Ubuntu virtualization tools (uvtool): \fI\%https://launchpad.net/uvtool\fP
244 .SH FILES
245 .sp
246-State and configuration for \fImaas\-test\fP is stored in the user\(aqs home directory,
247-under \fI~/.maas\-test\fP\&. This includes an ssh key pair for communicating with the
248-virtual machine.
249+State and configuration for \fImaas\-test\fP is stored in \fI/var/cache/maas\-test\fP\&.
250+This includes an ssh key pair for communicating with the virtual machine.
251 .sp
252 If you choose to run a local proxy, downloaded data will also be cached there.
253 It can quickly grow to gigabyte sizes.
254
255=== modified file 'packages.txt'
256--- packages.txt 2013-12-06 07:02:08 +0000
257+++ packages.txt 2014-01-09 05:58:44 +0000
258@@ -11,7 +11,6 @@
259 python-testresources
260 python-testtools
261 python-virtualenv
262-python-xdg
263 python3-fixtures
264 python3-lxml
265 python3-mock
266@@ -19,7 +18,6 @@
267 python3-six
268 python3-testresources
269 python3-testtools
270-python3-xdg
271 qemu-kvm
272 uvtool
273 uvtool-libvirt

Subscribers

People subscribed via source and target branches