diff --git a/swift/cli/recon.py b/swift/cli/recon.py index a0fcdf7835..f57f75c22a 100755 --- a/swift/cli/recon.py +++ b/swift/cli/recon.py @@ -770,11 +770,10 @@ class SwiftRecon(object): objq[url] = response['objects'] conq[url] = response['containers'] acctq[url] = response['accounts'] - if response['policies']: - for key in response['policies']: - pkey = "objects_%s" % key - stats.setdefault(pkey, {}) - stats[pkey][url] = response['policies'][key]['objects'] + for key in response.get('policies', {}): + pkey = "objects_%s" % key + stats.setdefault(pkey, {}) + stats[pkey][url] = response['policies'][key]['objects'] stats.update({"objects": objq, "containers": conq, "accounts": acctq}) for item in stats: if len(stats[item]) > 0: diff --git a/test/unit/cli/test_recon.py b/test/unit/cli/test_recon.py index 0b6ffd7a33..dd53ae9d54 100644 --- a/test/unit/cli/test_recon.py +++ b/test/unit/cli/test_recon.py @@ -246,7 +246,8 @@ class TestRecon(unittest.TestCase): def test_quarantine_check(self): hosts = [('127.0.0.1', 6010), ('127.0.0.1', 6020), - ('127.0.0.1', 6030), ('127.0.0.1', 6040)] + ('127.0.0.1', 6030), ('127.0.0.1', 6040), + ('127.0.0.1', 6050)] # sample json response from http://:/recon/quarantined responses = {6010: {'accounts': 0, 'containers': 0, 'objects': 1, 'policies': {'0': {'objects': 0}, @@ -259,13 +260,15 @@ class TestRecon(unittest.TestCase): '1': {'objects': 3}}}, 6040: {'accounts': 3, 'containers': 3, 'objects': 7, 'policies': {'0': {'objects': 3}, - '1': {'objects': 4}}}} + '1': {'objects': 4}}}, + # A server without storage policies enabled + 6050: {'accounts': 0, 'containers': 0, 'objects': 4}} # expected = {'objects_0': (0, 3, 1.5, 6, 0.0, 0, 4), 'objects_1': (1, 4, 2.5, 10, 0.0, 0, 4), - 'objects': (1, 7, 4.0, 16, 0.0, 0, 4), - 'accounts': (0, 3, 1.5, 6, 0.0, 0, 4), - 'containers': (0, 3, 1.5, 6, 0.0, 0, 4)} + 'objects': (1, 7, 4.0, 20, 0.0, 0, 5), + 'accounts': (0, 3, 1.2, 6, 0.0, 0, 5), + 'containers': (0, 3, 1.2, 6, 0.0, 0, 5)} def mock_scout_quarantine(app, host): url = 'http://%s:%s/recon/quarantined' % host