@@ -17,13 +17,76 @@ limitations under the License.
17
17
package cloud_test
18
18
19
19
import (
20
+ "fmt"
21
+ "os"
20
22
"testing"
21
23
24
+ "github.com/apache/cloudstack-go/v2/cloudstack"
22
25
. "github.com/onsi/ginkgo/v2"
23
26
. "github.com/onsi/gomega"
27
+ "k8s.io/apimachinery/pkg/util/uuid"
28
+ "sigs.k8s.io/cluster-api-provider-cloudstack/pkg/cloud"
29
+ "sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies"
30
+ "sigs.k8s.io/cluster-api-provider-cloudstack/test/helpers"
31
+ )
32
+
33
+ var (
34
+ realCloudClient cloud.Client
35
+ client cloud.Client
36
+ realCSClient * cloudstack.CloudStackClient
37
+ testDomainPath string // Needed in before and in after suite.
24
38
)
25
39
26
40
func TestCloud (t * testing.T ) {
27
41
RegisterFailHandler (Fail )
42
+ BeforeSuite (func () {
43
+ // Create a real cloud client.
44
+ projDir := os .Getenv ("PROJECT_DIR" )
45
+ fmt .Println (projDir )
46
+ fmt .Println (projDir )
47
+ fmt .Println (projDir )
48
+ var connectionErr error
49
+ realCloudClient , connectionErr = cloud .NewClient (projDir + "/cloud-config" )
50
+ Ω (connectionErr ).ShouldNot (HaveOccurred ())
51
+
52
+ // Create a real CloudStack client.
53
+ realCSClient , connectionErr = helpers .NewCSClient ()
54
+ Ω (connectionErr ).ShouldNot (HaveOccurred ())
55
+
56
+ // Create a new account and user to run tests that use a real ACS instance.
57
+ uid := string (uuid .NewUUID ())
58
+ newAccount := cloud.Account {
59
+ Name : "TestAccount-" + uid ,
60
+ Domain : cloud.Domain {Name : "TestDomain-" + uid , Path : "ROOT/TestDomain-" + uid }}
61
+ newUser := cloud.User {Account : newAccount }
62
+ Ω (helpers .GetOrCreateUserWithKey (realCSClient , & newUser )).Should (Succeed ())
63
+ testDomainPath = newAccount .Domain .Path
64
+
65
+ Ω (newUser .APIKey ).ShouldNot (BeEmpty ())
66
+
67
+ // Switch to test account user.
68
+ cfg := cloud.Config {APIKey : newUser .APIKey , SecretKey : newUser .SecretKey }
69
+ realCloudClient , connectionErr = realCloudClient .NewClientFromSpec (cfg )
70
+ Ω (connectionErr ).ShouldNot (HaveOccurred ())
71
+ })
72
+ AfterSuite (func () {
73
+ if realCSClient != nil { // Check for nil in case the before suite setup failed.
74
+ // Delete created domain.
75
+ id , err , found := helpers .GetDomainByPath (realCSClient , testDomainPath )
76
+ Ω (err ).ShouldNot (HaveOccurred ())
77
+ Ω (found ).Should (BeTrue ())
78
+ Ω (helpers .DeleteDomain (realCSClient , id )).Should (Succeed ())
79
+ }
80
+ })
28
81
RunSpecs (t , "Cloud Suite" )
29
82
}
83
+
84
+ // FetchIntegTestResources runs through basic CloudStack Client setup methods needed to test others.
85
+ func FetchIntegTestResources () {
86
+ realCloudClient .ResolveZone (dummies .CSZone1 )
87
+ Ω (dummies .CSZone1 .Spec .ID ).ShouldNot (BeEmpty ())
88
+ dummies .CSMachine1 .Status .ZoneID = dummies .CSZone1 .Spec .ID
89
+ dummies .CSMachine1 .Spec .DiskOffering .Name = ""
90
+ dummies .CSCluster .Spec .ControlPlaneEndpoint .Host = ""
91
+ Ω (realCloudClient .GetOrCreateIsolatedNetwork (dummies .CSZone1 , dummies .CSISONet1 , dummies .CSCluster )).Should (Succeed ())
92
+ }
0 commit comments