From: Plamen Dimitrov Date: Thu, 21 Apr 2022 07:48:40 +0000 (+0300) Subject: Wait for arnied in addition to generate to preserve backward compatibility X-Git-Tag: v1.7.1~4^2 X-Git-Url: http://developer.intra2net.com/git/?p=pyi2ncommon;a=commitdiff_plain;h=3e582fbf640028cd9f3cdd3e3a3360abcf423dae Wait for arnied in addition to generate to preserve backward compatibility We simplify this a bit though by waiting for the arnied availability just once during initialization of the cnf store and not on each get/set/unset_cnf call (now query, commit, and delete calls). As this is done for backward compability which is guaranteed for the binary cnfvar driver only, we leave a TODO where we will have to consider what is the best future for the varlink driver: either busy-loop on socket availability to once again wait with a timeout or drop this assumption entirely for better control and easier use. --- diff --git a/src/cnfvar/store.py b/src/cnfvar/store.py index c22e217..915e087 100644 --- a/src/cnfvar/store.py +++ b/src/cnfvar/store.py @@ -52,6 +52,9 @@ class CnfStore: :type: :py:class:`arnied_api.Arnied` """ self._driver = backend_driver + # TODO: implement `self._wait_for_arnied()` which should busy-loop with + # the arnied varlink socket and handle "Disconnected" errors, then perhaps + # drop the old binary cnf store method from the arnied wrapper log.debug(f"Initialized cnf store with driver `{backend_driver.__name__}`") def query(self, name=None, instance=None): @@ -258,6 +261,9 @@ class BinaryCnfStore(CnfStore): :type: :py:class:`CnfBinary` """ super().__init__(backend_driver=backend_driver) + # We assume that any external events happening to arnied require reinitializing + # the cnf store which is bound to the lifespan of a single arnied process. + self._call_arnied(arnied_wrapper.verify_running, timeout=self.ARNIED_TIMEOUT) log.debug(f"Initialized binary cnf store with driver `{backend_driver.__name__}`") def query(self, name=None, instance=None): @@ -309,7 +315,6 @@ class BinaryCnfStore(CnfStore): cnf.renumber() log.debug("Committing variables via binaries:\n%s", cnf) - self._call_arnied(arnied_wrapper.verify_running, timeout=self.ARNIED_TIMEOUT) try: self._driver.set_cnf(input_str=str(cnf), fix_problems=fix_problems) except subprocess.CalledProcessError as ex: @@ -338,7 +343,6 @@ class BinaryCnfStore(CnfStore): cnf.renumber() log.debug("Deleting variables via binaries:\n%s", cnf) - self._call_arnied(arnied_wrapper.verify_running, timeout=self.ARNIED_TIMEOUT) try: self._driver.set_cnf(input_str=str(cnf), delete=True, fix_problems=fix_problems) except subprocess.CalledProcessError as ex: