Add juju-exec for juju 3 compatibility
In juju3, juju-run is moved to juju-exec gsss should be able to handle both Closes-bug: #1993652 Change-Id: I980306269a68c04735811324f6b826622bc6647c
This commit is contained in:
parent
289671d18f
commit
9304d15434
@ -452,7 +452,7 @@ def juju_proxy_settings():
|
||||
m.groupdict()['var']: m.groupdict()['val']
|
||||
for m in re.finditer(
|
||||
'^((JUJU_CHARM_)?(?P<var>(HTTP|HTTPS|NO)_PROXY))=(?P<val>.*)$',
|
||||
juju_run_cmd(['env']), re.MULTILINE)
|
||||
juju_exec_cmd(['env']), re.MULTILINE)
|
||||
}
|
||||
|
||||
proxy_settings = {}
|
||||
@ -464,14 +464,18 @@ def juju_proxy_settings():
|
||||
return proxy_settings if proxy_settings else None
|
||||
|
||||
|
||||
def juju_run_cmd(cmd):
|
||||
def juju_exec_cmd(cmd):
|
||||
'''Execute the passed commands under the local unit context if required'''
|
||||
# NOTE: determine whether juju-run is actually required
|
||||
# NOTE: determine whether juju-exec is actually required
|
||||
# supporting execution via actions.
|
||||
if not os.environ.get('JUJU_CONTEXT_ID'):
|
||||
if os.path.exists('/usr/bin/juju-exec'):
|
||||
juju_exec = 'juju-exec'
|
||||
else:
|
||||
juju_exec = 'juju-run'
|
||||
id_conf, _ = get_conf()
|
||||
unit_name = id_conf['unit_name']
|
||||
_cmd = ['juju-run', unit_name, ' '.join(cmd)]
|
||||
_cmd = [juju_exec, unit_name, ' '.join(cmd)]
|
||||
else:
|
||||
_cmd = cmd
|
||||
log.info("Executing command: {}".format(_cmd))
|
||||
@ -486,7 +490,7 @@ def status_set(status, message):
|
||||
# NOTE: format of message is different for out of
|
||||
# context execution.
|
||||
if not os.environ.get('JUJU_CONTEXT_ID'):
|
||||
juju_run_cmd(['status-set', status,
|
||||
juju_exec_cmd(['status-set', status,
|
||||
'"{}"'.format(message)])
|
||||
else:
|
||||
subprocess.check_output([
|
||||
@ -501,7 +505,7 @@ def status_set(status, message):
|
||||
def update_endpoint_urls(region, publicurl, adminurl, internalurl):
|
||||
# Notify keystone via the identity service relation about
|
||||
# any endpoint changes.
|
||||
for rid in juju_run_cmd(['relation-ids', 'identity-service']).split():
|
||||
for rid in juju_exec_cmd(['relation-ids', 'identity-service']).split():
|
||||
log.info("Updating relation data for: {}".format(rid))
|
||||
_cmd = ['relation-set', '-r', rid]
|
||||
relation_data = {
|
||||
@ -513,7 +517,7 @@ def update_endpoint_urls(region, publicurl, adminurl, internalurl):
|
||||
}
|
||||
for k, v in relation_data.items():
|
||||
_cmd.append('{}={}'.format(k, v))
|
||||
juju_run_cmd(_cmd)
|
||||
juju_exec_cmd(_cmd)
|
||||
|
||||
|
||||
def cleanup():
|
||||
|
1
tox.ini
1
tox.ini
@ -26,6 +26,7 @@ requires =
|
||||
pip < 20.3
|
||||
virtualenv < 20.0
|
||||
setuptools < 50.0.0
|
||||
tox < 4.0.0
|
||||
|
||||
# NOTE: https://wiki.canonical.com/engineering/OpenStack/InstallLatestToxOnOsci
|
||||
minversion = 3.18.0
|
||||
|
@ -28,9 +28,9 @@ class TestGlanceSimpleStreamsSync(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.maxDiff = 4096
|
||||
|
||||
@mock.patch('files.glance_simplestreams_sync.juju_run_cmd')
|
||||
def test_proxy_settings(self, juju_run_cmd):
|
||||
juju_run_cmd.return_value = '''
|
||||
@mock.patch('files.glance_simplestreams_sync.juju_exec_cmd')
|
||||
def test_proxy_settings(self, juju_exec_cmd):
|
||||
juju_exec_cmd.return_value = '''
|
||||
LANG=C.UTF-8
|
||||
JUJU_CONTEXT_ID=glance-simplestreams-sync/0-run-commands-3325280900519425661
|
||||
JUJU_CHARM_HTTP_PROXY=http://squid.internal:3128
|
||||
@ -46,9 +46,9 @@ JUJU_CHARM_NO_PROXY=127.0.0.1,localhost,::1
|
||||
"no_proxy": "127.0.0.1,localhost,::1",
|
||||
})
|
||||
|
||||
@mock.patch('files.glance_simplestreams_sync.juju_run_cmd')
|
||||
def test_legacy_proxy_settings(self, juju_run_cmd):
|
||||
juju_run_cmd.return_value = '''
|
||||
@mock.patch('files.glance_simplestreams_sync.juju_exec_cmd')
|
||||
def test_legacy_proxy_settings(self, juju_exec_cmd):
|
||||
juju_exec_cmd.return_value = '''
|
||||
LANG=C.UTF-8
|
||||
JUJU_CONTEXT_ID=glance-simplestreams-sync/0-run-commands-3325280900519425661
|
||||
HTTP_PROXY=http://squid.internal:3128
|
||||
@ -64,9 +64,9 @@ NO_PROXY=127.0.0.1,localhost,::1
|
||||
"no_proxy": "127.0.0.1,localhost,::1",
|
||||
})
|
||||
|
||||
@mock.patch('files.glance_simplestreams_sync.juju_run_cmd')
|
||||
def test_proxy_settings_not_set(self, juju_run_cmd):
|
||||
juju_run_cmd.return_value = '''
|
||||
@mock.patch('files.glance_simplestreams_sync.juju_exec_cmd')
|
||||
def test_proxy_settings_not_set(self, juju_exec_cmd):
|
||||
juju_exec_cmd.return_value = '''
|
||||
LANG=C.UTF-8
|
||||
JUJU_CONTEXT_ID=glance-simplestreams-sync/0-run-commands-3325280900519425661
|
||||
'''
|
||||
|
Loading…
x
Reference in New Issue
Block a user