def test_resources_no_default(self): cfg = PluginConfig( {"run_config": {"resources": {"node2": {"cpu": "100m"}}}} ) assert cfg.run_config.resources.is_set_for("node2") assert cfg.run_config.resources.get_for("node2") == {"cpu": "100m"} assert cfg.run_config.resources.is_set_for("node3") is False
def create_generator(self, config={}, params={}, catalog={}): project_name = "my-awesome-project" config_loader = MagicMock() config_loader.get.return_value = catalog context = type( "obj", (object, ), { "params": params, "config_loader": config_loader, "pipelines": { "pipeline": Pipeline([ node(identity, "A", "B", name="node1"), node(identity, "B", "C", name="node2"), ]) }, }, ) self.generator_under_test = PipelineGenerator( PluginConfig({ "host": "http://unittest", "run_config": config }), project_name, context, )
def test_defaults(self): cfg = PluginConfig({"run_config": {}}) assert cfg.run_config.image_pull_policy == "IfNotPresent" assert cfg.run_config.description is None SECONDS_IN_ONE_WEEK = 3600 * 24 * 7 assert cfg.run_config.ttl == SECONDS_IN_ONE_WEEK assert cfg.run_config.volume is None
def test_plugin_config(self): cfg = PluginConfig(yaml.safe_load(CONFIG_YAML)) assert cfg.host == "https://example.com" assert cfg.run_config.image == "gcr.io/project-image/test" assert cfg.run_config.image_pull_policy == "Always" assert cfg.run_config.experiment_name == "Test Experiment" assert cfg.run_config.run_name == "test run" assert cfg.run_config.wait_for_completion assert cfg.run_config.volume.storageclass == "default" assert cfg.run_config.volume.size == "3Gi" assert cfg.run_config.volume.access_modes == "[ReadWriteOnce]"
def test_plugin_config(self): cfg = PluginConfig(yaml.safe_load(CONFIG_YAML)) assert cfg.host == "https://example.com" assert cfg.run_config.image == "gcr.io/project-image/test" assert cfg.run_config.image_pull_policy == "Always" assert cfg.run_config.experiment_name == "Test Experiment" assert cfg.run_config.run_name == "test run" assert cfg.run_config.wait_for_completion assert cfg.run_config.volume.storageclass == "default" assert cfg.run_config.volume.size == "3Gi" assert cfg.run_config.volume.keep is True assert cfg.run_config.volume.access_modes == ["ReadWriteOnce"] assert cfg.run_config.resources.is_set_for("node1") is False assert cfg.run_config.description == "My awesome pipeline" assert cfg.run_config.ttl == 300
def create_client(self, config, kfp_client_mock, pipeline_generator_mock): project_name = "my-awesome-project" self.client_under_test = KubeflowClient( PluginConfig({ "host": "http://unittest", "run_config": config }), project_name, None, # context, ) self.client_under_test.client = kfp_client_mock self.kfp_client_mock = self.client_under_test.client @dsl.pipeline(name=project_name) def empty_pipeline(): pass self.client_under_test.generator.generate_pipeline.return_value = ( empty_pipeline)
def test_resources_default_and_node_specific(self): cfg = PluginConfig( { "run_config": { "resources": { "__default__": {"cpu": "200m", "memory": "64Mi"}, "node2": {"cpu": "100m"}, } } } ) assert cfg.run_config.resources.is_set_for("node2") assert cfg.run_config.resources.get_for("node2") == { "cpu": "100m", "memory": "64Mi", } assert cfg.run_config.resources.is_set_for("node3") assert cfg.run_config.resources.get_for("node3") == { "cpu": "200m", "memory": "64Mi", }
def test_should_use_jwt_token_in_kfp_client(self, kfp_client_mock, pipeline_generator_mock, auth_handler_mock): # given os.environ["IAP_CLIENT_ID"] = "unittest-client-id" auth_handler_mock.return_value.obtain_id_token.return_value = ( "unittest-token") # when self.client_under_test = KubeflowClient( PluginConfig({ "host": "http://unittest", "run_config": {} }), None, None, ) # then kfp_client_mock.assert_called_with("http://unittest", existing_token="unittest-token")
def test_missing_required_config(self): cfg = PluginConfig({}) with self.assertRaises(MissingConfigException): print(cfg.host)
def test_defaults(self): cfg = PluginConfig({"run_config": {}}) assert cfg.run_config.image_pull_policy == "IfNotPresent"
def test_do_not_keep_volume_by_default(self): cfg = PluginConfig({"run_config": {"volume": {}}}) assert cfg.run_config.volume.keep is False
schedule, ui, upload_pipeline, ) from kedro_kubeflow.config import PluginConfig from kedro_kubeflow.context_helper import ContextHelper test_config = PluginConfig( { "host": "https://example.com", "run_config": { "image": "gcr.io/project-image/test", "image_pull_policy": "Always", "experiment_name": "Test Experiment", "run_name": "test run", "wait_for_completion": True, "volume": { "storageclass": "default", "size": "3Gi", "access_modes": "[ReadWriteOnce]", }, }, } ) class TestPluginCLI(unittest.TestCase): def test_list_pipelines(self): context_helper = MagicMock(ContextHelper) config = dict(context_helper=context_helper) runner = CliRunner()