示例#1
0
class TestSpawner(BaseTestCase):
    def setUp(self):

        self.spawner = Spawner()
        super().setUp()

    def test_start_apply_stop_get(self):
        k8s_manager = mock.MagicMock()
        k8s_manager.create_custom_object.return_value = ("", "")
        self.spawner._k8s_manager = k8s_manager

        self.spawner.create(run_uuid="", run_kind=V1RunKind.JOB, resource={})
        assert k8s_manager.create_custom_object.call_count == 1

        self.spawner.apply(run_uuid="", run_kind=V1RunKind.JOB, resource={})
        assert k8s_manager.update_custom_object.call_count == 1

        self.spawner.stop(run_uuid="", run_kind=V1RunKind.JOB)
        assert k8s_manager.delete_custom_object.call_count == 1

        self.spawner.get(run_uuid="", run_kind=V1RunKind.JOB)
        assert k8s_manager.get_custom_object.call_count == 1

    def test_start_apply_stop_get_raises_for_non_recognized_kinds(self):

        with self.assertRaises(PolyaxonAgentError):
            self.spawner.create(run_uuid="", run_kind="foo", resource={})

        with self.assertRaises(PolyaxonAgentError):
            self.spawner.apply(run_uuid="", run_kind="foo", resource={})

        with self.assertRaises(PolyaxonAgentError):
            self.spawner.stop(run_uuid="", run_kind="foo")

        with self.assertRaises(PolyaxonAgentError):
            self.spawner.get(run_uuid="", run_kind="foo")
示例#2
0
def wait(uuid: str, kind: str, max_retries: int):
    """Delete an s3 subpath."""
    from polyaxon import settings
    from polyaxon.agents.spawners.spawner import Spawner

    spawner = Spawner(namespace=settings.CLIENT_CONFIG.namespace, in_cluster=True)
    retry = 1
    while retry < max_retries:
        try:
            k8s_operation = spawner.get(run_uuid=uuid, run_kind=kind)
        except:  # noqa
            k8s_operation = None
        if k8s_operation:
            retry += 1
            time.sleep(retry)
        else:
            return

    sys.exit(1)