diff --git a/conftest.py b/conftest.py index bd97b75bd..c43bcea9c 100644 --- a/conftest.py +++ b/conftest.py @@ -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) @@ -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)) @@ -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): """ diff --git a/elyra/cli/pipeline_app.py b/elyra/cli/pipeline_app.py index 7e4f6e11b..8d406aa6b 100644 --- a/elyra/cli/pipeline_app.py +++ b/elyra/cli/pipeline_app.py @@ -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: @@ -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: @@ -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) @@ -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) diff --git a/elyra/tests/cli/test_pipeline_app.py b/elyra/tests/cli/test_pipeline_app.py index f53594fd6..68c81a74a 100644 --- a/elyra/tests/cli/test_pipeline_app.py +++ b/elyra/tests/cli/test_pipeline_app.py @@ -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( @@ -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(): @@ -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():