Merge "c-h sync - restore proxy env vars for add-apt-repository"
This commit is contained in:
commit
2401bdcb6b
|
@ -16,6 +16,7 @@ import inspect
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import six
|
||||||
from six.moves import zip
|
from six.moves import zip
|
||||||
|
|
||||||
import charmhelpers.core.unitdata
|
import charmhelpers.core.unitdata
|
||||||
|
@ -148,7 +149,10 @@ class CommandLine(object):
|
||||||
def run(self):
|
def run(self):
|
||||||
"Run cli, processing arguments and executing subcommands."
|
"Run cli, processing arguments and executing subcommands."
|
||||||
arguments = self.argument_parser.parse_args()
|
arguments = self.argument_parser.parse_args()
|
||||||
argspec = inspect.getargspec(arguments.func)
|
if six.PY2:
|
||||||
|
argspec = inspect.getargspec(arguments.func)
|
||||||
|
else:
|
||||||
|
argspec = inspect.getfullargspec(arguments.func)
|
||||||
vargs = []
|
vargs = []
|
||||||
for arg in argspec.args:
|
for arg in argspec.args:
|
||||||
vargs.append(getattr(arguments, arg))
|
vargs.append(getattr(arguments, arg))
|
||||||
|
@ -173,7 +177,10 @@ def describe_arguments(func):
|
||||||
Analyze a function's signature and return a data structure suitable for
|
Analyze a function's signature and return a data structure suitable for
|
||||||
passing in as arguments to an argparse parser's add_argument() method."""
|
passing in as arguments to an argparse parser's add_argument() method."""
|
||||||
|
|
||||||
argspec = inspect.getargspec(func)
|
if six.PY2:
|
||||||
|
argspec = inspect.getargspec(func)
|
||||||
|
else:
|
||||||
|
argspec = inspect.getfullargspec(func)
|
||||||
# we should probably raise an exception somewhere if func includes **kwargs
|
# we should probably raise an exception somewhere if func includes **kwargs
|
||||||
if argspec.defaults:
|
if argspec.defaults:
|
||||||
positional_args = argspec.args[:-len(argspec.defaults)]
|
positional_args = argspec.args[:-len(argspec.defaults)]
|
||||||
|
|
|
@ -46,9 +46,13 @@ class ServiceEvent():
|
||||||
self.service = service
|
self.service = service
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
self.action = action
|
self.action = action
|
||||||
if not policy_requestor_name:
|
if policy_requestor_name:
|
||||||
|
self.policy_requestor_name = policy_requestor_name
|
||||||
|
else:
|
||||||
self.policy_requestor_name = hookenv.service_name()
|
self.policy_requestor_name = hookenv.service_name()
|
||||||
if not policy_requestor_type:
|
if policy_requestor_type:
|
||||||
|
self.policy_requestor_type = policy_requestor_type
|
||||||
|
else:
|
||||||
self.policy_requestor_type = 'charm'
|
self.policy_requestor_type = 'charm'
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
@ -99,7 +103,9 @@ def read_event_file(file_name):
|
||||||
contents['timestamp'],
|
contents['timestamp'],
|
||||||
contents['service'],
|
contents['service'],
|
||||||
contents['reason'],
|
contents['reason'],
|
||||||
contents['action'])
|
contents['action'],
|
||||||
|
policy_requestor_name=contents.get('policy_requestor_name'),
|
||||||
|
policy_requestor_type=contents.get('policy_requestor_type'))
|
||||||
return event
|
return event
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ from charmhelpers.core.hookenv import (
|
||||||
relation_id,
|
relation_id,
|
||||||
relation_ids,
|
relation_ids,
|
||||||
relation_set,
|
relation_set,
|
||||||
|
service_name as ch_service_name,
|
||||||
status_set,
|
status_set,
|
||||||
hook_name,
|
hook_name,
|
||||||
application_version_set,
|
application_version_set,
|
||||||
|
@ -1089,8 +1090,12 @@ def _determine_os_workload_status(
|
||||||
try:
|
try:
|
||||||
if config(POLICYD_CONFIG_NAME):
|
if config(POLICYD_CONFIG_NAME):
|
||||||
message = "{} {}".format(policyd_status_message_prefix(), message)
|
message = "{} {}".format(policyd_status_message_prefix(), message)
|
||||||
|
# Get deferred restarts events that have been triggered by a policy
|
||||||
|
# written by this charm.
|
||||||
deferred_restarts = list(set(
|
deferred_restarts = list(set(
|
||||||
[e.service for e in deferred_events.get_deferred_restarts()]))
|
[e.service
|
||||||
|
for e in deferred_events.get_deferred_restarts()
|
||||||
|
if e.policy_requestor_name == ch_service_name()]))
|
||||||
if deferred_restarts:
|
if deferred_restarts:
|
||||||
svc_msg = "Services queued for restart: {}".format(
|
svc_msg = "Services queued for restart: {}".format(
|
||||||
', '.join(sorted(deferred_restarts)))
|
', '.join(sorted(deferred_restarts)))
|
||||||
|
|
|
@ -468,15 +468,20 @@ def config(scope=None):
|
||||||
|
|
||||||
|
|
||||||
@cached
|
@cached
|
||||||
def relation_get(attribute=None, unit=None, rid=None):
|
def relation_get(attribute=None, unit=None, rid=None, app=None):
|
||||||
"""Get relation information"""
|
"""Get relation information"""
|
||||||
_args = ['relation-get', '--format=json']
|
_args = ['relation-get', '--format=json']
|
||||||
|
if app is not None:
|
||||||
|
if unit is not None:
|
||||||
|
raise ValueError("Cannot use both 'unit' and 'app'")
|
||||||
|
_args.append('--app')
|
||||||
if rid:
|
if rid:
|
||||||
_args.append('-r')
|
_args.append('-r')
|
||||||
_args.append(rid)
|
_args.append(rid)
|
||||||
_args.append(attribute or '-')
|
_args.append(attribute or '-')
|
||||||
if unit:
|
# unit or application name
|
||||||
_args.append(unit)
|
if unit or app:
|
||||||
|
_args.append(unit or app)
|
||||||
try:
|
try:
|
||||||
return json.loads(subprocess.check_output(_args).decode('UTF-8'))
|
return json.loads(subprocess.check_output(_args).decode('UTF-8'))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -487,12 +492,14 @@ def relation_get(attribute=None, unit=None, rid=None):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def relation_set(relation_id=None, relation_settings=None, **kwargs):
|
def relation_set(relation_id=None, relation_settings=None, app=False, **kwargs):
|
||||||
"""Set relation information for the current unit"""
|
"""Set relation information for the current unit"""
|
||||||
relation_settings = relation_settings if relation_settings else {}
|
relation_settings = relation_settings if relation_settings else {}
|
||||||
relation_cmd_line = ['relation-set']
|
relation_cmd_line = ['relation-set']
|
||||||
accepts_file = "--file" in subprocess.check_output(
|
accepts_file = "--file" in subprocess.check_output(
|
||||||
relation_cmd_line + ["--help"], universal_newlines=True)
|
relation_cmd_line + ["--help"], universal_newlines=True)
|
||||||
|
if app:
|
||||||
|
relation_cmd_line.append('--app')
|
||||||
if relation_id is not None:
|
if relation_id is not None:
|
||||||
relation_cmd_line.extend(('-r', relation_id))
|
relation_cmd_line.extend(('-r', relation_id))
|
||||||
settings = relation_settings.copy()
|
settings = relation_settings.copy()
|
||||||
|
|
|
@ -14,9 +14,11 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from inspect import getargspec
|
import inspect
|
||||||
from collections import Iterable, OrderedDict
|
from collections import Iterable, OrderedDict
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from charmhelpers.core import host
|
from charmhelpers.core import host
|
||||||
from charmhelpers.core import hookenv
|
from charmhelpers.core import hookenv
|
||||||
|
|
||||||
|
@ -169,7 +171,10 @@ class ServiceManager(object):
|
||||||
if not units:
|
if not units:
|
||||||
continue
|
continue
|
||||||
remote_service = units[0].split('/')[0]
|
remote_service = units[0].split('/')[0]
|
||||||
argspec = getargspec(provider.provide_data)
|
if six.PY2:
|
||||||
|
argspec = inspect.getargspec(provider.provide_data)
|
||||||
|
else:
|
||||||
|
argspec = inspect.getfullargspec(provider.provide_data)
|
||||||
if len(argspec.args) > 1:
|
if len(argspec.args) > 1:
|
||||||
data = provider.provide_data(remote_service, service_ready)
|
data = provider.provide_data(remote_service, service_ready)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -658,17 +658,11 @@ def _add_apt_repository(spec):
|
||||||
:param spec: the parameter to pass to add_apt_repository
|
:param spec: the parameter to pass to add_apt_repository
|
||||||
:type spec: str
|
:type spec: str
|
||||||
"""
|
"""
|
||||||
series = get_distrib_codename()
|
|
||||||
if '{series}' in spec:
|
if '{series}' in spec:
|
||||||
|
series = get_distrib_codename()
|
||||||
spec = spec.replace('{series}', series)
|
spec = spec.replace('{series}', series)
|
||||||
# software-properties package for bionic properly reacts to proxy settings
|
_run_with_retries(['add-apt-repository', '--yes', spec],
|
||||||
# set via apt.conf (see lp:1433761), however this is not the case for LTS
|
cmd_env=env_proxy_settings(['https', 'http']))
|
||||||
# and non-LTS releases before bionic.
|
|
||||||
if series in ('trusty', 'xenial'):
|
|
||||||
_run_with_retries(['add-apt-repository', '--yes', spec],
|
|
||||||
cmd_env=env_proxy_settings(['https', 'http']))
|
|
||||||
else:
|
|
||||||
_run_with_retries(['add-apt-repository', '--yes', spec])
|
|
||||||
|
|
||||||
|
|
||||||
def _add_cloud_pocket(pocket):
|
def _add_cloud_pocket(pocket):
|
||||||
|
|
Loading…
Reference in New Issue