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

introduce dell adaptor tests based on a fake dell server #24

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

rauhersu
Copy link
Contributor

@rauhersu rauhersu commented Nov 14, 2024

  1. Context

This is a follow-up of the previous loopback plugin effort to increase our test coverage for the plugins initiated with this PR.
Now, this PR targets the dell plugin and as a consequence, a minor refactor of the previous loopback test (mainly dir structure and renaming) has been performed too.

All these new tests are run executing make test from the project root

  1. Notes for the reviewers

    2.1 - The loopback-plg dir contains the existing tests for the loopback plugin.
    2.2 - The dell-plg dir contains the new test code, targeting the dell plugin.
    2.3 - The assets dir contains new manifests needed by the dell plugin for the new testing scenario. It contains 'common logic' used by both plugins.
    2.4 - The dell-server dir contains code generated on parsing the Dell swagger (drop2) specification, tweaked by @donpenney

    This PR is only focused on a rest scenario for the dell plugin, specifically the authentication token request to the dell server, but this dell test suite has been designed to be scalable and might test the whole rest flow plus a complete reconciliation if no architectural constraint prevents it (i.e: a real cluster is needed).

  2. Technicalities

    3.1 - Envtest is used to setup a minimal control plane. No cluster is needed.
    3.2 - A goroutine is triggered to start up the fake dell server while the test is run in the main one - here -
    3.3 - The fake dell server exposes all API routes - here - but only the 'get token' scenario is under test so far - here - . Posterior MRs might cover the whole API. Also, every response is mocked to test the Dell plugin behaviour on a test basis.

  3. Other

    4.1 - While writing this I have just noticed we need to update our manifests according to Tao's latest changes: CNF-15609: Enhance Loopback Plugin for Node Pool Configuration Changes #23 we might hold this PR to merge that before and update this PR accordingly.
    4.2 - @donpenney , I see a lot of 'errors' indicated by the linter (wrapcheck) for the generated code (from the swagger file)
    4.3 - It might be interesting to test this 'get token' scenario provisioning the configmap with a cabundle; so far I have not included this.

@openshift-ci openshift-ci bot requested a review from browsell November 14, 2024 12:42
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 14, 2024
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 14, 2024
@rauhersu
Copy link
Contributor Author

rauhersu commented Nov 14, 2024

/hold

We might want to merge Tao's MR first and update this one with new manifests structure

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 14, 2024
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 14, 2024
@donpenney
Copy link
Collaborator

#23 has been merged
#19 should be merged shortly

@donpenney
Copy link
Collaborator

I would recommend using loopback-adaptor and dell-adaptor instead of plg to be consistent with the naming convention in the plugin architecture

@donpenney
Copy link
Collaborator

Please add a Makefile target for generating the test server code. I would also recommend putting it in a generated directory for clarity. Make sure to also add an entry to the .gitattributes file to set this folder as containing generated code.

@donpenney
Copy link
Collaborator

We should also be able to edit the .golangci-lint.yaml config file to ignore the generated code, and could consider ignoring test code as well

@donpenney
Copy link
Collaborator

I would recommend using loopback-adaptor and dell-adaptor instead of plg to be consistent with the naming convention in the plugin architecture

Similarly, please rename test/plugins to test/adaptors. You could then use loopback and dell-hwmgr under here to align with the folders under adaptors

@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 15, 2024
@rauhersu
Copy link
Contributor Author

rauhersu commented Nov 15, 2024

Thanks for the feedback, @donpenney

Comments about my new push below.

I would recommend using loopback-adaptor and dell-adaptor instead of plg to be consistent with the naming convention in the plugin architecture

Done

Please add a Makefile target for generating the test server code. I would also recommend putting it in a generated directory for clarity. Make sure to also add an entry to the .gitattributes file to set this folder as containing generated code.

I am only re-using your types.go from the dell adaptor folder, no extra Makefile target is needed.

The reason is that the server generated code (the http dispatch infra) does not favour our intend to mock the dispatch functions dynamically on a test basis, as I am doing for our tests: here and here . I believe I am able to provide a better customisation on the http side instead, based on gorilla/mux . See muxinfra.go.

Note that my muxinfra is pretty standard golang code leveraging mux, and orthogonal to openapi changes, so I am expecting not to change this for any reason.

Otoh, if we need to update our openapi spec, on the pure server side code I am only expecting to update this routes function when updating endpoints for the corresponding test.

We should also be able to edit the .golangci-lint.yaml config file to ignore the generated code, and could consider ignoring test code as well

Have not done it so far but we might simply add the nolint annotation for api package, right ? As that file will be autogenerated and newer files will override this, can we do it on a file basis instead - types.go - ?

I'd recommend using hwmgr in the filename rather than hm for consistency

Done

Similarly, please rename test/plugins to test/adaptors. You could then use loopback and dell-hwmgr under here to align with the folders under adaptors

Done

@rauhersu rauhersu changed the title introduce dell plugin tests with a fake dell server introduce dell adaptor tests based on a fake dell server Nov 15, 2024
@rauhersu
Copy link
Contributor Author

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 15, 2024
Comment on lines 20 to 23
"github.com/gorilla/mux"
"log"
"net/http"
"time"
Copy link
Collaborator

Choose a reason for hiding this comment

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

golangci-lint wants the system imports first, with external imports separated

Suggested change
"github.com/gorilla/mux"
"log"
"net/http"
"time"
"log"
"net/http"
"time"
"github.com/gorilla/mux"

@rauhersu
Copy link
Contributor Author

rauhersu commented Nov 18, 2024

@donpenney , see this new commit added:

5f994c9

No new functionality, two improvements added:

  • the required CRDs cloned by git add a 'retry' mechanism useful to deal with glitches. See crds.go.
  • the fake dell server generated code has been integrated with less changes for the developer to extend: muxinfra.go has been deleted, see the attached README containing all the details.

test/adaptors/README.md Outdated Show resolved Hide resolved

// fetch required CRD
crdPath := filepath.Join(tmpDir, crdRepoName)
err := crds.GetRequiredCrdsFromGit(crdRepo, crdPath)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this just getting the main/latest content? The go.mod locks us to a specific version of the APIs from oran-o2ims. We'd need to do the same here, to ensure that the CRD structure aligns with what's expected by the plugin code.

Copy link
Contributor Author

@rauhersu rauhersu Nov 19, 2024

Choose a reason for hiding this comment

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

Yes, it is getting the latest. How do we take the decision to update to a specific oran-o2ims api from the code perspective ?

From the testing side, using this git mechanism, we are no more granular than a branch. I am guessing we are not going have a git tag to sync to either. Not sure if can derive the associated CRD file then: go.mod version --> crd file

If we just need a branch as a parameter, it is pretty straightforward; we will just need to update this file on a release branch basis (release-4.18, release-4.19, ...)

Copy link
Contributor Author

@rauhersu rauhersu Nov 21, 2024

Choose a reason for hiding this comment

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

This has been addressed as part of the new changes, see the README: Testing dependencies and the new code in utils.go

ctx, cancel = context.WithCancel(
context.Background())
err := server.Shutdown(ctx)
Expect(err).NotTo(HaveOccurred(), "failed to stop dell server")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Expect(err).NotTo(HaveOccurred(), "failed to stop dell server")
Expect(err).NotTo(HaveOccurred(), "failed to stop test server")

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

@rauhersu rauhersu force-pushed the main.dell.squash branch 5 times, most recently from b1c1a15 to ab9a828 Compare November 21, 2024 18:02
@donpenney
Copy link
Collaborator

Please fix remaining linter warnings

test/adaptors/crds/crds.go Outdated Show resolved Hide resolved
test/adaptors/crds/crds.go Show resolved Hide resolved

// GetRequiredCRDsFromGit clones an oran-o2ims repo in a specific path and checks out a specific commit
// to fetch required CRDs from there
func GetRequiredCRDsFromGit(crdRepo string, commit string, crdPath string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func GetRequiredCRDsFromGit(crdRepo string, commit string, crdPath string) error {
func GetRequiredCRDsFromGit(crdRepo, commit, crdPath string) error {

test/adaptors/crds/crds.go Outdated Show resolved Hide resolved
backoff := retry.NewFibonacci(1 * time.Second)
err := retry.Do(ctx, retry.WithMaxRetries(retries, backoff), cloneFn)
if err != nil {
return fmt.Errorf("failed to clone repo:%s, err:%v", crdRepo, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("failed to clone repo:%s, err:%v", crdRepo, err)
return fmt.Errorf("failed to clone repo:%s, err:%w", crdRepo, err)

// checkout the specific commit
w, err := r.Worktree()
if err != nil {
return fmt.Errorf("failed to get git worktree repo:%s, err:%v", crdRepo, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("failed to get git worktree repo:%s, err:%v", crdRepo, err)
return fmt.Errorf("failed to get git worktree repo:%s, err:%w", crdRepo, err)

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

test/adaptors/crds/crds.go Outdated Show resolved Hide resolved
test/adaptors/crds/crds.go Outdated Show resolved Hide resolved
A minor refactor of the existing loopback tests has been peformed too
@rauhersu
Copy link
Contributor Author

Thanks once again, @donpenney . Regarding the linter comments, I have had some issues because of the linter tool already included. Cc'ed you over here: https://redhat-internal.slack.com/archives/C07A9NFCS01/p1732707795237589

Copy link

openshift-ci bot commented Nov 27, 2024

@rauhersu: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/ci-bundle-operator-bundle c7a158a link true /test ci-bundle-operator-bundle
ci/prow/ci-job c7a158a link true /test ci-job
ci/prow/images c7a158a link true /test images

Full PR test history. Your PR dashboard.

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-sigs/prow repository. I understand the commands that are listed here.

@donpenney
Copy link
Collaborator

/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 27, 2024
Copy link

openshift-ci bot commented Nov 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: donpenney

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 27, 2024
@donpenney donpenney merged commit 3880b1b into openshift-kni:main Nov 27, 2024
4 of 8 checks passed
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants