diff --git a/pkg/customizations/subscription/subscription.go b/pkg/customizations/subscription/subscription.go index c1c6467608..0968c7331c 100644 --- a/pkg/customizations/subscription/subscription.go +++ b/pkg/customizations/subscription/subscription.go @@ -9,16 +9,17 @@ import ( // ServerUrl denotes the host to register the system with // BaseUrl specifies the repository URL for DNF type ImageOptions struct { - Organization string `json:"organization"` - ActivationKey string `json:"activation_key"` - ServerUrl string `json:"server_url"` - BaseUrl string `json:"base_url"` - Insights bool `json:"insights"` - Rhc bool `json:"rhc"` - Proxy string `json:"proxy"` - TemplateName string `json:"template_name"` - TemplateUUID string `json:"template_uuid"` - PatchURL string `json:"patch_url"` + Organization string `json:"organization"` + ActivationKey string `json:"activation_key"` + ServerUrl string `json:"server_url"` + BaseUrl string `json:"base_url"` + Insights bool `json:"insights"` + Rhc bool `json:"rhc"` + Proxy string `json:"proxy"` + TemplateName string `json:"template_name"` + TemplateUUID string `json:"template_uuid"` + PatchURL string `json:"patch_url"` + ContentSets []string `json:"content_sets"` // List of repo IDs to enable using subscription-manager on first boot } type RHSMStatus string diff --git a/pkg/manifest/subscription.go b/pkg/manifest/subscription.go index 2b2d4247c3..6ba0439042 100644 --- a/pkg/manifest/subscription.go +++ b/pkg/manifest/subscription.go @@ -188,6 +188,14 @@ func subscriptionService( } } } + // Enable content sets if specified + if len(subscriptionOptions.ContentSets) > 0 { + contentSetsCmd := "/usr/sbin/subscription-manager repos" + for _, contentSet := range subscriptionOptions.ContentSets { + contentSetsCmd += fmt.Sprintf(" --enable=%s", shutil.Quote(contentSet)) + } + commands = append(commands, contentSetsCmd) + } commands = append(commands, fmt.Sprintf("/usr/bin/rm %s", shutil.Quote(subkeyFilepath))) diff --git a/pkg/manifest/subscription_test.go b/pkg/manifest/subscription_test.go index 7be3d2e56d..895a06e9f1 100644 --- a/pkg/manifest/subscription_test.go +++ b/pkg/manifest/subscription_test.go @@ -640,6 +640,59 @@ func TestSubscriptionService(t *testing.T) { expectedDirs: make([]*fsnode.Directory, 0), expectedServices: []string{serviceFilename}, }, + "with-content-sets": { + subOpts: subscription.ImageOptions{ + Organization: "theorg-iob-etc", + ActivationKey: "thekey-iob-etc", + ServerUrl: "theserverurl-iob-etc", + BaseUrl: "thebaseurl-iob-etc", + Rhc: false, + Insights: false, + ContentSets: []string{"content-label-1", "content-label-2"}, + }, + srvcOpts: &subscriptionServiceOptions{ + InsightsOnBoot: true, + UnitPath: osbuild.EtcUnitPath, + }, + expectedStage: &osbuild.Stage{ + Type: stageType, + Options: &osbuild.SystemdUnitCreateStageOptions{ + Filename: serviceFilename, + UnitType: unitType, + UnitPath: osbuild.EtcUnitPath, + Config: osbuild.SystemdUnit{ + Unit: &osbuild.UnitSection{ + Description: serviceDescription, + ConditionPathExists: []string{ + subkeyFilepath, + }, + Wants: serviceWants, + After: serviceAfter, + }, + Service: &osbuild.ServiceSection{ + Type: osbuild.OneshotServiceType, + ExecStart: []string{ + "/usr/sbin/subscription-manager config --server.hostname 'theserverurl-iob-etc'", + `/usr/sbin/subscription-manager register --org="${ORG_ID}" --activationkey="${ACTIVATION_KEY}" --baseurl 'thebaseurl-iob-etc'`, + "/usr/sbin/subscription-manager repos --enable='content-label-1' --enable='content-label-2'", + "/usr/bin/rm '" + subkeyFilepath + "'", + }, + EnvironmentFile: []string{ + subkeyFilepath, + }, + }, + Install: &osbuild.InstallSection{ + WantedBy: serviceWantedBy, + }, + }, + }, + }, + expectedFiles: []*fsnode.File{ + mkKeyfile("theorg-iob-etc", "thekey-iob-etc"), + }, + expectedDirs: make([]*fsnode.Directory, 0), + expectedServices: []string{serviceFilename}, + }, } for name := range testCases {