From: Mark Beierl Date: Mon, 15 May 2023 20:17:02 +0000 (-0400) Subject: Python3.10/Ubuntu 22.04 part 2 X-Git-Tag: release-v14.0-start~7 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F94%2F13394%2F2;p=osm%2FN2VC.git Python3.10/Ubuntu 22.04 part 2 Removal of loop from all methods Change-Id: I05bfe90f82b8c8acba3172de89c7d8e0ee08402b Signed-off-by: Mark Beierl --- diff --git a/n2vc/k8s_helm_conn.py b/n2vc/k8s_helm_conn.py index 84879c8..813d7cc 100644 --- a/n2vc/k8s_helm_conn.py +++ b/n2vc/k8s_helm_conn.py @@ -81,9 +81,6 @@ class K8sHelmConnector(K8sHelmBaseConnector): asyncio.ensure_future( self._local_async_exec(command=command, raise_exception_on_error=False) ) - # loop = asyncio.get_event_loop() - # loop.run_until_complete(self._local_async_exec(command=command, - # raise_exception_on_error=False)) except Exception as e: self.warning( msg="helm init failed (it was already initialized): {}".format(e) diff --git a/n2vc/k8s_juju_conn.py b/n2vc/k8s_juju_conn.py index 7dacfb9..c197221 100644 --- a/n2vc/k8s_juju_conn.py +++ b/n2vc/k8s_juju_conn.py @@ -51,7 +51,6 @@ class K8sJujuConnector(K8sConnector): kubectl_command: str = "/usr/bin/kubectl", juju_command: str = "/usr/bin/juju", log: object = None, - loop: object = None, on_update_db=None, ): """ @@ -60,14 +59,12 @@ class K8sJujuConnector(K8sConnector): :param kubectl_command: path to kubectl executable :param helm_command: path to helm executable :param log: logger - :param: loop: Asyncio loop """ # parent class K8sConnector.__init__(self, db, log=log, on_update_db=on_update_db) self.fs = fs - self.loop = loop or asyncio.get_event_loop() self.log.debug("Initializing K8S Juju connector") db_uri = EnvironConfig(prefixes=["OSMLCM_", "OSMMON_"]).get("database_uri") @@ -915,11 +912,11 @@ class K8sJujuConnector(K8sConnector): if not self.libjuju: async with self.loading_libjuju: vca_connection = await get_connection(self._store) - self.libjuju = Libjuju(vca_connection, loop=self.loop, log=self.log) + self.libjuju = Libjuju(vca_connection, log=self.log) return self.libjuju else: vca_connection = await get_connection(self._store, vca_id) - return Libjuju(vca_connection, loop=self.loop, log=self.log, n2vc=self) + return Libjuju(vca_connection, log=self.log, n2vc=self) def _get_kubectl(self, credentials: str) -> Kubectl: """ diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index de116f0..e934fd0 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -65,7 +65,6 @@ class Libjuju: def __init__( self, vca_connection: Connection, - loop: asyncio.AbstractEventLoop = None, log: logging.Logger = None, n2vc: N2VCConnector = None, ): @@ -73,7 +72,6 @@ class Libjuju: Constructor :param: vca_connection: n2vc.vca.connection object - :param: loop: Asyncio loop :param: log: Logger :param: n2vc: N2VC object """ @@ -82,15 +80,13 @@ class Libjuju: self.n2vc = n2vc self.vca_connection = vca_connection - self.loop = loop or asyncio.get_event_loop() - self.loop.set_exception_handler(self.handle_exception) self.creating_model = asyncio.Lock() if self.vca_connection.is_default: self.health_check_task = self._create_health_check_task() def _create_health_check_task(self): - return self.loop.create_task(self.health_check()) + return asyncio.get_event_loop().create_task(self.health_check()) async def get_controller(self, timeout: float = 60.0) -> Controller: """ @@ -1640,10 +1636,6 @@ class Libjuju: await self.disconnect_model(model) await self.disconnect_controller(controller) - def handle_exception(self, loop, context): - # All unhandled exceptions by libjuju are handled here. - pass - async def health_check(self, interval: float = 300.0): """ Health check to make sure controller and controller_model connections are OK diff --git a/n2vc/n2vc_conn.py b/n2vc/n2vc_conn.py index 5752da7..4fa7e36 100644 --- a/n2vc/n2vc_conn.py +++ b/n2vc/n2vc_conn.py @@ -54,7 +54,6 @@ class N2VCConnector(abc.ABC, Loggable): db: object, fs: object, log: object, - loop: object, on_update_db=None, **kwargs, ): @@ -64,7 +63,6 @@ class N2VCConnector(abc.ABC, Loggable): :param object fs: FileSystem object managing the package artifacts (repo common FsBase) :param object log: the logging object to log to - :param object loop: the loop to use for asyncio (default current thread loop) :param on_update_db: callback called when n2vc connector updates database. Received arguments: table: e.g. "nsrs" @@ -85,7 +83,6 @@ class N2VCConnector(abc.ABC, Loggable): # store arguments into self self.db = db self.fs = fs - self.loop = loop or asyncio.get_event_loop() self.on_update_db = on_update_db # generate private/public key-pair diff --git a/n2vc/n2vc_juju_conn.py b/n2vc/n2vc_juju_conn.py index f799f44..66a88db 100644 --- a/n2vc/n2vc_juju_conn.py +++ b/n2vc/n2vc_juju_conn.py @@ -61,7 +61,6 @@ class N2VCJujuConnector(N2VCConnector): db: object, fs: object, log: object = None, - loop: object = None, on_update_db=None, ): """ @@ -70,14 +69,11 @@ class N2VCJujuConnector(N2VCConnector): :param: db: Database object from osm_common :param: fs: Filesystem object from osm_common :param: log: Logger - :param: loop: Asyncio loop :param: on_update_db: Callback function to be called for updating the database. """ # parent class constructor - N2VCConnector.__init__( - self, db=db, fs=fs, log=log, loop=loop, on_update_db=on_update_db - ) + N2VCConnector.__init__(self, db=db, fs=fs, log=log, on_update_db=on_update_db) # silence websocket traffic log logging.getLogger("websockets.protocol").setLevel(logging.INFO) @@ -1148,11 +1144,11 @@ class N2VCJujuConnector(N2VCConnector): if not self.libjuju: async with self.loading_libjuju: vca_connection = await get_connection(self._store) - self.libjuju = Libjuju(vca_connection, loop=self.loop, log=self.log) + self.libjuju = Libjuju(vca_connection, log=self.log) return self.libjuju else: vca_connection = await get_connection(self._store, vca_id) - return Libjuju(vca_connection, loop=self.loop, log=self.log, n2vc=self) + return Libjuju(vca_connection, log=self.log, n2vc=self) def _write_ee_id_db(self, db_dict: dict, ee_id: str): # write ee_id to database: _admin.deployed.VCA.x @@ -1536,6 +1532,6 @@ class N2VCJujuConnector(N2VCConnector): :param: vca_id: VCA ID """ vca_connection = await get_connection(self._store, vca_id=vca_id) - libjuju = Libjuju(vca_connection, loop=self.loop, log=self.log, n2vc=self) + libjuju = Libjuju(vca_connection, log=self.log, n2vc=self) controller = await libjuju.get_controller() await libjuju.disconnect_controller(controller) diff --git a/n2vc/tests/unit/test_k8s_juju_conn.py b/n2vc/tests/unit/test_k8s_juju_conn.py index 1cc0809..1de1288 100644 --- a/n2vc/tests/unit/test_k8s_juju_conn.py +++ b/n2vc/tests/unit/test_k8s_juju_conn.py @@ -72,7 +72,6 @@ class K8sJujuConnTestCase(asynctest.TestCase): fs=fslocal.FsLocal(), db=self.db, log=None, - loop=self.loop, on_update_db=None, ) self.k8s_juju_conn._store.get_vca_id.return_value = None diff --git a/n2vc/tests/unit/test_libjuju.py b/n2vc/tests/unit/test_libjuju.py index 9f21bc6..38d8d0e 100644 --- a/n2vc/tests/unit/test_libjuju.py +++ b/n2vc/tests/unit/test_libjuju.py @@ -78,7 +78,7 @@ class LibjujuTestCase(asynctest.TestCase): } ) logging.disable(logging.CRITICAL) - self.libjuju = Libjuju(vca_connection, self.loop) + self.libjuju = Libjuju(vca_connection) self.loop.run_until_complete(self.libjuju.disconnect()) diff --git a/n2vc/tests/unit/test_n2vc_juju_conn.py b/n2vc/tests/unit/test_n2vc_juju_conn.py index deb98ce..456ec1e 100644 --- a/n2vc/tests/unit/test_n2vc_juju_conn.py +++ b/n2vc/tests/unit/test_n2vc_juju_conn.py @@ -73,7 +73,6 @@ class N2VCJujuConnTestCase(asynctest.TestCase): db=self.db, fs=fslocal.FsLocal(), log=None, - loop=self.loop, on_update_db=None, ) N2VCJujuConnector.get_public_key.assert_not_called()