Merge lp:~gnuoy/charms/trusty/glance/stable-charm-sync into lp:~openstack-charmers-archive/charms/trusty/glance/trunk

Proposed by Liam Young
Status: Merged
Merged at revision: 53
Proposed branch: lp:~gnuoy/charms/trusty/glance/stable-charm-sync
Merge into: lp:~openstack-charmers-archive/charms/trusty/glance/trunk
Diff against target: 306 lines (+163/-14)
8 files modified
.bzrignore (+2/-0)
Makefile (+8/-2)
charm-helpers.yaml (+1/-1)
hooks/charmhelpers/contrib/openstack/context.py (+9/-4)
hooks/charmhelpers/core/fstab.py (+116/-0)
hooks/charmhelpers/core/host.py (+24/-6)
hooks/charmhelpers/fetch/__init__.py (+1/-0)
hooks/charmhelpers/fetch/bzrurl.py (+2/-1)
To merge this branch: bzr merge lp:~gnuoy/charms/trusty/glance/stable-charm-sync
Reviewer Review Type Date Requested Status
Chris Glass (community) Approve
Review via email: mp+230675@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Chris Glass (tribaal) wrote :

Looks good! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.bzrignore'
2--- .bzrignore 1970-01-01 00:00:00 +0000
3+++ .bzrignore 2014-08-13 16:35:01 +0000
4@@ -0,0 +1,2 @@
5+bin
6+.coverage
7
8=== modified file 'Makefile'
9--- Makefile 2014-05-21 10:13:31 +0000
10+++ Makefile 2014-08-13 16:35:01 +0000
11@@ -1,4 +1,5 @@
12 #!/usr/bin/make
13+PYTHON := /usr/bin/env python
14
15 lint:
16 @echo "Running flake8 tests: "
17@@ -8,8 +9,13 @@
18 @charm proof
19 @echo "OK"
20
21-sync:
22- @charm-helper-sync -c charm-helpers.yaml
23+bin/charm_helpers_sync.py:
24+ @mkdir -p bin
25+ @bzr cat lp:charm-helpers/tools/charm_helpers_sync/charm_helpers_sync.py \
26+ > bin/charm_helpers_sync.py
27+
28+sync: bin/charm_helpers_sync.py
29+ @$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers.yaml
30
31 test:
32 @$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests
33
34=== modified file 'charm-helpers.yaml'
35--- charm-helpers.yaml 2014-03-27 10:45:42 +0000
36+++ charm-helpers.yaml 2014-08-13 16:35:01 +0000
37@@ -1,4 +1,4 @@
38-branch: lp:charm-helpers
39+branch: lp:~openstack-charmers/charm-helpers/stable
40 destination: hooks/charmhelpers
41 include:
42 - core
43
44=== modified file 'hooks/charmhelpers/contrib/openstack/context.py'
45--- hooks/charmhelpers/contrib/openstack/context.py 2014-05-19 11:40:27 +0000
46+++ hooks/charmhelpers/contrib/openstack/context.py 2014-08-13 16:35:01 +0000
47@@ -24,6 +24,7 @@
48 unit_get,
49 unit_private_ip,
50 ERROR,
51+ INFO
52 )
53
54 from charmhelpers.contrib.hahelpers.cluster import (
55@@ -657,7 +658,7 @@
56 self.interface = interface
57
58 def __call__(self):
59- ctxt = {}
60+ ctxt = {'sections': {}}
61 for rid in relation_ids(self.interface):
62 for unit in related_units(rid):
63 sub_config = relation_get('subordinate_configuration',
64@@ -683,10 +684,14 @@
65
66 sub_config = sub_config[self.config_file]
67 for k, v in sub_config.iteritems():
68- ctxt[k] = v
69+ if k == 'sections':
70+ for section, config_dict in v.iteritems():
71+ log("adding section '%s'" % (section))
72+ ctxt[k][section] = config_dict
73+ else:
74+ ctxt[k] = v
75
76- if not ctxt:
77- ctxt['sections'] = {}
78+ log("%d section(s) found" % (len(ctxt['sections'])), level=INFO)
79
80 return ctxt
81
82
83=== added file 'hooks/charmhelpers/core/fstab.py'
84--- hooks/charmhelpers/core/fstab.py 1970-01-01 00:00:00 +0000
85+++ hooks/charmhelpers/core/fstab.py 2014-08-13 16:35:01 +0000
86@@ -0,0 +1,116 @@
87+#!/usr/bin/env python
88+# -*- coding: utf-8 -*-
89+
90+__author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>'
91+
92+import os
93+
94+
95+class Fstab(file):
96+ """This class extends file in order to implement a file reader/writer
97+ for file `/etc/fstab`
98+ """
99+
100+ class Entry(object):
101+ """Entry class represents a non-comment line on the `/etc/fstab` file
102+ """
103+ def __init__(self, device, mountpoint, filesystem,
104+ options, d=0, p=0):
105+ self.device = device
106+ self.mountpoint = mountpoint
107+ self.filesystem = filesystem
108+
109+ if not options:
110+ options = "defaults"
111+
112+ self.options = options
113+ self.d = d
114+ self.p = p
115+
116+ def __eq__(self, o):
117+ return str(self) == str(o)
118+
119+ def __str__(self):
120+ return "{} {} {} {} {} {}".format(self.device,
121+ self.mountpoint,
122+ self.filesystem,
123+ self.options,
124+ self.d,
125+ self.p)
126+
127+ DEFAULT_PATH = os.path.join(os.path.sep, 'etc', 'fstab')
128+
129+ def __init__(self, path=None):
130+ if path:
131+ self._path = path
132+ else:
133+ self._path = self.DEFAULT_PATH
134+ file.__init__(self, self._path, 'r+')
135+
136+ def _hydrate_entry(self, line):
137+ # NOTE: use split with no arguments to split on any
138+ # whitespace including tabs
139+ return Fstab.Entry(*filter(
140+ lambda x: x not in ('', None),
141+ line.strip("\n").split()))
142+
143+ @property
144+ def entries(self):
145+ self.seek(0)
146+ for line in self.readlines():
147+ try:
148+ if not line.startswith("#"):
149+ yield self._hydrate_entry(line)
150+ except ValueError:
151+ pass
152+
153+ def get_entry_by_attr(self, attr, value):
154+ for entry in self.entries:
155+ e_attr = getattr(entry, attr)
156+ if e_attr == value:
157+ return entry
158+ return None
159+
160+ def add_entry(self, entry):
161+ if self.get_entry_by_attr('device', entry.device):
162+ return False
163+
164+ self.write(str(entry) + '\n')
165+ self.truncate()
166+ return entry
167+
168+ def remove_entry(self, entry):
169+ self.seek(0)
170+
171+ lines = self.readlines()
172+
173+ found = False
174+ for index, line in enumerate(lines):
175+ if not line.startswith("#"):
176+ if self._hydrate_entry(line) == entry:
177+ found = True
178+ break
179+
180+ if not found:
181+ return False
182+
183+ lines.remove(line)
184+
185+ self.seek(0)
186+ self.write(''.join(lines))
187+ self.truncate()
188+ return True
189+
190+ @classmethod
191+ def remove_by_mountpoint(cls, mountpoint, path=None):
192+ fstab = cls(path=path)
193+ entry = fstab.get_entry_by_attr('mountpoint', mountpoint)
194+ if entry:
195+ return fstab.remove_entry(entry)
196+ return False
197+
198+ @classmethod
199+ def add(cls, device, mountpoint, filesystem, options=None, path=None):
200+ return cls(path=path).add_entry(Fstab.Entry(device,
201+ mountpoint, filesystem,
202+ options=options))
203
204=== modified file 'hooks/charmhelpers/core/host.py'
205--- hooks/charmhelpers/core/host.py 2014-05-19 11:40:27 +0000
206+++ hooks/charmhelpers/core/host.py 2014-08-13 16:35:01 +0000
207@@ -17,6 +17,7 @@
208 from collections import OrderedDict
209
210 from hookenv import log
211+from fstab import Fstab
212
213
214 def service_start(service_name):
215@@ -35,7 +36,8 @@
216
217
218 def service_reload(service_name, restart_on_failure=False):
219- """Reload a system service, optionally falling back to restart if reload fails"""
220+ """Reload a system service, optionally falling back to restart if
221+ reload fails"""
222 service_result = service('reload', service_name)
223 if not service_result and restart_on_failure:
224 service_result = service('restart', service_name)
225@@ -144,7 +146,19 @@
226 target.write(content)
227
228
229-def mount(device, mountpoint, options=None, persist=False):
230+def fstab_remove(mp):
231+ """Remove the given mountpoint entry from /etc/fstab
232+ """
233+ return Fstab.remove_by_mountpoint(mp)
234+
235+
236+def fstab_add(dev, mp, fs, options=None):
237+ """Adds the given device entry to the /etc/fstab file
238+ """
239+ return Fstab.add(dev, mp, fs, options=options)
240+
241+
242+def mount(device, mountpoint, options=None, persist=False, filesystem="ext3"):
243 """Mount a filesystem at a particular mountpoint"""
244 cmd_args = ['mount']
245 if options is not None:
246@@ -155,9 +169,9 @@
247 except subprocess.CalledProcessError, e:
248 log('Error mounting {} at {}\n{}'.format(device, mountpoint, e.output))
249 return False
250+
251 if persist:
252- # TODO: update fstab
253- pass
254+ return fstab_add(device, mountpoint, filesystem, options=options)
255 return True
256
257
258@@ -169,9 +183,9 @@
259 except subprocess.CalledProcessError, e:
260 log('Error unmounting {}\n{}'.format(mountpoint, e.output))
261 return False
262+
263 if persist:
264- # TODO: update fstab
265- pass
266+ return fstab_remove(mountpoint)
267 return True
268
269
270@@ -306,6 +320,10 @@
271 '''
272 if not pkgcache:
273 apt_pkg.init()
274+ # Force Apt to build its cache in memory. That way we avoid race
275+ # conditions with other applications building the cache in the same
276+ # place.
277+ apt_pkg.config.set("Dir::Cache::pkgcache", "")
278 pkgcache = apt_pkg.Cache()
279 pkg = pkgcache[package]
280 return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
281
282=== modified file 'hooks/charmhelpers/fetch/__init__.py'
283--- hooks/charmhelpers/fetch/__init__.py 2014-05-19 11:40:27 +0000
284+++ hooks/charmhelpers/fetch/__init__.py 2014-08-13 16:35:01 +0000
285@@ -113,6 +113,7 @@
286 # Tell apt to build an in-memory cache to prevent race conditions (if
287 # another process is already building the cache).
288 apt_pkg.config.set("Dir::Cache::pkgcache", "")
289+ apt_pkg.config.set("Dir::Cache::srcpkgcache", "")
290
291 cache = apt_pkg.Cache()
292 _pkgs = []
293
294=== modified file 'hooks/charmhelpers/fetch/bzrurl.py'
295--- hooks/charmhelpers/fetch/bzrurl.py 2013-11-06 04:26:01 +0000
296+++ hooks/charmhelpers/fetch/bzrurl.py 2014-08-13 16:35:01 +0000
297@@ -39,7 +39,8 @@
298 def install(self, source):
299 url_parts = self.parse_url(source)
300 branch_name = url_parts.path.strip("/").split("/")[-1]
301- dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", branch_name)
302+ dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",
303+ branch_name)
304 if not os.path.exists(dest_dir):
305 mkdir(dest_dir, perms=0755)
306 try:

Subscribers

People subscribed via source and target branches