From 1d48c929533e0db9e75033459a45b8d4b0440db3 Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Mon, 18 Jan 2021 13:36:32 +0100 Subject: [PATCH] Add support for `org.osbuild.rhsm` stage Add support to configure `org.osbuild.rhsm` osbuild stage. This stage allows the configuration of Red Hat Subscription Manager (RHSM) related components. Currently it is possible to configure only the enablement status of RHSM DNF plugins. Add `/docs/news/unreleased/osbuild-rhsm-stage.md` with information about the added support for `org.osbuild.rhsm` osbuild stage. Signed-off-by: Tomas Hozza --- docs/news/unreleased/osbuild-rhsm-stage.md | 6 ++++ internal/osbuild/rhsm_stage.go | 34 ++++++++++++++++++++++ internal/osbuild/rhsm_stage_test.go | 16 ++++++++++ internal/osbuild/stage.go | 2 ++ internal/osbuild/stage_test.go | 29 ++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 docs/news/unreleased/osbuild-rhsm-stage.md create mode 100644 internal/osbuild/rhsm_stage.go create mode 100644 internal/osbuild/rhsm_stage_test.go diff --git a/docs/news/unreleased/osbuild-rhsm-stage.md b/docs/news/unreleased/osbuild-rhsm-stage.md new file mode 100644 index 000000000..abe50a2e1 --- /dev/null +++ b/docs/news/unreleased/osbuild-rhsm-stage.md @@ -0,0 +1,6 @@ +# Add support for `org.osbuild.rhsm` osbuild stage + +Add support for `org.osbuild.rhsm` osbuild stage. This stage is available in +osbuild since version 24. The stage currently allows only configuring the +enablement status of two RHSM DNF plugins, specifically of `product-id` and +`subscription-manager` DNF plugins. diff --git a/internal/osbuild/rhsm_stage.go b/internal/osbuild/rhsm_stage.go new file mode 100644 index 000000000..38f096d41 --- /dev/null +++ b/internal/osbuild/rhsm_stage.go @@ -0,0 +1,34 @@ +package osbuild + +// RHSMStageOptions describes configuration of the RHSM stage. +// +// The RHSM stage allows configuration of Red Hat Subscription Manager (RHSM) +// related components. Currently it allows only configuration of the enablement +// state of DNF plugins used by the Subscription Manager. +type RHSMStageOptions struct { + DnfPlugins *RHSMStageOptionsDnfPlugins `json:"dnf-plugins,omitempty"` +} + +func (RHSMStageOptions) isStageOptions() {} + +// RHSMStageOptionsDnfPlugins describes configuration of all RHSM DNF plugins +type RHSMStageOptionsDnfPlugins struct { + ProductID *RHSMStageOptionsDnfPlugin `json:"product-id,omitempty"` + SubscriptionManager *RHSMStageOptionsDnfPlugin `json:"subscription-manager,omitempty"` +} + +// RHSMStageOptionsDnfPlugin describes configuration of a specific RHSM DNF +// plugin +// +// Only the enablement state of a DNF plugin can be currenlty set. +type RHSMStageOptionsDnfPlugin struct { + Enabled bool `json:"enabled"` +} + +// NewRHSMStage creates a new RHSM stage +func NewRHSMStage(options *RHSMStageOptions) *Stage { + return &Stage{ + Name: "org.osbuild.rhsm", + Options: options, + } +} diff --git a/internal/osbuild/rhsm_stage_test.go b/internal/osbuild/rhsm_stage_test.go new file mode 100644 index 000000000..47b1a33aa --- /dev/null +++ b/internal/osbuild/rhsm_stage_test.go @@ -0,0 +1,16 @@ +package osbuild + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNewRhsmStage(t *testing.T) { + expectedStage := &Stage{ + Name: "org.osbuild.rhsm", + Options: &RHSMStageOptions{}, + } + actualStage := NewRHSMStage(&RHSMStageOptions{}) + assert.Equal(t, expectedStage, actualStage) +} diff --git a/internal/osbuild/stage.go b/internal/osbuild/stage.go index dd2689585..4aeddad8a 100644 --- a/internal/osbuild/stage.go +++ b/internal/osbuild/stage.go @@ -60,6 +60,8 @@ func (stage *Stage) UnmarshalJSON(data []byte) error { options = new(KeymapStageOptions) case "org.osbuild.firewall": options = new(FirewallStageOptions) + case "org.osbuild.rhsm": + options = new(RHSMStageOptions) case "org.osbuild.rpm": options = new(RPMStageOptions) case "org.osbuild.rpm-ostree": diff --git a/internal/osbuild/stage_test.go b/internal/osbuild/stage_test.go index 35463aad8..3753dd3d8 100644 --- a/internal/osbuild/stage_test.go +++ b/internal/osbuild/stage_test.go @@ -172,6 +172,35 @@ func TestStage_UnmarshalJSON(t *testing.T) { data: []byte(`{"name":"org.osbuild.locale","options":{"language":""}}`), }, }, + { + name: "rhsm-empty", + fields: fields{ + Name: "org.osbuild.rhsm", + Options: &RHSMStageOptions{}, + }, + args: args{ + data: []byte(`{"name":"org.osbuild.rhsm","options":{}}`), + }, + }, + { + name: "rhsm", + fields: fields{ + Name: "org.osbuild.rhsm", + Options: &RHSMStageOptions{ + DnfPlugins: &RHSMStageOptionsDnfPlugins{ + ProductID: &RHSMStageOptionsDnfPlugin{ + Enabled: false, + }, + SubscriptionManager: &RHSMStageOptionsDnfPlugin{ + Enabled: false, + }, + }, + }, + }, + args: args{ + data: []byte(`{"name":"org.osbuild.rhsm","options":{"dnf-plugins":{"product-id":{"enabled":false},"subscription-manager":{"enabled":false}}}}`), + }, + }, { name: "rpm-empty", fields: fields{