123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549 |
- #
- # Copyright 2018-2022 Elyra Authors
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- #
- import sys
- import pytest
- from elyra.pipeline.pipeline import GenericOperation
- from elyra.pipeline.pipeline import Operation
- from elyra.pipeline.pipeline import Pipeline
- @pytest.fixture
- def good_operation():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- return test_operation
- @pytest.fixture
- def good_pipeline():
- test_pipeline = Pipeline(
- id="Random-UUID-123123123123123", name="test-pipeline", runtime="kfp", runtime_config="default_kfp"
- )
- return test_pipeline
- def test_create_operation_minimal(good_operation):
- test_operation = good_operation
- assert test_operation.id == "test-id"
- assert test_operation.type == "execution-node"
- assert test_operation.classifier == "execute-notebook-node"
- assert test_operation.name == "test"
- assert test_operation.filename == "elyra/pipeline/tests/resources/archive/test.ipynb"
- assert test_operation.runtime_image == "tensorflow/tensorflow:latest"
- assert test_operation.name == "test"
- def test_create_operation_with_dependencies():
- dependencies = ["elyra/pipline/tests/resources", "elyra/pipline/tests/resources/archive"]
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "dependencies": dependencies,
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert test_operation.dependencies == dependencies
- def test_create_operation_include_subdirectories():
- include_subdirectories = True
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "include_subdirectories": include_subdirectories,
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert test_operation.include_subdirectories == include_subdirectories
- def test_create_operation_with_environmental_variables():
- env_variables = ['FOO="Bar"', 'BAR="Foo']
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "env_vars": env_variables,
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert test_operation.env_vars == env_variables
- def test_create_operation_with_inputs():
- inputs = ["input1.txt", "input2.txt"]
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "inputs": inputs,
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert test_operation.inputs == inputs
- def test_create_operation_with_outputs():
- outputs = ["output1.txt", "output2.txt"]
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "outputs": outputs,
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert test_operation.outputs == outputs
- def test_create_operation_with_parent_operations():
- parent_operation_ids = ["id-123123-123123-123123", "id-456456-456456-456456"]
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- parent_operation_ids=parent_operation_ids,
- component_params=component_parameters,
- )
- assert test_operation.parent_operation_ids == parent_operation_ids
- def test_create_operation_correct_naming():
- label = "test.ipynb"
- filename = "elyra/pipeline/tests/resources/archive/" + label
- component_parameters = {"filename": filename, "runtime_image": "tensorflow/tensorflow:latest"}
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name=label,
- component_params=component_parameters,
- )
- assert test_operation.name == label.split(".")[0]
- def test_fail_create_operation_missing_id():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- with pytest.raises(TypeError):
- Operation(
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- def test_fail_create_operation_missing_type():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- with pytest.raises(TypeError):
- GenericOperation(
- id="test-id", classifier="execute-notebook-node", name="test", component_params=component_parameters
- )
- def test_fail_create_operation_missing_classifier():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- with pytest.raises(TypeError):
- Operation(id="test-id", type="execution-node", name="test", component_params=component_parameters)
- def test_fail_create_operation_missing_runtime_image():
- component_parameters = {"filename": "elyra/pipeline/tests/resources/archive/test.ipynb"}
- with pytest.raises(ValueError):
- GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- def test_fail_create_operation_missing_name():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- with pytest.raises(TypeError):
- GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- component_params=component_parameters,
- )
- def test_fail_operations_are_equal(good_operation):
- parent_operation_ids = ["id-123123-123123-123123", "id-456456-456456-456456"]
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- compare_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- parent_operation_ids=parent_operation_ids,
- component_params=component_parameters,
- )
- with pytest.raises(AssertionError):
- assert compare_operation == good_operation
- def test_operations_are_equal(good_operation):
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- compare_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert compare_operation == good_operation
- def test_create_pipeline_minimal(good_pipeline):
- test_pipeline = good_pipeline
- assert test_pipeline.id == "Random-UUID-123123123123123"
- assert test_pipeline.name == "test-pipeline"
- assert test_pipeline.runtime == "kfp"
- assert test_pipeline.runtime_config == "default_kfp"
- def test_fail_create_pipeline_missing_id():
- with pytest.raises(TypeError):
- Pipeline(name="test-pipeline", runtime="kfp", runtime_config="default_kfp")
- def test_fail_create_pipeline_missing_name():
- with pytest.raises(TypeError):
- Pipeline(id="Random-UUID-123123123123123", runtime="kfp", runtime_config="default_kfp")
- def test_fail_create_pipeline_missing_runtime():
- with pytest.raises(TypeError):
- Pipeline(id="Random-UUID-123123123123123", name="test-pipeline", runtime_config="default_kfp")
- def test_fail_create_pipeline_missing_runtime_config():
- with pytest.raises(TypeError):
- Pipeline(id="Random-UUID-123123123123123", name="test-pipeline", runtime="kfp")
- def test_pipelines_are_equal(good_pipeline):
- compare_pipeline = Pipeline(
- id="Random-UUID-123123123123123", name="test-pipeline", runtime="kfp", runtime_config="default_kfp"
- )
- assert compare_pipeline == good_pipeline
- def test_fail_pipelines_are_equal(good_pipeline):
- test_operations_dict = {"123123123": good_operation, "234234234": good_operation}
- compare_pipeline = Pipeline(
- id="Random-UUID-123123123123123", name="test-pipeline", runtime="kfp", runtime_config="default_kfp"
- )
- for key, operation in test_operations_dict.items():
- compare_pipeline.operations[key] = operation
- with pytest.raises(AssertionError):
- assert compare_pipeline == good_pipeline
- def test_env_list_to_dict_function():
- env_variables = [
- "KEY=value",
- None,
- "",
- " =empty_key",
- "=no_key",
- "EMPTY_VALUE= ",
- "NO_VALUE=",
- "KEY2=value2",
- "TWO_EQUALS=KEY=value",
- "==",
- ]
- env_variables_dict = {"KEY": "value", "KEY2": "value2", "TWO_EQUALS": "KEY=value"}
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "env_vars": env_variables,
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert test_operation.env_vars.to_dict() == env_variables_dict
- def test_validate_resource_values():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "cpu": "4",
- "gpu": "6",
- "memory": "10",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert test_operation.cpu == "4"
- assert test_operation.gpu == "6"
- assert test_operation.memory == "10"
- def test_validate_resource_values_as_none():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert test_operation.cpu is None
- assert test_operation.gpu is None
- assert test_operation.memory is None
- def test_validate_gpu_accepts_zero_as_value():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "cpu": "4",
- "gpu": "0",
- "memory": "10",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert test_operation.gpu == "0"
- def test_validate_max_resource_value():
- system_max_size = str(sys.maxsize - 1)
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "memory": system_max_size,
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- test_operation = GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- assert test_operation.memory == system_max_size
- def test_fail_validate_max_resource_value_exceeded():
- system_max_size = str(sys.maxsize)
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "memory": system_max_size,
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- with pytest.raises(ValueError):
- GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- def test_fail_creating_operation_with_negative_gpu_resources():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "gpu": "-1",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- with pytest.raises(ValueError):
- GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- def test_fail_creating_operation_with_0_cpu_resources():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "cpu": "0",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- with pytest.raises(ValueError):
- GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- def test_fail_creating_operation_with_negative_cpu_resources():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "cpu": "-1",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- with pytest.raises(ValueError):
- GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- def test_fail_creating_operation_with_0_memory_resources():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "memory": "0",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- with pytest.raises(ValueError):
- GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- def test_fail_creating_operation_with_negative_memory_resources():
- component_parameters = {
- "filename": "elyra/pipeline/tests/resources/archive/test.ipynb",
- "memory": "-1",
- "runtime_image": "tensorflow/tensorflow:latest",
- }
- with pytest.raises(ValueError):
- GenericOperation(
- id="test-id",
- type="execution-node",
- classifier="execute-notebook-node",
- name="test",
- component_params=component_parameters,
- )
- def test_scrub_list_function():
- env_variables_input = ["FOO=Bar", "BAR=Foo", None, ""]
- env_variables_output = ["FOO=Bar", "BAR=Foo"]
- assert Operation._scrub_list(env_variables_input) == env_variables_output
|