Merge remote-tracking branch 'origin' into set-project
diff --git a/staffeln/conductor/backup.py b/staffeln/conductor/backup.py
index 4fd4f32..b2ce21e 100755
--- a/staffeln/conductor/backup.py
+++ b/staffeln/conductor/backup.py
@@ -146,8 +146,10 @@
             return False
 
         except OpenstackSDKException as e:
-            LOG.info(_("Backup %s deletion failed."
-                       "%s" % (backup_object.backup_id, str(e))))
+            LOG.info(
+                _("Backup %s deletion failed." "%s" % (backup_object.backup_id,
+                                                       str(e)))
+            )
             # TODO(Alex): Add it into the notification queue
             # remove from the backup table
             backup_object.delete_backup()
@@ -170,8 +172,11 @@
             backup_object.delete_backup()
 
         except OpenstackSDKException as e:
-            LOG.info(_("Backup %s deletion failed."
-                       "%s" % (backup_object.backup_id, str(e))))
+            LOG.info(
+                _("Backup %s deletion failed." "%s" % (backup_object.backup_id,
+                                                       str(e)))
+            )
+
             # TODO(Alex): Add it into the notification queue
             # remove from the backup table
             backup_object.delete_backup()
@@ -246,8 +251,8 @@
                 LOG.info(reason)
                 self.result.add_failed_backup(project_id, queue.volume_id, reason)
                 parsed = parse.parse("Error in creating volume backup {id}", str(error))
-                if parsed == None: return
-                queue.backup_id = parsed["id"]
+                if parsed is not None:
+                    queue.backup_id = parsed["id"]
                 queue.backup_status = constants.BACKUP_WIP
                 queue.save()
         else:
@@ -257,6 +262,17 @@
             #  Reserve for now because it is related to the WIP backup genenrators which
             #  are not finished in the current cycle
 
+
+    # backup gen was not created
+    def process_pre_failed_backup(self, task):
+        # 1.notify via email
+        reason = _("The backup creation for the volume %s was prefailed."
+                   % task.volume_id)
+        self.result.add_failed_backup(task.project_id, task.volume_id, reason)
+        # LOG.error(reason)
+        # 2. remove failed task from the task queue
+        task.delete_queue()
+
     def process_failed_backup(self, task):
         # 1. notify via email
         reason = _("The status of backup for the volume %s is error." % task.volume_id)
@@ -298,10 +314,17 @@
         Call the backups api to see if the backup is successful.
         """
         try:
+
             project_id = queue.project_id
+
+            # The case in which the error produced before backup gen created.
+            if queue.backup_id == "NULL":
+                self.process_pre_failed_backup(queue)
+                return
             if project_id not in self.project_list: self.process_non_existing_backup(queue)
             self.openstacksdk.set_project(self.project_list[project_id])
             backup_gen = self.openstacksdk.get_backup(queue.backup_id)
+
             if backup_gen == None:
                 # TODO(Alex): need to check when it is none
                 LOG.info(_("[Beta] Backup status of %s is returning none." % (queue.backup_id)))