More fixes for multiple host operations
1 files changed, 16 insertions(+), 5 deletions(-)

M djeploy/deploy.py
M djeploy/deploy.py +16 -5
@@ 12,7 12,7 @@ def get_release_dir(release_dir=None):
     return release_dir
 
 
-def get_releases_list(release_dir=None):
+def get_releases_list(release_dir=None, verify_dir_index=-1):
     ''' Returns sorted list of all current releases
     '''
     release_dir = get_release_dir(release_dir)

          
@@ 23,11 23,22 @@ def get_releases_list(release_dir=None):
             opts['capture'] = True
         releases = command.run('ls -xt', **opts)
         if isinstance(releases, dict):
+            last_dir = None
             for k, v in releases.iteritems():
-                releases[k] = [x.replace('/', '') for x in v.split()]
+                releases[k] = sorted([x.replace('/', '') for x in v.split()])
+
+                # Verify all results match for given deploy directory
+                if last_dir is None:
+                    last_dir = releases[k][verify_dir_index]
+                else:
+                    assert(last_dir == releases[k][verify_dir_index])
+
+            # Should all match. Just pick the last one and return
+            releases = releases[k]
         else:
-            releases = [x.replace('/', '') for x in releases.split()]
-    return sorted(releases)
+            releases = sorted([x.replace('/', '') for x in releases.split()])
+
+    return releases
 
 
 @task

          
@@ 134,7 145,7 @@ def generic_rollback(release_dir=None):
     opts = get_env('env_path')
     env_path = opts['env_path']
 
-    releases = get_releases_list(release_dir)
+    releases = get_releases_list(release_dir, verify_dir_index=-2)
     release = releases[-2]
     with command.cd(env_path):
         command.run('ln -nfs releases/%s current' % release)