Skip to content

Commit

Permalink
external: don't have arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Simon de Vlieger <[email protected]>
  • Loading branch information
supakeen committed May 28, 2024
1 parent dca5605 commit 70f6f47
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 39 deletions.
2 changes: 1 addition & 1 deletion doc/03-omnifest/01-directive.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ otk.meta.kiwi:

External directives. Directives starting with `otk.external` are redirected
to `/usr/libexec/otk/`-binaries. For example the directive
`otk.external.osbuild.depsolve_dnf4` will execute `otk-osbuild depsolve_dnf4`
`otk.external.osbuild_depsolve_dnf4` will execute `otk_external_osbuild_depsolve_dnf4`
with the tree under the directive on stdin and expect a new tree to replace
the directive with on stdout.

Expand Down
22 changes: 9 additions & 13 deletions doc/03-omnifest/02-external.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,12 @@ it finds the first match:
- `/usr/lib/otk`

The filename for an external executable is based on the external name. When the
following directive is encountered: `otk.external.<name>.<argument>` then
`otk` will try to find an executable called `otk_external_<name>` in the previously
following directive is encountered: `otk.external.<name>` then `otk` will try to
try to find an executable called `otk_external_<name>` in the previously
mentioned search paths.

It will call this executable with `<argument>` as its first argument. Here are
some examples:

- `otk.external.foo` -> `otk_external_foo`
- `otk.external.foo.bar_baz` -> `otk_external_foo bar_baz`
- `otk.external.foo.bar.baz` -> `otk_external_foo bar baz`
- `otk.external.foo_baz` -> `otk_external_foo_baz`

## Implementations

Expand All @@ -99,41 +95,41 @@ These directives can be used as children under an `otk.target.osbuild` tree.

These directives are only allowed within a [`otk.target.osbuild.<name>`](./01-directive.md#otktargetconsumername).

#### `otk.external.osbuild.depsolve_dnf4`
#### `otk.external.osbuild_depsolve_dnf4`

Solves a list of package specifications to RPMs and specifies them in the
osbuild manifest as sources.

#### `otk.external.osbuild.depsolve_dnf5`
#### `otk.external.osbuild_depsolve_dnf5`

Expects a `map` as its value.

`osbuild` directives to write files. **If a stage exists for the type of file
you want to write: use it.** See the [best practices](../04-best-practices.md).

#### `otk.external.osbuild.file_from_text`
#### `otk.external.osbuild_file_from_text`

Write inline text to a file. Creates a source in the manifest and copies that
source to the destination in the tree.

Path components up to the destination must be pre-existing in the tree.

```yaml
otk.external.osbuild.file_from_text:
otk.external.osbuild_file_from_text:
destination: /path/to
text: |
Hello, World!
```

#### `otk.external.osbuild.file_from_path`
#### `otk.external.osbuild_file_from_path`

Copy a file. Source is relative to the path of the entrypoint omnifest. Creates
a source in the manifest and copies that source to the destination in tree.

Path components up to the destination must be pre-existing in the tree.

```yaml
otk.external.osbuild.file_from_path:
otk.external.osbuild_file_from_path:
source: README.md
destination: /path/to
```
2 changes: 1 addition & 1 deletion example/centos/centos-9-x86_64-ami.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ otk.define.centos-9-x86_64-ami:
# [list_item1, list_item2, ..]"
# (i.e. define the partition table as a map of root/boot/boot-efi vars)
# *and* it needs to undstand modifications (e.g. adding extra parititions somehow, size contraints)
otk.external.osbuild.create_partition_table_defines:
otk.external.osbuild_create_partition_table_defines:
total_size: 10G

otk.include.centos-9-x86_64: "common/centos-9.yaml"
2 changes: 1 addition & 1 deletion example/centos/centos-9-x86_64-qcow2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ otk.define.centos-9-x86_64-qcow2:
# [list_item1, list_item2, ..]"
# (i.e. define the partition table as a map of root/boot/boot-efi vars)
# *and* it needs to undstand modifications (e.g. adding extra parititions somehow, size contraints)
otk.external.osbuild.create_partition_table_defines:
otk.external.osbuild_create_partition_table_defines:
total_size: 10G

otk.include.centos-9-x86_64: "common/centos-9.yaml"
2 changes: 1 addition & 1 deletion example/centos/fragment/files.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
otk.op.loop:
item: ${modfication.files}
foreach:
- otk.external.osbuild.embed_file:
- otk.external.osbuild_embed_file:
text: ${item.text}
path: ${item.path}
- type: org.osbuild.chmod
Expand Down
2 changes: 1 addition & 1 deletion example/centos/pipeline/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: build
source-epoch: ${source_epoch}
runner: "org.osbuild.centos9"
stages:
- otk.external.osbuild.depsolve_dnf4:
- otk.external.osbuild_depsolve_dnf4:
architecture: ${architecture}
releasever: ${version}
module_platform_id: platform:el${version}
Expand Down
10 changes: 5 additions & 5 deletions example/centos/pipeline/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ name: image
build: "name:build"

stages:
- otk.external.osbuild_partition_table.gen_truncate_stage:
- otk.external.osbuild_partition_table_gen_truncate_stage:
from: filesystems
- otk.external.osbuild_partition_table.gen_sfdisk_stage:
- otk.external.osbuild_partition_table_gen_sfdisk_stage:
from: filesystems
- otk.external.osbuild_partition_table.gen_mkfs_stages:
- otk.external.osbuild_partition_table_gen_mkfs_stages:
from: filesystems
- type: org.osbuild.copy
options:
paths:
from: input://root-tree/
to: mount://-/
devices:
otk.external.osbuild.partition_table.gen_devices:
otk.external.osbuild_partition_table_gen_devices:
from: filesystems
mounts:
otk.external.osbuild.partition_table.gen_mounts:
otk.external.osbuild_partition_table_gen_mounts:
from: filesystems
# TODO drop this stage conditionally on legacy boot support (or not) [is this our use-case for conditionals?]
- type: org.osbuild.grub2.inst
Expand Down
4 changes: 2 additions & 2 deletions example/centos/pipeline/os-ostree.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build: "name:build"

stages:
# Install RPMs
- otk.external.osbuild.depsolve_dnf4:
- otk.external.osbuild_depsolve_dnf4:
architecture: ${architecture}
releasever: ${version}
module_platform_id: platform:el${version}
Expand All @@ -14,7 +14,7 @@ stages:
packages: ${packages.os.packages}

# Disk bits
- otk.external.osbuild.partition_table.gen_fstab_stage:
- otk.external.osbuild_partition_table_gen_fstab_stage:
source: ${filesystem}

# Boot bits
Expand Down
4 changes: 2 additions & 2 deletions example/centos/pipeline/os.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build: "name:build"

stages:
# Install RPMs
- otk.external.osbuild.depsolve_dnf4:
- otk.external.osbuild_depsolve_dnf4:
architecture: ${architecture}
releasever: ${version}
module_platform_id: platform:el${version}
Expand All @@ -14,7 +14,7 @@ stages:
packages: ${packages.os.packages}

# Disk bits
- otk.external.osbuild.partition_table.gen_fstab_stage:
- otk.external.osbuild_partition_table_gen_fstab_stage:
source: ${filesystem}

# Boot bits
Expand Down
2 changes: 1 addition & 1 deletion example/fedora/osbuild/buildroot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: buildroot
source-epoch: 1659397331
stages:
- otk.external.osbuild.depsolve_dnf4:
- otk.external.osbuild_depsolve_dnf4:
architecture: ${architecture}
releasever: "40"
module_platform_id: f${version}
Expand Down
2 changes: 1 addition & 1 deletion example/fedora/osbuild/pipeline/raw.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: raw
source-epoch: 1659397331
stages:
# - otk.external.osbuild.depsolve_dnf4:
# - otk.external.osbuild_depsolve_dnf4:
# architecture: ${architecture}
# module_platform_id: f${version}
# repositories: ${repositories}
Expand Down
2 changes: 1 addition & 1 deletion example/fedora/osbuild/pipeline/tree.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: tree
build: name:root
stages:
- otk.external.osbuild.depsolve_dnf4:
- otk.external.osbuild_depsolve_dnf4:
architecture: ${architecture}
releasever: "40"
module_platform_id: f${version}
Expand Down
9 changes: 7 additions & 2 deletions src/otk/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import logging
import pathlib
import re
import subprocess
import sys
import os
Expand Down Expand Up @@ -47,8 +48,12 @@ def call(context: Context, directive: str, tree: Any) -> Any:


def convert(directive):
exe, *args = directive.removeprefix(PREFIX_EXTERNAL).split(".")
return (f"otk_external_{exe}", args)
exe = directive.removeprefix(PREFIX_EXTERNAL)

if not re.fullmatch("[a-zA-Z_]+", exe):
raise RuntimeError("Invalid name {exe!r}")

return f"otk_external_{exe}"


def search(exe):
Expand Down
18 changes: 11 additions & 7 deletions test/test_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
from otk.external import convert


@pytest.mark.parametrize("text,exe,args", [
("otk.external.osbuild.foo", "otk_external_osbuild", ["foo",]),
("otk.external.osbuild.foo.bar", "otk_external_osbuild", ["foo", "bar",]),
("otk.external.foo.bar", "otk_external_foo", ["bar",]),
("otk.external.foo", "otk_external_foo", []),
@pytest.mark.parametrize("text,exe", [
("otk.external.osbuild_foo", "otk_external_osbuild_foo",),
])
def test_convert(text, exe, args):
assert convert(text) == (exe, args)
def test_convert(text, exe):
assert convert(text) == exe

@pytest.mark.parametrize("text", [
"otk.external.osbuild.foo",
])
def test_convert_validate(text):
with pytest.raises(RuntimeError):
assert convert(text)

0 comments on commit 70f6f47

Please sign in to comment.