'Poll (briefly) while the state is in continue_states.
Continues until the state changes from continue_states or max_retries
are hit. If expected_end_status is specified, we assert that the end
status of the resource is expected_end_status.'

def _poll_resource_while(self, res_id, continue_states, res_type=VOLUME, expected_end_status=None, max_retries=5, status_field='status'):

    retries = 0
    while (retries <= max_retries):
        try:
            if (res_type == VOLUME):
                found_res = self.api.get_volume(res_id)
            elif (res_type == GROUP):
                found_res = self.api.get_group(res_id)
            elif (res_type == GROUP_SNAPSHOT):
                found_res = self.api.get_group_snapshot(res_id)
            else:
                return None
        except client.OpenStackApiException404:
            return None
        except client.OpenStackApiException:
            continue
        self.assertEqual(res_id, found_res['id'])
        res_status = found_res[status_field]
        if (res_status not in continue_states):
            if expected_end_status:
                self.assertEqual(expected_end_status, res_status)
            return found_res
        time.sleep(1)
        retries += 1
