2
2
// +build vdc functional openapi ALL
3
3
4
4
/*
5
- * Copyright 2020 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
5
+ * Copyright 2022 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
6
6
*/
7
7
8
8
package govcd
@@ -21,29 +21,26 @@ func (vcd *TestVCD) Test_VdcComputePolicies(check *C) {
21
21
check .Skip (fmt .Sprintf (TestRequiresSysAdminPrivileges , check .TestName ()))
22
22
}
23
23
24
- org , err := vcd .client .GetAdminOrgByName (vcd .org .Org .Name )
25
- check .Assert (err , IsNil )
26
- check .Assert (org , NotNil )
27
-
24
+ client := & vcd .client .Client
28
25
// Step 1 - Create a new VDC compute policies
29
26
newComputePolicy := & VdcComputePolicy {
30
- client : org . client ,
27
+ client : client ,
31
28
VdcComputePolicy : & types.VdcComputePolicy {
32
29
Name : check .TestName () + "_empty" ,
33
30
Description : "Empty policy created by test" ,
34
31
},
35
32
}
36
33
37
- createdPolicy , err := org .CreateVdcComputePolicy (newComputePolicy .VdcComputePolicy )
34
+ createdPolicy , err := client .CreateVdcComputePolicy (newComputePolicy .VdcComputePolicy )
38
35
check .Assert (err , IsNil )
39
36
40
- AddToCleanupList (createdPolicy .VdcComputePolicy .ID , "vdcComputePolicy" , vcd . org . Org . Name , "Test_VdcComputePolicies" )
37
+ AddToCleanupList (createdPolicy .VdcComputePolicy .ID , "vdcComputePolicy" , "" , check . TestName () )
41
38
42
39
check .Assert (createdPolicy .VdcComputePolicy .Name , Equals , newComputePolicy .VdcComputePolicy .Name )
43
40
check .Assert (createdPolicy .VdcComputePolicy .Description , Equals , newComputePolicy .VdcComputePolicy .Description )
44
41
45
42
newComputePolicy2 := & VdcComputePolicy {
46
- client : org . client ,
43
+ client : client ,
47
44
VdcComputePolicy : & types.VdcComputePolicy {
48
45
Name : check .TestName (),
49
46
Description : "Not Empty policy created by test" ,
@@ -60,10 +57,10 @@ func (vcd *TestVCD) Test_VdcComputePolicies(check *C) {
60
57
},
61
58
}
62
59
63
- createdPolicy2 , err := org .CreateVdcComputePolicy (newComputePolicy2 .VdcComputePolicy )
60
+ createdPolicy2 , err := client .CreateVdcComputePolicy (newComputePolicy2 .VdcComputePolicy )
64
61
check .Assert (err , IsNil )
65
62
66
- AddToCleanupList (createdPolicy2 .VdcComputePolicy .ID , "vdcComputePolicy" , vcd . org . Org . Name , "Test_VdcComputePolicies" )
63
+ AddToCleanupList (createdPolicy2 .VdcComputePolicy .ID , "vdcComputePolicy" , "" , check . TestName () )
67
64
68
65
check .Assert (createdPolicy2 .VdcComputePolicy .Name , Equals , newComputePolicy2 .VdcComputePolicy .Name )
69
66
check .Assert (* createdPolicy2 .VdcComputePolicy .CPUSpeed , Equals , 100 )
@@ -84,7 +81,7 @@ func (vcd *TestVCD) Test_VdcComputePolicies(check *C) {
84
81
check .Assert (updatedPolicy .VdcComputePolicy , DeepEquals , createdPolicy2 .VdcComputePolicy )
85
82
86
83
// Step 3 - Get all VDC compute policies
87
- allExistingPolicies , err := org .GetAllVdcComputePolicies (nil )
84
+ allExistingPolicies , err := client .GetAllVdcComputePolicies (nil )
88
85
check .Assert (err , IsNil )
89
86
check .Assert (allExistingPolicies , NotNil )
90
87
@@ -95,12 +92,12 @@ func (vcd *TestVCD) Test_VdcComputePolicies(check *C) {
95
92
queryParams := url.Values {}
96
93
queryParams .Add ("filter" , "id==" + onePolicy .VdcComputePolicy .ID )
97
94
98
- expectOnePolicyResultById , err := org .GetAllVdcComputePolicies (queryParams )
95
+ expectOnePolicyResultById , err := client .GetAllVdcComputePolicies (queryParams )
99
96
check .Assert (err , IsNil )
100
97
check .Assert (len (expectOnePolicyResultById ) == 1 , Equals , true )
101
98
102
99
// Step 2.2 - retrieve
103
- exactItem , err := org .GetVdcComputePolicyById (onePolicy .VdcComputePolicy .ID )
100
+ exactItem , err := client .GetVdcComputePolicyById (onePolicy .VdcComputePolicy .ID )
104
101
check .Assert (err , IsNil )
105
102
106
103
check .Assert (err , IsNil )
@@ -115,13 +112,13 @@ func (vcd *TestVCD) Test_VdcComputePolicies(check *C) {
115
112
err = createdPolicy .Delete ()
116
113
check .Assert (err , IsNil )
117
114
// Step 5 - try to read deleted VDC computed policy should end up with error 'ErrorEntityNotFound'
118
- deletedPolicy , err := org .GetVdcComputePolicyById (createdPolicy .VdcComputePolicy .ID )
115
+ deletedPolicy , err := client .GetVdcComputePolicyById (createdPolicy .VdcComputePolicy .ID )
119
116
check .Assert (ContainsNotFound (err ), Equals , true )
120
117
check .Assert (deletedPolicy , IsNil )
121
118
122
119
err = createdPolicy2 .Delete ()
123
120
check .Assert (err , IsNil )
124
- deletedPolicy2 , err := org .GetVdcComputePolicyById (createdPolicy2 .VdcComputePolicy .ID )
121
+ deletedPolicy2 , err := client .GetVdcComputePolicyById (createdPolicy2 .VdcComputePolicy .ID )
125
122
check .Assert (ContainsNotFound (err ), Equals , true )
126
123
check .Assert (deletedPolicy2 , IsNil )
127
124
}
@@ -131,6 +128,7 @@ func (vcd *TestVCD) Test_SetAssignedComputePolicies(check *C) {
131
128
check .Skip (fmt .Sprintf (TestRequiresSysAdminPrivileges , check .TestName ()))
132
129
}
133
130
131
+ client := & vcd .client .Client
134
132
org , err := vcd .client .GetAdminOrgByName (vcd .org .Org .Name )
135
133
check .Assert (err , IsNil )
136
134
check .Assert (org , NotNil )
@@ -145,29 +143,29 @@ func (vcd *TestVCD) Test_SetAssignedComputePolicies(check *C) {
145
143
client : org .client ,
146
144
VdcComputePolicy : & types.VdcComputePolicy {
147
145
Name : check .TestName () + "1" ,
148
- Description : "Policy created by Test_SetVdcComputePolicies " ,
146
+ Description : "Policy created by Test_SetAssignedComputePolicies " ,
149
147
CoresPerSocket : takeIntAddress (1 ),
150
148
CPUReservationGuarantee : takeFloatAddress (0.26 ),
151
149
CPULimit : takeIntAddress (200 ),
152
150
},
153
151
}
154
- createdPolicy , err := org .CreateVdcComputePolicy (newComputePolicy .VdcComputePolicy )
152
+ createdPolicy , err := client .CreateVdcComputePolicy (newComputePolicy .VdcComputePolicy )
155
153
check .Assert (err , IsNil )
156
- AddToCleanupList (createdPolicy .VdcComputePolicy .ID , "vdcComputePolicy" , vcd . org . Org . Name , "Test_VdcComputePolicies" )
154
+ AddToCleanupList (createdPolicy .VdcComputePolicy .ID , "vdcComputePolicy" , "" , check . TestName () )
157
155
158
156
newComputePolicy2 := & VdcComputePolicy {
159
157
client : org .client ,
160
158
VdcComputePolicy : & types.VdcComputePolicy {
161
159
Name : check .TestName () + "2" ,
162
- Description : "Policy created by Test_SetVdcComputePolicies " ,
160
+ Description : "Policy created by Test_SetAssignedComputePolicies " ,
163
161
CoresPerSocket : takeIntAddress (2 ),
164
162
CPUReservationGuarantee : takeFloatAddress (0.52 ),
165
163
CPULimit : takeIntAddress (400 ),
166
164
},
167
165
}
168
- createdPolicy2 , err := org .CreateVdcComputePolicy (newComputePolicy2 .VdcComputePolicy )
166
+ createdPolicy2 , err := client .CreateVdcComputePolicy (newComputePolicy2 .VdcComputePolicy )
169
167
check .Assert (err , IsNil )
170
- AddToCleanupList (createdPolicy2 .VdcComputePolicy .ID , "vdcComputePolicy" , vcd . org . Org . Name , "Test_VdcComputePolicies" )
168
+ AddToCleanupList (createdPolicy2 .VdcComputePolicy .ID , "vdcComputePolicy" , "" , check . TestName () )
171
169
172
170
// Get default compute policy
173
171
allAssignedComputePolicies , err := adminVdc .GetAllAssignedVdcComputePolicies (nil )
@@ -200,4 +198,9 @@ func (vcd *TestVCD) Test_SetAssignedComputePolicies(check *C) {
200
198
201
199
_ , err = adminVdc .SetAssignedComputePolicies (policyReferences )
202
200
check .Assert (err , IsNil )
201
+
202
+ err = createdPolicy .Delete ()
203
+ check .Assert (err , IsNil )
204
+ err = createdPolicy2 .Delete ()
205
+ check .Assert (err , IsNil )
203
206
}
0 commit comments