def _wait_for_state_change(target_state, task):
    store = {'state': None, 'retries': CONF.cimc.max_retry}

    def _wait(store):

        current_power_state = None
        with common.cimc_handle(task) as handle:
            try:
                rack_unit = handle.get_imc_managedobject(
                    None, None, params={"Dn": "sys/rack-unit-1"}
                )
            except imcsdk.ImcException as e:
                raise exception.CIMCException(node=task.node.uuid, error=e)
            else:
                current_power_state = rack_unit[0].get_attr("OperPower")
        store['state'] = CIMC_TO_IRONIC_POWER_STATE.get(current_power_state)

        if store['state'] == target_state:
            raise loopingcall.LoopingCallDone()

        store['retries'] -= 1
        if store['retries'] <= 0:
            store['state'] = states.ERROR
            raise loopingcall.LoopingCallDone()

    timer = loopingcall.FixedIntervalLoopingCall(_wait, store)
    timer.start(interval=CONF.cimc.action_interval).wait()
    return store['state']
Wait and check for the power state change
dataset/ETHPy150Open openstack/ironic/ironic/drivers/modules/cimc/power.py/_wait_for_state_change