Skip to content
Merged
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
21 changes: 11 additions & 10 deletions pkg/customizations/subscription/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pkg/manifest/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
53 changes: 53 additions & 0 deletions pkg/manifest/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading