Ejemplo n.º 1
0
async def test_2way_protocol(unused_tcp_port, no_tid_check, postgres_db,
                             database_name):
    configure(unused_tcp_port, database_name, postgres_db.port)

    rs = Server()
    server = SessionSpy()
    rs.get_slice(SLICE_SESSION_MANAGER).add_listener(server)
    rs.add_slice(server)
    await rs.start()

    agent = Agent("agent")
    await agent.add_end_point_name("agent")
    agent.set_environment(uuid.uuid4())
    await agent.start()

    await retry_limited(lambda: len(server.get_sessions()) == 1, 10)
    assert len(server.get_sessions()) == 1
    await assert_agent_counter(agent, 1, 0)

    client = protocol.Client("client")
    status = await client.get_status_x(str(agent.environment))
    assert status.code == 200
    assert "agents" in status.result
    assert len(status.result["agents"]) == 1
    assert status.result["agents"][0]["status"], "ok"
    await server.stop()

    await rs.stop()
    await agent.stop()
    await assert_agent_counter(agent, 1, 0)
Ejemplo n.º 2
0
async def test_agent_timeout(unused_tcp_port, no_tid_check, async_finalizer,
                             postgres_db, database_name):
    from inmanta.config import Config

    configure(unused_tcp_port, database_name, postgres_db.port)

    Config.set("server", "agent-timeout", "1")

    rs = Server()
    server = SessionSpy()
    rs.get_slice(SLICE_SESSION_MANAGER).add_listener(server)
    rs.add_slice(server)
    await rs.start()
    async_finalizer(rs.stop)

    env = uuid.uuid4()

    # agent 1
    agent = Agent("agent")
    await agent.add_end_point_name("agent")
    agent.set_environment(env)
    await agent.start()
    async_finalizer(agent.stop)

    # wait till up
    await retry_limited(lambda: len(server.get_sessions()) == 1, timeout=10)
    assert len(server.get_sessions()) == 1
    await assert_agent_counter(agent, 1, 0)

    # agent 2
    agent2 = Agent("agent")
    await agent2.add_end_point_name("agent")
    agent2.set_environment(env)
    await agent2.start()
    async_finalizer(agent2.stop)

    # wait till up
    await retry_limited(lambda: len(server.get_sessions()) == 2, timeout=10)
    assert len(server.get_sessions()) == 2
    await assert_agent_counter(agent, 1, 0)
    await assert_agent_counter(agent2, 1, 0)

    # see if it stays up
    await check_sessions(server.get_sessions())
    await sleep(1.1)
    assert len(server.get_sessions()) == 2
    await check_sessions(server.get_sessions())

    # take it down
    await agent2.stop()

    # Timeout=2
    # -> 1sec: Wait for agent-timeout
    # -> 1sec: Wait until session bookkeeping is updated
    await retry_limited(lambda: len(server.get_sessions()) == 1, timeout=2)
    print(server.get_sessions())
    await check_sessions(server.get_sessions())
    assert server.expires == 1
    await assert_agent_counter(agent, 1, 0)
    await assert_agent_counter(agent2, 1, 0)
Ejemplo n.º 3
0
 async def prestart(self, server: protocol.Server) -> None:
     await super().prestart(server)
     self.autostarted_agent_manager = cast(
         AutostartedAgentManager,
         server.get_slice(SLICE_AUTOSTARTED_AGENT_MANAGER))
     self.resource_service = cast(ResourceService,
                                  server.get_slice(SLICE_RESOURCE))
Ejemplo n.º 4
0
 async def start_server():
     rs = Server()
     server = SessionSpy()
     rs.get_slice(SLICE_SESSION_MANAGER).add_listener(server)
     rs.add_slice(server)
     await rs.start()
     async_finalizer(rs.stop)
     return server, rs
Ejemplo n.º 5
0
 async def prestart(self, server: protocol.Server) -> None:
     await super().prestart(server)
     self.server_slice = cast(Server, server.get_slice(SLICE_SERVER))
     self.agent_manager = cast(AgentManager,
                               server.get_slice(SLICE_AGENT_MANAGER))
     self.autostarted_agent_manager = cast(
         AutostartedAgentManager,
         server.get_slice(SLICE_AUTOSTARTED_AGENT_MANAGER))
     self.orchestration_service = cast(
         OrchestrationService, server.get_slice(SLICE_ORCHESTRATION))
     self.resource_service = cast(ResourceService,
                                  server.get_slice(SLICE_RESOURCE))
Ejemplo n.º 6
0
    async def prestart(self, server: protocol.Server) -> None:
        self._server = server
        self._server_storage: Dict[str, str] = self.check_storage()
        self.compiler: "CompilerService" = cast(
            "CompilerService", server.get_slice(SLICE_COMPILER))

        self.setup_dashboard()
Ejemplo n.º 7
0
 async def prestart(self, server: protocol.Server) -> None:
     await super().prestart(server)
     self._compiler_service = cast(CompilerService, server.get_slice(SLICE_COMPILER))
     self._compiler_service.add_listener(self)
Ejemplo n.º 8
0
 async def prestart(self, server: protocol.Server) -> None:
     await super().prestart(server)
     self.file_slice = cast(FileService, server.get_slice(SLICE_FILE))
Ejemplo n.º 9
0
 async def prestart(self, server: protocol.Server) -> None:
     await super().prestart(server)
     self.server_slice = cast(Server, server.get_slice(SLICE_SERVER))
     self.agentmanager = cast(AgentManager,
                              server.get_slice(SLICE_AGENT_MANAGER))
Ejemplo n.º 10
0
def feature_manager(server: Server) -> FeatureManager:
    return server.get_slice(SLICE_SERVER).feature_manager
Ejemplo n.º 11
0
 async def prestart(self, server: protocol.Server) -> None:
     await super().prestart(server)
     self.server_slice = cast(Server, server.get_slice(SLICE_SERVER))