Merge lp:~james-page/charms/trusty/ceph/fix-apt-race-stable into lp:~openstack-charmers-archive/charms/trusty/ceph/trunk

Proposed by James Page
Status: Merged
Merged at revision: 75
Proposed branch: lp:~james-page/charms/trusty/ceph/fix-apt-race-stable
Merge into: lp:~openstack-charmers-archive/charms/trusty/ceph/trunk
Diff against target: 222 lines (+143/-8)
4 files modified
charm-helpers-sync.yaml (+1/-1)
hooks/charmhelpers/core/fstab.py (+116/-0)
hooks/charmhelpers/core/host.py (+24/-6)
hooks/charmhelpers/fetch/bzrurl.py (+2/-1)
To merge this branch: bzr merge lp:~james-page/charms/trusty/ceph/fix-apt-race-stable
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+228702@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Chris Glass (tribaal) wrote :

This is simply a rollout of the charm-helpers changes made here: https://code.launchpad.net/~james-page/charm-helpers/fix-apt-race/+merge/227894

Revision history for this message
Liam Young (gnuoy) wrote :

Approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charm-helpers-sync.yaml'
--- charm-helpers-sync.yaml 2014-03-25 17:03:59 +0000
+++ charm-helpers-sync.yaml 2014-07-29 15:09:35 +0000
@@ -1,4 +1,4 @@
1branch: lp:charm-helpers1branch: lp:~openstack-charmers/charm-helpers/stable
2destination: hooks/charmhelpers2destination: hooks/charmhelpers
3include:3include:
4 - core4 - core
55
=== added file 'hooks/charmhelpers/core/fstab.py'
--- hooks/charmhelpers/core/fstab.py 1970-01-01 00:00:00 +0000
+++ hooks/charmhelpers/core/fstab.py 2014-07-29 15:09:35 +0000
@@ -0,0 +1,116 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4__author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>'
5
6import os
7
8
9class Fstab(file):
10 """This class extends file in order to implement a file reader/writer
11 for file `/etc/fstab`
12 """
13
14 class Entry(object):
15 """Entry class represents a non-comment line on the `/etc/fstab` file
16 """
17 def __init__(self, device, mountpoint, filesystem,
18 options, d=0, p=0):
19 self.device = device
20 self.mountpoint = mountpoint
21 self.filesystem = filesystem
22
23 if not options:
24 options = "defaults"
25
26 self.options = options
27 self.d = d
28 self.p = p
29
30 def __eq__(self, o):
31 return str(self) == str(o)
32
33 def __str__(self):
34 return "{} {} {} {} {} {}".format(self.device,
35 self.mountpoint,
36 self.filesystem,
37 self.options,
38 self.d,
39 self.p)
40
41 DEFAULT_PATH = os.path.join(os.path.sep, 'etc', 'fstab')
42
43 def __init__(self, path=None):
44 if path:
45 self._path = path
46 else:
47 self._path = self.DEFAULT_PATH
48 file.__init__(self, self._path, 'r+')
49
50 def _hydrate_entry(self, line):
51 # NOTE: use split with no arguments to split on any
52 # whitespace including tabs
53 return Fstab.Entry(*filter(
54 lambda x: x not in ('', None),
55 line.strip("\n").split()))
56
57 @property
58 def entries(self):
59 self.seek(0)
60 for line in self.readlines():
61 try:
62 if not line.startswith("#"):
63 yield self._hydrate_entry(line)
64 except ValueError:
65 pass
66
67 def get_entry_by_attr(self, attr, value):
68 for entry in self.entries:
69 e_attr = getattr(entry, attr)
70 if e_attr == value:
71 return entry
72 return None
73
74 def add_entry(self, entry):
75 if self.get_entry_by_attr('device', entry.device):
76 return False
77
78 self.write(str(entry) + '\n')
79 self.truncate()
80 return entry
81
82 def remove_entry(self, entry):
83 self.seek(0)
84
85 lines = self.readlines()
86
87 found = False
88 for index, line in enumerate(lines):
89 if not line.startswith("#"):
90 if self._hydrate_entry(line) == entry:
91 found = True
92 break
93
94 if not found:
95 return False
96
97 lines.remove(line)
98
99 self.seek(0)
100 self.write(''.join(lines))
101 self.truncate()
102 return True
103
104 @classmethod
105 def remove_by_mountpoint(cls, mountpoint, path=None):
106 fstab = cls(path=path)
107 entry = fstab.get_entry_by_attr('mountpoint', mountpoint)
108 if entry:
109 return fstab.remove_entry(entry)
110 return False
111
112 @classmethod
113 def add(cls, device, mountpoint, filesystem, options=None, path=None):
114 return cls(path=path).add_entry(Fstab.Entry(device,
115 mountpoint, filesystem,
116 options=options))
0117
=== modified file 'hooks/charmhelpers/core/host.py'
--- hooks/charmhelpers/core/host.py 2014-05-19 11:38:45 +0000
+++ hooks/charmhelpers/core/host.py 2014-07-29 15:09:35 +0000
@@ -17,6 +17,7 @@
17from collections import OrderedDict17from collections import OrderedDict
1818
19from hookenv import log19from hookenv import log
20from fstab import Fstab
2021
2122
22def service_start(service_name):23def service_start(service_name):
@@ -35,7 +36,8 @@
3536
3637
37def service_reload(service_name, restart_on_failure=False):38def service_reload(service_name, restart_on_failure=False):
38 """Reload a system service, optionally falling back to restart if reload fails"""39 """Reload a system service, optionally falling back to restart if
40 reload fails"""
39 service_result = service('reload', service_name)41 service_result = service('reload', service_name)
40 if not service_result and restart_on_failure:42 if not service_result and restart_on_failure:
41 service_result = service('restart', service_name)43 service_result = service('restart', service_name)
@@ -144,7 +146,19 @@
144 target.write(content)146 target.write(content)
145147
146148
147def mount(device, mountpoint, options=None, persist=False):149def fstab_remove(mp):
150 """Remove the given mountpoint entry from /etc/fstab
151 """
152 return Fstab.remove_by_mountpoint(mp)
153
154
155def fstab_add(dev, mp, fs, options=None):
156 """Adds the given device entry to the /etc/fstab file
157 """
158 return Fstab.add(dev, mp, fs, options=options)
159
160
161def mount(device, mountpoint, options=None, persist=False, filesystem="ext3"):
148 """Mount a filesystem at a particular mountpoint"""162 """Mount a filesystem at a particular mountpoint"""
149 cmd_args = ['mount']163 cmd_args = ['mount']
150 if options is not None:164 if options is not None:
@@ -155,9 +169,9 @@
155 except subprocess.CalledProcessError, e:169 except subprocess.CalledProcessError, e:
156 log('Error mounting {} at {}\n{}'.format(device, mountpoint, e.output))170 log('Error mounting {} at {}\n{}'.format(device, mountpoint, e.output))
157 return False171 return False
172
158 if persist:173 if persist:
159 # TODO: update fstab174 return fstab_add(device, mountpoint, filesystem, options=options)
160 pass
161 return True175 return True
162176
163177
@@ -169,9 +183,9 @@
169 except subprocess.CalledProcessError, e:183 except subprocess.CalledProcessError, e:
170 log('Error unmounting {}\n{}'.format(mountpoint, e.output))184 log('Error unmounting {}\n{}'.format(mountpoint, e.output))
171 return False185 return False
186
172 if persist:187 if persist:
173 # TODO: update fstab188 return fstab_remove(mountpoint)
174 pass
175 return True189 return True
176190
177191
@@ -306,6 +320,10 @@
306 '''320 '''
307 if not pkgcache:321 if not pkgcache:
308 apt_pkg.init()322 apt_pkg.init()
323 # Force Apt to build its cache in memory. That way we avoid race
324 # conditions with other applications building the cache in the same
325 # place.
326 apt_pkg.config.set("Dir::Cache::pkgcache", "")
309 pkgcache = apt_pkg.Cache()327 pkgcache = apt_pkg.Cache()
310 pkg = pkgcache[package]328 pkg = pkgcache[package]
311 return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)329 return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
312330
=== modified file 'hooks/charmhelpers/fetch/bzrurl.py'
--- hooks/charmhelpers/fetch/bzrurl.py 2013-11-13 22:09:26 +0000
+++ hooks/charmhelpers/fetch/bzrurl.py 2014-07-29 15:09:35 +0000
@@ -39,7 +39,8 @@
39 def install(self, source):39 def install(self, source):
40 url_parts = self.parse_url(source)40 url_parts = self.parse_url(source)
41 branch_name = url_parts.path.strip("/").split("/")[-1]41 branch_name = url_parts.path.strip("/").split("/")[-1]
42 dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", branch_name)42 dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",
43 branch_name)
43 if not os.path.exists(dest_dir):44 if not os.path.exists(dest_dir):
44 mkdir(dest_dir, perms=0755)45 mkdir(dest_dir, perms=0755)
45 try:46 try:

Subscribers

People subscribed via source and target branches