Skip to content

Commit 9cf3052

Browse files
committed
Add additional test cases
Signed-off-by: Evan Lezar <[email protected]>
1 parent 36f8eef commit 9cf3052

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

pkg/mig/reconfigure/reconfigure_test.go

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,183 @@ func TestReconfigure(t *testing.T) {
127127
},
128128
expectedError: fmt.Errorf(`unable to get the value of the "example.com/config.state" label: error getting label`),
129129
},
130+
{
131+
description: "reconfigure exits if config is applied",
132+
options: reconfigureMIGOptions{
133+
NodeName: "NodeName",
134+
MIGPartedConfigFile: "/path/to/config/file.yaml",
135+
SelectedMIGConfig: "selected-mig-config",
136+
DriverLibraryPath: "/path/to/libnvidia-ml.so.1",
137+
HostRootMount: "/host/",
138+
ConfigStateLabel: "example.com/config.state",
139+
},
140+
migParted: &migPartedMock{
141+
assertValidMIGConfigFunc: func() error {
142+
return nil
143+
},
144+
assertMIGConfigFunc: func() error {
145+
return nil
146+
},
147+
},
148+
checkMigParted: func(mpm *migPartedMock) {
149+
require.Len(t, mpm.calls.assertValidMIGConfig, 1)
150+
require.Len(t, mpm.calls.assertMIGConfig, 1)
151+
require.Len(t, mpm.calls.applyMIGConfig, 0)
152+
require.Len(t, mpm.calls.assertMIGModeOnly, 0)
153+
require.Len(t, mpm.calls.applyMIGModeOnly, 0)
154+
},
155+
nodeLabeller: &nodeWithLabels{
156+
mock: &nodeLabellerMock{
157+
getNodeLabelValueFunc: func(s string) (string, error) {
158+
return "current-state", nil
159+
},
160+
},
161+
},
162+
checkNodeLabeller: func(nwl *nodeWithLabels) {
163+
calls := nwl.mock.getNodeLabelValueCalls()
164+
require.Len(t, calls, 1)
165+
require.EqualValues(t, []struct{ S string }{{"example.com/config.state"}}, calls)
166+
},
167+
expectedError: nil,
168+
},
169+
{
170+
description: "mode change required after reboot is error",
171+
options: reconfigureMIGOptions{
172+
NodeName: "NodeName",
173+
MIGPartedConfigFile: "/path/to/config/file.yaml",
174+
SelectedMIGConfig: "selected-mig-config",
175+
DriverLibraryPath: "/path/to/libnvidia-ml.so.1",
176+
HostRootMount: "/host/",
177+
ConfigStateLabel: "example.com/config.state",
178+
},
179+
migParted: &migPartedMock{
180+
assertValidMIGConfigFunc: func() error {
181+
return nil
182+
},
183+
assertMIGConfigFunc: func() error {
184+
return fmt.Errorf("config needs updating")
185+
},
186+
assertMIGModeOnlyFunc: func() error {
187+
return fmt.Errorf("mode needs updating")
188+
},
189+
},
190+
checkMigParted: func(mpm *migPartedMock) {
191+
require.Len(t, mpm.calls.assertValidMIGConfig, 1)
192+
require.Len(t, mpm.calls.assertMIGConfig, 1)
193+
require.Len(t, mpm.calls.assertMIGModeOnly, 1)
194+
require.Len(t, mpm.calls.applyMIGConfig, 0)
195+
require.Len(t, mpm.calls.applyMIGModeOnly, 0)
196+
},
197+
nodeLabeller: &nodeWithLabels{
198+
mock: &nodeLabellerMock{
199+
getNodeLabelValueFunc: func(s string) (string, error) {
200+
return "rebooting", nil
201+
},
202+
},
203+
},
204+
checkNodeLabeller: func(nwl *nodeWithLabels) {
205+
calls := nwl.mock.getNodeLabelValueCalls()
206+
require.Len(t, calls, 1)
207+
require.EqualValues(t, []struct{ S string }{{"example.com/config.state"}}, calls)
208+
},
209+
expectedError: fmt.Errorf("MIG mode change failed after reboot: mode needs updating"),
210+
},
211+
{
212+
description: "mode does not need updating; apply config error is returned",
213+
options: reconfigureMIGOptions{
214+
NodeName: "NodeName",
215+
MIGPartedConfigFile: "/path/to/config/file.yaml",
216+
SelectedMIGConfig: "selected-mig-config",
217+
DriverLibraryPath: "/path/to/libnvidia-ml.so.1",
218+
HostRootMount: "/host/",
219+
ConfigStateLabel: "example.com/config.state",
220+
},
221+
migParted: &migPartedMock{
222+
assertValidMIGConfigFunc: func() error {
223+
return nil
224+
},
225+
assertMIGConfigFunc: func() error {
226+
return fmt.Errorf("config needs updating")
227+
},
228+
assertMIGModeOnlyFunc: func() error {
229+
return nil
230+
},
231+
applyMIGModeOnlyFunc: func() error {
232+
return nil
233+
},
234+
applyMIGConfigFunc: func() error {
235+
return fmt.Errorf("failed to apply config")
236+
},
237+
},
238+
checkMigParted: func(mpm *migPartedMock) {
239+
require.Len(t, mpm.calls.assertValidMIGConfig, 1)
240+
require.Len(t, mpm.calls.assertMIGConfig, 1)
241+
require.Len(t, mpm.calls.assertMIGModeOnly, 2)
242+
require.Len(t, mpm.calls.applyMIGModeOnly, 1)
243+
require.Len(t, mpm.calls.applyMIGConfig, 1)
244+
},
245+
nodeLabeller: &nodeWithLabels{
246+
mock: &nodeLabellerMock{
247+
getNodeLabelValueFunc: func(s string) (string, error) {
248+
return "current-state", nil
249+
},
250+
},
251+
},
252+
checkNodeLabeller: func(nwl *nodeWithLabels) {
253+
calls := nwl.mock.getNodeLabelValueCalls()
254+
require.Len(t, calls, 1)
255+
require.EqualValues(t, []struct{ S string }{{"example.com/config.state"}}, calls)
256+
},
257+
expectedError: fmt.Errorf("failed to apply config"),
258+
},
259+
{
260+
description: "mode does not need updating; apply config succeeds",
261+
options: reconfigureMIGOptions{
262+
NodeName: "NodeName",
263+
MIGPartedConfigFile: "/path/to/config/file.yaml",
264+
SelectedMIGConfig: "selected-mig-config",
265+
DriverLibraryPath: "/path/to/libnvidia-ml.so.1",
266+
HostRootMount: "/host/",
267+
ConfigStateLabel: "example.com/config.state",
268+
},
269+
migParted: &migPartedMock{
270+
assertValidMIGConfigFunc: func() error {
271+
return nil
272+
},
273+
assertMIGConfigFunc: func() error {
274+
return fmt.Errorf("config needs updating")
275+
},
276+
assertMIGModeOnlyFunc: func() error {
277+
return nil
278+
},
279+
applyMIGModeOnlyFunc: func() error {
280+
return nil
281+
},
282+
applyMIGConfigFunc: func() error {
283+
return nil
284+
},
285+
},
286+
checkMigParted: func(mpm *migPartedMock) {
287+
require.Len(t, mpm.calls.assertValidMIGConfig, 1)
288+
require.Len(t, mpm.calls.assertMIGConfig, 1)
289+
require.Len(t, mpm.calls.assertMIGModeOnly, 2)
290+
require.Len(t, mpm.calls.applyMIGModeOnly, 1)
291+
require.Len(t, mpm.calls.applyMIGConfig, 1)
292+
},
293+
nodeLabeller: &nodeWithLabels{
294+
mock: &nodeLabellerMock{
295+
getNodeLabelValueFunc: func(s string) (string, error) {
296+
return "current-state", nil
297+
},
298+
},
299+
},
300+
checkNodeLabeller: func(nwl *nodeWithLabels) {
301+
calls := nwl.mock.getNodeLabelValueCalls()
302+
require.Len(t, calls, 1)
303+
require.EqualValues(t, []struct{ S string }{{"example.com/config.state"}}, calls)
304+
},
305+
expectedError: nil,
306+
},
130307
}
131308

132309
for _, tc := range testCases {

0 commit comments

Comments
 (0)