예제 #1
0
    async def test_apps_stats_check_uri_regex(self):
        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}")
            with aioresponses(
                    passthrough=[local_address, settings.STATS_API_URL
                                 ]) as rsps:
                agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S0"
                build_mesos_cluster(rsps, agent_id)  # namespace=asgard-infra

                resp = await client.get(
                    f"/apps/asgard/pgsql-9.4/stats?account_id={ACCOUNT_DEV_ID}",
                    headers={
                        "Authorization":
                        f"Token {USER_WITH_MULTIPLE_ACCOUNTS_AUTH_KEY}"
                    },
                )
                self.assertEqual(HTTPStatus.OK, resp.status)

                resp = await client.get(
                    f"/apps/asgard/pgsql-9..4/stats?account_id={ACCOUNT_DEV_ID}",
                    headers={
                        "Authorization":
                        f"Token {USER_WITH_MULTIPLE_ACCOUNTS_AUTH_KEY}"
                    },
                )
                self.assertEqual(HTTPStatus.OK, resp.status)
예제 #2
0
    async def test_agents_with_atrrs_two_attrs_filter(self):
        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()

        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}")
            with aioresponses(passthrough=[local_address]) as rsps:
                build_mesos_cluster(
                    rsps,
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",  # namespace=asgard-infra
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S3",  # namespace=asgard-infra
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S4",  # namespace=asgard-dev
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S44",  # namespace=dev
                )
                resp = await client.get(
                    "/agents/with-attrs?workload=general&dc=gcp",
                    headers={"Authorization": f"Token {self.user_auth_key}"},
                )
                self.assertEqual(200, resp.status)
                data = await resp.json()
                self.assertEqual(1, len(data["agents"]))
                self.assertEqual(
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",
                    data["agents"][0]["id"],
                )
예제 #3
0
    async def test_agents_list_includes_app_list(self):
        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()
        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}")
            with aioresponses(passthrough=[local_address]) as rsps:
                build_mesos_cluster(
                    rsps,
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",  # namespace=asgard-infra
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S3",  # namespace=asgard-infra
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S10",  # namespace=asgard
                )
                resp = await client.get(
                    "/agents",
                    headers={"Authorization": f"Token {self.user_auth_key}"},
                )
                self.assertEqual(200, resp.status)
                data = await resp.json()
                self.assertEqual(2, len(data["agents"]))
                self.assertEqual(
                    set(["asgard-infra"]),
                    set([
                        agent["attributes"]["owner"]
                        for agent in data["agents"]
                    ]),
                )
                self.assertEqual(
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",
                    data["agents"][0]["id"],
                )
                self.assertEqual(
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S3",
                    data["agents"][1]["id"],
                )
                self.assertEqual("MESOS", data["agents"][0]["type"])

                self.assertEqual(5, data["agents"][0]["total_apps"])
                expected_app_ids = sorted([
                    "infra/asgard/api",
                    "infra/rabbitmq",
                    "captura/kirby/feeder",
                    "portal/api",
                    "captura/wetl/visitcentral",
                ])
                self.assertEqual(
                    expected_app_ids,
                    sorted([
                        app["id"] for app in data["agents"][0]["applications"]
                    ]),
                )

                self.assertEqual(0, data["agents"][1]["total_apps"])
                expected_app_ids_agent_s3 = sorted([])
                self.assertEqual(
                    expected_app_ids_agent_s3,
                    sorted([
                        app["id"] for app in data["agents"][1]["applications"]
                    ]),
                )
예제 #4
0
 async def test_get_agent_by_id_logs_error_if_failed(self):
     """
     O campo total_apps retorna com valor 0 caso não tenha sido possível obter a lista de apps rodando em um Agent.
     Nesse caso o campo `errors` deverá estar preenchido
     """
     agent_data = get_fixture(
         "agents/ead07ffb-5a61-42c9-9386-21b680597e6c-S10/info.json")
     agent_id = agent_data["id"]
     agent_hostname = agent_data["hostname"]
     with aioresponses() as rsps, mock.patch.object(
             log, "logger") as logger_mock:
         build_mesos_cluster(rsps, {
             "id": agent_id,
             "apps": ClusterOptions.CONNECTION_ERROR
         })
         agent = await self.mesos_backend.get_agent_by_id(
             agent_id, self.user, self.account)
         self.assertEqual(agent_id, agent.id)
         self.assertEqual([], agent.applications)
         self.assertEqual(0, agent.total_apps)
         self.assertEqual({"total_apps": "INDISPONIVEL"}, agent.errors)
         logger_mock.exception.assert_called_with({
             "event":
             "Erro buscando agent applications",
             "agent":
             agent_id,
             "hostname":
             agent_hostname,
         })
예제 #5
0
    async def test_agents_with_atrrs_one_attr_filter_with_account_id(self):
        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()

        with aioresponses(passthrough=[TEST_LOCAL_AIOHTTP_ADDRESS]) as rsps:
            build_mesos_cluster(
                rsps,
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",  # namespace=asgard-infra
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S3",  # namespace=asgard-infra
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S4",  # namespace=asgard-dev
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S44",  # namespace=dev
            )
            resp = await self.client.get(
                "/agents/with-attrs?workload=general&account_id=40",
                headers={"Authorization": f"Token {self.user_auth_key}"},
            )
            self.assertEqual(200, resp.status)
            data = await resp.json()
            self.assertEqual(2, len(data["agents"]))
            self.assertEqual(
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",
                data["agents"][0]["id"],
            )
            self.assertEqual(
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S3",
                data["agents"][1]["id"],
            )
예제 #6
0
    async def test_agents_with_attrs_empty_response(self):
        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()

        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}")
            with aioresponses(passthrough=[local_address]) as rsps:
                build_mesos_cluster(
                    rsps,
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S44",
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",  # namespace=asgard-infra
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S10",  # namespace=asgard
                )
                resp = await client.get(
                    "/agents/with-attrs?tag1=not-found",
                    headers={"Authorization": f"Token {self.user_auth_key}"},
                )
                self.assertEqual(200, resp.status)
                data = await resp.json()
                self.assertEqual(
                    {
                        "agents": [],
                        "stats": {
                            "cpu_pct": "0.00",
                            "ram_pct": "0.00"
                        },
                    },
                    data,
                )
예제 #7
0
    async def test_apps_stats_with_avg_1_min(self):
        with aioresponses(passthrough=[
                TEST_LOCAL_AIOHTTP_ADDRESS, settings.STATS_API_URL
        ]) as rsps:
            agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S0"

            build_mesos_cluster(rsps, agent_id)  # namespace=asgard-infra

            app_stats_datapoints = get_fixture(
                f"agents/{agent_id}/app_stats.json")

            await self._load_app_stats_into_storage(self.INDEX_NAME,
                                                    self.utc_now,
                                                    app_stats_datapoints)
            resp = await self.client.get(
                f"/apps/infra/asgard/api/stats/avg-1min?account_id={ACCOUNT_DEV_ID}",
                headers={
                    "Authorization":
                    f"Token {USER_WITH_MULTIPLE_ACCOUNTS_AUTH_KEY}"
                },
            )
            self.assertEqual(HTTPStatus.OK, resp.status)
            data = await resp.json()
            self.assertEqual(
                AppStats(cpu_pct="0.25", ram_pct="15.05",
                         cpu_thr_pct="1.00").dict(),
                data["stats"],
            )
예제 #8
0
    async def test_agents_with_attrs_empty_response(self):
        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()

        with aioresponses(passthrough=[TEST_LOCAL_AIOHTTP_ADDRESS]) as rsps:
            build_mesos_cluster(
                rsps,
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S44",
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",  # namespace=asgard-infra
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S10",  # namespace=asgard
            )
            resp = await self.client.get(
                "/agents/with-attrs?tag1=not-found",
                headers={"Authorization": f"Token {self.user_auth_key}"},
            )
            self.assertEqual(200, resp.status)
            data = await resp.json()
            self.assertEqual(
                {
                    "agents": [],
                    "stats": {
                        "cpu_pct": "0.00",
                        "ram_pct": "0.00"
                    }
                },
                data,
            )
예제 #9
0
    async def test_agent_app_list_apps_running(self):
        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()

        with aioresponses(passthrough=[TEST_LOCAL_AIOHTTP_ADDRESS]) as rsps:
            build_mesos_cluster(rsps, "ead07ffb-5a61-42c9-9386-21b680597e6c-S0")
            resp = await self.client.get(
                "/agents/ead07ffb-5a61-42c9-9386-21b680597e6c-S0/apps",
                headers={"Authorization": f"Token {self.user_auth_key}"},
            )
            self.assertEqual(200, resp.status)
            data = await resp.json()
            self.assertEqual(5, len(data["apps"]))
            expected_app_ids = sorted(
                [
                    "captura/wetl/visitcentral",
                    "portal/api",
                    "captura/kirby/feeder",
                    "infra/asgard/api",
                    "infra/rabbitmq",
                ]
            )
            self.assertEqual(
                expected_app_ids, sorted([app["id"] for app in data["apps"]])
            )
예제 #10
0
    async def test_apps_stats_app_not_found(self):
        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}")
            with aioresponses(
                    passthrough=[local_address, settings.STATS_API_URL
                                 ]) as rsps:
                agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S0"
                build_mesos_cluster(rsps, agent_id)  # namespace=asgard-infra

                app_stats_datapoints = get_fixture(
                    f"agents/{agent_id}/app_stats.json")

                resp = await client.get(
                    f"/apps/asgard/api/not-exist/stats?account_id={ACCOUNT_DEV_ID}",
                    headers={
                        "Authorization":
                        f"Token {USER_WITH_MULTIPLE_ACCOUNTS_AUTH_KEY}"
                    },
                )
                self.assertEqual(HTTPStatus.OK, resp.status)
                data = await resp.json()
                self.assertEqual(
                    AppStats(cpu_pct="0", ram_pct="0", cpu_thr_pct="0").dict(),
                    data["stats"],
                )
예제 #11
0
    async def test_get_agents_filtered_by_namespace(self):
        with aioresponses() as rsps:
            build_mesos_cluster(
                rsps,
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S10",
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S11",
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S12",
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S9",
            )

            agents = await self.mesos_backend.get_agents(
                self.user, self.account)
            self.assertEqual(4, len(agents))
            self.assertEqual(
                set(["asgard"]),
                set([agent.attributes["owner"] for agent in agents]),
            )
            self.assertEqual("ead07ffb-5a61-42c9-9386-21b680597e6c-S10",
                             agents[0].id)
            self.assertEqual(2, agents[0].total_apps)

            self.assertEqual("ead07ffb-5a61-42c9-9386-21b680597e6c-S11",
                             agents[1].id)
            self.assertEqual(0, agents[1].total_apps)

            self.assertEqual("ead07ffb-5a61-42c9-9386-21b680597e6c-S12",
                             agents[2].id)
            self.assertEqual(1, agents[2].total_apps)

            self.assertEqual("ead07ffb-5a61-42c9-9386-21b680597e6c-S9",
                             agents[3].id)
            self.assertEqual(1, agents[3].total_apps)
예제 #12
0
 async def test_get_agents_remove_unused_fields(self):
     with aioresponses() as rsps:
         build_mesos_cluster(rsps,
                             "ead07ffb-5a61-42c9-9386-21b680597e6c-S9")
         agents = await self.mesos_backend.get_agents(
             self.user, self.account)
         self.assertEqual(1, len(agents))
         self.assertEqual("asgard", agents[0].attributes["owner"])
예제 #13
0
 async def test_mesos_client_get_agents_empty_cluster(self):
     """
     Retorna a lista de agents do cluster mesos
     """
     async with MesosClient(*settings.MESOS_API_URLS) as mesos:
         with aioresponses() as rsps:
             build_mesos_cluster(rsps)
             agents = await mesos.get_agents()
             self.assertEquals(0, len(agents))
예제 #14
0
 async def test_get_apps_running_for_agent_mesos_orchestrator_zero_apps(
         self):
     with aioresponses(passthrough=[TEST_LOCAL_AIOHTTP_ADDRESS]) as rsps:
         agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S44"
         build_mesos_cluster(rsps, agent_id)
         agent = await self.agents_service.get_agent_by_id(
             agent_id, self.user, self.account, self.mesos_orchestrator)
         apps = await self.agents_service.get_apps_running_for_agent(
             self.user, agent, self.mesos_orchestrator)
         self.assertEquals([], apps)
예제 #15
0
 async def test_get_agent_by_id_includes_individual_usage_stats(self):
     agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S10"
     with aioresponses() as rsps:
         build_mesos_cluster(rsps, agent_id)
         agent = await self.mesos_backend.get_agent_by_id(
             agent_id, self.user, self.account)
         self.assertEqual(agent_id, agent.id)
         self.assertEqual({
             "cpu_pct": "16.00",
             "ram_pct": "22.50"
         }, agent.stats)
예제 #16
0
 async def test_get_agent_by_id_returns_None_for_agent_in_another_namespace(
         self):
     slave_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S0"
     with aioresponses() as rsps:
         build_mesos_cluster(rsps, slave_id)
         agent = await self.mesos_backend.get_agent_by_id(
             slave_id,  # Agent from asgard-infra namespace
             self.user,
             self.account,
         )
         self.assertIsNone(agent)
예제 #17
0
 async def test_get_agent_by_id_includes_app_count_and_list(self):
     agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S10"
     with aioresponses() as rsps:
         build_mesos_cluster(rsps, agent_id)
         agent = await self.mesos_backend.get_agent_by_id(
             agent_id, self.user, self.account)
         self.assertEqual(agent_id, agent.id)
         self.assertEqual(2, agent.total_apps)
         expected_app_ids = sorted(
             ["captura/wetl/visitcentral", "infra/asgard/api"])
         self.assertEqual(expected_app_ids,
                          sorted([app.id for app in agent.applications]))
예제 #18
0
 async def test_get_apps_returns_empty_list_if_no_apps_running_on_agent(
         self):
     agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S4"
     slave = get_fixture(f"agents/{agent_id}/info.json")
     slave_id = slave["id"]
     self.account.owner = slave["attributes"]["owner"]
     with aioresponses() as rsps:
         build_mesos_cluster(rsps, agent_id)
         agent = await self.mesos_backend.get_agent_by_id(
             slave_id, self.user, self.account)
         apps = await self.mesos_backend.get_apps_running_for_agent(
             self.user, agent)
         self.assertEqual(0, len(apps))
 async def test_get_app_stats_has_some_data(self):
     with aioresponses() as rsps:
         agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S0"
         build_mesos_cluster(rsps, agent_id)
         add_agent_task_stats(rsps,
                              agent_id,
                              index_name="asgard-app-stats-2019-03-29-*")
         stats = await self.apps_backend.get_app_stats(
             MesosApp(id="infra-asgard-api"), self.user, self.account)
         self.assertEqual(
             AppStats(cpu_pct="4.51", ram_pct="22.68", cpu_thr_pct="2.89"),
             stats,
         )
예제 #20
0
    async def test_tasks_list_from_one_app_tasks_running(self):
        with aioresponses() as rsps:
            build_mesos_cluster(rsps, self.agent_id)
            app_id = "infra/asgard/api"
            tasks = await self.agent.tasks(app_id=app_id)
            self.assertEqual(2, len(tasks))

            expected_task_names = [
                "infra_asgard_api.7e5d20eb-248a-11e9-91ea-024286d5b96a",
                "infra_asgard_api.323a6f04-1d75-11e9-91ea-024286d5b96a",
            ]
            self.assertEqual(expected_task_names,
                             [task.name for task in tasks])
예제 #21
0
    async def test_agents_list_should_populate_errors_for_each_field(self):
        """
        Cada campo que tiver dado problema no momento de ser preenchido estará no
        campo {"errors": {...}} onde a key é o nome do campo e o value é a mensagem de erro.
        """

        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()
        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}")
            with aioresponses(passthrough=[local_address]) as rsps:
                build_mesos_cluster(
                    rsps,
                    {
                        "id": "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",
                        "apps": ClusterOptions.CONNECTION_ERROR,
                    },  # namespace=asgard-infra
                    {"id": "ead07ffb-5a61-42c9-9386-21b680597e6c-S3"
                     },  # namespace=asgard-infra
                    {"id": "ead07ffb-5a61-42c9-9386-21b680597e6c-S10"
                     },  # namespace=asgard
                )

                resp = await client.get(
                    "/agents",
                    headers={"Authorization": f"Token {self.user_auth_key}"},
                )
                self.assertEqual(200, resp.status)
                data = await resp.json()
                self.assertEqual(2, len(data["agents"]))
                self.assertEqual(
                    set(["asgard-infra"]),
                    set([
                        agent["attributes"]["owner"]
                        for agent in data["agents"]
                    ]),
                )
                self.assertEqual(
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",
                    data["agents"][0]["id"],
                )
                self.assertEqual(
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S3",
                    data["agents"][1]["id"],
                )
                self.assertEqual("MESOS", data["agents"][0]["type"])
                self.assertEqual(0, data["agents"][0]["total_apps"])
                self.assertEqual([], data["agents"][0]["applications"])
                self.assertTrue("INDISPONIVEL" in data["agents"][0]["errors"]
                                ["total_apps"])
예제 #22
0
    async def test_agent_app_list_zero_apps_running(self):
        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()

        slave_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S3"
        with aioresponses(passthrough=[TEST_LOCAL_AIOHTTP_ADDRESS]) as rsps:
            build_mesos_cluster(rsps, slave_id)
            resp = await self.client.get(
                f"/agents/{slave_id}/apps",
                headers={"Authorization": f"Token {self.user_auth_key}"},
            )
            self.assertEqual(200, resp.status)
            data = await resp.json()
            self.assertEqual(0, len(data["apps"]))
 async def test_get_agent_by_id_adds_app_count_on_error_dict_if_failed(
         self):
     """
     O campo total_apps deve estar no "errors" caso tenha acontecido alguma falha ao carregá-lo.
     """
     agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S10"
     with aioresponses(passthrough=[TEST_LOCAL_AIOHTTP_ADDRESS]) as rsps:
         build_mesos_cluster(rsps, {
             "id": agent_id,
             "apps": ClusterOptions.CONNECTION_ERROR
         })
         agent = await self.mesos_backend.get_agent_by_id(
             agent_id, self.user, self.account)
         self.assertEqual(agent_id, agent.id)
         self.assertEqual({"total_apps": "INDISPONIVEL"}, agent.errors)
예제 #24
0
 async def test_mesos_client_get_agents(self):
     """
     Retorna a lista de agents do cluster mesos
     """
     agent_ids = [
         "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",
         "ead07ffb-5a61-42c9-9386-21b680597e6c-S10",
         "ead07ffb-5a61-42c9-9386-21b680597e6c-S4",
     ]
     async with MesosClient(*settings.MESOS_API_URLS) as mesos:
         with aioresponses() as rsps:
             build_mesos_cluster(rsps, *agent_ids)
             agents = await mesos.get_agents()
             self.assertEquals(3, len(agents))
             self.assertEqual(agent_ids, [agent.id for agent in agents])
예제 #25
0
    async def test_agents_list_should_return_only_agents_from_specific_account(
            self):

        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}")
            with aioresponses(passthrough=[local_address]) as rsps:
                build_mesos_cluster(
                    rsps,
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S44",
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",  # namespace=asgard-infra
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S10",  # namespace=asgard
                )
                resp = await client.get(
                    "/agents",
                    headers={
                        "Authorization":
                        "Token 69ed620926be4067a36402c3f7e9ddf0"
                    },
                )
                self.assertEqual(200, resp.status)
                data = await resp.json()
                self.assertEqual(1, len(data["agents"]))
                self.assertEqual(
                    set(["dev"]),
                    set([
                        agent["attributes"]["owner"]
                        for agent in data["agents"]
                    ]),
                )
                self.assertEqual(
                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S44",
                    data["agents"][0]["id"],
                )
                self.assertEqual("MESOS", data["agents"][0]["type"])
                self.assertEqual(
                    {
                        "cpu_pct": "38.72",
                        "ram_pct": "25.79"
                    },
                    data["agents"][0]["stats"],
                )
                self.assertEqual({
                    "cpu_pct": "38.72",
                    "ram_pct": "25.79"
                }, data["stats"])
                self.assertEqual(0, data["agents"][0]["total_apps"])
예제 #26
0
 async def test_get_apps_running_for_agent_mesos_orchestrator_zero_apps(
     self
 ):
     async with HttpClientContext(app) as client:
         local_address = (
             f"http://{client._server.host}:{client._server.port}"
         )
         with aioresponses(passthrough=[local_address]) as rsps:
             agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S44"
             build_mesos_cluster(rsps, agent_id)
             agent = await self.agents_service.get_agent_by_id(
                 agent_id, self.user, self.account, self.mesos_orchestrator
             )
             apps = await self.agents_service.get_apps_running_for_agent(
                 self.user, agent, self.mesos_orchestrator
             )
             self.assertEquals([], apps)
예제 #27
0
    async def test_agent_app_list_zero_apps_running(self):
        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()

        slave_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S3"
        async with HttpClientContext(app) as client:
            local_address = (
                f"http://{client._server.host}:{client._server.port}")
            with aioresponses(passthrough=[local_address]) as rsps:
                build_mesos_cluster(rsps, slave_id)
                resp = await client.get(
                    f"/agents/{slave_id}/apps",
                    headers={"Authorization": f"Token {self.user_auth_key}"},
                )
                self.assertEqual(200, resp.status)
                data = await resp.json()
                self.assertEqual(0, len(data["apps"]))
예제 #28
0
    async def test_mesos_client_get_agent_by_id_check_all_fields(self):
        agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S0"
        async with MesosClient(*settings.MESOS_API_URLS) as mesos:
            with aioresponses() as rsps:
                build_mesos_cluster(rsps,
                                    "ead07ffb-5a61-42c9-9386-21b680597e6c-S0")

                agent = await mesos.get_agent_by_id(agent_id=agent_id)
                self.assertTrue(isinstance(agent, MesosAgent))
                self.assertEqual(agent_id, agent.id)
                self.assertEqual(
                    {
                        "mesos": "slave",
                        "workload": "general",
                        "dc": "gcp",
                        "owner": "asgard-infra",
                    },
                    agent.attributes,
                )
                self.assertEqual("172.18.0.51", agent.hostname)
                self.assertEqual(5051, agent.port)
                self.assertEqual(True, agent.active)
                self.assertEqual("1.4.1", agent.version)
                self.assertEqual(
                    {
                        "disk": "0",
                        "mem": "1724.032",
                        "gpus": "0",
                        "cpus": "1.374",
                    },
                    agent.used_resources,
                )
                self.assertEqual(
                    {
                        "disk": "26877",
                        "mem": "2560",
                        "gpus": "0",
                        "cpus": "2.5",
                        "ports": "[30000-31999]",
                    },
                    agent.resources,
                )
예제 #29
0
    async def test_agents_with_atrrs_includes_app_list(self):
        self._prepare_additional_fixture_data()
        await self.pg_data_mocker.create()

        with aioresponses(passthrough=[TEST_LOCAL_AIOHTTP_ADDRESS]) as rsps:
            build_mesos_cluster(
                rsps,
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",  # namespace=asgard-infra
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S3",  # namespace=asgard-infra
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S4",  # namespace=asgard-dev
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S44",  # namespace=dev
            )
            resp = await self.client.get(
                "/agents/with-attrs?workload=general&dc=gcp",
                headers={"Authorization": f"Token {self.user_auth_key}"},
            )
            self.assertEqual(200, resp.status)
            data = await resp.json()
            self.assertEqual(1, len(data["agents"]))
            self.assertEqual(
                "ead07ffb-5a61-42c9-9386-21b680597e6c-S0",
                data["agents"][0]["id"],
            )
            self.assertEqual(5, data["agents"][0]["total_apps"])
            expected_app_ids = sorted(
                [
                    "infra/asgard/api",
                    "infra/rabbitmq",
                    "captura/kirby/feeder",
                    "portal/api",
                    "captura/wetl/visitcentral",
                ]
            )
            self.assertEqual(
                expected_app_ids,
                sorted(
                    [app["id"] for app in data["agents"][0]["applications"]]
                ),
            )
    async def test_get_app_stats_exception_on_search(self):
        """
        Returns AppStats with errors filled if any exception happend during ES query
        """
        with aioresponses() as rsps:
            agent_id = "ead07ffb-5a61-42c9-9386-21b680597e6c-S0"
            build_mesos_cluster(rsps, agent_id)

            index_name = "asgard-app-stats-2019-03-29-*"
            url = f"{settings.STATS_API_URL}/{index_name}/_search"
            rsps.get(url, exception=Exception("Connection error to ES"))

            stats = await self.apps_backend.get_app_stats(
                MesosApp(id="infra-asgard-api"), self.user, self.account)
            self.assertEqual(
                AppStats(
                    cpu_pct="0",
                    ram_pct="0",
                    cpu_thr_pct="0",
                    errors={"global": "Connection error to ES"},
                ),
                stats,
            )