async def test_to_client_model_disabled_field(self, chronos_job_fixture):
        asgard_job = ChronosScheduledJobConverter.to_asgard_model(
            ChronosJob(**chronos_job_fixture))
        self.assertFalse(
            ChronosScheduledJobConverter.to_client_model(asgard_job).disabled)

        asgard_job.enabled = False
        self.assertTrue(
            ChronosScheduledJobConverter.to_client_model(asgard_job).disabled)
    async def test_to_client_model_required_fields(self, chronos_job_fixture):
        asgard_job_dict = ChronosScheduledJobConverter.to_asgard_model(
            ChronosJob(**chronos_job_fixture)).dict()

        del asgard_job_dict["env"]
        del asgard_job_dict["fetch"]
        del asgard_job_dict["constraints"]
        chronos_job = ChronosScheduledJobConverter.to_client_model(
            ScheduledJob(**asgard_job_dict))

        chronos_converted = ChronosScheduledJobConverter.to_client_model(
            ChronosScheduledJobConverter.to_asgard_model(chronos_job))

        self.assertEqual(chronos_converted.dict(), chronos_job.dict())
    async def test_to_client_model_retries_field(self, chronos_job_fixture):
        chronos_job = ChronosJob(**chronos_job_fixture)
        asgard_job = ChronosScheduledJobConverter.to_asgard_model(chronos_job)
        self.assertEqual(chronos_job_fixture["retries"], asgard_job.retries)

        asgard_job.retries = 4
        chronos_job_converted = ChronosScheduledJobConverter.to_client_model(
            asgard_job)
        self.assertEqual(asgard_job.retries, chronos_job_converted.retries)
    async def test_to_asgard_model_required_fields(self, chronos_job_fixture):
        del chronos_job_fixture["environmentVariables"]
        del chronos_job_fixture["constraints"]
        del chronos_job_fixture["fetch"]

        asgard_job = ChronosScheduledJobConverter.to_asgard_model(
            ChronosJob(**chronos_job_fixture))

        asgard_job_converted = ChronosScheduledJobConverter.to_asgard_model(
            ChronosScheduledJobConverter.to_client_model(asgard_job))
        self.assertEqual(asgard_job_converted.dict(), asgard_job.dict())
    async def test_convert_to_client_full_model(self, chronos_job_fixture):
        """
        Confirma que os campos que são, na verdade, sub-modelos também são
        incluídos na conversão.
        """
        chronos_job_original = ChronosJob(**chronos_job_fixture)
        asgard_job = ChronosScheduledJobConverter.to_asgard_model(
            chronos_job_original)

        chronos_job_converted = ChronosScheduledJobConverter.to_client_model(
            asgard_job)
        self.assertEqual(chronos_job_original.dict(),
                         chronos_job_converted.dict())
Beispiel #6
0
 async def delete_job(self, job: ScheduledJob, user: User,
                      account: Account) -> ScheduledJob:
     stored_job = await self.get_job_by_id(job.id, user, account)
     try:
         if stored_job:
             stored_job.id = f"{account.namespace}-{stored_job.id}"
             await self.client.delete_job(
                 ChronosScheduledJobConverter.to_client_model(stored_job))
             return job
         raise NotFoundEntity(f"Job not found: {job.id}")
     except HTTPBadRequest:
         # Chronos retorna HTTP 400 se o job sendo removido não existe
         pass
     return job
Beispiel #7
0
    async def _save_job(self, job: ScheduledJob, user: User,
                        account: Account) -> ScheduledJob:
        job.add_constraint(f"owner:LIKE:{account.owner}")
        [
            job.add_fetch_uri(fetch)
            for fetch in settings.SCHEDULED_JOBS_DEFAULT_FETCH_URIS
        ]

        namespaced_job_id = f"{account.namespace}-{job.id}"
        chronos_job = ChronosScheduledJobConverter.to_client_model(job)
        chronos_job.name = namespaced_job_id
        cretaed_chronos_job = await self.client.create_job(chronos_job)
        asgard_job = ChronosScheduledJobConverter.to_asgard_model(
            cretaed_chronos_job)
        asgard_job.remove_namespace(account)
        return asgard_job
    async def test_to_client_model_env_field(self):

        asgard_dict_with_env_data = {
            "id": "my-app",
            "cpus": 1,
            "mem": 32,
            "description": "Example",
            "schedule": {
                "value": "2019"
            },
            "container": {
                "image": "alpine",
                "network": "BRIDGE"
            },
            "env": {
                "SERVICE_A_ADDRESS": "https://a.service.local",
                "SERVICE_B_ADDRESS": "https://b.service.local",
            },
        }
        asgard_scheduled_job = ScheduledJob(**asgard_dict_with_env_data)
        chronos_job = ChronosScheduledJobConverter.to_client_model(
            asgard_scheduled_job)
        self.assertEqual(
            [
                {
                    "name": "SERVICE_A_ADDRESS",
                    "value": "https://a.service.local",
                },
                {
                    "name": "SERVICE_B_ADDRESS",
                    "value": "https://b.service.local",
                },
            ],
            [
                chronos_job.environmentVariables[0].dict(),
                chronos_job.environmentVariables[1].dict(),
            ],
        )