def test_zone_operation_error(self): op = gce.ZoneOperation( gce.Project('123'), 'zone-id', { 'name': 'op', 'status': 'DONE', 'error': { 'errors': [ {'message': 'A', 'code': 'ERROR_CODE'}, {'message': 'B'}, ], }, }) self.assertTrue(op.has_error_code('ERROR_CODE')) self.assertFalse(op.has_error_code('NOT_ERROR_CODE')) self.assertEqual('A B', op.error)
def test_zone_operation_poll(self): self.mock_requests([ ( { 'url': 'https://www.googleapis.com/compute/v1/projects/123' '/zones/zone-id/operations/op', }, { 'name': 'op', 'status': 'DONE', }, ), ]) op = gce.ZoneOperation( gce.Project('123'), 'zone-id', {'name': 'op', 'status': 'PENDING'}) self.assertFalse(op.done) self.assertFalse(op.error) self.assertTrue(op.poll()) # Second 'poll' is skipped if the operation is already done. self.assertTrue(op.poll())