# The new OpenQA client is here
---
## Inspecting the jobs
```!
openqa-cli api --host http://openqa.opensuse.org \
jobs/overview
```
<span class="fragment">
Tip: Use pretty JSON output!
```!
openqa-cli api --host http://openqa.opensuse.org \
--pretty jobs/overview
```
</span>
---
## Get details for a job
```!
openqa-cli api jobs/1222737
```
By default the client talks to **localhost**.
<span class="fragment">
```!
openqa-cli api --host openqa.opensuse.org jobs/1222737
```
Specify the host to work on production!</span>
---
## Trigger builds
```!
openqa-cli api -X POST isos \
DISTRI=sle VERSION=15 FLAVOR=Desktop-DVD-Updates \
ARCH=x86_64 TEST=qam-all \
FOO=1 BAR=baz
```
- Use `api -X POST` to post
- `isos` is the API route
- Followed by the variables we need
<span class="fragment">
```json
{"error":"no api key","error_status":403}
```
Oops! Not allowed! :expressionless:
</span>
---
## Authentication
Some API calls require credentials. `client.conf` is understood by most OpenQA tools:
```ini
[openqa.example.com]
key = 1234567890ABCDEF
secret = 1234567890ABCDEF
```
<span class="fragment">
Or specify the login with the command:
```!
openqa-cli api --host http://openqa.example.com \
--apikey 1234567890ABCDEF \
--apisecret 1234567890ABCDEF \
-X POST isos \
...
```
</span>
---
## Post jobs
Now that we have authentication working, let's look at more common use cases!
```!
openqa-cli api --host http://openqa.example.com \
-X POST jobs \
DISTRI=sle VERSION=15-SP2 \
FLAVOR=Online ARCH=x86_64 \
TEST=create_hdd_textmode \
MACHINE=64bit BUILD=189.1
```
---
## Post comments
```!
openqa-cli api --host http://openqa.example.com \
-X POST jobs/2/comments text=hello
```
<span class="fragment">
Delete the comment again
```!
openqa-cli api --host http://openqa.example.com \
-X DELETE jobs/2/comments/1
```
</span>
---
## Delete a job
```!
openqa-cli api --host http://openqa.exmaple.com \
-X DELETE jobs/67
```
- Use `api -X DELETE` to delete
---
## Getting job template YAML
```!
openqa-cli api --host openqa.opensuse.org \
-a 'Accept: application/yaml' \
job_templates_scheduling/73 > MicroOS.yaml
cp MicroOS.yaml{,.bak}
```
- Save the YAML for the MicroOS job group to a file, using > in the shell.
- Use `-a` to say that we want YAML output from the API.
- Make a *backup* of the YAML.
- We can now **edit** the YAML document. :construction_worker:
---
## Updating YAML
```!
openqa-validate-yaml MicroOS.yaml
```
- Validate the YAML locally. This will fail on syntax errors.
- Note: Test suites and settings are not validated this way!
<span class="fragment">
```!
openqa-cli api -X POST job_templates_scheduling/73 \
schema=JobTemplates-01.yaml \
template="$(cat MicroOS.yaml)" \
reference="$(cat MicroOS.yaml.bak)"
```
- Update the job group.
- Specify the YAML file.
- Use the reference to avoid editing conflicts.
:sunglasses:
</span>
---
## Archive mode
Get all the assets in one fell swoop:
```!
openqa-cli archive 408 /tmp/openqa_job_408
```
Tip: Optionally add `--with-thumbnails`
---
## Extensible
Commands are implemented as simple plug-ins.
```perl
getopt \@args,
'l|asset-size-limit=i' => \(my $limit),
't|with-thumbnails' => \my $thumbnails;
@args = $self->decode_args(@args);
die $self->usage unless my $job = shift @args;
die $self->usage unless my $path = shift @args;
my $url = $self->url_for("jobs/$job/details");
my $client = $self->client($url);
$client->archive->run(
{url => $url, archive => $path,
'with-thumbnails' => $thumbnails,
'asset-size-limit' => $limit});
```
---
## Shortcuts
Say we have a test on O3
https://openqa.opensuse.org/tests/1222737
<span class="fragment">
And we want to look at the details
openqa-cli api --o3 --pretty jobs/4078851
</span>
<span class="fragment">
This also works for OSD
https://openqa.suse.de/tests/1222737
openqa-cli api --osd --pretty jobs/1222737
</span>
---
## More features to play with
- `--data '{"group_id: 2"}'`
- `--data-file ./test.json`
- `--form --data '{"text":"example"}'`
- Pipes work, too!
- And full UTF-8 support!
See `openqa-cli --help`!
---
## Further reading
- open.qa/docs/#client
{"metaMigratedAt":"2023-06-15T07:43:30.530Z","metaMigratedFrom":"Content","title":"The new OpenQA client is here","breaks":true,"contributors":"[{\"id\":\"0ae20319-affa-4483-b324-765b30c4a2ca\",\"add\":5798,\"del\":1561}]"}