1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00
Files
installer/pkg/asset/agent/image/unconfigured_ignition_test.go
Pawan Pinjarkar da87462421 AGENT-1357: Remove AgentWorkflowTypeInstallInteractiveDisconnected workflow
Remove the interactive disconnected workflow type. The appliance
  embeds registries.conf and CA certificates directly in the system ignition
  for bootstrap, eliminating the need for a separate workflow type.

  Key changes:

  Command-line interface:
  - Remove --interactive flag from unconfigured-ignition command
  - Remove ContextWrapper and workflow context management

  Workflow handling:
  - Simplify to always use AgentWorkflowTypeInstall for unconfigured ignition
  - Remove AgentWorkflowTypeInstallInteractiveDisconnected constant
  - Remove workflow type switching logic in UnconfiguredIgnition
  - Remove workflow dependency from UnconfiguredIgnition asset

  Mirror configuration:
  - Remove RegistriesConf and CaBundle dependencies from UnconfiguredIgnition
  - Remove addMirrorData() call (appliance provides this)
  - Remove early returns for interactive workflow in mirror assets

  Testing:
  - Remove interactive-disconnected-workflow test case
  - Remove with-mirror-configs test case from unconfigured ignition tests
  - Update default dependencies in test helpers

  Rationale:
  The OVE appliance provides a more robust solution for disconnected
  installations by embedding all necessary configuration (registries,
  certificates, UI) directly in the appliance image. This approach:
  - Eliminates workflow type complexity
  - Decouples installer and appliance repositories
  - Simplifies the codebase by removing conditional logic
  - Aligns with the architecture where MCO manages post-bootstrap config

  After first node reboot, the Machine Config Operator manages registry
  configuration and trust bundles via IDMS/IDMT resources.

  Commit message text generated by: Claude AI <noreply@anthropic.com>
2025-12-12 07:22:36 -05:00

186 lines
5.3 KiB
Go

package image
import (
"context"
"encoding/base64"
"testing"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
aiv1beta1 "github.com/openshift/assisted-service/api/v1beta1"
"github.com/openshift/assisted-service/models"
hivev1 "github.com/openshift/hive/apis/hive/v1"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/agent/agentconfig"
"github.com/openshift/installer/pkg/asset/agent/common"
"github.com/openshift/installer/pkg/asset/agent/manifests"
"github.com/openshift/installer/pkg/asset/agent/workflow"
)
func TestUnconfiguredIgnition_Generate(t *testing.T) {
skipTestIfnmstatectlIsMissing(t)
defer setupEmbeddedResources(t)()
nmStateConfig := getTestNMStateConfig()
cases := []struct {
name string
overrideDeps []asset.Asset
expectedError string
expectedFiles []string
serviceEnabledMap map[string]bool
}{
{
name: "default-configs-and-no-nmstateconfigs",
expectedFiles: generatedFilesUnconfiguredIgnition("/usr/local/bin/pre-network-manager-config.sh", "/usr/local/bin/oci-eval-user-data.sh"),
serviceEnabledMap: map[string]bool{
"pre-network-manager-config.service": false,
"oci-eval-user-data.service": true,
"agent-check-config-image.service": true,
"agent-extract-tui.service": true},
},
{
name: "with-nmstateconfigs",
overrideDeps: []asset.Asset{
&nmStateConfig,
},
expectedFiles: generatedFilesUnconfiguredIgnition("/etc/assisted/network/host0/eth0.nmconnection",
"/etc/assisted/network/host0/mac_interface.ini", "/usr/local/bin/pre-network-manager-config.sh", "/usr/local/bin/oci-eval-user-data.sh"),
serviceEnabledMap: map[string]bool{
"pre-network-manager-config.service": true,
"oci-eval-user-data.service": true,
"agent-check-config-image.service": true},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
deps := buildUnconfiguredIgnitionAssetDefaultDependencies(t)
overrideDeps(deps, tc.overrideDeps)
parents := asset.Parents{}
parents.Add(deps...)
unconfiguredIgnitionAsset := &UnconfiguredIgnition{}
err := unconfiguredIgnitionAsset.Generate(context.Background(), parents)
if tc.expectedError != "" {
assert.Equal(t, tc.expectedError, err.Error())
} else {
assert.NoError(t, err)
assertExpectedFiles(t, unconfiguredIgnitionAsset.Config, tc.expectedFiles, nil)
assertServiceEnabled(t, unconfiguredIgnitionAsset.Config, tc.serviceEnabledMap)
}
})
}
}
// This test util create the minimum valid set of dependencies for the
// UnconfiguredIgnition asset.
func buildUnconfiguredIgnitionAssetDefaultDependencies(t *testing.T) []asset.Asset {
t.Helper()
infraEnv := getTestInfraEnv()
agentPullSecret := getTestAgentPullSecret(t)
clusterImageSet := getTestClusterImageSet()
return []asset.Asset{
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
&infraEnv,
&agentPullSecret,
&clusterImageSet,
&manifests.NMStateConfig{},
&common.InfraEnvID{},
&agentconfig.AgentConfig{},
}
}
func getTestInfraEnv() manifests.InfraEnvFile {
return manifests.InfraEnvFile{
Config: &aiv1beta1.InfraEnv{
Spec: aiv1beta1.InfraEnvSpec{
SSHAuthorizedKey: "my-ssh-key",
},
},
File: &asset.File{
Filename: "infraenv.yaml",
Data: []byte("infraenv"),
},
}
}
func getTestAgentPullSecret(t *testing.T) manifests.AgentPullSecret {
t.Helper()
secretDataBytes, err := base64.StdEncoding.DecodeString("c3VwZXItc2VjcmV0Cg==")
assert.NoError(t, err)
return manifests.AgentPullSecret{
Config: &v1.Secret{
Data: map[string][]byte{
".dockerconfigjson": secretDataBytes,
},
},
File: &asset.File{
Filename: "pull-secret.yaml",
Data: []byte("pull-secret"),
},
}
}
func getTestClusterImageSet() manifests.ClusterImageSet {
return manifests.ClusterImageSet{
Config: &hivev1.ClusterImageSet{
Spec: hivev1.ClusterImageSetSpec{
ReleaseImage: "registry.ci.openshift.org/origin/release:4.11",
},
},
File: &asset.File{
Filename: "cluster-image-set.yaml",
Data: []byte("cluster-image-set"),
},
}
}
func getTestNMStateConfig() manifests.NMStateConfig {
return manifests.NMStateConfig{
Config: []*aiv1beta1.NMStateConfig{
{
Spec: aiv1beta1.NMStateConfigSpec{
Interfaces: []*aiv1beta1.Interface{
{
Name: "eth0",
MacAddress: "00:01:02:03:04:05",
},
},
},
},
},
StaticNetworkConfig: []*models.HostStaticNetworkConfig{
{
MacInterfaceMap: models.MacInterfaceMap{
{LogicalNicName: "eth0", MacAddress: "00:01:02:03:04:05"},
},
NetworkYaml: "interfaces:\n- ipv4:\n address:\n - ip: 192.168.122.21\n prefix-length: 24\n enabled: true\n mac-address: 00:01:02:03:04:05\n name: eth0\n state: up\n type: ethernet\n",
},
},
File: &asset.File{
Filename: "nmstateconfig.yaml",
Data: []byte("nmstateconfig"),
},
}
}
func generatedFilesUnconfiguredIgnition(otherFiles ...string) []string {
unconfiguredIgnitionFiles := []string{
"/etc/assisted/manifests/pull-secret.yaml",
"/etc/assisted/manifests/cluster-image-set.yaml",
"/etc/assisted/manifests/infraenv.yaml",
"/etc/assisted/rendezvous-host.env.template",
}
unconfiguredIgnitionFiles = append(unconfiguredIgnitionFiles, otherFiles...)
return append(unconfiguredIgnitionFiles, commonFiles()...)
}