# -*- mode: python -*-
import flux
import arrow
from contextlib import contextmanager
from infinisim.infinibox import Infinibox as Simulator
from infinisdk import InfiniBox

@contextmanager
def doctest_context():
    simulator = Simulator()
    simulator.activate()
    system = InfiniBox(simulator, auth=('infinidat', '123456'))
    system.login()
    pool = system.pools.create()
    volume = system.volumes.create(pool=pool)

    cg = system.cons_groups.create(pool=pool)
    for _ in range(3):
        cg_volume = system.volumes.create(pool=pool)
        cg.add_member(cg_volume)

    try:
        yield {
            "current_time": arrow.get(flux.current_timeline.time()).shift(days=+15),
            "system": system,
            "volume": volume,
            "pool": pool,
            "cg": cg,
        }
    finally:
        simulator.deactivate()
