Merge pull request #38 from vexxhost/update-retention

Set the proper project in retention service
diff --git a/staffeln/conductor/backup.py b/staffeln/conductor/backup.py
index 6f251bd..cf1ccfa 100755
--- a/staffeln/conductor/backup.py
+++ b/staffeln/conductor/backup.py
@@ -92,7 +92,6 @@
         except OpenstackResourceNotFound:
             return False
 
-
     #  delete all backups forcily regardless of the status
     def hard_cancel_backup_task(self, task):
         try:
@@ -160,8 +159,13 @@
     #  delete all backups forcily regardless of the status
     def hard_remove_volume_backup(self, backup_object):
         try:
+            project_id = backup_object.project_id
+            if project_id not in self.project_list:
+                backup_object.delete_backup()
+
+            self.openstacksdk.set_project(project_id)
             backup = self.openstacksdk.get_backup(uuid=backup_object.backup_id,
-                                             project_id=backup_object.project_id)
+                                                  project_id=project_id)
             if backup == None: return backup_object.delete_backup()
 
             self.openstacksdk.delete_backup(uuid=backup_object.backup_id)
@@ -183,6 +187,11 @@
             # remove from the backup table
             backup_object.delete_backup()
 
+    def update_project_list(self):
+        projects = self.openstacksdk.get_projects()
+        for project in projects:
+            self.project_list[project.id] = project
+
     def check_instance_volumes(self):
         """Get the list of all the volumes from the project using openstacksdk
         Function first list all the servers in the project and get the volumes
@@ -243,7 +252,7 @@
                 if project_id not in self.project_list: self.process_non_existing_backup(queue)
                 self.openstacksdk.set_project(self.project_list[project_id])
                 volume_backup = self.openstacksdk.create_backup(volume_id=queue.volume_id,
-                                                           project_id=project_id)
+                                                                project_id=project_id)
                 queue.backup_id = volume_backup.id
                 queue.backup_status = constants.BACKUP_WIP
                 queue.save()
@@ -264,7 +273,6 @@
             #  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
diff --git a/staffeln/conductor/manager.py b/staffeln/conductor/manager.py
index 456e37e..13848a2 100755
--- a/staffeln/conductor/manager.py
+++ b/staffeln/conductor/manager.py
@@ -165,8 +165,9 @@
         LOG.info("%s rotation_engine" % self.name)

         # 1. get the list of backups to remove based on the retention time

         if not self.get_backup_list(): return

-

-        # 2. remove the backups

+        # 2. get project list

+        self.controller.update_project_list()

+        # 3. remove the backups

         self.remove_backups()

 

     # get the threshold time str