@@ -28,8 +28,8 @@ import (
2828 "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/ovhcloud/sdk"
2929)
3030
31- func newTestProvider ( t * testing. T ) * OVHCloudProvider {
32- cfg : = `{
31+ const (
32+ ovhConsumerConfiguration = `{
3333 "project_id": "projectID",
3434 "cluster_id": "clusterID",
3535 "authentication_type": "consumer",
@@ -38,10 +38,30 @@ func newTestProvider(t *testing.T) *OVHCloudProvider {
3838 "application_secret": "secret",
3939 "application_consumer_key": "consumer_key"
4040 }`
41+ openstackUserPasswordConfiguration = `{
42+ "project_id": "projectID",
43+ "cluster_id": "clusterID",
44+ "authentication_type": "openstack",
45+ "openstack_auth_url": "https://auth.local",
46+ "openstack_domain": "Default",
47+ "openstack_username": "user",
48+ "openstack_password": "password"
49+ }`
50+ openstackApplicationCredentialsConfiguration = `{
51+ "project_id": "projectID",
52+ "cluster_id": "clusterID",
53+ "authentication_type": "openstack_application",
54+ "openstack_auth_url": "https://auth.local",
55+ "openstack_domain": "Default",
56+ "openstack_application_credential_id": "credential_id",
57+ "openstack_application_credential_secret": "credential_secret"
58+ }`
59+ )
4160
61+ func newTestProvider (t * testing.T , cfg string ) (* OVHCloudProvider , error ) {
4262 manager , err := NewManager (bytes .NewBufferString (cfg ))
4363 if err != nil {
44- assert . FailNow ( t , "failed to create manager" , err )
64+ return nil , err
4565 }
4666
4767 client := & sdk.ClientMock {}
@@ -110,19 +130,38 @@ func newTestProvider(t *testing.T) *OVHCloudProvider {
110130 }
111131
112132 err = provider .Refresh ()
113- assert .NoError (t , err )
133+ if err != nil {
134+ return provider , err
135+ }
114136
115- return provider
137+ return provider , nil
116138}
117139
118140func TestOVHCloudProvider_BuildOVHcloud (t * testing.T ) {
119141 t .Run ("create new OVHcloud provider" , func (t * testing.T ) {
120- _ = newTestProvider (t )
142+ _ , err := newTestProvider (t , ovhConsumerConfiguration )
143+ assert .NoError (t , err )
144+ })
145+ }
146+
147+ // TestOVHCloudProvider_BuildOVHcloudOpenstackConfig validates that the configuration file is correct and the auth server is being resolved.
148+ func TestOVHCloudProvider_BuildOVHcloudOpenstackConfig (t * testing.T ) {
149+ t .Run ("create new OVHcloud provider" , func (t * testing.T ) {
150+ _ , err := newTestProvider (t , openstackUserPasswordConfiguration )
151+ assert .ErrorContains (t , err , "lookup auth.local" )
152+ })
153+ }
154+
155+ func TestOVHCloudProvider_BuildOVHcloudOpenstackApplicationConfig (t * testing.T ) {
156+ t .Run ("create new OVHcloud provider" , func (t * testing.T ) {
157+ _ , err := newTestProvider (t , openstackApplicationCredentialsConfiguration )
158+ assert .ErrorContains (t , err , "lookup auth.local" )
121159 })
122160}
123161
124162func TestOVHCloudProvider_Name (t * testing.T ) {
125- provider := newTestProvider (t )
163+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
164+ assert .NoError (t , err )
126165
127166 t .Run ("check OVHcloud provider name" , func (t * testing.T ) {
128167 name := provider .Name ()
@@ -132,7 +171,8 @@ func TestOVHCloudProvider_Name(t *testing.T) {
132171}
133172
134173func TestOVHCloudProvider_NodeGroups (t * testing.T ) {
135- provider := newTestProvider (t )
174+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
175+ assert .NoError (t , err )
136176
137177 t .Run ("check default node groups length" , func (t * testing.T ) {
138178 groups := provider .NodeGroups ()
@@ -149,7 +189,8 @@ func TestOVHCloudProvider_NodeGroups(t *testing.T) {
149189}
150190
151191func TestOVHCloudProvider_NodeGroupForNode (t * testing.T ) {
152- provider := newTestProvider (t )
192+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
193+ assert .NoError (t , err )
153194
154195 ListNodePoolNodesCall1 := provider .manager .Client .(* sdk.ClientMock ).On (
155196 "ListNodePoolNodes" ,
@@ -317,7 +358,8 @@ func TestOVHCloudProvider_NodeGroupForNode(t *testing.T) {
317358}
318359
319360func TestOVHCloudProvider_Pricing (t * testing.T ) {
320- provider := newTestProvider (t )
361+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
362+ assert .NoError (t , err )
321363
322364 t .Run ("not implemented" , func (t * testing.T ) {
323365 _ , err := provider .Pricing ()
@@ -326,7 +368,8 @@ func TestOVHCloudProvider_Pricing(t *testing.T) {
326368}
327369
328370func TestOVHCloudProvider_GetAvailableMachineTypes (t * testing.T ) {
329- provider := newTestProvider (t )
371+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
372+ assert .NoError (t , err )
330373
331374 t .Run ("check available machine types" , func (t * testing.T ) {
332375 flavors , err := provider .GetAvailableMachineTypes ()
@@ -337,7 +380,8 @@ func TestOVHCloudProvider_GetAvailableMachineTypes(t *testing.T) {
337380}
338381
339382func TestOVHCloudProvider_NewNodeGroup (t * testing.T ) {
340- provider := newTestProvider (t )
383+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
384+ assert .NoError (t , err )
341385
342386 t .Run ("check new node group default values" , func (t * testing.T ) {
343387 group , err := provider .NewNodeGroup ("b2-7" , nil , nil , nil , nil )
@@ -350,7 +394,8 @@ func TestOVHCloudProvider_NewNodeGroup(t *testing.T) {
350394}
351395
352396func TestOVHCloudProvider_GetResourceLimiter (t * testing.T ) {
353- provider := newTestProvider (t )
397+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
398+ assert .NoError (t , err )
354399
355400 t .Run ("check default resource limiter values" , func (t * testing.T ) {
356401 rl , err := provider .GetResourceLimiter ()
@@ -370,7 +415,8 @@ func TestOVHCloudProvider_GetResourceLimiter(t *testing.T) {
370415}
371416
372417func TestOVHCloudProvider_GPULabel (t * testing.T ) {
373- provider := newTestProvider (t )
418+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
419+ assert .NoError (t , err )
374420
375421 t .Run ("check gpu label annotation" , func (t * testing.T ) {
376422 label := provider .GPULabel ()
@@ -380,7 +426,8 @@ func TestOVHCloudProvider_GPULabel(t *testing.T) {
380426}
381427
382428func TestOVHCloudProvider_GetAvailableGPUTypes (t * testing.T ) {
383- provider := newTestProvider (t )
429+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
430+ assert .NoError (t , err )
384431
385432 t .Run ("check available gpu machine types" , func (t * testing.T ) {
386433 flavors := provider .GetAvailableGPUTypes ()
@@ -391,7 +438,8 @@ func TestOVHCloudProvider_GetAvailableGPUTypes(t *testing.T) {
391438}
392439
393440func TestOVHCloudProvider_Cleanup (t * testing.T ) {
394- provider := newTestProvider (t )
441+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
442+ assert .NoError (t , err )
395443
396444 t .Run ("check return nil" , func (t * testing.T ) {
397445 err := provider .Cleanup ()
@@ -400,7 +448,8 @@ func TestOVHCloudProvider_Cleanup(t *testing.T) {
400448}
401449
402450func TestOVHCloudProvider_Refresh (t * testing.T ) {
403- provider := newTestProvider (t )
451+ provider , err := newTestProvider (t , ovhConsumerConfiguration )
452+ assert .NoError (t , err )
404453
405454 t .Run ("check refresh reset node groups correctly" , func (t * testing.T ) {
406455 provider .manager .NodePoolsPerID = map [string ]* sdk.NodePool {}
0 commit comments