Skip to content

Commit 604def9

Browse files
authored
Merge pull request #400 from laozc/wmi-library-bump-wmi
cleanup: Bump microsoft/wmi to 0.34.0 containing WMI method call fix (library version)
2 parents e57d358 + a7f4365 commit 604def9

File tree

12 files changed

+310
-166
lines changed

12 files changed

+310
-166
lines changed

.github/workflows/windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
integration_tests:
66
strategy:
77
matrix:
8-
go: ['1.22']
8+
go: ['1.24']
99
platform: [windows-latest]
1010
runs-on: ${{ matrix.platform }}
1111
steps:
@@ -30,7 +30,7 @@ jobs:
3030
unit_tests:
3131
strategy:
3232
matrix:
33-
go: ['1.22']
33+
go: ['1.24']
3434
platform: [windows-latest]
3535
runs-on: ${{ matrix.platform }}
3636
steps:

go.mod

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
module github.com/kubernetes-csi/csi-proxy/v2
22

3-
go 1.22
3+
go 1.24.3
4+
5+
godebug winsymlink=0
6+
7+
toolchain go1.24.4
48

59
require (
610
github.com/go-ole/go-ole v1.3.0
7-
github.com/microsoft/wmi v0.25.1
11+
github.com/microsoft/wmi v0.34.0
812
github.com/pkg/errors v0.9.1
913
github.com/stretchr/testify v1.7.0
10-
golang.org/x/sys v0.25.0
14+
golang.org/x/sys v0.32.0
1115
k8s.io/klog/v2 v2.9.0
1216
)
1317

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc=
55
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
66
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
77
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
8-
github.com/microsoft/wmi v0.25.1 h1:sQv9hCEHtW5K6yEVL78T6XGRMGxk4aTpcJwCiB5rLN0=
9-
github.com/microsoft/wmi v0.25.1/go.mod h1:1zbdSF0A+5OwTUII5p3hN7/K6KF2m3o27pSG6Y51VU8=
8+
github.com/microsoft/wmi v0.34.0 h1:1OqBM8Ha8CWMbKYDH6EqUmozgxZ0IuoYwtLkgsJj2zc=
9+
github.com/microsoft/wmi v0.34.0/go.mod h1:uImvBuQss3NEnzU5bcwq0DsUh54seU3Sl//oBn62LDw=
1010
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
1111
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1212
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -15,8 +15,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
1515
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1616
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1717
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
18-
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
19-
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
18+
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
19+
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
2020
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2121
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2222
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/cim/wmi.go

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"runtime"
1010

1111
"github.com/go-ole/go-ole"
12-
"github.com/go-ole/go-ole/oleutil"
1312
"github.com/microsoft/wmi/pkg/base/query"
1413
wmierrors "github.com/microsoft/wmi/pkg/errors"
1514
cim "github.com/microsoft/wmi/pkg/wmiinstance"
@@ -91,105 +90,6 @@ func QueryInstances(namespace string, query *query.WmiQuery) ([]*cim.WmiInstance
9190
return instances, err
9291
}
9392

94-
// TODO: fix the panic in microsoft/wmi library and remove this workaround
95-
// Refer to https://github.com/microsoft/wmi/issues/167
96-
func executeClassMethodParam(classInst *cim.WmiInstance, method *cim.WmiMethod, inParam, outParam cim.WmiMethodParamCollection) (result *cim.WmiMethodResult, err error) {
97-
klog.V(6).Infof("[WMI] - Executing Method [%s]\n", method.Name)
98-
99-
iDispatchInstance := classInst.GetIDispatch()
100-
if iDispatchInstance == nil {
101-
return nil, wmierrors.Wrapf(wmierrors.InvalidInput, "InvalidInstance")
102-
}
103-
rawResult, err := iDispatchInstance.GetProperty("Methods_")
104-
if err != nil {
105-
return nil, err
106-
}
107-
defer rawResult.Clear()
108-
// Retrieve the method
109-
rawMethod, err := rawResult.ToIDispatch().CallMethod("Item", method.Name)
110-
if err != nil {
111-
return nil, err
112-
}
113-
defer rawMethod.Clear()
114-
115-
addInParam := func(inparamVariant *ole.VARIANT, paramName string, paramValue interface{}) error {
116-
rawProperties, err := inparamVariant.ToIDispatch().GetProperty("Properties_")
117-
if err != nil {
118-
return err
119-
}
120-
defer rawProperties.Clear()
121-
rawProperty, err := rawProperties.ToIDispatch().CallMethod("Item", paramName)
122-
if err != nil {
123-
return err
124-
}
125-
defer rawProperty.Clear()
126-
127-
p, err := rawProperty.ToIDispatch().PutProperty("Value", paramValue)
128-
if err != nil {
129-
return err
130-
}
131-
defer p.Clear()
132-
return nil
133-
}
134-
135-
params := []interface{}{method.Name}
136-
if len(inParam) > 0 {
137-
inparamsRaw, err := rawMethod.ToIDispatch().GetProperty("InParameters")
138-
if err != nil {
139-
return nil, err
140-
}
141-
defer inparamsRaw.Clear()
142-
143-
inparams, err := oleutil.CallMethod(inparamsRaw.ToIDispatch(), "SpawnInstance_")
144-
if err != nil {
145-
return nil, err
146-
}
147-
defer inparams.Clear()
148-
149-
for _, inp := range inParam {
150-
addInParam(inparams, inp.Name, inp.Value)
151-
}
152-
153-
params = append(params, inparams)
154-
}
155-
156-
result = &cim.WmiMethodResult{
157-
OutMethodParams: map[string]*cim.WmiMethodParam{},
158-
}
159-
outparams, err := classInst.GetIDispatch().CallMethod("ExecMethod_", params...)
160-
if err != nil {
161-
return
162-
}
163-
defer outparams.Clear()
164-
returnRaw, err := outparams.ToIDispatch().GetProperty("ReturnValue")
165-
if err != nil {
166-
return
167-
}
168-
defer returnRaw.Clear()
169-
if returnRaw.Value() != nil {
170-
result.ReturnValue = returnRaw.Value().(int32)
171-
klog.V(6).Infof("[WMI] - Return [%d] ", result.ReturnValue)
172-
}
173-
174-
for _, outp := range outParam {
175-
returnRawIn, err1 := outparams.ToIDispatch().GetProperty(outp.Name)
176-
if err1 != nil {
177-
err = err1
178-
return
179-
}
180-
defer returnRawIn.Clear()
181-
182-
value, err1 := cim.GetVariantValue(returnRawIn)
183-
if err1 != nil {
184-
err = err1
185-
return
186-
}
187-
188-
result.OutMethodParams[outp.Name] = cim.NewWmiMethodParam(outp.Name, value)
189-
}
190-
return
191-
}
192-
19393
// InvokeCimMethod calls a static method on a specific WMI class with given input parameters,
19494
// returning the method's return value, output parameters, and any error encountered.
19595
func InvokeCimMethod(namespace, class, methodName string, inputParameters map[string]interface{}) (int, map[string]interface{}, error) {
@@ -225,7 +125,7 @@ func InvokeCimMethod(namespace, class, methodName string, inputParameters map[st
225125

226126
var outParam cim.WmiMethodParamCollection
227127
var result *cim.WmiMethodResult
228-
result, err = executeClassMethodParam(classInst, method, inParam, outParam)
128+
result, err = method.Execute(inParam, outParam)
229129
if err != nil {
230130
return -1, nil, err
231131
}

vendor/github.com/microsoft/wmi/pkg/base/instance/instancemanager.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/microsoft/wmi/pkg/errors/errors.go

Lines changed: 15 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/microsoft/wmi/pkg/wmiinstance/WmiMethod.go

Lines changed: 24 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/sys/windows/dll_windows.go

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)