Inform user of storage destruction/detachment in remove-{application,unit} #7100

Merged
merged 2 commits into from Mar 16, 2017

Conversation

Projects
None yet
3 participants
Member

axw commented Mar 15, 2017

Description of change

We introduce new DestroyApplication and DestroyUnit
methods to the Application facade. These supersede
the existing Destroy and DestroyUnits methods,
respectively. The new methods are bulk, and return
information relating to the entities being destroyed.

This enables us to inform the user of storage that is
destroyed, or detached and left in the model, when
removing an application or unit with the remove-application
or remove-unit commands.

We will do the same for remove-machine in a follow-up.

Also, move a few tests over to the unit test suite in
apiserver/application.

QA steps

  1. juju bootstrap localhost
  2. juju deploy postgresql -n2 --storage pgdata=rootfs
  3. juju remove-unit postgresql/0
    should see:

removing unit postgresql/0

  • removing storage pgdata/0
  1. juju remove-application postgresql/1 --verbose
    should see:

removing application postgresql

  • removing unit postgresql/1
  • removing storage pgdata/1

Also tested backwards compatibility (new server & old client, and vice versa).

Documentation changes

  • The remove-application command now accepts multiple application names, and will remove them all.
  • The user will be informed of removals. When removing an application, the units are only listed if the user specified --verbose (as removing an application implies the units will all be removed, it's probably a bit noisy to be on by default)

Bug reference

None.

apiserver/application: Destroy{Application,Unit}
Introduce new DestroyApplication and DestroyUnit
methods to the Application facade. These supersede
the existing Destroy and DestroyUnits methods,
respectively. The new methods are bulk, and return
information relating to the entities being destroyed.

This will enable us to inform the user of storage
that is destroyed, or detached and left in the model.

Also, move a few tests over to the unit test suite.

Awesome to remove JujuConnSuite. I think we need a couple of feature tests though to replace the now deleted full stack tests.

api/application/client.go
-// Destroy destroys a given application.
-func (c *Client) Destroy(application string) error {
+// DestroyUnit decreases the number of units dedicated to an application.
+func (c *Client) DestroyUnit(unitNames ...string) ([]params.DestroyUnitResult, error) {
@wallyworld

wallyworld Mar 16, 2017

Owner

We agreed that client side should be plural?

@axw

axw Mar 16, 2017

Member

Yeah, misremembered the branch. After adding it I don't like it there either, but I'll make it plural for now.

api/application/client.go
+ }
+ for i, name := range unitNames {
+ if !names.IsValidUnit(name) {
+ return nil, errors.NotValidf("unit name %q", name)
@wallyworld

wallyworld Mar 16, 2017

Owner

This should set the error in that unit's Result struct.
One bad unit name shouldn't prevent the rest from being destroyed?

@axw

axw Mar 16, 2017

Member

IMO it's OK here because the user has specified something invalid, rather than there being a server-side error for one of the parameters. I'll do it anyway, but question the value.

api/application/client.go
params := params.ApplicationDestroy{
ApplicationName: application,
}
return c.facade.FacadeCall("Destroy", params, nil)
}
+// DestroyApplication destroys the given applications.
+func (c *Client) DestroyApplication(appNames ...string) ([]params.DestroyApplicationResult, error) {
@wallyworld

wallyworld Mar 16, 2017

Owner

ditto about plural?

@axw

axw Mar 16, 2017

Member

done

api/application/client.go
+ }
+ for i, name := range appNames {
+ if !names.IsValidApplication(name) {
+ return nil, errors.NotValidf("application name %q", name)
@wallyworld

wallyworld Mar 16, 2017

Owner

ditto about error handling

@axw

axw Mar 16, 2017

Member

ditto

- jujutesting.JujuConnSuite
-
- client *application.Client
+ testing.IsolationSuite
@@ -36,3 +37,34 @@ func (client *Client) AddMachines(machineParams []params.AddMachineParams) ([]pa
}
return results.Machines, err
}
+
+// DestroyMachines removes a given set of machines.
+func (client *Client) DestroyMachines(machines ...string) ([]params.DestroyMachineResult, error) {
@wallyworld

wallyworld Mar 16, 2017

Owner

Can you add a todo to the CLI to use this new api instead of the one on the client facade?
And a deprecation todo on the client facade.

@wallyworld

wallyworld Mar 16, 2017

Owner

also, tests?

@axw

axw Mar 16, 2017

Member

will do this in a follow-up

+
+// DeployApplication is a wrapper around juju.DeployApplication, to
+// match the function signature expected by NewAPI.
+func DeployApplication(backend Backend, args jjj.DeployApplicationParams) error {
@wallyworld

wallyworld Mar 16, 2017

Owner

Personally, I'd rather this not be exported.
This is a case where adding an alias to export_test makes sense IMO.

@axw

axw Mar 16, 2017

Member

And I'd rather we didn't have hard-coded dependencies. Exporting this is a step towards being able to pass the dependency in, but providing an easy to get to default.

+ if err != nil {
+ return nil, err
+ }
+ name := unitTag.Id()
unit, err := api.backend.Unit(name)
@wallyworld

wallyworld Mar 16, 2017

Owner

Is the check for life != alive missing?

@axw

axw Mar 16, 2017

Member

Didn't need to be there in the first place, we check life in state.

@@ -342,15 +342,15 @@ func opClientAddServiceUnits(c *gc.C, st api.Connection, mst *state.State) (func
}
func opClientDestroyServiceUnits(c *gc.C, st api.Connection, mst *state.State) (func(), error) {
- err := application.NewClient(st).DestroyUnits("wordpress/99")
+ err := application.NewClient(st).DestroyUnitsDeprecated("wordpress/99")
@wallyworld

wallyworld Mar 16, 2017

Owner

IMO we should be calling the new methods

@axw

axw Mar 16, 2017

Member

added tests to cover the new methods also

- client, err := c.getAPI()
- if err != nil {
- return err
+func (c *removeApplicationCommand) removeApplicationsDeprecated(
@wallyworld

wallyworld Mar 16, 2017

Owner

Worth a todo so we can search and remove later

@axw

axw Mar 16, 2017

Member

done

+ logger.Warningf("%s", err)
+ continue
+ }
+ ctx.Infof("- removing %s", names.ReadableString(storageTag))
@wallyworld

wallyworld Mar 16, 2017

Owner

Having it worded as "removing" will be confusing, because for destroy-controller, we say "destroying machine" or whatever and then when that all is done, the job is finished. But here that same expectation doesn't hold true.
I think "will remove blah" is better as it better communicates the async semantics of the operation.

@axw

axw Mar 16, 2017

Member

are you suggesting this?

removing application foo
- will remove storage bar/0
- will detach storage baz/1

?

@wallyworld

wallyworld Mar 16, 2017

Owner

yeah, something to indicate that when the commend ends, it may not have happened yet

Member

axw commented Mar 16, 2017

Awesome to remove JujuConnSuite. I think we need a couple of feature tests though to replace the now deleted full stack tests.

I believe we have enough full-stack tests in cmd/juju/application already.

Owner

wallyworld commented Mar 16, 2017

Full stack tests in cmd/juju/application good - so long as we remember to add feature tests when those cmd tests are made into proper unit tests

Member

axw commented Mar 16, 2017

$$merge$$

Contributor

jujubot commented Mar 16, 2017

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

Contributor

jujubot commented Mar 16, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10471

cmd/juju/application: use new Destroy* methods
Use the new DestroyApplication and DestroyUnit
methods, printing out the names of storage that
is destroyed or detached when removing an
application or unit.
Member

axw commented Mar 16, 2017

$$merge$$

Contributor

jujubot commented Mar 16, 2017

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

Contributor

jujubot commented Mar 16, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10473

Member

axw commented Mar 16, 2017

$$merge$$

Contributor

jujubot commented Mar 16, 2017

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

@jujubot jujubot merged commit 26a076f into juju:develop Mar 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment