Esempio n. 1
0
def test_can_start_gridappsd_within_dependency_context_manager_all_cleanup():

    Containers.reset_all_containers()

    with run_dependency_containers(True) as cont:
        # True in this method will remove the containsers
        with run_gridappsd_container(True) as dep_con:
            # Default cleanup is true within run_gridappsd_container method
            timeout = 0
            gapps = None
            time.sleep(10)
            while timeout < 30:
                try:
                    gapps = GridAPPSD()
                    gapps.connect()
                    break
                except:
                    time.sleep(1)
                    timeout += 1

            assert gapps
            assert gapps.connected

    # Filter out the two config containers that we start up for volume data.
    containers = [
        x.name for x in Containers.container_list() if "config" not in x.name
    ]
    assert not len(containers)
Esempio n. 2
0
def docker_dependencies():
    print("Docker dependencies")
    Containers.reset_all_containers()

    with run_dependency_containers(stop_after=True) as dep:
        yield dep
    print("Cleanup docker dependencies")
Esempio n. 3
0
def docker_dependencies():
    print("Docker dependencies")
    # Containers.reset_all_containers()

    with run_dependency_containers(
            stop_after=STOP_CONTAINER_AFTER_TEST) as dep:
        yield dep
    print("Cleanup docker dependencies")
Esempio n. 4
0
def test_multiple_runs_in_a_row_with_dependency_context_manager():

    Containers.reset_all_containers()

    with run_dependency_containers():
        pass

    containers = [
        x for x in Containers.container_list() if "config" not in x.name
    ]
    assert len(containers) == 5

    with run_gridappsd_container():
        timeout = 0
        gapps = None

        while timeout < 30:
            try:
                gapps = GridAPPSD()
                gapps.connect()
                break
            except:
                time.sleep(1)
                timeout += 1

        assert gapps
        assert gapps.connected

    with run_gridappsd_container():
        timeout = 0
        gapps = None
        time.sleep(10)
        while timeout < 30:
            try:
                gapps = GridAPPSD()
                gapps.connect()
                break
            except:
                time.sleep(1)
                timeout += 1

        assert gapps
        assert gapps.connected
Esempio n. 5
0
def test_can_dependencies_continue_after_context_manager():
    my_config = DEFAULT_DOCKER_DEPENDENCY_CONFIG.copy()
    Containers.reset_all_containers()

    time.sleep(3)
    my_dep_containers = None
    with run_dependency_containers() as containers:
        my_dep_containers = containers
        time.sleep(10)

    real_containers = Containers.container_list()
    for k in my_dep_containers.container_def.keys():
        found = False
        for c in real_containers:
            if c.name == k:
                found = True
                break
        assert found, f"Couldn't find {k} container in list"

    Containers.reset_all_containers()
Esempio n. 6
0
def test_can_start_gridapps():
    Containers.reset_all_containers()
    with run_dependency_containers() as cont:
        with run_gridappsd_container() as cont2:
            g = GridAPPSD()
            assert g.connected
LOCAL_MOUNT_POINT_FOR_SERVICE = Path(__file__).parent.parent.absolute()

# Mount point inside the gridappsd container itself.  This allows the container
# to start up the services inside the container.
SERVICE_MOUNT_POINT = "/gridappsd/services/gridappsd-sensor-simulator"
CONFIG_MOUNT_POINT = "/gridappsd/services/sensor_simulator.config"

# Directory that holds our json configurations that are going to be used
TEST_DATA_DIR = Path(__file__).parent.joinpath('test_data')
# Appending data_tests elements to TEST_DATA_DIR will get full path of the
# file to be loaded for a test.
data_tests = ("test1.json",)
client = docker.from_env()

if not client.containers.list(filters=dict(name='mysql')):
    with run_dependency_containers():
        pass

container = client.containers.list(filters=dict(name='gridappsd'))

if container:
    # Stop the gridappsd container
    container[0].stop()

config = deepcopy(DEFAULT_GRIDAPPSD_DOCKER_CONFIG)

config['gridappsd']['volumes'][str(LOCAL_MOUNT_POINT_FOR_SERVICE)] = dict(
    bind=str(SERVICE_MOUNT_POINT),
    mode="rw")
fncs_measurements = open("fncs_measurements.json", "w")