From 909bdf89542a9d021eb2ddcb951950f36245bc8b Mon Sep 17 00:00:00 2001
From: Sergey Gotliv <sgotliv@redhat.com>
Date: Sun, 3 Apr 2016 07:37:33 +0300
Subject: [PATCH] Fix downloading from "marker" item

The documentation of "swift download" hints that "marker" option
is supported, but in reality we forgot to patch it through, so
all downloads were always done with the default, empty marker.

Closes-Bug: #1565393
Change-Id: I38bd29d2baa9188b61397dec75ce1d864041653c
---
 swiftclient/service.py     |  2 +-
 swiftclient/shell.py       |  4 ++--
 tests/unit/test_service.py | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/swiftclient/service.py b/swiftclient/service.py
index 99c833e0..7d6f6bef 100644
--- a/swiftclient/service.py
+++ b/swiftclient/service.py
@@ -883,7 +883,7 @@ class SwiftService(object):
 
     @staticmethod
     def _list_container_job(conn, container, options, result_queue):
-        marker = ''
+        marker = options.get('marker', '')
         error = None
         try:
             while True:
diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index 2c5bca82..c1b893d0 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -203,7 +203,7 @@ def st_delete(parser, args, output_manager):
             output_manager.error(err.value)
 
 
-st_download_options = '''[--all] [--marker] [--prefix <prefix>]
+st_download_options = '''[--all] [--marker <marker>] [--prefix <prefix>]
                       [--output <out_file>] [--output-dir <out_directory>]
                       [--object-threads <threads>]
                       [--container-threads <threads>] [--no-download]
@@ -225,7 +225,7 @@ Positional arguments:
 Optional arguments:
   -a, --all             Indicates that you really want to download
                         everything in the account.
-  -m, --marker          Marker to use when starting a container or account
+  -m, --marker <marker> Marker to use when starting a container or account
                         download.
   -p, --prefix <prefix> Only download items beginning with <prefix>
   -r, --remove-prefix   An optional flag for --prefix <prefix>, use this
diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py
index e9310aa7..30947807 100644
--- a/tests/unit/test_service.py
+++ b/tests/unit/test_service.py
@@ -687,6 +687,41 @@ class TestServiceList(_TestServiceBase):
         self.assertEqual(expected_r_long, self._get_queue(mock_q))
         self.assertIsNone(self._get_queue(mock_q))
 
+    def test_list_container_marker(self):
+        mock_q = Queue()
+        mock_conn = self._get_mock_connection()
+
+        get_container_returns = [
+            (None, [{'name': 'b'}, {'name': 'c'}]),
+            (None, [])
+        ]
+        mock_get_cont = Mock(side_effect=get_container_returns)
+        mock_conn.get_container = mock_get_cont
+
+        expected_r = self._get_expected({
+            'action': 'list_container_part',
+            'container': 'test_c',
+            'success': True,
+            'listing': [{'name': 'b'}, {'name': 'c'}],
+            'marker': 'b'
+        })
+
+        _opts = self.opts.copy()
+        _opts['marker'] = 'b'
+        SwiftService._list_container_job(mock_conn, 'test_c', _opts, mock_q)
+
+        # This does not test if the marker is propagated, because we always
+        # get the final call to the get_container with the final item 'c',
+        # even if marker wasn't set. This test just makes sure the whole
+        # stack works in a sane way.
+        mock_kw = mock_get_cont.call_args[1]
+        self.assertEqual(mock_kw['marker'], 'c')
+
+        # This tests that the lower levels get the marker delivered.
+        self.assertEqual(expected_r, self._get_queue(mock_q))
+
+        self.assertIsNone(self._get_queue(mock_q))
+
     def test_list_container_exception(self):
         mock_q = Queue()
         mock_conn = self._get_mock_connection()