def test_missing_from_node(self): self.resp = [ # Response for call to get node id [{ 'id': '0ff84778-cdb8-4e5a-b897-f912641ca87c', 'name': 'ubuntu' }], # Response for call to get list of active volumes [{ 'id': 'c270f302-9102-4327-bb0d-c8eaf9df872f', 'size': 5, 'status': 'ACTIVE' }, { 'id': '91e81aec-b6da-40e9-82fb-f04a99a866eb', 'size': 3, 'status': 'ACTIVE' }, { 'id': 'e2c2591a-d6c6-11e3-8f58-080027bab7b1', 'size': 1, 'status': 'ACTIVE', }] ] result = audit.volumes(self.helper) self.assertEquals(len(result), 2) self.assertEquals(result[0]['volume'], 'e2c2591a-d6c6-11e3-8f58-080027bab7b1') self.assertNotEqual(result[0]['msg'], None)
def test_sizes_do_not_match(self): self.resp = [ # Response for call to get node id [{ 'id': '0ff84778-cdb8-4e5a-b897-f912641ca87c', 'name': 'ubuntu' }], # Response for call to get list of active volumes [{ 'id': 'c270f302-9102-4327-bb0d-c8eaf9df872f', 'size': 5, 'status': 'ACTIVE' }, { 'id': '91e81aec-b6da-40e9-82fb-f04a99a866eb', 'size': 2, 'status': 'ACTIVE' }, { 'id': 'c21395aa-5a67-4d4e-ac70-d4ed8c6e7d98', 'size': 1, 'status': 'ACTIVE', }] ] result = audit.volumes(self.helper) self.assertEquals(len(result), 1) self.assertEquals(result[0]['volume'], '91e81aec-b6da-40e9-82fb-f04a99a866eb') self.assertNotEqual(result[0]['msg'], None)
def test_no_problems(self): self.resp = [ # Response for call to get node id [{ 'id': '0ff84778-cdb8-4e5a-b897-f912641ca87c', 'name': 'ubuntu' }], # Response for call to get list of active volumes [{ 'id': 'c270f302-9102-4327-bb0d-c8eaf9df872f', 'size': 5, 'status': 'ACTIVE' }, { 'id': '91e81aec-b6da-40e9-82fb-f04a99a866eb', 'size': 3, 'status': 'ACTIVE' }, { 'id': 'c21395aa-5a67-4d4e-ac70-d4ed8c6e7d98', 'size': 1, 'status': 'ACTIVE', }] ] # Should not report any issue, since the local volumes # are identical to the volumes returned by the API self.assertEquals(audit.volumes(self.helper), [])
def test_sizes_do_not_match(self): self.resp = [ # Response for call to get node id [{ 'id': '0ff84778-cdb8-4e5a-b897-f912641ca87c', 'name': 'ubuntu'}], # Response for call to get list of active volumes [{ 'id': 'c270f302-9102-4327-bb0d-c8eaf9df872f', 'size': 5, 'status': 'ACTIVE'}, { 'id': '91e81aec-b6da-40e9-82fb-f04a99a866eb', 'size': 2, 'status': 'ACTIVE'}, { 'id': 'c21395aa-5a67-4d4e-ac70-d4ed8c6e7d98', 'size': 1, 'status': 'ACTIVE', }] ] result = audit.volumes(self.helper) self.assertEquals(len(result), 1) self.assertEquals(result[0]['volume'], '91e81aec-b6da-40e9-82fb-f04a99a866eb') self.assertNotEqual(result[0]['msg'], None)
def test_missing_from_node(self): self.resp = [ # Response for call to get node id [{ 'id': '0ff84778-cdb8-4e5a-b897-f912641ca87c', 'name': 'ubuntu'}], # Response for call to get list of active volumes [{ 'id': 'c270f302-9102-4327-bb0d-c8eaf9df872f', 'size': 5, 'status': 'ACTIVE'}, { 'id': '91e81aec-b6da-40e9-82fb-f04a99a866eb', 'size': 3, 'status': 'ACTIVE'}, { 'id': 'e2c2591a-d6c6-11e3-8f58-080027bab7b1', 'size': 1, 'status': 'ACTIVE', }] ] result = audit.volumes(self.helper) self.assertEquals(len(result), 2) self.assertEquals(result[0]['volume'], 'e2c2591a-d6c6-11e3-8f58-080027bab7b1') self.assertNotEqual(result[0]['msg'], None)
def test_no_problems(self): self.resp = [ # Response for call to get node id [{ 'id': '0ff84778-cdb8-4e5a-b897-f912641ca87c', 'name': 'ubuntu'}], # Response for call to get list of active volumes [{ 'id': 'c270f302-9102-4327-bb0d-c8eaf9df872f', 'size': 5, 'status': 'ACTIVE'}, { 'id': '91e81aec-b6da-40e9-82fb-f04a99a866eb', 'size': 3, 'status': 'ACTIVE'}, { 'id': 'c21395aa-5a67-4d4e-ac70-d4ed8c6e7d98', 'size': 1, 'status': 'ACTIVE', }] ] # Should not report any issue, since the local volumes # are identical to the volumes returned by the API self.assertEquals(audit.volumes(self.helper), [])
def audit_volumes(self): """ Report any inconsistencies with node volumes and what the API reports about the volumes """ helper = self.load_conf(self.config) first = audit.volumes(helper) if not len(first): return 0 sleep(1) second = audit.volumes(helper) # If the lists do not match, something must have # changed while we were sleeping if not audit.compare_lists(first, second, key='volume'): return self.audit_volumes() print "\n The following Volumes failed to pass audit" self.display(first) return 1