~1chb1n/charms/trusty/cinder-ceph/next.1601-test-update2

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/core/host.py

  • Committer: Edward Hope-Morley
  • Date: 2015-02-24 11:03:24 UTC
  • Revision ID: edward.hope-morley@canonical.com-20150224110324-2y4g3dktfacav9d3
[trivial] charmhelpers sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
191
191
 
192
192
 
193
193
def write_file(path, content, owner='root', group='root', perms=0o444):
194
 
    """Create or overwrite a file with the contents of a string"""
 
194
    """Create or overwrite a file with the contents of a byte string."""
195
195
    log("Writing file {} {}:{} {:o}".format(path, owner, group, perms))
196
196
    uid = pwd.getpwnam(owner).pw_uid
197
197
    gid = grp.getgrnam(group).gr_gid
198
 
    with open(path, 'w') as target:
 
198
    with open(path, 'wb') as target:
199
199
        os.fchown(target.fileno(), uid, gid)
200
200
        os.fchmod(target.fileno(), perms)
201
201
        target.write(content)
305
305
    ceph_client_changed function.
306
306
    """
307
307
    def wrap(f):
308
 
        def wrapped_f(*args):
 
308
        def wrapped_f(*args, **kwargs):
309
309
            checksums = {}
310
310
            for path in restart_map:
311
311
                checksums[path] = file_hash(path)
312
 
            f(*args)
 
312
            f(*args, **kwargs)
313
313
            restarts = []
314
314
            for path in restart_map:
315
315
                if checksums[path] != file_hash(path):
361
361
        ip_output = (line for line in ip_output if line)
362
362
        for line in ip_output:
363
363
            if line.split()[1].startswith(int_type):
364
 
                matched = re.search('.*: (bond[0-9]+\.[0-9]+)@.*', line)
 
364
                matched = re.search('.*: (' + int_type + r'[0-9]+\.[0-9]+)@.*', line)
365
365
                if matched:
366
366
                    interface = matched.groups()[0]
367
367
                else: