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

Turn rpm-ostree code into a client #100

Merged

Conversation

ashcrow
Copy link
Member

@ashcrow ashcrow commented Sep 28, 2018

This change allows for modification of rpm-ostree related code so
unittesting can occur. Instead of the functionality being spread
through private functions within the daemon package, a structure
which implements DeploymentClient is used and is passed in to
the Daemon at creation.

Part of #101

/cc @jlebon @sdemos @kikisdeliveryservice

@openshift-ci-robot openshift-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 28, 2018
@ashcrow
Copy link
Member Author

ashcrow commented Sep 28, 2018

/hold

I'd like to wait on merging things like this until after the current round of testing.

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 28, 2018
@kikisdeliveryservice
Copy link
Contributor

I'm really excited about these PRs (and future unit testing). Thanks for getting this started!

@ashcrow
Copy link
Member Author

ashcrow commented Oct 1, 2018

Deployment is also an rpm-ostree component. I fear there will be more collisions in names like this. I am, however, good with prefixing with something like NodeDeploymentClient or HostDeploymentClient.

@abhinavdahiya thoughts?

@jlebon
Copy link
Member

jlebon commented Oct 1, 2018

Hmm yeah, I think that makes sense overall for the goal of unit testing. That said for upstream CI, hopefully we can get a real cluster going and test there?

I am, however, good with prefixing with something like NodeDeploymentClient or HostDeploymentClient.

Or maybe something like NodeUpdater?

@ashcrow
Copy link
Member Author

ashcrow commented Oct 1, 2018

Or maybe something like NodeUpdater?

I'm 👍 to that. I'll make the change in a bit.

@ashcrow
Copy link
Member Author

ashcrow commented Oct 1, 2018

Hmm yeah, I think that makes sense overall for the goal of unit testing. That said for upstream CI, hopefully we can get a real cluster going and test there?

Agreed, but that's a different set of work :-)

@ashcrow
Copy link
Member Author

ashcrow commented Oct 1, 2018

Updated.

}

// GetBootedDeployment returns the current deployment found
func (r *RpmOstreeClient) GetBootedDeployment(rootMount string) (*RpmOstreeDeployment, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this function called by anything external to this package? I only see the one change. if not, I would probably advocate for removing it from the client interface and just having it as a method on RpmOstreeClient.

Copy link
Member Author

Choose a reason for hiding this comment

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

/cc @jlebon

Copy link
Member

Choose a reason for hiding this comment

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

Yup, that sounds good to me!

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

@ashcrow ashcrow force-pushed the mcd-deployment-client branch 2 times, most recently from f10d421 to 4732d45 Compare October 4, 2018 16:01
This change allows for modification of rpm-ostree related code so
unittesting can occur. Instead of the functionality being spread
through private functions within the daemon package, a structure
which implements NodeUpdaterClient is used and is passed in to
the Daemon at creation.

Signed-off-by: Steve Milner <smilner@redhat.com>
@ashcrow
Copy link
Member Author

ashcrow commented Oct 4, 2018

Should test implementations be in the same file as the main implementation or should they be implemented within a $NAME_test.go with the understanding other $NAME_test.gos will use them as well?

@jlebon
Copy link
Member

jlebon commented Oct 4, 2018

Code looks sane to me!

Should test implementations be in the same file as the main implementation or should they be implemented within a $NAME_test.go with the understanding other $NAME_test.gos will use them as well?

I'll let folks more experienced with golang decide.

@ashcrow
Copy link
Member Author

ashcrow commented Oct 4, 2018

FWIW my inclination is to put the test implementations in $NAME_test.go files to keep the main implementation files easy to follow.

@ashcrow
Copy link
Member Author

ashcrow commented Oct 4, 2018

In terms of testing usage. This would look something like this (untested, uncompiled, but close :-)):

testClient := RpmOstreeClientMock{
	GetBootedOSImageURLReturns: []GetBootedOSImageURLReturn{
            OsImageURL: "theurl",
            Version: "some-version",
            Error: nil,
        }
	RunPivotReturns: []error{nil, fmt.Errorf("broken")}
}

// Create an instance that uses the client
// Execute a method that calls GetBootedOSImageURL off the client. It will get the contents past to GetBootedOSImageURLReturns every time it is executed.
// Execute a method that calls RunPivot. The first time it will return no error. The second run and beyond will return an the "broken" error.

@ashcrow
Copy link
Member Author

ashcrow commented Oct 4, 2018

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 4, 2018
Signed-off-by: Steve Milner <smilner@redhat.com>
Signed-off-by: Steve Milner <smilner@redhat.com>
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 8, 2018
}

// Create a Daemon instance with mocked clients
d := Daemon{
Copy link
Member Author

Choose a reason for hiding this comment

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

I would expect creating a test Daemon instance would likely be added as well to keep many of the tests from recreating the instances each time.

@ashcrow
Copy link
Member Author

ashcrow commented Oct 8, 2018

Moved test code into *_test.go and added an example test for update.go.

@ashcrow
Copy link
Member Author

ashcrow commented Oct 8, 2018

@sdemos PTAL

@ashcrow
Copy link
Member Author

ashcrow commented Oct 8, 2018

FWIW

Running tool: /usr/bin/go test -timeout 30s github.com/openshift/machine-config-operator/pkg/daemon -run ^TestUpdateOS$

ok  	github.com/openshift/machine-config-operator/pkg/daemon	0.007s
Success: Tests passed.

Copy link
Contributor

@sdemos sdemos left a comment

Choose a reason for hiding this comment

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

this all looks good to me. I'll let @jlebon give the final go-ahead since it hits on the rpm-ostree code.

@sdemos
Copy link
Contributor

sdemos commented Oct 8, 2018

just kidding, he is out today, I'll just do it.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 8, 2018
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ashcrow, sdemos

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-merge-robot openshift-merge-robot merged commit c0a19e0 into openshift:master Oct 8, 2018
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. 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.

None yet

6 participants