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

unittests: Fixes unit tests for Windows (part 2) #110399

Merged
merged 1 commit into from Aug 1, 2022

Conversation

claudiubelu
Copy link
Contributor

@claudiubelu claudiubelu commented Jun 6, 2022

What type of PR is this?

/kind failing-test

/sig testing
/sig windows

What this PR does / why we need it:

Currently, there are some unit tests that are failing on Windows due to various reasons:

  • volume mounting is a bit different on Windows: Mount will create the parent dirs and mklink at the volume path later (otherwise mklink will raise an error).
  • os.Chmod is not working as intended on Windows.
  • path.Dir() will always return "." on Windows, and filepath.Dir() should be used instead (which works correctly).
  • on Windows, you can't typically run binaries without extensions. If the file C:\\foo.bat exists, we can still run C:\\foo because Windows will append one of the supported file extensions ($env:PATHEXT) to it and run it.
  • Windows file permissions do not work the same way as the Linux ones.
  • /tmp directory being used, which might not exist on Windows. Instead, the OS-specific Temp directory should be used.

Fixes a few other issues:

  • rbd.go: Return error in a case in which an error is encountered. This will prevent "rbd: failed to setup" and "rbd: successfully setup" log messages to be logged at the same time.

Which issue(s) this PR fixes:

Related: #51540

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 6, 2022
@claudiubelu claudiubelu changed the title Unittests 2 WIP: Unittests 2 Jun 6, 2022
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. area/dependency Issues or PRs related to dependency changes area/kubelet kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. and removed do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 6, 2022
@k8s-ci-robot k8s-ci-robot requested review from andyzhangx, cofyc and a team June 6, 2022 07:55
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 6, 2022
@claudiubelu claudiubelu force-pushed the unittests-2 branch 2 times, most recently from de03108 to 746688b Compare June 6, 2022 11:32
@claudiubelu claudiubelu changed the title WIP: Unittests 2 unittests: Fixes unit tests for Windows (part 2) Jun 6, 2022
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jun 6, 2022
@adelina-t
Copy link
Contributor

besides minor nits that @thockin captured: /lgtm

@claudiubelu
Copy link
Contributor Author

/test pull-kubernetes-unit

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 19, 2022
@markjacksonfishing
Copy link

Hello @claudiubelu, my name is Marky Jackson and I am one of the k8s 1.25 bug triage shadow assigned to track this body of work. Is this still on track for 1.25?

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 25, 2022
@claudiubelu
Copy link
Contributor Author

Hello @claudiubelu, my name is Marky Jackson and I am one of the k8s 1.25 bug triage shadow assigned to track this body of work. Is this still on track for 1.25?

Yes. I've addressed the comments above, waiting for other reviews / for this to get merged.

@claudiubelu
Copy link
Contributor Author

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

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 29, 2022
@claudiubelu claudiubelu force-pushed the unittests-2 branch 2 times, most recently from 8d59bbc to 3bd36f4 Compare July 29, 2022 17:40
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 29, 2022
@claudiubelu
Copy link
Contributor Author

FYI: This PR has minimal code changes, and it mostly contains test changes. This PR has been included in this PR #110981, in which we've ran the pull-ci-kubernetes-unit-windows job, in which we can see that these tests now pass.

@claudiubelu
Copy link
Contributor Author

/test pull-kubernetes-e2e-capz-azure-disk

@claudiubelu
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-storage-snapshot

@claudiubelu
Copy link
Contributor Author

/assign @thockin

@claudiubelu claudiubelu force-pushed the unittests-2 branch 2 times, most recently from d8f0489 to 38092cb Compare August 1, 2022 15:56
Currently, there are some unit tests that are failing on Windows due to
various reasons:

- volume mounting is a bit different on Windows: Mount will create the
  parent dirs and mklink at the volume path later (otherwise mklink will
  raise an error).
- os.Chmod is not working as intended on Windows.
- path.Dir() will always return "." on Windows, and filepath.Dir()
  should be used instead (which works correctly).
- on Windows, you can't typically run binaries without extensions. If
  the file C:\\foo.bat exists, we can still run C:\\foo because Windows
  will append one of the supported file extensions ($env:PATHEXT) to it
  and run it.
- Windows file permissions do not work the same way as the Linux ones.
- /tmp directory being used, which might not exist on Windows. Instead,
  the OS-specific Temp directory should be used.

Fixes a few other issues:

- rbd.go: Return error in a case in which an error is encountered. This
  will prevent "rbd: failed to setup" and "rbd: successfully setup" log
  messages to be logged at the same time.
@claudiubelu
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-storage-snapshot

if err := os.MkdirAll(dir, 0755); err != nil && !os.IsNotExist(err) {
t.Errorf("failed to create dir [%s]: %v", dir, err)
}

// do a fake local mount
diskMounter := util.NewSafeFormatAndMountFromHost(plug.GetPluginName(), plug.host)
if err := diskMounter.FormatAndMount("/fake/device", dir, "testfs", nil); err != nil {
device := "/fake/device"
if goruntime.GOOS == "windows" {
Copy link
Member

Choose a reason for hiding this comment

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

@BenTheElder I know you have feelings about this. I am inclined to approve, but finding a more consistent pattern would be good.

Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

Thanks!

/lgtm
/approve

@@ -1146,7 +1146,7 @@ func (fc *FakeProvisioner) Provision(selectedNode *v1.Node, allowedTopologies []
return nil, fmt.Errorf("expected error")
}
}
fullpath := fmt.Sprintf("/tmp/hostpath_pv/%s", uuid.NewUUID())
fullpath := fmt.Sprintf("/%s/hostpath_pv/%s", os.TempDir(), uuid.NewUUID())
Copy link
Member

Choose a reason for hiding this comment

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

Why does this not need to use Join? Knowing that code tends to get copied, this should either be consistent or comment why not?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 1, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: claudiubelu, thockin

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 Aug 1, 2022
@k8s-ci-robot k8s-ci-robot merged commit b167260 into kubernetes:master Aug 1, 2022
SIG Node PR Triage automation moved this from Needs Reviewer to Done Aug 1, 2022
SIG Auth Old automation moved this from Needs Triage to Closed / Done Aug 1, 2022
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. area/dependency Issues or PRs related to dependency changes area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
SIG Auth Old
Closed / Done
Development

Successfully merging this pull request may close these issues.

None yet

9 participants