Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move CLI component cache build to occur before pre-processing #2913

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
@pytest.fixture
def component_cache(jp_environ):
"""
Initialize a component cache
Initialize a component cache that emulates a running server process
"""
# Create new instance and load the cache
component_cache = ComponentCache.instance(emulate_server_app=True)
Expand All @@ -61,7 +61,6 @@ def component_cache(jp_environ):
def catalog_instance(component_cache, request):
"""Creates an instance of a component catalog and removes after test."""
instance_metadata = request.param

instance_name = "component_cache"
md_mgr = MetadataManager(schemaspace=ComponentCatalogs.COMPONENT_CATALOGS_SCHEMASPACE_ID)
catalog = md_mgr.create(instance_name, Metadata(**instance_metadata))
Expand All @@ -70,6 +69,22 @@ def catalog_instance(component_cache, request):
md_mgr.remove(instance_name)


@pytest.fixture
def catalog_instance_no_server_process(request):
"""
Creates an instance of a component catalog that does not emulate a server process,
then removes instance after test. This is used for testing CLI functionality where
a server process would not be present.
"""
instance_metadata = request.param
instance_name = "component_cache"
md_mgr = MetadataManager(schemaspace=ComponentCatalogs.COMPONENT_CATALOGS_SCHEMASPACE_ID)
md_mgr.create(instance_name, Metadata(**instance_metadata))
ComponentCache.clear_instance() # Clear cache instance created during instance creation
yield
md_mgr.remove(instance_name)


@pytest.fixture
def metadata_manager_with_teardown(jp_environ):
"""
Expand Down
22 changes: 7 additions & 15 deletions elyra/cli/pipeline_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,10 @@ def validate(pipeline_path, runtime_config="local"):
print_banner("Elyra Pipeline Validation")

runtime = _get_runtime_schema_name(runtime_config)

pipeline_definition = _preprocess_pipeline(pipeline_path, runtime=runtime, runtime_config=runtime_config)

pipeline_runtime_type = _get_pipeline_runtime_type(pipeline_definition)
if pipeline_runtime_type:
if runtime != "local":
_build_component_cache()

pipeline_definition = _preprocess_pipeline(pipeline_path, runtime=runtime, runtime_config=runtime_config)
try:
_validate_pipeline_definition(pipeline_definition)
except Exception:
Expand Down Expand Up @@ -364,17 +361,13 @@ def submit(json_option, pipeline_path, runtime_config_name, monitor_option, time
print_banner("Elyra Pipeline Submission")

runtime_config = _get_runtime_config(runtime_config_name)

runtime_schema = runtime_config.schema_name
if runtime_schema != "local":
_build_component_cache()

pipeline_definition = _preprocess_pipeline(
pipeline_path, runtime=runtime_schema, runtime_config=runtime_config_name
)

pipeline_runtime_type = _get_pipeline_runtime_type(pipeline_definition)
if pipeline_runtime_type:
_build_component_cache()

try:
_validate_pipeline_definition(pipeline_definition)
except Exception:
Expand Down Expand Up @@ -697,8 +690,10 @@ def export(pipeline_path, runtime_config, output, overwrite):
print_banner("Elyra pipeline export")

rtc = _get_runtime_config(runtime_config)
runtime_schema = rtc.schema_name
runtime_type = rtc.metadata.get("runtime_type")
runtime_schema = rtc.schema_name
if runtime_schema != "local":
_build_component_cache()

pipeline_definition = _preprocess_pipeline(pipeline_path, runtime=runtime_schema, runtime_config=runtime_config)

Expand Down Expand Up @@ -752,9 +747,6 @@ def export(pipeline_path, runtime_config, output, overwrite):
f"Output file '{str(output_file)}' exists and " "option '--overwrite' was not specified."
)

if pipeline_runtime_type:
_build_component_cache()

# validate the pipeline
try:
_validate_pipeline_definition(pipeline_definition)
Expand Down
18 changes: 12 additions & 6 deletions elyra/tests/cli/test_pipeline_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,10 @@ def test_describe_custom_component_dependencies_json():
# ------------------------------------------------------------------


@pytest.mark.parametrize("catalog_instance", [KFP_COMPONENT_CACHE_INSTANCE], indirect=True)
def test_validate_with_kfp_components(jp_environ, kubeflow_pipelines_runtime_instance, catalog_instance):
@pytest.mark.parametrize("catalog_instance_no_server_process", [KFP_COMPONENT_CACHE_INSTANCE], indirect=True)
def test_validate_with_kfp_components(
jp_environ, kubeflow_pipelines_runtime_instance, catalog_instance_no_server_process
):
runner = CliRunner()
pipeline_file_path = Path(__file__).parent / "resources" / "pipelines" / "kfp_3_node_custom.pipeline"
result = runner.invoke(
Expand Down Expand Up @@ -1066,8 +1068,10 @@ def test_export_incompatible_runtime_config(kubeflow_pipelines_runtime_instance,
)


@pytest.mark.parametrize("catalog_instance", [KFP_COMPONENT_CACHE_INSTANCE], indirect=True)
def test_export_kubeflow_output_option(jp_environ, kubeflow_pipelines_runtime_instance, catalog_instance):
@pytest.mark.parametrize("catalog_instance_no_server_process", [KFP_COMPONENT_CACHE_INSTANCE], indirect=True)
def test_export_kubeflow_output_option(
jp_environ, kubeflow_pipelines_runtime_instance, catalog_instance_no_server_process
):
"""Verify that the '--output' option works as expected for Kubeflow Pipelines"""
runner = CliRunner()
with runner.isolated_filesystem():
Expand Down Expand Up @@ -1217,8 +1221,10 @@ def test_export_airflow_output_option(airflow_runtime_instance):
), result.output


@pytest.mark.parametrize("catalog_instance", [KFP_COMPONENT_CACHE_INSTANCE], indirect=True)
def test_export_kubeflow_overwrite_option(jp_environ, kubeflow_pipelines_runtime_instance, catalog_instance):
@pytest.mark.parametrize("catalog_instance_no_server_process", [KFP_COMPONENT_CACHE_INSTANCE], indirect=True)
def test_export_kubeflow_overwrite_option(
jp_environ, kubeflow_pipelines_runtime_instance, catalog_instance_no_server_process
):
"""Verify that the '--overwrite' option works as expected for Kubeflow Pipelines"""
runner = CliRunner()
with runner.isolated_filesystem():
Expand Down