- """
- "Juju bundle that models the KDU, in any of the following ways:
- - <juju-repo>/<juju-bundle>
- - <juju-bundle folder under k8s_models folder in the package>
- - <juju-bundle tgz file (w/ or w/o extension) under k8s_models folder
- in the package>
- - <URL_where_to_fetch_juju_bundle>
- """
- try:
- previous_workdir = os.getcwd()
- except FileNotFoundError:
- previous_workdir = "/app/storage"
-
- bundle = kdu_model
- if kdu_model.startswith("cs:"):
- bundle = kdu_model
- elif kdu_model.startswith("http"):
- # Download the file
- pass
- else:
- new_workdir = kdu_model.strip(kdu_model.split("/")[-1])
-
- os.chdir(new_workdir)
-
- bundle = "local:{}".format(kdu_model)
-
- if not bundle:
- # Raise named exception that the bundle could not be found
- raise Exception()
-
- self.log.debug("[install] deploying {}".format(bundle))
- await model.deploy(bundle)
-
- # Get the application
- if atomic:
- # applications = model.applications
- self.log.debug("[install] Applications: {}".format(model.applications))
- for name in model.applications:
- self.log.debug("[install] Waiting for {} to settle".format(name))
- application = model.applications[name]
- try:
- # It's not enough to wait for all units to be active;
- # the application status needs to be active as well.
- self.log.debug("Waiting for all units to be active...")
- await model.block_until(
- lambda: all(
- unit.agent_status == "idle"
- and application.status in ["active", "unknown"]
- and unit.workload_status in ["active", "unknown"]
- for unit in application.units
- ),
- timeout=timeout,
- )
- self.log.debug("All units active.")
-
- # TODO use asyncio.TimeoutError
- except concurrent.futures._base.TimeoutError:
- os.chdir(previous_workdir)
- self.log.debug("[install] Timeout exceeded; resetting cluster")
- await self.reset(cluster_uuid)
- return False
-
- # Wait for the application to be active
- if model.is_connected():
- self.log.debug("[install] Disconnecting model")
- await model.disconnect()
- await controller.disconnect()
- os.chdir(previous_workdir)
-
- return kdu_instance
- raise Exception("Unable to install")
+ """
+ "Juju bundle that models the KDU, in any of the following ways:
+ - <juju-repo>/<juju-bundle>
+ - <juju-bundle folder under k8s_models folder in the package>
+ - <juju-bundle tgz file (w/ or w/o extension) under k8s_models folder
+ in the package>
+ - <URL_where_to_fetch_juju_bundle>
+ """
+ try:
+ previous_workdir = os.getcwd()
+ except FileNotFoundError:
+ previous_workdir = "/app/storage"
+
+ self.log.debug("[install] deploying {}".format(bundle))
+ await self.libjuju.deploy(
+ bundle, model_name=kdu_instance, wait=atomic, timeout=timeout
+ )
+
+ # Get the application
+ # if atomic:
+ # # applications = model.applications
+ # self.log.debug("[install] Applications: {}".format(model.applications))
+ # for name in model.applications:
+ # self.log.debug("[install] Waiting for {} to settle".format(name))
+ # application = model.applications[name]
+ # try:
+ # # It's not enough to wait for all units to be active;
+ # # the application status needs to be active as well.
+ # self.log.debug("Waiting for all units to be active...")
+ # await model.block_until(
+ # lambda: all(
+ # unit.agent_status == "idle"
+ # and application.status in ["active", "unknown"]
+ # and unit.workload_status in ["active", "unknown"]
+ # for unit in application.units
+ # ),
+ # timeout=timeout,
+ # )
+ # self.log.debug("All units active.")
+
+ # # TODO use asyncio.TimeoutError
+ # except concurrent.futures._base.TimeoutError:
+ # os.chdir(previous_workdir)
+ # self.log.debug("[install] Timeout exceeded; resetting cluster")
+ # await self.reset(cluster_uuid)
+ # return False
+
+ # Wait for the application to be active
+ # if model.is_connected():
+ # self.log.debug("[install] Disconnecting model")
+ # await model.disconnect()
+ # await controller.disconnect()
+ os.chdir(previous_workdir)
+ return True