Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/user/reference/config/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All config files share the same schema — there is no distinction between a "ro
| `component-groups` | map of objects | Named groups of components with shared defaults | [Component Groups](component-groups.md) |
| `images` | map of objects | Image definitions (VMs, containers) | [Images](images.md) |
| `tests` | map of objects | Named test definitions (new-shape, parse-only) | [Tests and Test Groups](tests.md) |
| `tmt` | object | Project-wide TMT metadata, such as components with dist-git tests enabled | [Tests — Dist-git TMT Tests](tests.md#dist-git-tmt-tests) |
| `test-groups` | map of objects | Named bundles of test references (new-shape, parse-only) | [Tests and Test Groups](tests.md) |
| `sku-groups` | map of objects | Named Azure VM size lists for image test fan-out | [Tests — SKU Groups](tests.md#sku-groups) |
| `vm-skus` | map of objects | Per-VM-size metadata for external test orchestration | [Tests — VM SKUs](tests.md#vm-skus) |
Expand Down
17 changes: 17 additions & 0 deletions docs/user/reference/config/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ plan = "/plans/example"
After associating `example-tmt` with a component, run it locally with
`azldev component test <component> --image-path <image.qcow2> --rpm <package.rpm>`.

### Dist-git TMT Tests

The top-level `[tmt.dist-git]` section lists components whose own dist-git TMT
tests are enabled. Listed components need no `[tests.<name>]` entry: the test
source is the component's prepared sources (see
[`azldev component prepare-sources`](../cli/azldev_component_prepare-sources.md)),
and consumers read the list from `azldev config dump`.

```toml
[tmt.dist-git]
enabled-components = ["bash", "util-linux"]
```

| Field | TOML Key | Type | Description |
|-------|----------|------|-------------|
| Enabled components | `enabled-components` | string array | Names of defined components. Entries must be unique across all config files; an undefined component is an error. |

### Pytest Fields

The `[tests.<name>.pytest]` subtable configures a pytest run. azldev validates
Expand Down
25 changes: 25 additions & 0 deletions internal/app/azldev/cmds/config/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ func TestSchema_TestGroupMembersAreClosed(t *testing.T) {
assert.NotContains(t, props, "group", "test-group members must not expose group")
}

func TestSchema_TmtDistGitEnabledComponents(t *testing.T) {
schemaText, err := config.GenerateAzlDevTOMLJSONSchema()
require.NoError(t, err)

var schema map[string]any
require.NoError(t, json.Unmarshal([]byte(schemaText), &schema))
defs := mustSchemaMap(t, schema["$defs"], "$defs")
root := mustSchemaMap(t, defs["ConfigFile"], "ConfigFile")
rootProps := mustSchemaMap(t, root["properties"], "ConfigFile properties")
tmt := mustSchemaMap(t, rootProps["tmt"], "tmt")
assert.Equal(t, "#/$defs/TmtDiscoveryConfig", tmt["$ref"])
discovery := mustSchemaMap(t, defs["TmtDiscoveryConfig"], "TmtDiscoveryConfig")
discoveryProps := mustSchemaMap(t, discovery["properties"], "TmtDiscoveryConfig properties")
distGit := mustSchemaMap(t, discoveryProps["dist-git"], "dist-git")
assert.Equal(t, "#/$defs/TmtDistGitConfig", distGit["$ref"])
distGitConfig := mustSchemaMap(t, defs["TmtDistGitConfig"], "TmtDistGitConfig")
props := mustSchemaMap(t, distGitConfig["properties"], "TmtDistGitConfig properties")
components := mustSchemaMap(t, props["enabled-components"], "enabled-components")
assert.Equal(t, "array", components["type"])
assert.Equal(t, true, components["uniqueItems"])
items := mustSchemaMap(t, components["items"], "enabled-components items")
assert.Equal(t, "string", items["type"])
assert.Equal(t, false, distGitConfig["additionalProperties"])
}

// mustSchemaMap asserts that value is a JSON object and returns it.
func mustSchemaMap(t *testing.T, value any, name string) map[string]any {
t.Helper()
Expand Down
27 changes: 27 additions & 0 deletions internal/projectconfig/configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type ConfigFile struct {
// Definitions of individual tests (new schema, [tests.X]).
Tests map[string]TestDefinition `toml:"tests,omitempty" validate:"dive" jsonschema:"title=Tests,description=Definitions of individual tests"`

Tmt *TmtDiscoveryConfig `toml:"tmt,omitempty" jsonschema:"title=TMT discovery,description=Project-wide TMT discovery metadata"`

// Definitions of test groups (new schema, [test-groups.X]).
TestGroups map[string]TestGroup `toml:"test-groups,omitempty" validate:"dive" jsonschema:"title=Test Groups,description=Definitions of named bundles of tests"`

Expand All @@ -86,6 +88,31 @@ type ConfigFile struct {
dir string `toml:"-" validate:"dir"`
}

// TmtDiscoveryConfig holds project-wide TMT discovery metadata ([tmt]).
type TmtDiscoveryConfig struct {
DistGit *TmtDistGitConfig `toml:"dist-git,omitempty" json:"distGit,omitempty" jsonschema:"title=Dist-git TMT discovery,description=Opt-in metadata for component-owned dist-git TMT tests"`
}

// TmtDistGitConfig lists the components whose dist-git TMT tests are enabled ([tmt.dist-git]).
type TmtDistGitConfig struct {
EnabledComponents []string `toml:"enabled-components,omitempty" json:"enabledComponents,omitempty" validate:"unique,dive,required" jsonschema:"title=Enabled components,description=Source component names opted into dist-git TMT discovery,uniqueItems=true"`
}

// validateTmtDistGit rejects enabled components that are not defined in the project.
func validateTmtDistGit(tmt *TmtDiscoveryConfig, components map[string]ComponentConfig) error {
if tmt == nil || tmt.DistGit == nil {
return nil
}

for _, name := range tmt.DistGit.EnabledComponents {
if _, ok := components[name]; !ok {
return fmt.Errorf("%w: %#q", ErrUndefinedTmtDistGitComponent, name)
Comment on lines +108 to +109
}
}

return nil
}

// SourcePath returns the absolute path to the config file on disk.
func (f ConfigFile) SourcePath() string {
return f.sourcePath
Expand Down
22 changes: 22 additions & 0 deletions internal/projectconfig/configfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/microsoft/azure-linux-dev-tools/internal/projectconfig"
"github.com/microsoft/azure-linux-dev-tools/internal/utils/fileutils"
"github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -19,6 +20,27 @@ func TestProjectConfigFileValidation_EmptyFile(t *testing.T) {
assert.NoError(t, file.Validate())
}

func TestProjectConfigFileValidation_TmtDistGit(t *testing.T) {
var file projectconfig.ConfigFile

decoder := toml.NewDecoder(bytes.NewBufferString(`[tmt.dist-git]
enabled-components = ["bash", "hostname", "selinux-policy", "util-linux"]
`)).DisallowUnknownFields()
require.NoError(t, decoder.Decode(&file))
require.NoError(t, file.Validate())
require.NotNil(t, file.Tmt)
require.NotNil(t, file.Tmt.DistGit)
assert.Equal(t, []string{"bash", "hostname", "selinux-policy", "util-linux"}, file.Tmt.DistGit.EnabledComponents)

for _, names := range [][]string{{"bash", "bash"}, {""}} {
file.Tmt.DistGit.EnabledComponents = names
require.Error(t, file.Validate())
}

file.Tmt.DistGit.EnabledComponents = nil
assert.NoError(t, file.Validate())
}

func TestProjectConfigFileValidation_TestDefinitionMismatchedSubtable(t *testing.T) {
file := projectconfig.ConfigFile{
Tests: map[string]projectconfig.TestDefinition{
Expand Down
17 changes: 17 additions & 0 deletions internal/projectconfig/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ func mergeConfigFile(resolvedCfg *ProjectConfig, loadedCfg *ConfigFile, options
return err
}

mergeTmt(resolvedCfg, loadedCfg)

if err := mergeTestGroups(resolvedCfg, loadedCfg); err != nil {
return err
}
Expand Down Expand Up @@ -394,6 +396,21 @@ func mergeTests(resolvedCfg *ProjectConfig, loadedCfg *ConfigFile) error {
return nil
}

// mergeTmt appends the dist-git enabled components from a loaded config file; the
// merged list is checked for duplicates and unknown components during validation.
func mergeTmt(resolvedCfg *ProjectConfig, loadedCfg *ConfigFile) {
if loadedCfg.Tmt == nil || loadedCfg.Tmt.DistGit == nil {
return
}

if resolvedCfg.Tmt == nil {
resolvedCfg.Tmt = &TmtDiscoveryConfig{DistGit: &TmtDistGitConfig{}}
}

distGit := resolvedCfg.Tmt.DistGit
distGit.EnabledComponents = append(distGit.EnabledComponents, loadedCfg.Tmt.DistGit.EnabledComponents...)
}

// mergeTestGroups merges named test groups from a loaded config file into the
// resolved config. Duplicate group names are not allowed.
func mergeTestGroups(resolvedCfg *ProjectConfig, loadedCfg *ConfigFile) error {
Expand Down
57 changes: 57 additions & 0 deletions internal/projectconfig/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1733,3 +1733,60 @@ upstream-distro = { name = "fedora", version = "rawhide" }
require.NotNil(t, component.UpstreamCommitConfigFile())
assert.Equal(t, "/project/component.toml", component.UpstreamCommitConfigFile().sourcePath)
}

func TestLoadAndResolveProjectConfig_TmtDistGit(t *testing.T) {
const mainFile = "includes = [\"include.toml\"]\n[components.a]\n[components.b]\n"

tests := []struct {
name string
main, extra string
wantEnabled []string
wantErr error
wantAnyError bool
}{
{
name: "merged across files",
main: mainFile + "[tmt.dist-git]\nenabled-components = [\"a\"]\n",
extra: "[tmt.dist-git]\nenabled-components = [\"b\"]\n",
wantEnabled: []string{"a", "b"},
},
{
name: "undefined component",
main: mainFile + "[tmt.dist-git]\nenabled-components = [\"missing\"]\n",
extra: "",
wantErr: ErrUndefinedTmtDistGitComponent,
},
{
name: "duplicate across files",
main: mainFile + "[tmt.dist-git]\nenabled-components = [\"a\"]\n",
extra: "[tmt.dist-git]\nenabled-components = [\"a\"]\n",
wantAnyError: true,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ctx := testctx.NewCtx()
require.NoError(t, fileutils.MkdirAll(ctx.FS(), "/project"))
require.NoError(t, fileutils.WriteFile(ctx.FS(), testConfigPath, []byte(test.main), fileperms.PrivateFile))
require.NoError(t, fileutils.WriteFile(ctx.FS(), "/project/include.toml", []byte(test.extra), fileperms.PrivateFile))

config, err := loadAndResolveProjectConfig(ctx.FS(), loadOptions{}, testConfigPath)

if test.wantErr != nil {
require.ErrorIs(t, err, test.wantErr)

return
}

if test.wantAnyError {
require.Error(t, err)

return
}

require.NoError(t, err)
assert.Equal(t, test.wantEnabled, config.Tmt.DistGit.EnabledComponents)
})
}
}
7 changes: 7 additions & 0 deletions internal/projectconfig/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type ProjectConfig struct {
// Definitions of individual tests.
Tests map[string]TestDefinition `toml:"tests,omitempty" json:"tests,omitempty" jsonschema:"title=Tests,description=Mapping of test names to configurations"`

// Project-wide TMT discovery metadata.
Tmt *TmtDiscoveryConfig `toml:"tmt,omitempty" json:"tmt,omitempty" jsonschema:"title=TMT discovery,description=Project-wide TMT discovery metadata"`

// Definitions of named test groups.
TestGroups map[string]TestGroup `toml:"test-groups,omitempty" json:"testGroups,omitempty" jsonschema:"title=Test Groups,description=Mapping of test group names to configurations"`

Expand Down Expand Up @@ -121,6 +124,10 @@ func (cfg *ProjectConfig) validate(withoutLockfile bool) error {
return err
}

if err := validateTmtDistGit(cfg.Tmt, cfg.Components); err != nil {
return err
}

if err := validateRpmRepos(cfg.Resources.RpmRepos); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions internal/projectconfig/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ var (
ErrSKUGroupNotAllowed = errors.New("sku-groups not allowed outside image test references")
// ErrDuplicateVMSKU is returned when duplicate conflicting [vm-skus] entries are found.
ErrDuplicateVMSKU = errors.New("duplicate VM SKU")
// ErrUndefinedTmtDistGitComponent is returned when [tmt.dist-git] enables a component that is not defined.
ErrUndefinedTmtDistGitComponent = errors.New("undefined component in tmt.dist-git.enabled-components")
// ErrUnknownTestType is returned for unrecognized test types.
ErrUnknownTestType = errors.New("unknown test type")
// ErrMissingTestField is returned when a required test config field is missing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@
"title": "Tests",
"description": "Definitions of individual tests"
},
"tmt": {
"$ref": "#/$defs/TmtDiscoveryConfig",
"title": "TMT discovery",
"description": "Project-wide TMT discovery metadata"
},
"test-groups": {
"additionalProperties": {
"$ref": "#/$defs/TestGroup"
Expand Down Expand Up @@ -1684,6 +1689,32 @@
"additionalProperties": false,
"type": "object"
},
"TmtDiscoveryConfig": {
"properties": {
"dist-git": {
"$ref": "#/$defs/TmtDistGitConfig",
"title": "Dist-git TMT discovery",
"description": "Opt-in metadata for component-owned dist-git TMT tests"
}
},
"additionalProperties": false,
"type": "object"
},
"TmtDistGitConfig": {
"properties": {
"enabled-components": {
"items": {
"type": "string"
},
"type": "array",
"uniqueItems": true,
"title": "Enabled components",
"description": "Source component names opted into dist-git TMT discovery"
}
},
"additionalProperties": false,
"type": "object"
},
"ToolsConfig": {
"properties": {
"imageCustomizer": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@
"title": "Tests",
"description": "Definitions of individual tests"
},
"tmt": {
"$ref": "#/$defs/TmtDiscoveryConfig",
"title": "TMT discovery",
"description": "Project-wide TMT discovery metadata"
},
"test-groups": {
"additionalProperties": {
"$ref": "#/$defs/TestGroup"
Expand Down Expand Up @@ -1684,6 +1689,32 @@
"additionalProperties": false,
"type": "object"
},
"TmtDiscoveryConfig": {
"properties": {
"dist-git": {
"$ref": "#/$defs/TmtDistGitConfig",
"title": "Dist-git TMT discovery",
"description": "Opt-in metadata for component-owned dist-git TMT tests"
}
},
"additionalProperties": false,
"type": "object"
},
"TmtDistGitConfig": {
"properties": {
"enabled-components": {
"items": {
"type": "string"
},
"type": "array",
"uniqueItems": true,
"title": "Enabled components",
"description": "Source component names opted into dist-git TMT discovery"
}
},
"additionalProperties": false,
"type": "object"
},
"ToolsConfig": {
"properties": {
"imageCustomizer": {
Expand Down
31 changes: 31 additions & 0 deletions schemas/azldev.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@
"title": "Tests",
"description": "Definitions of individual tests"
},
"tmt": {
"$ref": "#/$defs/TmtDiscoveryConfig",
"title": "TMT discovery",
"description": "Project-wide TMT discovery metadata"
},
"test-groups": {
"additionalProperties": {
"$ref": "#/$defs/TestGroup"
Expand Down Expand Up @@ -1684,6 +1689,32 @@
"additionalProperties": false,
"type": "object"
},
"TmtDiscoveryConfig": {
"properties": {
"dist-git": {
"$ref": "#/$defs/TmtDistGitConfig",
"title": "Dist-git TMT discovery",
"description": "Opt-in metadata for component-owned dist-git TMT tests"
}
},
"additionalProperties": false,
"type": "object"
},
"TmtDistGitConfig": {
"properties": {
"enabled-components": {
"items": {
"type": "string"
},
"type": "array",
"uniqueItems": true,
"title": "Enabled components",
"description": "Source component names opted into dist-git TMT discovery"
}
},
"additionalProperties": false,
"type": "object"
},
"ToolsConfig": {
"properties": {
"imageCustomizer": {
Expand Down
Loading