def test_scale_remote_pod(pod_params): num_replicas, scale_to, shards = pod_params pod_id = None args = set_pod_parser().parse_args( ['--replicas', str(num_replicas), '--shards', str(shards)] ) payload = replace_enum_to_str(ArgNamespace.flatten_to_dict(args)) try: workspace_id = jinad_client.workspaces.create( paths=[os.path.join(cur_dir, cur_dir)] ) success, pod_id = jinad_client.pods.create( workspace_id=workspace_id, payload=payload ) assert success remote_pod_args = jinad_client.pods.get(pod_id)['arguments']['object'][ 'arguments' ] assert remote_pod_args['identity'] == pod_id assert remote_pod_args['replicas'] == num_replicas assert remote_pod_args['shards'] == shards jinad_client.pods.scale(id=pod_id, replicas=scale_to) remote_pod_args = jinad_client.pods.get(pod_id)['arguments']['object'][ 'arguments' ] assert remote_pod_args['identity'] == pod_id assert remote_pod_args['replicas'] == scale_to assert remote_pod_args['shards'] == shards finally: if pod_id: assert jinad_client.pods.delete(pod_id), 'Pod termination failed' print(f'Remote Pod {pod_id} successfully terminated')
async def test_scale_remote_pod_async( deployment_params, async_jinad_client, slow_down_tests ): num_replicas, scale_to, shards = deployment_params args = set_deployment_parser().parse_args( ['--replicas', str(num_replicas), '--shards', str(shards)] ) payload = replace_enum_to_str(ArgNamespace.flatten_to_dict(args)) workspace_id = await async_jinad_client.workspaces.create( paths=[os.path.join(cur_dir, cur_dir)] ) success, pod_id = await async_jinad_client.deployments.create( workspace_id=workspace_id, payload=payload ) assert success resp = await async_jinad_client.deployments.get(pod_id) remote_pod_args = resp['arguments']['object']['arguments'] assert remote_pod_args['replicas'] == num_replicas assert remote_pod_args['shards'] == shards await async_jinad_client.deployments.scale(id=pod_id, replicas=scale_to) resp = await async_jinad_client.deployments.get(pod_id) remote_pod_args = resp['arguments']['object']['arguments'] assert remote_pod_args['replicas'] == scale_to assert remote_pod_args['shards'] == shards assert await async_jinad_client.deployments.delete(pod_id)
async def test_jinad_pod_create_async_given_unprocessable_entity( pod_args, async_jinad_client): payload = replace_enum_to_str(ArgNamespace.flatten_to_dict(pod_args)) payload['pod_role'] = 'RANDOM' # patch an invalid pod role type workspace_id = await async_jinad_client.workspaces.create( paths=[os.path.join(cur_dir, cur_dir)]) success, resp = await async_jinad_client.deployments.create( workspace_id=workspace_id, payload=payload) assert not success assert 'validation error in the payload' in resp
async def test_async_jinad_client(async_jinad_client, pod_args): workspace_id = await async_jinad_client.workspaces.create(paths=[cur_dir]) assert DaemonID(workspace_id) success, pod_id = await async_jinad_client.pods.create( workspace_id=workspace_id, payload=replace_enum_to_str(vars(pod_args))) assert success assert pod_id assert is_pod_ready(pod_args) assert await async_jinad_client.pods.delete(pod_id) assert not is_pod_ready(pod_args) assert await async_jinad_client.workspaces.delete(workspace_id)
async def test_rolloing_update_remote_pod(async_jinad_client, pod_args): payload = replace_enum_to_str(ArgNamespace.flatten_to_dict(pod_args)) workspace_id = await async_jinad_client.workspaces.create( paths=[os.path.join(cur_dir, cur_dir)] ) success, pod_id = await async_jinad_client.deployments.create( workspace_id=workspace_id, payload=payload ) assert success await async_jinad_client.deployments.rolling_update( id=pod_id, uses_with={'foo': 'bar-new', 'dump_path': 'test'} ) # TODO: HOW TO CHECK PEA ARGS IN JINAD? ROLLING UPDATE WON'T CHANGE POD ARGS # TODO: PEA_STORE IS EMPTY _ = await async_jinad_client.deployments.get(pod_id) assert async_jinad_client.deployments.delete(pod_id) assert async_jinad_client.workspaces.delete(workspace_id)
async def test_remote_jinad_pod_async(pod_args, async_jinad_client): payload = replace_enum_to_str(ArgNamespace.flatten_to_dict(pod_args)) workspace_id = await async_jinad_client.workspaces.create( paths=[os.path.join(cur_dir, cur_dir)]) assert await async_jinad_client.deployments.alive() # create pod success, pod_id = await async_jinad_client.deployments.create( workspace_id=workspace_id, payload=payload) assert success # get pod status resp = await async_jinad_client.deployments.get(pod_id) remote_pod_args = resp['arguments']['object']['arguments'] # delete pod assert await async_jinad_client.deployments.delete(pod_id) resp = await async_jinad_client.deployments.get(pod_id) assert resp == pod_id + ' not found in store'
async def _create_remote_pod(self): """Create Workspace, Pod on remote JinaD server""" with ImportExtensions(required=True): # rich & aiohttp are used in `AsyncJinaDClient` import rich import aiohttp from daemon.clients import AsyncJinaDClient assert rich assert aiohttp # NOTE: args.timeout_ready is always set to -1 for JinadRuntime so that wait_for_success doesn't fail in Pod, # so it can't be used for Client timeout. self.client = AsyncJinaDClient(host=self.args.host, port=self.args.port_jinad, logger=self._logger) if not await self.client.alive: raise DaemonConnectivityError # Create a remote workspace with upload_files workspace_id = await self.client.workspaces.create( paths=self.filepaths, id=self.args.workspace_id, complete=True, ) if not workspace_id: self._logger.critical(f'remote workspace creation failed') raise DaemonWorkspaceCreationFailed payload = replace_enum_to_str(vars(self._mask_args())) # Create a remote Pod in the above workspace success, response = await self.client.pods.create( workspace_id=workspace_id, payload=payload, envs=self.envs) if not success: self._logger.critical(f'remote pod creation failed') raise DaemonPodCreationFailed(response) else: self.pod_id = response