Skip to content

Commit

Permalink
Ensure get_juju_(raw_)output always decodes result to utf-8 string
Browse files Browse the repository at this point in the history
This removes the need to do this manually at each call-site.
  • Loading branch information
achilleasa committed Jan 15, 2021
1 parent ca5dcd7 commit 5aa7bc4
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion acceptancetests/assess_container_networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def assess_internet_connection(client, targets):
log.info('Assessing internet connection.')
for target in targets:
log.info("Assessing internet connection for {}".format(target))
routes = ssh(client, target, 'ip route show').decode('utf-8')
routes = ssh(client, target, 'ip route show')

d = re.search(r'^default\s+via\s+([\d\.]+)\s+', routes, re.MULTILINE)
if d:
Expand Down
2 changes: 1 addition & 1 deletion acceptancetests/assess_deploy_webscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def extract_module_logs(client, module):
'--no-tail', '--replay', '-l', 'TRACE',
'--include-module', module,
)
return deploy_logs.decode('utf-8')
return deploy_logs


def extract_txn_metrics(logs, module):
Expand Down
2 changes: 1 addition & 1 deletion acceptancetests/assess_destroy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_current_controller(client):
:param client: Jujupy ModelClient object
:return: String name of current controller
"""
raw = client.get_juju_output('switch', include_e=False).decode('utf-8')
raw = client.get_juju_output('switch', include_e=False)
raw = raw.split(':')[0]
return raw

Expand Down
2 changes: 1 addition & 1 deletion acceptancetests/assess_model_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def expect_migration_attempt_to_fail(source_client, dest_client):
'migrate', *args, merge_stderr=True, include_e=False)
except CalledProcessError as e:
print(e.output, file=sys.stderr)
if 'permission denied' not in e.output:
if 'permission denied' not in e.output.decode('utf-8'):
raise
log.info('SUCCESS: Migrate command failed as expected.')
else:
Expand Down
4 changes: 2 additions & 2 deletions acceptancetests/assess_persistent_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_storage_list(client):
'storage', '--format', 'json', include_e=False)
# Bug 1708340 https://bugs.launchpad.net/juju/+bug/1708340
# juju storage --format json output will be empty if no storage exists.
if raw_output == b'':
if raw_output == '':
storage_list = storage_output = ''
else:
storage_output = json.loads(raw_output)
Expand Down Expand Up @@ -165,7 +165,7 @@ def assert_app_removal_msg(client, charm_name):
# merge_stderr=True is required
app_removal_output = client.get_juju_output(
'remove-application', charm_name, '--show-log',
include_e=False, merge_stderr=True).decode('utf-8')
include_e=False, merge_stderr=True)
remove_app_output_check = False
for line in app_removal_output.split('\n'):
if 'will remove unit {}'.format(charm_name) in line:
Expand Down
4 changes: 2 additions & 2 deletions acceptancetests/jujupy/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def get_active_controller(self, juju_data_dir):
try:
current = json.loads(self.get_juju_output(
'controllers', ('--format', 'json'), set(),
juju_data_dir, model=None).decode('ascii'))
juju_data_dir, model=None))
except subprocess.CalledProcessError:
raise NoActiveControllers(
'No active controller for {}'.format(juju_data_dir))
Expand All @@ -314,7 +314,7 @@ def get_active_user(self, juju_data_dir, controller):
try:
current = json.loads(self.get_juju_output(
'controllers', ('--format', 'json'), set(),
juju_data_dir, model=None).decode('ascii'))
juju_data_dir, model=None))
except subprocess.CalledProcessError:
raise NoActiveControllers(
'No active controller for {}'.format(juju_data_dir))
Expand Down
10 changes: 5 additions & 5 deletions acceptancetests/jujupy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ def get_status(self, timeout=60, raw=False, controller=False, *args):
return self.status_class.from_text(
self.get_juju_output(
self._show_status, '--format', 'yaml',
controller=controller).decode('utf-8'))
controller=controller))
except subprocess.CalledProcessError:
pass
raise StatusTimeout(
Expand All @@ -1190,7 +1190,7 @@ def get_controllers(self, timeout=60):
self.get_juju_output(
self._show_controller, '--format', 'yaml',
include_e=False,
).decode('utf-8'),
),
)
except subprocess.CalledProcessError:
pass
Expand All @@ -1207,7 +1207,7 @@ def get_controller_config(self, controller_name, timeout=60):
'--controller', controller_name,
'--format', 'yaml',
include_e=False,
).decode('utf-8'),
),
)
except subprocess.CalledProcessError:
pass
Expand Down Expand Up @@ -1256,7 +1256,7 @@ def get_model_config(self):
def get_env_option(self, option):
"""Return the value of the environment's configured option."""
return self.get_juju_output(
'model-config', option).decode(getpreferredencoding())
'model-config', option)

def set_env_option(self, option, value):
"""Set the value of the option in the environment."""
Expand Down Expand Up @@ -1910,7 +1910,7 @@ def action_do(self, unit, action, *args):
"""
args = (unit, action) + args

output = self.get_juju_output("run-action", *args).decode('utf-8')
output = self.get_juju_output("run-action", *args)
action_id_pattern = re.compile('Action queued with id: "([0-9]+)"')
match = action_id_pattern.search(output)
if match is None:
Expand Down
4 changes: 2 additions & 2 deletions acceptancetests/substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def start_libvirt_domain(uri, domain):
try:
subprocess.check_output(command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
if 'already active' in e.output:
if 'already active' in e.output.decode('utf-8'):
return '%s is already running; nothing to do.' % domain
raise Exception('%s failed:\n %s' % (command, e.output))
sleep(30)
Expand All @@ -962,7 +962,7 @@ def stop_libvirt_domain(uri, domain):
try:
subprocess.check_output(command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
if 'domain is not running' in e.output:
if 'domain is not running' in e.output.decode('utf-8'):
return ('%s is not running; nothing to do.' % domain)
raise Exception('%s failed:\n %s' % (command, e.output))
sleep(30)
Expand Down
2 changes: 1 addition & 1 deletion acceptancetests/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def list_models(client):
"""
try:
raw = client.get_juju_output('list-models', '--format', 'json',
include_e=False).decode('utf-8')
include_e=False)
except subprocess.CalledProcessError as e:
log.error('Failed to list current models due to error: {}'.format(e))
raise e
Expand Down

0 comments on commit 5aa7bc4

Please sign in to comment.