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

checks related fixes #787

Merged
merged 2 commits into from
Sep 21, 2017
Merged

checks related fixes #787

merged 2 commits into from
Sep 21, 2017

Conversation

unclejack
Copy link
Contributor

This PR makes the following changes:

  • fixes the issues reported by make checks across the entire repository, except for vendor
  • removes the exception which excluded the test directory from all tests

This was an issue whenever code was being modified in the test directory. Some files would end up being formatted by gofmt. These gofmt related changes would appear in commits. It's a good idea to follow these rules for the entire code base and not play ping-pong with gofmt when making other changes.

The fixes made to pass checks are the following:

  • remove punctuation from the end of the errors
  • make errors start with a lowercase character
  • gofmt all the code
  • rename one variable in the tests to pass checks

Copy link
Contributor

@dseevr dseevr left a comment

Choose a reason for hiding this comment

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

LGTM aside from the capitalization stuff

@@ -932,7 +932,7 @@ func (s *systemtestSuite) CheckBgpConnectionForaNode(c *C, node remotessh.Testbe
return nil
}
}
return errors.New("BGP connection not established")
return errors.New("bGP connection not established")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be all lowercase

@@ -947,7 +947,7 @@ func (s *systemtestSuite) CheckBgpNoConnectionForaNode(c *C, node remotessh.Test
return nil
}
}
return errors.New("BGP connection persists")
return errors.New("bGP connection persists")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@@ -740,15 +740,15 @@ func (d *docker) verifyVTEPs(expVTEPS map[string]bool) (string, error) {
for vtep := range expVTEPS {
_, found := actVTEPs[vtep]
if !found {
return str, errors.New("VTEP " + vtep + " not found")
return str, errors.New("vTEP " + vtep + " not found")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@@ -731,15 +731,15 @@ func (k *kubernetes) verifyVTEPs(expVTEPS map[string]bool) (string, error) {
for vtep := range expVTEPS {
_, found := actVTEPs[vtep]
if !found {
return str, errors.New("VTEP " + vtep + " not found")
return str, errors.New("vTEP " + vtep + " not found")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@@ -698,7 +698,7 @@ func (w *swarm) verifyVTEPs(expVTEPS map[string]bool) (string, error) {
for vtep := range expVTEPS {
_, found := actVTEPs[vtep]
if !found {
return str, errors.New("VTEP " + vtep + " not found")
return str, errors.New("vTEP " + vtep + " not found")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@unclejack
Copy link
Contributor Author

@dseevr: I've made the changes. PTAL

Copy link
Contributor

@jojimt jojimt left a comment

Choose a reason for hiding this comment

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

It looks like this PR changes the capitalization of the first letter of a whole bunch of messages from upper case to lower case. It is unclear what value this adds. Can we not do this? It is likely to cause confusion/inconsistency as we print these errors in many paces, in a variety of formats.

@@ -95,7 +95,7 @@ func NewOvsSwitch(bridgeName, netType, localIP string, fwdMode string,
datapath = "vrouter"
default:
log.Errorf("Invalid datapath mode")
return nil, errors.New("Invalid forwarding mode. Expects 'bridge' or 'routing'")
return nil, errors.New("invalid forwarding mode. Expects 'bridge' or 'routing'")
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not see the point of this change. The original string looks better to me.

Copy link
Contributor Author

@unclejack unclejack Mar 17, 2017

Choose a reason for hiding this comment

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

The point of this change is that error messages are meant to start with a lowercase letter and not have any punctuation at the end.

The goal of this convention is to be able to compose errors nicely. If you run into an error, you can do something like return fmt.Errorf("encountered error while opening file: %v", err); this error would be composable even further, e.g.: "failed to save data: encountered error while opening file: file doesn't exist".

There are some language conventions which should be followed. Others follow these conventions as well. I didn't come up with these conventions.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is also the convention that our errored repo follows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/pkg/errors is also using lowercase letters for the errors. The static analysis tools we use are used by other repositories as well. This is more of a convention, rather than a personal preference.

@unclejack unclejack force-pushed the checks_fixes branch 3 times, most recently from c437e95 to 8ff3c13 Compare March 28, 2017 16:40
@dseevr
Copy link
Contributor

dseevr commented May 26, 2017

@unclejack could you take a quick look at getting this one passing, too? I think this would be worthwhile to get merged as a step towards cleaning up our tests

@unclejack unclejack force-pushed the checks_fixes branch 2 times, most recently from 31a3191 to a418f42 Compare May 26, 2017 05:57
@unclejack
Copy link
Contributor Author

This is running into some failures for some reason. I've got to look into this.

@gkvijay
Copy link
Member

gkvijay commented May 26, 2017

This is only changing the error message format. I don't see how that is helping our tests.

@unclejack
Copy link
Contributor Author

@gkvijay: This PR is also removing a blacklist which prevents any kind of code quality tool on the tests themselves. The changes I've made are the ones needed to make it possible to run those tools on the code base. Please feel free to try the other commit on a code checkout to see how make checks fails.

I've had issues in the past where I had to craft PRs just to avoid gofmt related changes because the code wasn't properly formatted. We still have code in tests which isn't properly formatted. Obviously, this can never stop if we have the test directory in the blacklist.

@@ -122,7 +122,7 @@ func createEP(req *epSpec) (*epAttr, error) {
netID := req.Network + "." + req.Tenant
ep, err := netdGetEndpoint(netID + "-" + req.EndpointID)
if err == nil {
return nil, fmt.Errorf("EP %s already exists", req.EndpointID)
return nil, fmt.Errorf("the EP %s already exists", req.EndpointID)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you change EP-> endpoint ?

@@ -230,7 +230,7 @@ func masterReq(path string, req interface{}, resp interface{}, isDel bool) error
}

log.Errorf("Error making POST request. All master failed")
return errors.New("POST request failed")
return errors.New("the POST request failed")
Copy link
Contributor

Choose a reason for hiding this comment

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

In general if you are changing a string,
can you make it to more descriptive like "http POST request to master failed "

@rchirakk
Copy link
Contributor

@unclejack can you fix the build failure ?
let's merge it in 1.1 or post 1.1

@unclejack
Copy link
Contributor Author

@rchirakk: I've fixed the PR. The CI is running into some issues, but the issue is confirmed to be fixed. Perhaps this should be merged after 1.1. We can include it in 1.1.1.

@@ -48,7 +48,7 @@ func nsToPID(ns string) (int, error) {
// Make sure ns is well formed
ok := strings.HasPrefix(ns, "/proc/")
if !ok {
return -1, fmt.Errorf("Invalid nw name space: %v", ns)
return -1, fmt.Errorf("invalid network namespace: %v", ns)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -330,7 +330,7 @@ func tcFilterCheckBw(expBw, expBurst int64) error {
qdiscoutput := strings.Split(qdiscShow, "ingress")
if len(qdiscoutput) < 2 {
log.Errorf("Got `tc qdisco show` output:\n%s", qdiscShow)
return fmt.Errorf("Unexpected `tc qdisco show` output")
return fmt.Errorf("unexpected `tc qdisc show` output")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

no more disco 👍

func ErrIfKeyExists(err error) error {
if err == nil || strings.Contains(err.Error(), "Key not found") {
if err == nil || strings.Contains(err.Error(), "key not found") {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to cover all the cases,
better make it independent case, (use string.Tolower(err.Error()) before comparison)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rchirakk: This was just a quick fix for us to be able to use gofmt, go vet, golint and the other tools on the entire code base. I intend to send some more PRs to refactor the error handling across the code base. I'd rather focus on starting the refactor work to avoid such issues in the future and make our code better.

@rchirakk
Copy link
Contributor

LGTM other than the minor question/comment.
@gkvijay @DivyaVavili possible candidate for 1.1.1 ?

@unclejack
Copy link
Contributor Author

Are there any other changes I should make for this? Please let me know.

@unclejack
Copy link
Contributor Author

The 1.1.x release is out.

We need to move forward with this PR.

/cc @DivyaVavili @gkvijay @rchirakk @rhim

@unclejack
Copy link
Contributor Author

Is anyone still interested in this PR?

Copy link
Contributor

@rhim rhim left a comment

Choose a reason for hiding this comment

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

LGTM. Minor comments. Once CI is clean, it is OK to merge.

@@ -86,7 +86,7 @@ func (c *NWClient) AddPod(podInfo interface{}) (*cniapi.RspAddPod, error) {
if err != nil {
return nil, err
}
return &data, fmt.Errorf("Internal Server Error")
return &data, fmt.Errorf("internal Server Error")
Copy link
Contributor

Choose a reason for hiding this comment

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

lower case all words?

Copy link
Contributor

Choose a reason for hiding this comment

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

See the other comments in this PR discussion. This makes error messages composable

@@ -122,7 +122,7 @@ func createEP(req *epSpec) (*epAttr, error) {
netID := req.Network + "." + req.Tenant
ep, err := netdGetEndpoint(netID + "-" + req.EndpointID)
if err == nil {
return nil, fmt.Errorf("EP %s already exists", req.EndpointID)
return nil, fmt.Errorf("the endpoint %s already exists", req.EndpointID)
Copy link
Contributor

Choose a reason for hiding this comment

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

EP has a specific meaning in contiv, and can be left as in.

@rhim
Copy link
Contributor

rhim commented Sep 11, 2017

@unclejack please rebase and resubmit to get it merged in.

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
@unclejack
Copy link
Contributor Author

I've fixed this, but the CI is failing.

@dseevr
Copy link
Contributor

dseevr commented Sep 12, 2017

Is the k8s CI run expected to fail at this point? I remember there was some work in progress on it...

@unclejack
Copy link
Contributor Author

@dseevr: It should work at this point. The failures are weird.

@unclejack
Copy link
Contributor Author

@dseevr @rhim: This should be good to go now. PTAL

@rhim
Copy link
Contributor

rhim commented Sep 18, 2017

ping @contiv/maintainers-core-networking. Please merge this PR.

@unclejack
Copy link
Contributor Author

Is there something else I should do to get this PR merged? Does anyone have any questions or concerns related to this? I'd rather address any concerns now and not require another rebase and test cycle.

@rhim
Copy link
Contributor

rhim commented Sep 21, 2017 via email

@srampal srampal merged commit a2e4909 into contiv:master Sep 21, 2017
@unclejack unclejack deleted the checks_fixes branch September 21, 2017 21:18
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

7 participants