def get_pods_for_frontend(self, include_private_info=True): flapp_details = self.get_flapp_details() flapp = FlApp.from_json(flapp_details.get('flapp', None)) pods_json = None if 'pods' in flapp_details: pods_json = flapp_details['pods'].get('items', None) pods = [] if pods_json is not None: pods = [Pod.from_json(p) for p in pods_json] # deduplication pods both in pods and flapp result = {} for pod in flapp.pods: result[pod.name] = pod for pod in pods: result[pod.name] = pod return [pod.to_dict(include_private_info) for pod in result.values()]
def test_from_json(self): json = { 'metadata': { 'name': 'test-pod', 'labels': { 'app-name': 'u244777dac51949c5b2b-data-join-job', 'fl-replica-type': 'master' }, }, 'status': { 'pod_ip': '172.10.0.20', 'phase': 'Running', 'conditions': [{ 'type': 'Failed', 'reason': 'Test reason' }], 'containerStatuses': [{ 'containerID': 'docker://034eaf58d4e24581232832661636da9949b6e2fb056398939fc2c0f2809d4c64', 'image': 'artifact.bytedance.com/fedlearner/fedlearner:438d603', 'state': { 'running': { 'message': 'Test message' } } }] } } expected_pod = Pod(name='test-pod', state=PodState.RUNNING, pod_type=PodType.MASTER, pod_ip='172.10.0.20', container_states=[ ContainerState(state='running', message='Test message') ], pod_conditions=[ PodCondition(cond_type='Failed', reason='Test reason') ]) self.assertEqual(Pod.from_json(json), expected_pod)