-
Notifications
You must be signed in to change notification settings - Fork 3
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
Create a first PoC #1
Comments
Hi @stalep, I'm gearing up to try to produce this. (I'm working my way through the setup instructions -- it's been an odyssey -- I'm up to trying to run the Horreum tests, but they are failing due to a lack of Docker...so that's the next stumbling block for me to remove.) If you want to assign this issue to me, feel free. |
Hi @webbnh, we've noticed an issue with the openapi-python generator in the latest version of Horreum. I'm looking at it and we plan to have it fixed in the upcoming version. I'll ping you when it's fixed in master! |
They openapi-python generator now work with master @webbnh |
Hi all, Contrary to all appearances, I am trying to make headway on this stuff. 🥴 I was able to generate the API client, but the tool has some complaints, and so it doesn't generate code for all the APIs:
I got confirmation from the tool's maintainer: it indeed does not currently support We have various options. The simplest might be to tweak the YAML for those two APIs: /api/run/{id}/description:
post:
[...]
requestBody:
content:
text/plain:
schema:
type: string
[...] and replace I'm not blocked by this, but let me know if you want me to post a PR with this change. |
Hi @webbnh we have a pr open that fixes the python generation. Hoping to have it merged by tomorrow! |
Hi @stalep, what was the PR, and has it been merged, yet? (Was it Hyperfoil/Horreum#1292?) The reason I ask is that, at JoeT's prompting, I've found a bug in the Do you want me to create a PR? Here's the change:
|
@webbnh The |
I opened an issue in the project that creates the openapi.yaml |
@willr3, thanks for mentioning, that. BTW, what do you mean by "each time the project compiles"?...it's a little weird to have a build output checked into the repository....
Ah, good...so I'm not alone! 😁
The field at issue is either The first API I hit the problem in is |
I opened a PR that fix the annotations and should generate an |
💪
I admire your optimism. (Did you see openapi-generators/openapi-python-client#699?) |
my optimism is waning given: 699 How are you testing the python client? Do you start a new project and import the generated |
I went with the simplistic approach for my first pass:
My current script is just endeavoring to try out all of the APIs that I can. It doesn't do much that is actually useful, other than to call them and report the result. So far, I'm only trying the Here's what I've got so far.#! /usr/bin/env python3
from horreum_rest_api_client import AuthenticatedClient, Client
from horreum_rest_api_client.api.config.version import sync_detailed as version
from horreum_rest_api_client.api.config.keycloak import sync_detailed as keycloak
from horreum_rest_api_client.api.config.test_datastore import sync_detailed as datastore_test
from horreum_rest_api_client.api.dataset.get_dataset import sync_detailed as get_dataset
from horreum_rest_api_client.api.dataset.get_summary import sync_detailed as dataset_summary
from horreum_rest_api_client.api.dataset.label_values import sync_detailed as dataset_label_values
from horreum_rest_api_client.api.dataset.list_by_test import sync_detailed as dataset_list_test
from horreum_rest_api_client.api.dataset.list_by_schema import sync_detailed as dataset_list_schema
from horreum_rest_api_client.api.experiment.models import sync_detailed as models
from horreum_rest_api_client.api.experiment.profiles import sync_detailed as profiles
from horreum_rest_api_client.api.experiment.run_experiments import sync_detailed as exp_run
from horreum_rest_api_client.api.run.list_all_runs import sync_detailed as run_list
from horreum_rest_api_client.api.schema.list_ import sync_detailed as schema_list
from horreum_rest_api_client.api.test.folders import sync_detailed as test_folders
from horreum_rest_api_client.api.test.list_ import sync_detailed as test_list
production_instance = "https://horreum.corp.redhat.com"
local_instance = "http://localhost:8080/"
output_width = 140
def api_call(api_str, fn, **kwargs):
print(f"{api_str}:", end="\t")
response = fn(client=client, **kwargs)
if 200 <= response.status_code < 300:
output = str(response.parsed)[:output_width]
if len(output) >= output_width:
output += "..."
print(output)
else:
print("failed with", response.status_code)
return response
a_client = AuthenticatedClient(
base_url=production_instance,
raise_on_unexpected_status=True,
token="secret", # I don't think this is being checked with the test server
verify_ssl=False,
)
u_client = Client(base_url=production_instance, verify_ssl=False)
with u_client as client:
api_call("version", version)
api_call("keycloak", keycloak)
api_call("datastore_test", datastore_test, id=294) # Requires authorization
api_call("test list", test_list)
api_call("test folders", test_folders, roles="__all")
api_call("schema list", schema_list)
api_call("run list", run_list)
api_call("ds list schema", dataset_list_schema, uri="urn:ckq_memory_cpu2:0.1")
api_call("ds list test", dataset_list_test, test_id=294)
api_call("ds label vals", dataset_label_values, dataset_id=124811)
api_call("ds summary", dataset_summary, dataset_id=124811)
api_call("get dataset", get_dataset, id=124811)
api_call("exp profiles", profiles, test_id=294) # need a test which has a profile
# api_call("run experiment", exp_run, dataset_id=124810) # crashes with a dataset which has no profiles In "real" code, you presumably wouldn't use my with u_client as client:
response = version(client=client)
response = get_dataset(client=client, id=124811)
// etc. |
Thank you for the code. I was able to get more of it running with the 'openapi.yaml' changes in my PR than with master so we are taking steps in the right direction You asked earlier what I mean about generating the openapi.yaml. The horreum-api module of the Horreum project has code annotations on the service endpoints and the data classes. Part of the compilation creates a new openapi.yaml and places it in the docs module. The same compilation then uses the openapi.yaml to generate the Typescript client for the web interface module in Horreum. We have caught breaking changes to data types or endpoint paths with this method but nothing is perfect. |
Excellent. I've been accumulating fixes here, although I'm a few commits behind
All of that makes good sense, except for the part where the YAML file is supposed to be committed to the repo before the build which is supposed to create it. 😆 I see that John has made some changes to the Maven configuration which look relevant (unfortunately, I don't speak Maven), but, really, the |
I've resync'd with And, yes, everything that I have in the demo script so far seems to work. 🎉 |
We host the src code and the documentation for the website (https://horreum.hyperfoil.io/) in the same repo. This way we can ensure that PRs with functional changes contain all user documentation and the website is always up-to-date with the latest stable branch of Horrum. There is a bit of an anomaly with this set-up, in that, for build artefacts that are published on the website (which is only The yaml is generated as part of the build, and after a change has been made and tested locally the src code change and the openapi.yaml changes should be checked in the same PR.
There was an issue with maven not running certain phases given some conditions, the recent changes rectify this. the The main issue I see with treating |
Thanks, @johnaohara. While you were typing that in here, I was preaching over here. 😀 Even so, it might be good if you had a test which verified that the |
I think that is a good idea :) atm it is a manual check. The anomaly exists because we have taken a shortcut in hosting the website artefacts in the same repo as the src code. we should update the the website build to pull in an openapi.yaml that has been published somewhere as part of a release. We have another concern in that for developers developing against the current master branch we probably should publish the openapi.yaml somewhere without having to expect them to build the project from a snapshot. i.e. if you are a python dev, working on a python client, we wouldn't expect you to install the entire java toolchain just to get the current SNAPSHOT |
Hi @webbnh, I just ran the openapi python gen client from master and it ran without any warnings/errors. |
We now have a pr (Hyperfoil/Horreum#1360) that will generate python and go code as part of the Horreum build. |
I've got my little demo script converted to the new Python client.#! /usr/bin/env python3from openapi_client.api_client import ApiClient production_instance = "https://horreum.corp.redhat.com" def api_call(sect, fn, *args, **kwargs): with ApiClient(configuration=Configuration(host=production_instance)) as c: Unfortunately, almost all of the responses fail to parse. I don't know whether that's a problem in what I'm doing, or a problem in the |
I want to create an example python project to run through the api with a test DB when I get back from vacation. I mostly use python for Jupiter notebooks. @webbnh is there a python unit test library you would recommend for creating the tests for the python client? |
@willr3, I'm accustomed to using PyTest and to running it under Tox. However, it's not obvious to me that you want to write unit tests for this. (It could be a terminology problem, but unit tests generally operate by isolating certain portions of the code-under-test (aka CUT) from their dependencies, by replacing the dependencies with fake or mock implementations of them.) What I think you want to test is integration -- that the generated client actually works with the real API implementation -- and for that you'll need functional tests. This is not to say that PyTest cannot be used to implement functional testing (it can, but its forte is unit testing). But, I just want to make sure that your focus is useful and that your choice of words doesn't confuse things. 🙂 |
Coming out of PerfConf I am excited to see the fruit of this investigation! In chatting with @johnaohara in RDU I wanted to put a comment here about shipping a python client package versus expecting users to generate the client from OpenAPI. It is my understanding with chatting with @johnaohara the expectation is there will be a python client shipped with each version of horreum -- there isn't an expectation the user builds the client from the OpenAPI spec. |
@jtaleric, that is my understanding, as well: the Horreum build now produces a Python client. This needs to be packaged as a Python "package" and made available for consumers' use. So, there are two work items (beyond making sure it all works, which is what I'm currently exploring, albeit at a glacial pace): get the Horreum build to produce the package file(s) [I'm sure this is well-trodden ground, but I myself haven't had to tread it, yet], and devise a policy and mechanism for publishing them [doing "releases" is reasonably straightforward; however, making branch builds, etc. available might require more "stuff"]. |
ack. I know there has been some discussions with shipping a client package vs users building a client, I just wanted to make sure everyone is on the same page, and it sounds like we are so great! 😄 |
Presumably this should be assigned to @lampajr for closure. 🙂 |
Sorry I missed this comment 😞 Closing this issue 🚀 |
Using https://horreum.hyperfoil.io/openapi/ it should be possible to create a Python client connecting to Horreum.
There might be obstacles we do not know about, so a PoC would be welcome
To get started:
Download the API:
The text was updated successfully, but these errors were encountered: