-
Notifications
You must be signed in to change notification settings - Fork 39.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unit tests for operationGenerator.GenerateUnmapVolumeFunc #78267
unit tests for operationGenerator.GenerateUnmapVolumeFunc #78267
Conversation
Hi @mucahitkurt. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @davidz627 |
f1d3605
to
3aa7f01
Compare
|
||
csiplugin, err := plugMgr.FindPluginByName(csi.CSIPluginName) | ||
if err != nil { | ||
t.Fatalf("can't find plugin %v", csi.CSIPluginName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
csi.CSIPluginName should be a string? maybe %s is more clear here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks!
|
||
_, e := plugMgr.FindPluginByName(gcePdVolumePluginName) | ||
if e != nil { | ||
t.Errorf("Can't find the plugin by name: %v", gcePdVolumePluginName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before,%s can be more clear for string gcePdVolumePluginName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks!
var ee error | ||
unmapVolumeFunc.CompleteFunc(&ee) | ||
|
||
metric_family_name := "storage_operation_status_count" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recommend to use go style for variable declarations
https://golang.org/doc/effective_go.html#mixed-caps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks!
3aa7f01
to
f44ba7e
Compare
/ok-to-test |
/test pull-kubernetes-e2e-gce-storage-slow |
I have a question about unit testing metrics, Is there any best practice to test metrics? |
name string | ||
isCsiMigrationEnabled bool | ||
expectedPluginName string | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets move this struct inside test function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks!
{ | ||
name: "csi migration disabled", | ||
isCsiMigrationEnabled: false, | ||
expectedPluginName: gcePdVolumePluginName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to be consistent can we use plugin defined in the csitranslation library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks!
{ | ||
name: "csi migration enabled", | ||
isCsiMigrationEnabled: true, | ||
expectedPluginName: csi.CSIPluginName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the expected name is not accurate. When csi migration is enable, it will be full csi plugin name. Lets use name defined in csi translation library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find a const for the full csi plugin name in csi translation library so I joined the csi plugin name and plugin driver name.
f44ba7e
to
fade3b2
Compare
volumeToUnmount := getTestVolumeToUnmount(podName, pdName, pod) | ||
expectedPluginName := tc.expectedPluginName | ||
|
||
if tc.isCsiMigrationEnabled { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this entire block does. It seems like there is no result from this. the errors we're checking for in here could be other unit tests but I don't think need to be captured in the unmap test.
AFAIK translateSpec
and NewBlockVolumeMapper
would be implementations details of GenerateUnmapVolumeFunc
which we're actually testing later anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I wrote this part to run the test, not to test the behavior of some functionality related with this part, because GenerateUnmapVolumeFunc
call blockVolumePlugin.NewBlockVolumeUnmapper
and when the plugin is csi, csi plugin looks a file that contains some information about the volume, and GenerateUnmapVolumeFunc
fails if csi plugin can't find that file.
I call plugin.NewBlockVolumeMapper
for csi enabled case to create that file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, I get it now! Could you add a comment in the code explaining this. It's not clear from reading the code why NewBlockVolumeMapper
is being called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks!
{ | ||
name: "csi migration enabled", | ||
isCsiMigrationEnabled: true, | ||
expectedPluginName: fmt.Sprintf("%s:%s", csi.CSIPluginName, plugins.GCEPDDriverName), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think expectedPluginName
can actually be generated from isCsiMigrationEnabled
right? then instead of only doing this on GCE another test dimension could be the plugin we're using. So we can test GCE with migration enabled/disabled, AWS migration enabled/disabled. And we should be able to generated the expectedPluginName based on these dimensions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, I also added test cases for AWS EBS plugin.
return nil | ||
} | ||
|
||
func initTestPlugins(t *testing.T) (*volume.VolumePluginMgr, volume.VolumePlugin, string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
theres a function in csi_plugin_test.go
newTestPlugin
that looks very similar. Is there anyway we could reuse that or refactor that into something that could be usable by both tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed and moved the method csi.newTestPlugin
to the testing_helper
file to reuse it.
fade3b2
to
415702f
Compare
@mucahitkurt to workaround problems associated with testing metrics, it might be better idea to test for relative increase in values you are looking for, rather than absolute numbers. That might help in eliminating flakes. |
c289eb0
to
1f2026a
Compare
1f2026a
to
515169a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly lgtm, just 2 final comments!
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIMigration, true)() | ||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, tc.csiMigrationFeature, true)() | ||
expectedPluginName = fmt.Sprintf("%s:%s", csi.CSIPluginName, tc.csiDriverName) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !tc.isCsiMigrationEnabled
we should explicitly turn off the feature gates in preparation for whenever the gates are on by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks!
} | ||
} | ||
|
||
func findMetricWithNameAndLabels(metricFamilyName string, labelFilter map[string]string) *io_prometheus_client.Metric { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there no helper functions that exist in the codebase that do this exact thing? It's fine if the answer is no, but I'm just curious. Want to avoid duplicating code as much as possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found some functions that do the similar things but couldn't be sure about refactoring them to reuse, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to not refactor. I was hoping there would be some common util functions that already exist but it seems like that's not the case.
3f755bc
to
b8c19bb
Compare
/lgtm |
b8c19bb
to
4681bb8
Compare
@mucahitkurt Please resolve verify issues and ping me on github or slack when this PR is ready for lgtm again |
4681bb8
to
943fa0c
Compare
…apVolumeFunc for csi migration on/off scenarios Signed-off-by: Mucahit Kurt <[email protected]>
943fa0c
to
db1c077
Compare
@davidz627 I had some verification issue when I try to reuse the
I couldn't get over these verification faults so I created the function |
@mucahitkurt I see, no worries. Thanks for trying things out. /lgtm |
/approve |
/assign @mikedanese |
@kubernetes/sig-apps-pr-reviews PTAL, thanks! |
@mucahitkurt: Reiterating the mentions to trigger a notification: In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @janetkuo |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: janetkuo, jsafrane, mucahitkurt The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest Review the full test history for this PR. Silence the bot with an |
/retest |
What type of PR is this?
/kind cleanup
/sig storage
What this PR does / why we need it:
Unit tests for the volume plugin name that's used inside
GeneratedUnmapVolumeFunc
for csi migration on/off scenariosWhich issue(s) this PR fixes:
#77141
Special notes for your reviewer:
Added unit test for the just one function, If I'm on the right path I'll continue to write tests for the other operation generator functions.
Does this PR introduce a user-facing change?: