Make swift-recon compatible for servers without storage policies
Swift recon introduced a new key for storage policies, and the CLI expected this key in the server response. However, if one updates the CLI but not yet the server an exception will be raised, because there is no default value and no check if the key is included in the response. This change checks if the policies key is included in the response and updates one test to ensure backward compability. Closes-Bug: 1453599 Change-Id: I7c7a90f9933bec2ab45595df9dc600a6cba65666
This commit is contained in:
parent
736cf54adf
commit
b4c1d73ad5
@ -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:
|
||||
|
@ -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://<host>:<port>/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}}
|
||||
# <low> <high> <avg> <total> <Failed> <no_result> <reported>
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user