From 4a98fb20133363be27a501d3c0e1a61877058f5e Mon Sep 17 00:00:00 2001 From: Lukas Piwowarski Date: Wed, 22 Nov 2023 17:57:42 +0200 Subject: [PATCH] Add support for external plugins This patch ensures that the test operator takes advantage of the new parameters of the tempest container: - TEMPEST_EXTERNAL_PLUGIN_GIT_URL - TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL - TEMPEST_EXTERNAL_PLUGIN_REFSPEC The user can use these parameters by specifying the following values for the Tempest CR: - tempestRun.externalPlugin.repository - tempestRun.externalPlugin.changeRepository - tempestRun.externalPlugin.changeRefspec --- api/bases/test.openstack.org_tempests.yaml | 26 ++++++++++++++++ api/v1beta1/tempest_types.go | 30 +++++++++++++++++++ api/v1beta1/zz_generated.deepcopy.go | 22 +++++++++++++- .../bases/test.openstack.org_tempests.yaml | 26 ++++++++++++++++ config/manager/kustomization.yaml | 5 ++++ config/samples/test_v1beta1_tempest.yaml | 5 ++++ controllers/tempest_controller.go | 19 ++++++++++-- docs/source/samples/tempest-config.yaml | 3 ++ 8 files changed, 133 insertions(+), 3 deletions(-) diff --git a/api/bases/test.openstack.org_tempests.yaml b/api/bases/test.openstack.org_tempests.yaml index 191dddb5..6cf3572c 100644 --- a/api/bases/test.openstack.org_tempests.yaml +++ b/api/bases/test.openstack.org_tempests.yaml @@ -121,6 +121,32 @@ spec: default: "" description: ExcludeList type: string + externalPlugin: + description: ExternalPlugin contains information about plugin + that should be installed within the tempest container. If this + option is specified then only tests that are part of the external + plugin can be executed. + items: + properties: + changeRefspec: + default: "" + description: ChangeRefspec specifies which change the remote + repository should be checked out to (ChangeRepository + must be defined as well). + type: string + changeRepository: + default: "" + description: URL that points to a repository that contains + a change that should be applied to the repository defined + by Repository (ChangeRefspec must be defined as well). + type: string + repository: + default: "" + description: URL that points to a git repository containing + the external plugin. + type: string + type: object + type: array includeList: default: tempest.api.identity.v3 description: IncludeList diff --git a/api/v1beta1/tempest_types.go b/api/v1beta1/tempest_types.go index e8bbcee7..8635ed5b 100644 --- a/api/v1beta1/tempest_types.go +++ b/api/v1beta1/tempest_types.go @@ -35,6 +35,29 @@ type Hash struct { Hash string `json:"hash,omitempty"` } + +type ExternalPluginType struct { + // +kubebuilder:validation:Optional + // +kubebuilder:default="" + // URL that points to a git repository containing + // the external plugin. + Repository string `json:"repository,omitempty"` + + // +kubebuilder:validation:Optional + // +kubebuilder:default="" + // URL that points to a repository that contains a change + // that should be applied to the repository defined by Repository + // (ChangeRefspec must be defined as well). + ChangeRepository string `json:"changeRepository,omitempty"` + + // +kubebuilder:validation:Optional + // +kubebuilder:default="" + // ChangeRefspec specifies which change the remote repository + // should be checked out to (ChangeRepository must be defined + // as well). + ChangeRefspec string `json:"changeRefspec,omitempty"` +} + // TempestSpec TempestRun parts type TempestRunSpec struct { // +kubebuilder:validation:Optional @@ -71,6 +94,13 @@ type TempestRunSpec struct { // +kubebuilder:default:="" // WorkerFile is the detailed concurrency spec file WorkerFile string `json:"workerFile,omitempty"` + + // +kubebuilder:validation:Optional + // ExternalPlugin contains information about plugin + // that should be installed within the tempest container. + // If this option is specified then only tests that are part of + // the external plugin can be executed. + ExternalPlugin []ExternalPluginType `json:"externalPlugin,omitempty"` } // TempestSpec PythonTempestconf parts diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index ad5c474a..e915cf49 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -26,6 +26,21 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExternalPluginType) DeepCopyInto(out *ExternalPluginType) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalPluginType. +func (in *ExternalPluginType) DeepCopy() *ExternalPluginType { + if in == nil { + return nil + } + out := new(ExternalPluginType) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Hash) DeepCopyInto(out *Hash) { *out = *in @@ -123,6 +138,11 @@ func (in *TempestList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TempestRunSpec) DeepCopyInto(out *TempestRunSpec) { *out = *in + if in.ExternalPlugin != nil { + in, out := &in.ExternalPlugin, &out.ExternalPlugin + *out = make([]ExternalPluginType, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TempestRunSpec. @@ -165,7 +185,7 @@ func (in *TempestSpec) DeepCopyInto(out *TempestSpec) { if in.TempestRun != nil { in, out := &in.TempestRun, &out.TempestRun *out = new(TempestRunSpec) - **out = **in + (*in).DeepCopyInto(*out) } if in.TempestconfRun != nil { in, out := &in.TempestconfRun, &out.TempestconfRun diff --git a/config/crd/bases/test.openstack.org_tempests.yaml b/config/crd/bases/test.openstack.org_tempests.yaml index 191dddb5..6cf3572c 100644 --- a/config/crd/bases/test.openstack.org_tempests.yaml +++ b/config/crd/bases/test.openstack.org_tempests.yaml @@ -121,6 +121,32 @@ spec: default: "" description: ExcludeList type: string + externalPlugin: + description: ExternalPlugin contains information about plugin + that should be installed within the tempest container. If this + option is specified then only tests that are part of the external + plugin can be executed. + items: + properties: + changeRefspec: + default: "" + description: ChangeRefspec specifies which change the remote + repository should be checked out to (ChangeRepository + must be defined as well). + type: string + changeRepository: + default: "" + description: URL that points to a repository that contains + a change that should be applied to the repository defined + by Repository (ChangeRefspec must be defined as well). + type: string + repository: + default: "" + description: URL that points to a git repository containing + the external plugin. + type: string + type: object + type: array includeList: default: tempest.api.identity.v3 description: IncludeList diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 5c5f0b84..9bded114 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,7 @@ resources: - manager.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +images: +- name: controller + newName: quay.io/openstack-k8s-operators/test-operator-index diff --git a/config/samples/test_v1beta1_tempest.yaml b/config/samples/test_v1beta1_tempest.yaml index de773703..8d53742d 100644 --- a/config/samples/test_v1beta1_tempest.yaml +++ b/config/samples/test_v1beta1_tempest.yaml @@ -23,6 +23,11 @@ spec: # smoke: false # serial: false # parallel: true + # externalPlugin: + # - repository: "https://opendev.org/openstack/barbican-tempest-plugin.git" + # - repository: "https://opendev.org/openstack/neutron-tempest-plugin.git" + # changeRepository: "https://review.opendev.org/openstack/neutron-tempest-plugin" + # changeRefspec: "refs/changes/97/896397/2" tempestconfRun: # NOTE: All parameters have default values (use only when you want to override # the default behaviour) diff --git a/controllers/tempest_controller.go b/controllers/tempest_controller.go index 82bff502..12129d38 100644 --- a/controllers/tempest_controller.go +++ b/controllers/tempest_controller.go @@ -392,7 +392,8 @@ func getDefaultInt(variable int64) string { func setTempestConfigVars(envVars map[string]string, customData map[string]string, - tempestRun *testv1beta1.TempestRunSpec) { + tempestRun *testv1beta1.TempestRunSpec, + ctx context.Context) { testOperatorDir := "/etc/test_operator/" if tempestRun == nil { @@ -436,6 +437,20 @@ func setTempestConfigVars(envVars map[string]string, // Int envVars["TEMPEST_CONCURRENCY"] = getDefaultInt(tempestRun.Concurrency) + + // Dictionary + for _, externalPluginDictionary := range tempestRun.ExternalPlugin { + envVars["TEMPEST_EXTERNAL_PLUGIN_GIT_URL"] += externalPluginDictionary.Repository + "," + + if len(externalPluginDictionary.ChangeRepository) == 0 || len(externalPluginDictionary.ChangeRefspec) == 0 { + envVars["TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL"] += "-," + envVars["TEMPEST_EXTERNAL_PLUGIN_REFSPEC"] += "-," + continue + } + + envVars["TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL"] += externalPluginDictionary.ChangeRepository + "," + envVars["TEMPEST_EXTERNAL_PLUGIN_REFSPEC"] += externalPluginDictionary.ChangeRefspec + "," + } } func setTempestconfConfigVars(envVars map[string]string, @@ -524,7 +539,7 @@ func (r *TempestReconciler) generateServiceConfigMaps( customData := make(map[string]string) envVars := make(map[string]string) - setTempestConfigVars(envVars, customData, instance.Spec.TempestRun) + setTempestConfigVars(envVars, customData, instance.Spec.TempestRun, ctx) setTempestconfConfigVars(envVars, customData, instance.Spec.TempestconfRun) /* Tempestconf - end */ diff --git a/docs/source/samples/tempest-config.yaml b/docs/source/samples/tempest-config.yaml index 6a46d373..34e8b6f4 100644 --- a/docs/source/samples/tempest-config.yaml +++ b/docs/source/samples/tempest-config.yaml @@ -25,6 +25,9 @@ data: # TEMPEST_SMOKE: true # TEMPEST_PARALLEL: true # TEMPEST_SERIAL: true + # TEMPEST_EXTERNAL_PLUGIN_GIT_URL: "https://opendev.org/openstack/barbican-tempest-plugin.git,https://opendev.org/openstack/neutron-tempest-plugin.git" + # TEMPEST_EXTERNAL_PLUGIN_CHANGE_URL: "-,https://review.opendev.org/openstack/neutron-tempest-plugin" + # TEMPEST_EXTERNAL_PLUGIN_REFSPEC: "-,refs/changes/97/896397/2" # TEMPESTCONF env variables: # --------------------------