[gnuoy,trivial] Pre-release charmhelper sync
This commit is contained in:
parent
576f76d007
commit
1dea26a747
@ -1053,11 +1053,17 @@ class SubordinateConfigContext(OSContextGenerator):
|
|||||||
"""
|
"""
|
||||||
self.service = service
|
self.service = service
|
||||||
self.config_file = config_file
|
self.config_file = config_file
|
||||||
self.interface = interface
|
if isinstance(interface, list):
|
||||||
|
self.interfaces = interface
|
||||||
|
else:
|
||||||
|
self.interfaces = [interface]
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
ctxt = {'sections': {}}
|
ctxt = {'sections': {}}
|
||||||
for rid in relation_ids(self.interface):
|
rids = []
|
||||||
|
for interface in self.interfaces:
|
||||||
|
rids.extend(relation_ids(interface))
|
||||||
|
for rid in rids:
|
||||||
for unit in related_units(rid):
|
for unit in related_units(rid):
|
||||||
sub_config = relation_get('subordinate_configuration',
|
sub_config = relation_get('subordinate_configuration',
|
||||||
rid=rid, unit=unit)
|
rid=rid, unit=unit)
|
||||||
@ -1085,13 +1091,15 @@ class SubordinateConfigContext(OSContextGenerator):
|
|||||||
sub_config = sub_config[self.config_file]
|
sub_config = sub_config[self.config_file]
|
||||||
for k, v in six.iteritems(sub_config):
|
for k, v in six.iteritems(sub_config):
|
||||||
if k == 'sections':
|
if k == 'sections':
|
||||||
for section, config_dict in six.iteritems(v):
|
for section, config_list in six.iteritems(v):
|
||||||
log("adding section '%s'" % (section),
|
log("adding section '%s'" % (section),
|
||||||
level=DEBUG)
|
level=DEBUG)
|
||||||
ctxt[k][section] = config_dict
|
if ctxt[k].get(section):
|
||||||
|
ctxt[k][section].extend(config_list)
|
||||||
|
else:
|
||||||
|
ctxt[k][section] = config_list
|
||||||
else:
|
else:
|
||||||
ctxt[k] = v
|
ctxt[k] = v
|
||||||
|
|
||||||
log("%d section(s) found" % (len(ctxt['sections'])), level=DEBUG)
|
log("%d section(s) found" % (len(ctxt['sections'])), level=DEBUG)
|
||||||
return ctxt
|
return ctxt
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ from charmhelpers.contrib.openstack.utils import OPENSTACK_CODENAMES
|
|||||||
try:
|
try:
|
||||||
from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions
|
from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# python-jinja2 may not be installed yet, or we're running unittests.
|
apt_install('python-jinja2', fatal=True)
|
||||||
FileSystemLoader = ChoiceLoader = Environment = exceptions = None
|
from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions
|
||||||
|
|
||||||
|
|
||||||
class OSConfigException(Exception):
|
class OSConfigException(Exception):
|
||||||
|
@ -67,4 +67,4 @@ def is_device_mounted(device):
|
|||||||
out = check_output(['mount']).decode('UTF-8')
|
out = check_output(['mount']).decode('UTF-8')
|
||||||
if is_partition:
|
if is_partition:
|
||||||
return bool(re.search(device + r"\b", out))
|
return bool(re.search(device + r"\b", out))
|
||||||
return bool(re.search(device + r"[0-9]+\b", out))
|
return bool(re.search(device + r"[0-9]*\b", out))
|
||||||
|
45
hooks/charmhelpers/core/files.py
Normal file
45
hooks/charmhelpers/core/files.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2014-2015 Canonical Limited.
|
||||||
|
#
|
||||||
|
# This file is part of charm-helpers.
|
||||||
|
#
|
||||||
|
# charm-helpers is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License version 3 as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# charm-helpers is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
__author__ = 'Jorge Niedbalski <niedbalski@ubuntu.com>'
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def sed(filename, before, after, flags='g'):
|
||||||
|
"""
|
||||||
|
Search and replaces the given pattern on filename.
|
||||||
|
|
||||||
|
:param filename: relative or absolute file path.
|
||||||
|
:param before: expression to be replaced (see 'man sed')
|
||||||
|
:param after: expression to replace with (see 'man sed')
|
||||||
|
:param flags: sed-compatible regex flags in example, to make
|
||||||
|
the search and replace case insensitive, specify ``flags="i"``.
|
||||||
|
The ``g`` flag is always specified regardless, so you do not
|
||||||
|
need to remember to include it when overriding this parameter.
|
||||||
|
:returns: If the sed command exit code was zero then return,
|
||||||
|
otherwise raise CalledProcessError.
|
||||||
|
"""
|
||||||
|
expression = r's/{0}/{1}/{2}'.format(before,
|
||||||
|
after, flags)
|
||||||
|
|
||||||
|
return subprocess.check_call(["sed", "-i", "-r", "-e",
|
||||||
|
expression,
|
||||||
|
os.path.expanduser(filename)])
|
@ -21,6 +21,7 @@
|
|||||||
# Charm Helpers Developers <juju@lists.ubuntu.com>
|
# Charm Helpers Developers <juju@lists.ubuntu.com>
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
import copy
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import glob
|
import glob
|
||||||
@ -263,7 +264,7 @@ class Config(dict):
|
|||||||
self.path = path or self.path
|
self.path = path or self.path
|
||||||
with open(self.path) as f:
|
with open(self.path) as f:
|
||||||
self._prev_dict = json.load(f)
|
self._prev_dict = json.load(f)
|
||||||
for k, v in self._prev_dict.items():
|
for k, v in copy.deepcopy(self._prev_dict).items():
|
||||||
if k not in self:
|
if k not in self:
|
||||||
self[k] = v
|
self[k] = v
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user