Merge lp:~barry/ubuntu-system-image/citrain232 into lp:~ubuntu-managed-branches/ubuntu-system-image/system-image

Proposed by Barry Warsaw
Status: Merged
Approved by: Barry Warsaw
Approved revision: 237
Merged at revision: 235
Proposed branch: lp:~barry/ubuntu-system-image/citrain232
Merge into: lp:~ubuntu-managed-branches/ubuntu-system-image/system-image
Diff against target: 260 lines (+100/-22)
10 files modified
NEWS.rst (+6/-0)
PKG-INFO (+1/-1)
debian/changelog (+14/-0)
debian/control (+11/-10)
setup.cfg (+1/-1)
system_image.egg-info/PKG-INFO (+1/-1)
systemimage/settings.py (+28/-5)
systemimage/tests/test_config.py (+5/-2)
systemimage/tests/test_settings.py (+32/-1)
systemimage/version.txt (+1/-1)
To merge this branch: bzr merge lp:~barry/ubuntu-system-image/citrain232
Reviewer Review Type Date Requested Status
Ubuntu CI managed package branches Pending
Review via email: mp+229149@code.launchpad.net

Commit message

Description of the change

2.3.2 (2014-07-31)
==================
 * When system-image-{cli,dbus} is run as non-root, use a fallback location
   for the settings.db file, if the parent directory isn't writable.
   (LP: #1349478)

To post a comment you must log in.
236. By Barry Warsaw

* d/control:
  - Bump X-Python3-Version to (Python) 3.4.
  - Update run-time dependencies so that system-image-common now depends
    on python3-dbus and python3-xdg, while -dbus and -cli only need to
    depend on system-image-common.

237. By Barry Warsaw

bump version number for ppa happiness

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS.rst'
2--- NEWS.rst 2014-07-23 22:51:19 +0000
3+++ NEWS.rst 2014-08-01 18:33:04 +0000
4@@ -2,6 +2,12 @@
5 NEWS for system-image updater
6 =============================
7
8+2.3.2 (2014-07-31)
9+==================
10+ * When system-image-{cli,dbus} is run as non-root, use a fallback location
11+ for the settings.db file, if the parent directory isn't writable.
12+ (LP: #1349478)
13+
14 2.3.1 (2014-07-23)
15 ==================
16 * Fix a traceback that occurs when the `systemimage.testing` subpackage isn't
17
18=== modified file 'PKG-INFO'
19--- PKG-INFO 2014-07-23 17:56:24 +0000
20+++ PKG-INFO 2014-08-01 18:33:04 +0000
21@@ -1,6 +1,6 @@
22 Metadata-Version: 1.0
23 Name: system-image
24-Version: 2.3.1
25+Version: 2.3.2
26 Summary: Ubuntu System Image Based Upgrades
27 Home-page: UNKNOWN
28 Author: Barry Warsaw
29
30=== modified file 'debian/changelog'
31--- debian/changelog 2014-07-23 23:07:39 +0000
32+++ debian/changelog 2014-08-01 18:33:04 +0000
33@@ -1,3 +1,17 @@
34+system-image (2.3.2-0ubuntu2) UNRELEASED; urgency=medium
35+
36+ * New upstream release.
37+ - LP: #1349478 - When system-image-{cli,dbus} is run as non-root, use
38+ a fallback location for the settings.db file, if the parent
39+ directory isn't writable.
40+ * d/control:
41+ - Bump X-Python3-Version to (Python) 3.4.
42+ - Update run-time dependencies so that system-image-common now depends
43+ on python3-dbus and python3-xdg, while -dbus and -cli only need to
44+ depend on system-image-common.
45+
46+ -- Barry Warsaw <barry@ubuntu.com> Fri, 01 Aug 2014 14:32:02 -0400
47+
48 system-image (2.3.1-0ubuntu1) utopic; urgency=medium
49
50 [ Barry Warsaw ]
51
52=== modified file 'debian/control'
53--- debian/control 2014-07-17 18:11:57 +0000
54+++ debian/control 2014-08-01 18:33:04 +0000
55@@ -2,7 +2,7 @@
56 Maintainer: Barry Warsaw <barry@ubuntu.com>
57 Homepage: https://wiki.ubuntu.com/ImageBasedUpgrades
58 Section: python
59-X-Python3-Version: >= 3.3
60+X-Python3-Version: >= 3.4
61 Priority: optional
62 Build-Depends: dbus,
63 dbus-x11,
64@@ -36,18 +36,19 @@
65
66 Package: system-image-dbus
67 Architecture: all
68+Depends: system-image-common (= ${binary:Version}),
69+ ${misc:Depends},
70+ ${python3:Depends}
71+Description: Ubuntu system image updater command line client
72+ This is the command line client for the Ubuntu system image updater.
73+
74+Package: system-image-common
75+Architecture: all
76 Depends: python3-dbus,
77 python3-gi,
78- system-image-common (= ${binary:Version}),
79- ${misc:Depends},
80- ${python3:Depends}
81-Description: Ubuntu system image updater command line client
82- This is the command line client for the Ubuntu system image updater.
83-
84-Package: system-image-common
85-Architecture: all
86-Depends: python3-gnupg,
87+ python3-gnupg,
88 python3-pkg-resources,
89+ python3-xdg,
90 ubuntu-download-manager,
91 ${misc:Depends},
92 ${python3:Depends}
93
94=== modified file 'setup.cfg'
95--- setup.cfg 2014-07-23 22:51:19 +0000
96+++ setup.cfg 2014-08-01 18:33:04 +0000
97@@ -4,7 +4,7 @@
98 logging-filter = systemimage
99
100 [egg_info]
101+tag_svn_revision = 0
102 tag_date = 0
103 tag_build =
104-tag_svn_revision = 0
105
106
107=== modified file 'system_image.egg-info/PKG-INFO'
108--- system_image.egg-info/PKG-INFO 2014-07-23 17:56:24 +0000
109+++ system_image.egg-info/PKG-INFO 2014-08-01 18:33:04 +0000
110@@ -1,6 +1,6 @@
111 Metadata-Version: 1.0
112 Name: system-image
113-Version: 2.3.1
114+Version: 2.3.2
115 Summary: Ubuntu System Image Based Upgrades
116 Home-page: UNKNOWN
117 Author: Barry Warsaw
118
119=== modified file 'systemimage/settings.py'
120--- systemimage/settings.py 2014-07-23 22:51:19 +0000
121+++ systemimage/settings.py 2014-08-01 18:33:04 +0000
122@@ -23,7 +23,9 @@
123 import sqlite3
124
125 from contextlib import contextmanager
126+from pathlib import Path
127 from systemimage.config import config
128+from xdg.BaseDirectory import xdg_cache_home
129
130 SCHEMA_VERSION = '1'
131 AUTO_DOWNLOAD_DEFAULT = '1'
132@@ -32,7 +34,16 @@
133 class Settings:
134 def __init__(self, use_config=None):
135 self._use_config = use_config
136- # If the database file does not yet exist, create it.
137+ # If the database file does not yet exist, create it. This could fail,
138+ # as LP: #1349478 describes, if the parent directory containing
139+ # settings.db is not writable by the process. In that case, fall back
140+ # to a user path.
141+ self._dbpath = None
142+ try:
143+ with self._cursor():
144+ pass
145+ except sqlite3.OperationalError:
146+ self._check_fallback()
147 with self._cursor() as c:
148 c.execute('select tbl_name from sqlite_master')
149 if len(c.fetchall()) == 0:
150@@ -43,12 +54,24 @@
151 c.execute('insert into settings values ("__version__", ?)',
152 (SCHEMA_VERSION,))
153
154+ def _check_fallback(self):
155+ # This is refactored into a separate method for testing purposes.
156+ self._dbpath = Path(xdg_cache_home) / 'lib' / 'settings.db'
157+ try:
158+ self._dbpath.parent.mkdir(parents=True)
159+ except FileExistsError:
160+ # http://bugs.python.org/issue21539
161+ pass
162+ with self._cursor():
163+ pass
164+
165 @contextmanager
166 def _cursor(self):
167- dbpath = (config.system.settings_db
168- if self._use_config is None
169- else self._use_config.system.settings_db)
170- with sqlite3.connect(dbpath) as conn:
171+ if self._dbpath is None:
172+ self._dbpath = (config.system.settings_db
173+ if self._use_config is None
174+ else self._use_config.system.settings_db)
175+ with sqlite3.connect(str(self._dbpath)) as conn:
176 yield conn.cursor()
177
178 def set(self, key, value):
179
180=== modified file 'systemimage/tests/test_config.py'
181--- systemimage/tests/test_config.py 2014-07-23 22:51:19 +0000
182+++ systemimage/tests/test_config.py 2014-08-01 18:33:04 +0000
183@@ -28,7 +28,7 @@
184
185 from datetime import timedelta
186 from pkg_resources import resource_filename
187-from subprocess import check_output
188+from subprocess import CalledProcessError, check_output
189 from systemimage.config import Configuration
190 from systemimage.device import SystemProperty
191 from systemimage.reboot import Reboot
192@@ -198,7 +198,10 @@
193 config = Configuration()
194 # Silence the log exceptions this will provoke.
195 with patch('systemimage.device.logging.getLogger'):
196- self.assertEqual(config.device, '?')
197+ # It's possible getprop actually does exist on the system.
198+ with patch('systemimage.device.check_output',
199+ side_effect=CalledProcessError(1, 'ignore')):
200+ self.assertEqual(config.device, '?')
201
202 @configuration
203 def test_get_channel(self, ini_file):
204
205=== modified file 'systemimage/tests/test_settings.py'
206--- systemimage/tests/test_settings.py 2014-07-23 22:51:19 +0000
207+++ systemimage/tests/test_settings.py 2014-08-01 18:33:04 +0000
208@@ -23,9 +23,13 @@
209 import os
210 import unittest
211
212+from contextlib import ExitStack
213+from pathlib import Path
214 from systemimage.config import Configuration
215+from systemimage.helpers import temporary_directory
216 from systemimage.settings import Settings
217-from systemimage.testing.helpers import configuration
218+from systemimage.testing.helpers import chmod, configuration
219+from unittest.mock import patch
220
221
222 class TestSettings(unittest.TestCase):
223@@ -99,3 +103,30 @@
224 keyval = list(settings)
225 keyval.sort()
226 self.assertEqual(keyval, [('a', 'ant'), ('b', 'bee'), ('c', 'cat')])
227+
228+ @configuration
229+ def test_settings_db_permission_denied(self, ini_file):
230+ # LP: #1349478 - some tests are run as non-root, meaning they don't
231+ # have write permission to /var/lib/system-image. This is where
232+ # settings.db gets created, but if the process can't create files
233+ # there, we get a sqlite3 exception.
234+ config = Configuration(ini_file)
235+ db_file = Path(config.system.settings_db)
236+ self.assertFalse(db_file.exists())
237+ with ExitStack() as resources:
238+ resources.enter_context(chmod(str(db_file.parent), 0o555))
239+ # With no fallback, this will fail.
240+ with patch('systemimage.settings.Settings._check_fallback',
241+ side_effect=RuntimeError):
242+ self.assertRaises(RuntimeError, Settings)
243+ # Now, set the XDG cache directory to a temporary directory, allow
244+ # the fallback to work and try again.
245+ tmpdir = resources.enter_context(temporary_directory())
246+ resources.enter_context(
247+ patch('systemimage.settings.xdg_cache_home', tmpdir))
248+ settings = Settings()
249+ settings.set('bar', 'baz')
250+ self.assertEqual(Settings().get('bar'), 'baz')
251+ # The settings.db file still doesn't exist because it got
252+ # created in a different place.
253+ self.assertFalse(db_file.exists())
254
255=== modified file 'systemimage/version.txt'
256--- systemimage/version.txt 2014-07-23 22:51:19 +0000
257+++ systemimage/version.txt 2014-08-01 18:33:04 +0000
258@@ -1,1 +1,1 @@
259-2.3.1
260+2.3.2

Subscribers

People subscribed via source and target branches