Пример #1
0
def main(plan):
    # Add a test with an environment.
    plan.add(make_multitest(idx='1'))

    # Add an independent environment.
    plan.add_environment(
        LocalEnvironment('my_env1', [
            TCPServer(name='server'),
            TCPClient(name='client',
                      host=context('server', '{{host}}'),
                      port=context('server', '{{port}}'))
        ]))
Пример #2
0
def main(plan):
    # Add a test with an environment.
    plan.add(make_multitest(idx="1"))

    # Add an independent environment.
    plan.add_environment(
        LocalEnvironment(
            "my_env1",
            [
                TCPServer(name="server"),
                TCPClient(
                    name="client",
                    host=context("server", "{{host}}"),
                    port=context("server", "{{port}}"),
                ),
            ],
        ))
Пример #3
0
def test_top_level_environment():
    with log_propagation_disabled(TESTPLAN_LOGGER):
        with InteractivePlan(name='InteractivePlan',
                             interactive=True,
                             interactive_block=False,
                             parse_cmdline=False,
                             logger_level=TEST_INFO) as plan:
            plan.add_environment(
                LocalEnvironment('env1', [
                    TCPServer(name='server'),
                    TCPClient(name='client',
                              host=context('server', '{{host}}'),
                              port=context('server', '{{port}}'))
                ]))
            plan.run()
            wait(lambda: bool(plan.i.http_handler_info),
                 5,
                 raise_on_timeout=True)

            assert len(plan.resources.environments.envs) == 1

            # Create an environment using serializable arguments.
            # That is mandatory for HTTP usage.
            plan.i.create_new_environment('env2')
            plan.i.add_environment_resource('env2', 'TCPServer', name='server')
            plan.i.add_environment_resource('env2',
                                            'TCPClient',
                                            name='client',
                                            _ctx_host_ctx_driver='server',
                                            _ctx_host_ctx_value='{{host}}',
                                            _ctx_port_ctx_driver='server',
                                            _ctx_port_ctx_value='{{port}}')
            plan.i.add_created_environment('env2')

            assert len(plan.resources.environments.envs) == 2

            for env_uid in ('env1', 'env2'):
                env = plan.i.get_environment(env_uid)
                assert isinstance(env, Environment)
                resources = [res.uid() for res in env]
                assert resources == ['server', 'client']
                for resource in env:
                    assert resource.status.tag is None
                plan.i.start_environment(env_uid)  # START

                # INSPECT THE CONTEXT WHEN STARTED
                env_context = plan.i.get_environment_context(env_uid)
                for resource in [res.uid() for res in env]:
                    res_context = \
                        plan.i.environment_resource_context(env_uid, resource_uid=resource)
                    assert env_context[resource] == res_context
                    assert isinstance(res_context['host'], six.string_types)
                    assert isinstance(res_context['port'], int)
                    assert res_context['port'] > 0

                # CUSTOM RESOURCE OPERATIONS
                plan.i.environment_resource_operation(env_uid, 'server',
                                                      'accept_connection')
                plan.i.environment_resource_operation(env_uid,
                                                      'client',
                                                      'send_text',
                                                      msg='hello')
                received = plan.i.environment_resource_operation(
                    env_uid, 'server', 'receive_text')
                assert received == 'hello'
                plan.i.environment_resource_operation(env_uid,
                                                      'server',
                                                      'send_text',
                                                      msg='worlds')
                received = plan.i.environment_resource_operation(
                    env_uid, 'client', 'receive_text')
                assert received == 'worlds'

                for resource in env:
                    assert resource.status.tag is resource.STATUS.STARTED
                plan.i.stop_environment(env_uid)  # STOP
                for resource in env:
                    assert resource.status.tag is resource.STATUS.STOPPED
Пример #4
0
def test_top_level_environment():
    with InteractivePlan(
            name="InteractivePlan",
            interactive_port=0,
            interactive_block=False,
            parse_cmdline=False,
            logger_level=TEST_INFO,
    ) as plan:
        plan.add_environment(
            LocalEnvironment(
                "env1",
                [
                    TCPServer(name="server"),
                    TCPClient(
                        name="client",
                        host=context("server", "{{host}}"),
                        port=context("server", "{{port}}"),
                    ),
                ],
            ))
        plan.run()
        wait(lambda: bool(plan.i.http_handler_info), 5, raise_on_timeout=True)

        assert len(plan.resources.environments.envs) == 1

        # Create an environment using serializable arguments.
        # That is mandatory for HTTP usage.
        plan.i.create_new_environment("env2")
        plan.i.add_environment_resource("env2", "TCPServer", name="server")
        plan.i.add_environment_resource(
            "env2",
            "TCPClient",
            name="client",
            _ctx_host_ctx_driver="server",
            _ctx_host_ctx_value="{{host}}",
            _ctx_port_ctx_driver="server",
            _ctx_port_ctx_value="{{port}}",
        )
        plan.i.add_created_environment("env2")

        assert len(plan.resources.environments.envs) == 2

        for env_uid in ("env1", "env2"):
            env = plan.i.get_environment(env_uid)
            assert isinstance(env, Environment)
            resources = [res.uid() for res in env]
            assert resources == ["server", "client"]
            for resource in env:
                assert resource.status.tag is None
            plan.i.start_environment(env_uid)  # START

            # INSPECT THE CONTEXT WHEN STARTED
            env_context = plan.i.get_environment_context(env_uid)
            for resource in [res.uid() for res in env]:
                res_context = plan.i.environment_resource_context(
                    env_uid, resource_uid=resource)
                assert env_context[resource] == res_context
                assert isinstance(res_context["host"], str)
                assert isinstance(res_context["port"], int)
                assert res_context["port"] > 0

            # CUSTOM RESOURCE OPERATIONS
            plan.i.environment_resource_operation(env_uid, "server",
                                                  "accept_connection")
            plan.i.environment_resource_operation(env_uid,
                                                  "client",
                                                  "send_text",
                                                  msg="hello")
            received = plan.i.environment_resource_operation(
                env_uid, "server", "receive_text")
            assert received == "hello"
            plan.i.environment_resource_operation(env_uid,
                                                  "server",
                                                  "send_text",
                                                  msg="worlds")
            received = plan.i.environment_resource_operation(
                env_uid, "client", "receive_text")
            assert received == "worlds"

            for resource in env:
                assert resource.status.tag is resource.STATUS.STARTED
            plan.i.stop_environment(env_uid)  # STOP
            for resource in env:
                assert resource.status.tag is resource.STATUS.STOPPED