def test_handle_parsing_task_volumes_and_mounts(self): component_text = '''\ implementation: graph: tasks: task 1: componentRef: {name: Comp 1} executionOptions: kubernetesOptions: mainContainer: volumeMounts: - name: workdir mountPath: /mnt/vol podSpec: volumes: - name: workdir emptyDir: {} ''' struct = load_yaml(component_text) component_spec = ComponentSpec.from_dict(struct) self.assertEqual( component_spec.implementation.graph.tasks['task 1']. execution_options.kubernetes_options.pod_spec.volumes[0].name, 'workdir') self.assertIsNotNone( component_spec.implementation.graph.tasks['task 1']. execution_options.kubernetes_options.pod_spec.volumes[0].empty_dir)
def test_handle_parsing_graph_component(self): component_text = '''\ inputs: - {name: graph in 1} - {name: graph in 2} outputs: - {name: graph out 1} - {name: graph out 2} implementation: graph: tasks: task 1: componentRef: {name: Comp 1} arguments: in1 1: 11 task 2: componentRef: {name: Comp 2} arguments: in2 1: 21 in2 2: {taskOutput: {taskId: task 1, outputName: out1 1}} task 3: componentRef: {name: Comp 3} arguments: in3 1: {taskOutput: {taskId: task 2, outputName: out2 1}} in3 2: {graphInput: {inputName: graph in 1}} outputValues: graph out 1: {taskOutput: {taskId: task 3, outputName: out3 1}} graph out 2: {taskOutput: {taskId: task 1, outputName: out1 2}} ''' struct = load_yaml(component_text) ComponentSpec.from_dict(struct)
def test_handle_parsing_predicates(self): component_text = '''\ implementation: graph: tasks: task 1: componentRef: {name: Comp 1} task 2: componentRef: {name: Comp 2} arguments: in2 1: 21 in2 2: {taskOutput: {taskId: task 1, outputName: out1 1}} isEnabled: not: and: op1: '>': op1: {taskOutput: {taskId: task 1, outputName: out1 1}} op2: 0 op2: '==': op1: {taskOutput: {taskId: task 1, outputName: out1 2}} op2: 'head' ''' struct = load_yaml(component_text) ComponentSpec.from_dict(struct)
def test_loading_minimal_component(self): component_text = '''\ implementation: container: image: busybox ''' component_dict = load_yaml(component_text) task_factory1 = comp.load_component(text=component_text) self.assertEqual( task_factory1.component_spec.implementation.container.image, component_dict['implementation']['container']['image'])
def test_handle_parsing_task_execution_options_caching_strategy(self): component_text = '''\ implementation: graph: tasks: task 1: componentRef: {name: Comp 1} executionOptions: cachingStrategy: maxCacheStaleness: P30D ''' struct = load_yaml(component_text) component_spec = ComponentSpec.from_dict(struct) self.assertEqual( component_spec.implementation.graph.tasks['task 1']. execution_options.caching_strategy.max_cache_staleness, 'P30D')
def test_accessing_component_spec_from_task_factory(self): component_text = '''\ implementation: container: image: busybox ''' task_factory1 = comp.load_component_from_text(component_text) actual_component_spec = task_factory1.component_spec actual_component_spec_dict = actual_component_spec.to_dict() expected_component_spec_dict = load_yaml(component_text) expected_component_spec = ComponentSpec.from_dict( expected_component_spec_dict) self.assertEqual(expected_component_spec_dict, actual_component_spec_dict) self.assertEqual(expected_component_spec, task_factory1.component_spec)
def test_fail_on_cyclic_references(self): component_text = '''\ implementation: graph: tasks: task 1: componentRef: {name: Comp 1} arguments: in1 1: {taskOutput: {taskId: task 2, outputName: out2 1}} task 2: componentRef: {name: Comp 2} arguments: in2 1: {taskOutput: {taskId: task 1, outputName: out1 1}} ''' struct = load_yaml(component_text) with self.assertRaises(TypeError): ComponentSpec.from_dict(struct)
def test_handle_parsing_task_container_spec_options(self): component_text = '''\ implementation: graph: tasks: task 1: componentRef: {name: Comp 1} executionOptions: kubernetesOptions: mainContainer: resources: requests: memory: 1024Mi cpu: 200m ''' struct = load_yaml(component_text) component_spec = ComponentSpec.from_dict(struct) self.assertEqual( component_spec.implementation.graph.tasks['task 1']. execution_options.kubernetes_options.main_container.resources. requests['memory'], '1024Mi')
def test_load_component_from_url(self): url = 'https://raw.githubusercontent.com/kubeflow/pipelines/e54fe675432cfef1d115a7a2909f08ed95ea8933/sdk/python/tests/components/test_data/python_add.component.yaml' import requests resp = requests.get(url) component_text = resp.content component_dict = load_yaml(component_text) task_factory1 = comp.load_component_from_url(url) self.assertEqual( task_factory1.__doc__, component_dict['name'] + '\n' + component_dict['description']) arg1 = 3 arg2 = 5 task1 = task_factory1(arg1, arg2) self.assertEqual( task1.component_ref.spec.implementation.container.image, component_dict['implementation']['container']['image']) resolved_cmd = _resolve_command_line_and_paths( task1.component_ref.spec, task1.arguments) self.assertEqual(resolved_cmd.args[0], str(arg1)) self.assertEqual(resolved_cmd.args[1], str(arg2))