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

Fixes lp#1628919: help-tool fix for payload hook tools. #7515

Merged
merged 3 commits into from
Jun 20, 2017

Conversation

anastasiamac
Copy link
Contributor

Description of change

'juju help-tool' did not contain payload hook tools.
Payload hook tool commands are the only ones in juju codebase that required a valid hook context in the constructors. This approach, whilst commendable, does not work for help-tool command which uses mock dummy hook context to get help information from all commands it can see.

In fact, valid hook context is only important at the time when it is used, in the command's Run method. Majority of this PR changes payload hook commands to not error at construction time.

Also, since payload hook tools are implemented under component architecture, these hook tools needed to be explicitly registered to be in collection of all hook tools.

Added unit test to ensure that component based hook tools are displayed as part of help-tool output.

QA steps

Output of 'juju help-tool' should contain:

payload-register register a charm payload with juju
payload-status-set update the status of a payload
payload-unregister stop tracking a payload

Documentation changes

If output of 'juju help-tool' is shown in online documentation, it may need to be adjusted.

Bug reference

https://bugs.launchpad.net/juju/+bug/1628919

Copy link
Member

@jameinel jameinel left a comment

Choose a reason for hiding this comment

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

So is the primary change that we are just deferring when we are creating the hook context? And that it can now error? And I guess calling "registerHookContextCommands", right?

// Component-based features such as payloads and resources
// are different enough in implementation to the rest
// of Juju code that we need to ensure that help-tool can reach them
// explicitely.
Copy link
Member

Choose a reason for hiding this comment

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

explicitly

Copy link
Member

Choose a reason for hiding this comment

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

That said, we already do something like this for 'juju commands' where we have a list of commands that we expect to see registered and available.
Would it be reasonable to just list all commands here? It does need updating whenever we add/remove a command, but it also means we don't remove a registration without noticing.

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 was wondering that. I'll change and will hard code the list.It'll also reduce number of tests back down :D

}

func (s registerSuite) TestInitNilArgs(c *gc.C) {
err := s.command.Init(nil)
Copy link
Member

Choose a reason for hiding this comment

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

All test functions need to be '*' in their receivere.
(s *registerSuite)

Otherwise it does bad things with base classes like IsolationSuite (we track things in AddCleanup that do bad things if you use a value rather than a pointer)

There are several places where this needs to be fixed.

Are there any changes here that aren't just pulling 's.command' into SetUp() (and changing hook context into an acquisition function)? I didn't see any.

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'll change the receivers but no, all the changes here are related to how the command is constructed for the tests and how the tests get it.

return errors.Trace(err)
}

// TODO(ericsnow) Is the flush really necessary?

// We flush to state immedeiately so that status reflects the
// We flush to state immediately so that status reflects the
Copy link
Member

Choose a reason for hiding this comment

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

hm, I wonder if this was copy & pasted code. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No :) I am sure the same word is mistyped 3 times in the same way in the similar-ish looking code :D

@anastasiamac
Copy link
Contributor Author

So the primary changes are that payload hook command are registered (the call to registerHookContextCommands) and that constructors for these commands do not prevent construction if given hook context is malformed/non-functional.

…ed commands. Changed payload register test suite to have pointer receivers.
@anastasiamac
Copy link
Contributor Author

$$merge$$

@jujubot
Copy link
Collaborator

jujubot commented Jun 20, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit 3c332bc into juju:develop Jun 20, 2017
@anastasiamac anastasiamac deleted the help-tool-lp1628919 branch June 20, 2017 03:39
@anastasiamac
Copy link
Contributor Author

@pmatulis,

This change may require documentation update.

@pmatulis
Copy link

@anastasiamac Nothing to do here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants