Browse Source

Add re-raise argument to start() and cleanup()

To enhance the usability of the Orchestrator class as a reusable
component (e.g., used by WebUI), it should not catch and handle
certain exceptions, without at a minimum re-raising them.

Change-Id: I4ff8320f3a275fbdbe7cf3a21c217f1cf59ddacb
Fixes: bug #1226193
Changbin Liu 5 years ago
parent
commit
e76ace1914
1 changed files with 14 additions and 2 deletions
  1. 14
    2
      inception/orchestrator.py

+ 14
- 2
inception/orchestrator.py View File

@@ -243,9 +243,12 @@ class Orchestrator(object):
243 243
         self._worker_names = []
244 244
         self._gateway_floating_ip = None
245 245
 
246
-    def start(self):
246
+    def start(self, re_raise=False):
247 247
         """
248 248
         run the whole process
249
+
250
+        @param re_raise: whether re-raise caught exception, for the purpose of
251
+            notifying external caller. Default: False
249 252
         """
250 253
         try:
251 254
             self._check_existence()
@@ -269,6 +272,8 @@ class Orchestrator(object):
269 272
                 LOGGER.info("Although there was error in creating your "
270 273
                             "inception cloud '%s', resources have been "
271 274
                             "successfully cleaned up", self.prefix)
275
+            if re_raise:
276
+                raise
272 277
 
273 278
     def _check_existence(self):
274 279
         """
@@ -539,9 +544,12 @@ class Orchestrator(object):
539 544
         self._add_run_list(self._worker_names, "role[os-worker-combined]")
540 545
         self._run_chef_client(self._worker_ips)
541 546
 
542
-    def cleanup(self):
547
+    def cleanup(self, re_raise=False):
543 548
         """
544 549
         Clean up the whole inception cloud, based on self.prefix
550
+
551
+        @param re_raise: whether re-raise caught exception, for the purpose of
552
+            notifying external caller. Default: False
545 553
         """
546 554
         LOGGER.info("Let's clean up inception cloud '%s'...", self.prefix)
547 555
         ## find out servers info
@@ -568,6 +576,8 @@ class Orchestrator(object):
568 576
                     self.client.floating_ips.delete(floating_ip)
569 577
         except Exception:
570 578
             LOGGER.exception("Error in disassociating/releasing floating IP")
579
+            if re_raise:
580
+                raise
571 581
         ## try deleting each server
572 582
         for server in servers:
573 583
             try:
@@ -575,5 +585,7 @@ class Orchestrator(object):
575 585
                 server.delete()
576 586
             except Exception:
577 587
                 LOGGER.exception("Error in deleting server %s", server)
588
+                if re_raise:
589
+                    raise
578 590
                 continue
579 591
         LOGGER.info("Inception cloud '%s' has been cleaned up.", self.prefix)

Loading…
Cancel
Save