Skip to content
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

Conversation

mucahitkurt
Copy link
Contributor

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 scenarios

Which 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?:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. sig/storage Categorizes an issue or PR as relevant to SIG Storage. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 23, 2019
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot requested review from rootfs and screeley44 May 23, 2019 21:31
@mucahitkurt
Copy link
Contributor Author

/assign @davidz627

@mucahitkurt mucahitkurt force-pushed the cleanup/operation-generator-migration-scenarios-unit-tests branch from f1d3605 to 3aa7f01 Compare May 24, 2019 20:49

csiplugin, err := plugMgr.FindPluginByName(csi.CSIPluginName)
if err != nil {
t.Fatalf("can't find plugin %v", csi.CSIPluginName)
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

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"
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, thanks!

@mucahitkurt mucahitkurt force-pushed the cleanup/operation-generator-migration-scenarios-unit-tests branch from 3aa7f01 to f44ba7e Compare May 28, 2019 09:52
@jsafrane
Copy link
Member

/ok-to-test
/assign @gnufied

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 28, 2019
@mucahitkurt
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-storage-slow
/test pull-kubernetes-integration
/test pull-kubernetes-verify

@mucahitkurt
Copy link
Contributor Author

I have a question about unit testing metrics, prometheus.DefaultGatherer is global metric registry so there is no guarantee for a metric value is changed with the code that's tested by my unit test. And tests can be flaky when they are run as parallel.

Is there any best practice to test metrics?

name string
isCsiMigrationEnabled bool
expectedPluginName string
}
Copy link
Member

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

Copy link
Contributor Author

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,
Copy link
Member

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?

Copy link
Contributor Author

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,
Copy link
Member

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.

Copy link
Contributor Author

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.

@mucahitkurt mucahitkurt force-pushed the cleanup/operation-generator-migration-scenarios-unit-tests branch from f44ba7e to fade3b2 Compare May 28, 2019 21:44
volumeToUnmount := getTestVolumeToUnmount(podName, pdName, pod)
expectedPluginName := tc.expectedPluginName

if tc.isCsiMigrationEnabled {
Copy link
Contributor

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

Copy link
Contributor Author

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 GenerateUnmapVolumeFuncfails if csi plugin can't find that file.

I call plugin.NewBlockVolumeMapper for csi enabled case to create that file.

Copy link
Contributor

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

Copy link
Contributor Author

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),
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

@mucahitkurt mucahitkurt May 30, 2019

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.

@mucahitkurt mucahitkurt force-pushed the cleanup/operation-generator-migration-scenarios-unit-tests branch from fade3b2 to 415702f Compare May 29, 2019 01:49
@gnufied
Copy link
Member

gnufied commented May 29, 2019

@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.

@mucahitkurt mucahitkurt force-pushed the cleanup/operation-generator-migration-scenarios-unit-tests branch 2 times, most recently from c289eb0 to 1f2026a Compare May 30, 2019 22:54
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 30, 2019
@mucahitkurt mucahitkurt force-pushed the cleanup/operation-generator-migration-scenarios-unit-tests branch from 1f2026a to 515169a Compare May 30, 2019 23:00
Copy link
Contributor

@davidz627 davidz627 left a 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)
}
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@mucahitkurt mucahitkurt force-pushed the cleanup/operation-generator-migration-scenarios-unit-tests branch from 3f755bc to b8c19bb Compare June 4, 2019 19:41
@davidz627
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 4, 2019
@mucahitkurt mucahitkurt force-pushed the cleanup/operation-generator-migration-scenarios-unit-tests branch from b8c19bb to 4681bb8 Compare June 5, 2019 05:34
@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jun 5, 2019
@davidz627
Copy link
Contributor

@mucahitkurt Please resolve verify issues and ping me on github or slack when this PR is ready for lgtm again

@mucahitkurt mucahitkurt force-pushed the cleanup/operation-generator-migration-scenarios-unit-tests branch from 4681bb8 to 943fa0c Compare June 10, 2019 19:35
…apVolumeFunc for csi migration on/off scenarios

Signed-off-by: Mucahit Kurt <[email protected]>
@mucahitkurt mucahitkurt force-pushed the cleanup/operation-generator-migration-scenarios-unit-tests branch from 943fa0c to db1c077 Compare June 11, 2019 05:33
@mucahitkurt
Copy link
Contributor Author

@mucahitkurt Please resolve verify issues and ping me on github or slack when this PR is ready for lgtm again

@davidz627 I had some verification issue when I try to reuse the csi_plugin_test.newTestPlugin;

  • I created a different file and a the same package with csi to reuse the method NewTestPlugin but symbols and import verification failed because of usage of testing and testify in a non test file(cannot export a function from a test file).
  • I created a different file and a different package other than csi, like csi/testing, to reuse the method NewTestPlugin but I got cylic import fault for packages csi and csi/testing.

I couldn't get over these verification faults so I created the function NewTestPlugin under csi/testing but used only in operation_generator_test not in tests under csi package to pass those verification faults.

@davidz627
Copy link
Contributor

@mucahitkurt I see, no worries. Thanks for trying things out.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 11, 2019
@jsafrane
Copy link
Member

/approve

@mucahitkurt
Copy link
Contributor Author

/assign @mikedanese

@mucahitkurt
Copy link
Contributor Author

@kubernetes/sig-apps-pr-reviews PTAL, thanks!

@k8s-ci-robot
Copy link
Contributor

@mucahitkurt: Reiterating the mentions to trigger a notification:
@kubernetes/sig-apps-pr-reviews

In response to this:

@kubernetes/sig-apps-pr-reviews PTAL, thanks!

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.

@davidz627
Copy link
Contributor

/assign @janetkuo
could you PTAL

@janetkuo
Copy link
Member

janetkuo commented Jul 9, 2019

/approve

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 9, 2019
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@davidz627
Copy link
Contributor

/retest

@k8s-ci-robot k8s-ci-robot merged commit d59a603 into kubernetes:master Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants