diff --git a/TAG_GUIDE.md b/TAG_GUIDE.md index 9c06fe198..f8dd5e7c0 100644 --- a/TAG_GUIDE.md +++ b/TAG_GUIDE.md @@ -99,6 +99,9 @@ The pit tags organizes Go tests using **build tags**. These tags define when and ##### pit.daily - Tests that should run **every day** +##### pit.harvester.daily +- Tests that should run **every day** on a harvester setup + ##### pit.weekly - Tests that should run **once per week** diff --git a/validation/fleet/public_gitrepo_test.go b/validation/fleet/public_gitrepo_test.go index ce35f184a..296c71f0a 100644 --- a/validation/fleet/public_gitrepo_test.go +++ b/validation/fleet/public_gitrepo_test.go @@ -1,4 +1,4 @@ -//go:build validation || sanity || pit.daily +//go:build validation || sanity || pit.daily || pit.harvester.daily package fleet diff --git a/validation/harvester/provisioning/cloud_provider_test.go b/validation/harvester/provisioning/cloud_provider_test.go new file mode 100644 index 000000000..a6f586acc --- /dev/null +++ b/validation/harvester/provisioning/cloud_provider_test.go @@ -0,0 +1,100 @@ +//go:build validation || recurring || pit.harvester.daily + +package harvester + +import ( + "os" + "testing" + + "github.com/rancher/shepherd/clients/rancher" + "github.com/rancher/shepherd/extensions/cloudcredentials" + "github.com/rancher/shepherd/extensions/defaults/providers" + "github.com/rancher/shepherd/pkg/config" + "github.com/rancher/shepherd/pkg/config/operations" + "github.com/rancher/shepherd/pkg/session" + "github.com/rancher/tests/actions/clusters" + "github.com/rancher/tests/actions/config/defaults" + "github.com/rancher/tests/actions/provisioning" + "github.com/rancher/tests/actions/provisioninginput" + "github.com/rancher/tests/actions/qase" + "github.com/rancher/tests/actions/workloads/deployment" + "github.com/rancher/tests/actions/workloads/pods" + "github.com/sirupsen/logrus" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" +) + +type HarvesterProvisioningTestSuite struct { + suite.Suite + client *rancher.Client + session *session.Session + cattleConfig map[string]any +} + +func (p *HarvesterProvisioningTestSuite) TearDownSuite() { + p.session.Cleanup() +} + +func (p *HarvesterProvisioningTestSuite) SetupSuite() { + testSession := session.NewSession() + p.session = testSession + + client, err := rancher.NewClient("", testSession) + require.NoError(p.T(), err) + + p.client = client + + p.cattleConfig = config.LoadConfigFromFile(os.Getenv(config.ConfigEnvironmentKey)) + + p.cattleConfig, err = defaults.SetK8sDefault(client, defaults.RKE2, p.cattleConfig) + require.NoError(p.T(), err) +} + +func (p *HarvesterProvisioningTestSuite) TestCloudProvider() { + + nodeRolesDedicated := []provisioninginput.MachinePools{provisioninginput.EtcdMachinePool, provisioninginput.ControlPlaneMachinePool, provisioninginput.WorkerMachinePool} + nodeRolesDedicated[0].MachinePoolConfig.Quantity = 1 + nodeRolesDedicated[1].MachinePoolConfig.Quantity = 2 + nodeRolesDedicated[2].MachinePoolConfig.Quantity = 2 + clusterConfig := new(clusters.ClusterConfig) + operations.LoadObjectFromMap(defaults.ClusterConfigKey, p.cattleConfig, clusterConfig) + var err error + + clusterConfig.Provider = providers.Harvester + clusterConfig.MachinePools = nodeRolesDedicated + + provider := provisioning.CreateProvider(clusterConfig.Provider) + credentialSpec := cloudcredentials.LoadCloudCredential(string(provider.Name)) + machineConfigSpec := provider.LoadMachineConfigFunc(p.cattleConfig) + + logrus.Infof("Provisioning cluster") + cluster, err := provisioning.CreateProvisioningCluster(p.client, provider, credentialSpec, clusterConfig, machineConfigSpec, nil) + require.NoError(p.T(), err) + + logrus.Infof("Verifying the cluster is ready (%s)", cluster.Name) + provisioning.VerifyClusterReady(p.T(), p.client, cluster) + + logrus.Infof("Verifying cluster deployments (%s)", cluster.Name) + err = deployment.VerifyClusterDeployments(p.client, cluster) + require.NoError(p.T(), err) + + logrus.Infof("Verifying cluster pods (%s)", cluster.Name) + err = pods.VerifyClusterPods(p.client, cluster) + require.NoError(p.T(), err) + + logrus.Infof("Verifying cloud provider (%s)", cluster.Name) + provider.VerifyCloudProviderFunc(p.T(), p.client, cluster) + + params := provisioning.GetProvisioningSchemaParams(p.client, p.cattleConfig) + err = qase.UpdateSchemaParameters("Harvester_oot", params) + if err != nil { + logrus.Warningf("Failed to upload schema parameters %s", err) + } + +} + +// In order for 'go test' to run this suite, we need to create +// a normal test function and pass our suite to suite.Run +func TestHarvesterProvisioningTestSuite(t *testing.T) { + suite.Run(t, new(HarvesterProvisioningTestSuite)) +} diff --git a/validation/harvester/schemas/harvester_schemas.yaml b/validation/harvester/schemas/harvester_schemas.yaml index 4c275eaa6..710ad3383 100644 --- a/validation/harvester/schemas/harvester_schemas.yaml +++ b/validation/harvester/schemas/harvester_schemas.yaml @@ -34,7 +34,7 @@ custom_field: "15": "TestRKE2ProvisioningTestSuite TestK3SProvisioningTestSuite TestRKE1ProvisioningTestSuite" - title: "Node Driver Cloud Provider RKE2 - Loadbalancing and Storage" - description: "TestRKE2ProvisioningTestSuite TestK3SProvisioningTestSuite TestRKE1ProvisioningTestSuite" + description: "HarvesterProvisioningTestSuite" automation: 2 steps: - action: "Prerequisites" @@ -50,7 +50,7 @@ expectedresult: "writing and reading file(s) in the mountpoint are successful" position: 3 custom_field: - "15": "TestRKE2ProvisioningTestSuite TestK3SProvisioningTestSuite TestRKE1ProvisioningTestSuite" + "15": "HarvesterProvisioningTestSuite" - title: "Custom Cluster Provisioning" description: "TestCustomClusterRKE2ProvisioningTestSuite TestCustomClusterK3SProvisioningTestSuite TestCustomClusterRKE1ProvisioningTestSuite" automation: 2 diff --git a/validation/longhorn/chartinstall/installation_test.go b/validation/longhorn/chartinstall/installation_test.go index 1ed4c826d..e02ed22ab 100644 --- a/validation/longhorn/chartinstall/installation_test.go +++ b/validation/longhorn/chartinstall/installation_test.go @@ -1,4 +1,4 @@ -//go:build validation || pit.daily +//go:build validation || pit.daily || pit.harvester.daily package longhorn diff --git a/validation/networking/connectivity/network_policy_test.go b/validation/networking/connectivity/network_policy_test.go index fc9a7b954..8a28acb52 100644 --- a/validation/networking/connectivity/network_policy_test.go +++ b/validation/networking/connectivity/network_policy_test.go @@ -1,4 +1,4 @@ -//go:build (validation || infra.rke2k3s || cluster.any || sanity || pit.daily) && !stress && !extended +//go:build (validation || infra.rke2k3s || cluster.any || sanity || pit.daily || pit.harvester.daily) && !stress && !extended package connectivity diff --git a/validation/workloads/workload_test.go b/validation/workloads/workload_test.go index 2f0d734a0..f654a709d 100644 --- a/validation/workloads/workload_test.go +++ b/validation/workloads/workload_test.go @@ -1,4 +1,4 @@ -//go:build (validation || infra.any || cluster.any || sanity || pit.daily) && !stress && !extended +//go:build (validation || infra.any || cluster.any || sanity || pit.daily || pit.harvester.daily) && !stress && !extended package workloads