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

cmd/oci-runtime-tool: Implement --compliance-level #492

Merged
merged 2 commits into from
Oct 10, 2017

Conversation

wking
Copy link
Contributor

@wking wking commented Oct 2, 2017

The man-page entry and Bash completions for this option were added in 4029999 (#354), but the option was left unimplemented. The implementation in this commit is very similar to the existing runtimetest implementation from 4029999, except we warn instead of silently skipping non-fatal spec violations (more on that here).

The warning (vs. error) on invalid level arguments follows the runtimetest implementation from 6316a4e (#354). I'd personally prefer hard errors on invalid level arguments, but didn't want to break runtime-tools consistency over that.

The man-page entry and Bash completions for this option were added in
4029999 (oci error: add error level and reference, 2017-03-31, opencontainers#354),
but the option was left unimplemented.  The implementation in this
commit is very similar to the existing runtimetest implementation from
4029999, except we warn instead of silently skipping non-fatal spec
violations.

The warning (vs. error) on invalid level arguments follows the
runtimetest implementation from 6316a4e (use released version as
reference; improve Parse error, 2017-04-12, opencontainers#354).  I'd personally
prefer hard errors on invalid level arguments, but didn't want to
break runtime-tools consistency over that.

Signed-off-by: W. Trevor King <[email protected]>
@@ -27,8 +37,20 @@ var bundleValidateCommand = cli.Command{
}

if err := v.CheckAll(); err != nil {
return err

merr, ok := err.(*multierror.Error)
Copy link
Member

Choose a reason for hiding this comment

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

It'd be nice if this was a helper function we could reuse in tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'd be nice if this was a helper function we could reuse in tests.

We already have FindError, which you can use like this.

I've just pushed 91aa0e9 onto this series adding a FilterError helper, in case that's what you're looking for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just pushed 91aa0e9

I've pushed 91aa0e9be12cce which flips the order of the FilterError response variables to keep golint happy (avoiding “error should be the last type when returning multiple items”).

wking added a commit to wking/ocitools-v2 that referenced this pull request Oct 3, 2017
This doesn't save much time for folks who are iterating over the
removed errors (e.g. to print warnings about them), but Aleksa asked
for it [1].

I haven't used it in runtimetest.  I'm waiting for the in-flight
7aa3987 (cmd/runtimetest/main: Use TAP diagnostics for errors,
2017-07-28, opencontainers#439) to settle, since that commit cleans up some of the
runtimetest error-processing code with:

  validations := defaultValidations
  if platform == "linux" {
    validations = append(validations, linuxValidations...)
  }

and a single loop over the constructed validations array.

[1]: opencontainers#492 (comment)

Signed-off-by: W. Trevor King <[email protected]>
@wking wking force-pushed the validate-compliance-level branch from 91aa0e9 to be12cce Compare October 3, 2017 20:40
wking added a commit to wking/ocitools-v2 that referenced this pull request Oct 3, 2017
This doesn't save much time for folks who are iterating over the
removed errors (e.g. to print warnings about them), but Aleksa asked
for it [1].

I haven't used it in runtimetest.  I'm waiting for the in-flight
7aa3987 (cmd/runtimetest/main: Use TAP diagnostics for errors,
2017-07-28, opencontainers#439) to settle, since that commit cleans up some of the
runtimetest error-processing code with:

  validations := defaultValidations
  if platform == "linux" {
    validations = append(validations, linuxValidations...)
  }

and a single loop over the constructed validations array.

I initially had FilterError returning (filtered, removed), but golint
didn't like that:

  error should be the last type when returning multiple items

[1]: opencontainers#492 (comment)

Signed-off-by: W. Trevor King <[email protected]>
@wking wking force-pushed the validate-compliance-level branch from be12cce to 1cbca20 Compare October 4, 2017 00:16
wking added a commit to wking/ocitools-v2 that referenced this pull request Oct 4, 2017
This doesn't save much time for folks who are iterating over the
removed errors (e.g. to print warnings about them), but Aleksa asked
for it [1].

I haven't used it in runtimetest.  I'm waiting for the in-flight
7aa3987 (cmd/runtimetest/main: Use TAP diagnostics for errors,
2017-07-28, opencontainers#439) to settle, since that commit cleans up some of the
runtimetest error-processing code with:

  validations := defaultValidations
  if platform == "linux" {
    validations = append(validations, linuxValidations...)
  }

and a single loop over the constructed validations array.

I initially had FilterError returning (filtered, removed), but golint
didn't like that:

  error should be the last type when returning multiple items

[1]: opencontainers#492 (comment)

Signed-off-by: W. Trevor King <[email protected]>
@wking
Copy link
Contributor Author

wking commented Oct 4, 2017

be12cce has an API that passes golint.

@@ -27,8 +36,13 @@ var bundleValidateCommand = cli.Command{
}

if err := v.CheckAll(); err != nil {
removed, err := specerror.FilterError(err, complianceLevel)

Choose a reason for hiding this comment

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

I think removed is not so easy to understand, how about filtered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think removed is not so easy to understand, how about filtered?

I'm open to rewording, but FilterError is currently using removed for “these were removed from the input error due to their low level” and filtered for “the high-level and non-specerror stuff you still need to worry about”. If we decide to use filtered for the low-level stuff, what should we use for the high-level and non-specerror stuff?

Choose a reason for hiding this comment

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

How about just printing removed errors in FilterError, FilterError just returns filtered errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about just printing removed errors in FilterError, FilterError just returns filtered errors?

I'd rather not make UI decisions in a library function. Maybe the caller wants to silently ignore low-level errors. Or maybe they want to present them as TAP diagnostics (#439). Returning the low-level error slice leaves that sort of thing up to the caller.

Choose a reason for hiding this comment

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

but removed, err := specerror.FilterError(err, complianceLevel) looks very strange. That looks like removed is the expected result, err represents error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but removed, err := specerror.FilterError(err, complianceLevel) looks very strange. That looks like removed is the expected result, err represents error message.

So maybe low, high, alwaysNil := specerror.FilterError(...)?

Choose a reason for hiding this comment

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

I think alwaysNil is also not so good. How about just returning a struct includes filtered and low errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think alwaysNil is also not so good. How about just returning a struct includes filtered and low errors?

Works for me; I'll reroll in a few hours.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've rerolled to return a helper struct in 1cbca206089f63.

@wking wking force-pushed the validate-compliance-level branch from 1cbca20 to 6089f63 Compare October 10, 2017 04:18
This doesn't save much time for folks who are iterating over the
removed errors (e.g. to print warnings about them), but Aleksa asked
for it [1] and Ma suggested the helper struct [2].

I haven't used it in runtimetest.  I'm waiting for the in-flight
7aa3987 (cmd/runtimetest/main: Use TAP diagnostics for errors,
2017-07-28, opencontainers#439) to settle, since that commit cleans up some of the
runtimetest error-processing code with:

  validations := defaultValidations
  if platform == "linux" {
    validations = append(validations, linuxValidations...)
  }

and a single loop over the constructed validations array.

[1]: opencontainers#492 (comment)
[2]: opencontainers#492 (comment)

Signed-off-by: W. Trevor King <[email protected]>
@Mashimiao
Copy link

Mashimiao commented Oct 10, 2017

LGTM

Approved with PullApprove

1 similar comment
@zhouhao3
Copy link

zhouhao3 commented Oct 10, 2017

LGTM

Approved with PullApprove

@zhouhao3 zhouhao3 merged commit 929bd5e into opencontainers:master Oct 10, 2017
@wking wking deleted the validate-compliance-level branch November 7, 2017 04:39
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.

4 participants