def test_build_and_run_instance(ebnt: Ebonite, regression_and_data, container_name, mock_env): reg, data = regression_and_data mock_env = ebnt.meta_repo.create_environment(mock_env) check_ebonite_port_free() model = ebnt.create_model(reg, data, 'test_model') p = mock_env.params with p.builder.build_image.called_within_context( ), p.runner.run.called_within_context(): instance = ebnt.build_and_run_instance(model, container_name, environment=mock_env) assert ebnt.get_environment( instance.environment.name) == instance.environment assert ebnt.get_image(instance.image.name, instance.image.task) == instance.image assert ebnt.get_instance(instance.name, instance.image, instance.environment) == instance with pytest.raises(ImageWithInstancesError): ebnt.delete_image(instance.image) with pytest.raises(EnvironmentWithInstancesError): ebnt.delete_environment(instance.environment) with p.runner.stop.called_within_context( ), p.runner.remove_instance.called_within_context(): ebnt.delete_instance(instance)
def test_build_and_run_instance(ebnt: Ebonite, regression_and_data, container_name): reg, data = regression_and_data check_ebonite_port_free() model = ebnt.create_model('test model', reg, data) instance = ebnt.build_and_run_instance(container_name, model) time.sleep(.1) assert ebnt.get_environment( instance.environment.name) == instance.environment assert ebnt.get_image(instance.image.name, instance.image.model) == instance.image assert ebnt.get_instance(instance.name, instance.image, instance.environment) == instance assert instance.is_running() ebnt.stop_instance(instance) time.sleep(.1) assert not instance.is_running()