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

Make rebot call the Reboot API #25

Merged
merged 21 commits into from
May 2, 2019
Merged

Conversation

robertodauria
Copy link
Contributor

@robertodauria robertodauria commented May 1, 2019

This PR makes rebot call the Reboot API instead of the deprecated drac.py.

A mix of abstraction and "monkey patching" has been used to achieve 100% test coverage in the new reboot package and an equivalent coverage for main.go (86%).


This change is Reviewable

@robertodauria robertodauria requested a review from pboothe May 1, 2019 14:19
@robertodauria robertodauria requested review from stephen-soltesz and removed request for pboothe May 1, 2019 14:31
Copy link

@stephen-soltesz stephen-soltesz left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 5 files reviewed, 6 unresolved discussions (waiting on @evfirerob and @stephen-soltesz)


main.go, line 39 at r1 (raw file):

	defaultCredentialsPath = "/tmp/credentials"
	defaultHistoryPath     = "/tmp/candidateHistory.json"
	defaultPrometheusAddr  = "prometheus.mlab-sandbox.measurementlab.net"

Should the project be a parameter?


main.go, line 223 at r1 (raw file):

	flag.StringVar(&rebootAddr, "reboot.addr", "",
		"Reboot API instance to send reboot request to.")
	flag.StringVar(&rebootUsername, "reboot.username", "",

Rebot uses two different mechanisms to discovery the user/pass for prometheus and the user/pass for the reboot api. Could it use the same mechanism?


main.go, line 257 at r1 (raw file):

	// Create the HTTPRebooter.
	baseURL := rebootAddr + rebootEndpoint

The rebootEndpoint feels like it's a property of the NewHTTPRebooter interface that does not need to be exposed to the user of the rebooter interface.

What do you think of moving this constant to the reboot package?


reboot/reboot.go, line 31 at r1 (raw file):
Would it be equivalent to say:

	newHTTPRequest = http.NewRequest

Where else can this be used?


reboot/reboot.go, line 82 at r1 (raw file):

	if err != nil {
		log.WithError(err).Error("Cannot send reboot request.")
		metricRebootRequests.WithLabelValues(toReboot.Name, toReboot.Site, "reboot", "failure").Add(1)

Would it be helpful to distinguish these failure cases like "failure-request", "failure-read", "failure-status", etc?


reboot/reboot_test.go, line 36 at r1 (raw file):

	client := NewTestClient(func(req *http.Request) *http.Response {
		fmt.Println(req.Header.Get("Authorization"))
		if req.Header.Get("Authorization") != "Basic dXNlcjpwYXNz" {

Please add a comment about this basic auth string, something like $ echo -n user:pass | base64 would be enough. It's hard to know how to verify this without some extra hints for the reader.

Above all other code, unit tests must be "correct by inspection". Writing them to be "obviously correct" is the goal.

Copy link
Contributor Author

@robertodauria robertodauria left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 5 files reviewed, 6 unresolved discussions (waiting on @stephen-soltesz)


main.go, line 39 at r1 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

Should the project be a parameter?

Done. Instead of -prometheus.addr we will need to specify -project and the URL is built according to that.


main.go, line 223 at r1 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

Rebot uses two different mechanisms to discovery the user/pass for prometheus and the user/pass for the reboot api. Could it use the same mechanism?

Done. I've added -prometheus.username and -prometheus.password and removed the code to get credentials from a file.


main.go, line 257 at r1 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

The rebootEndpoint feels like it's a property of the NewHTTPRebooter interface that does not need to be exposed to the user of the rebooter interface.

What do you think of moving this constant to the reboot package?

Done. Makes sense, definitely an oversight.


reboot/reboot.go, line 31 at r1 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

Would it be equivalent to say:

	newHTTPRequest = http.NewRequest

Where else can this be used?

Done.


reboot/reboot.go, line 82 at r1 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

Would it be helpful to distinguish these failure cases like "failure-request", "failure-read", "failure-status", etc?

Done.


reboot/reboot_test.go, line 36 at r1 (raw file):

Previously, stephen-soltesz (Stephen Soltesz) wrote…

Please add a comment about this basic auth string, something like $ echo -n user:pass | base64 would be enough. It's hard to know how to verify this without some extra hints for the reader.

Above all other code, unit tests must be "correct by inspection". Writing them to be "obviously correct" is the goal.

Done. Thanks!

Copy link

@stephen-soltesz stephen-soltesz left a comment

Choose a reason for hiding this comment

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

:lgtm::

Reviewed 1 of 5 files at r1, 4 of 4 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


main.go, line 223 at r1 (raw file):

Previously, evfirerob (Roberto D'Auria) wrote…

Done. I've added -prometheus.username and -prometheus.password and removed the code to get credentials from a file.

Now that you're using ArgsFromEnv these could all be environment variables too. 👍

@robertodauria robertodauria merged commit e246404 into master May 2, 2019
@robertodauria robertodauria deleted the sandbox-roberto-reboot-api branch May 2, 2019 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants