From: Pete Vander Giessen Date: Mon, 30 Jan 2017 15:06:28 +0000 (-0500) Subject: Better fix for moving stuff into an Executor. X-Git-Tag: 0.2.0~1^2~1 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=efca4234627865400e0d2ab74a0f77bd6988c397;p=osm%2FN2VC.git Better fix for moving stuff into an Executor. Hides all the underpinnings in the utils class. --- diff --git a/juju/controller.py b/juju/controller.py index d64a2f7..113325e 100644 --- a/juju/controller.py +++ b/juju/controller.py @@ -1,5 +1,4 @@ import asyncio -import concurrent.futures import logging from . import tag @@ -103,10 +102,7 @@ class Controller(object): # Add our ssh key to the model, to work around # https://bugs.launchpad.net/juju/+bug/1643076 try: - ssh_key = await self.loop.run_in_executor( - concurrent.futures.ThreadPoolExecutor(), - utils.read_ssh_key - ) + ssh_key = await utils.read_ssh_key(loop=self.loop) await utils.execute_process( 'juju', 'add-ssh-key', '-m', model_name, ssh_key, log=log) except Exception as e: diff --git a/juju/utils.py b/juju/utils.py index b9a9b67..78322e7 100644 --- a/juju/utils.py +++ b/juju/utils.py @@ -1,4 +1,5 @@ import asyncio +import concurrent.futures import os from pathlib import Path @@ -24,10 +25,10 @@ async def execute_process(*cmd, log=None): return p.returncode == 0 -def read_ssh_key(): +def _read_ssh_key(): ''' - Attempt to read the local juju admin's public ssh key, so that it - can be passed on to a model. + Inner function for read_ssh_key, suitable for passing to our + Executor. ''' default_data_dir = Path(Path.home(), ".local", "share", "juju") @@ -37,3 +38,15 @@ def read_ssh_key(): ssh_key = ssh_key_file.readlines()[0].strip() return ssh_key + +async def read_ssh_key(loop): + ''' + Attempt to read the local juju admin's public ssh key, so that it + can be passed on to a model. + + ''' + ssh_key = await loop.run_in_executor( + concurrent.futures.ThreadPoolExecutor(), + _read_ssh_key + ) + return ssh_key