~rogpeppe/juju-core/438-local-instance-Addresses

« back to all changes in this revision

Viewing changes to state/apiserver/common/tools_test.go

[r=fwereade],[bug=1234035] Fix upgrade 1.14 -> 1.15

This adds a Tools() API call to provisioner API,
similarly to the upgrader API. Common code factored
out into apiserver/common/tools.go.

SetAgentTools() renamed to SetAgentVersion() in
machine and unit state types. Also renamed a few
types in params to be shorter or better reflect
what are they about. Added DEPRECATE(v1.18) tags
to bits of the API that need cleanup.

Live tested on EC2 - after copying the tools from
/tools/releases/ to /tools/ the upgrade proceeds
and finishes successfully.

https://codereview.appspot.com/14231044/

R=fwereade, jameinel

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package common_test
 
5
 
 
6
import (
 
7
        "fmt"
 
8
 
 
9
        gc "launchpad.net/gocheck"
 
10
 
 
11
        "launchpad.net/juju-core/juju/testing"
 
12
        "launchpad.net/juju-core/state"
 
13
        "launchpad.net/juju-core/state/api/params"
 
14
        "launchpad.net/juju-core/state/apiserver/common"
 
15
        apiservertesting "launchpad.net/juju-core/state/apiserver/testing"
 
16
        "launchpad.net/juju-core/version"
 
17
)
 
18
 
 
19
type toolsSuite struct {
 
20
        testing.JujuConnSuite
 
21
        machine0 *state.Machine
 
22
}
 
23
 
 
24
var _ = gc.Suite(&toolsSuite{})
 
25
 
 
26
func (s *toolsSuite) SetUpTest(c *gc.C) {
 
27
        s.JujuConnSuite.SetUpTest(c)
 
28
        var err error
 
29
        s.machine0, err = s.State.AddMachine("series", state.JobHostUnits)
 
30
        c.Assert(err, gc.IsNil)
 
31
}
 
32
 
 
33
func (s *toolsSuite) TestTools(c *gc.C) {
 
34
        getCanRead := func() (common.AuthFunc, error) {
 
35
                return func(tag string) bool {
 
36
                        return tag == "machine-0" || tag == "machine-42"
 
37
                }, nil
 
38
        }
 
39
        tg := common.NewToolsGetter(s.State, getCanRead)
 
40
        c.Assert(tg, gc.NotNil)
 
41
 
 
42
        err := s.machine0.SetAgentVersion(version.Current)
 
43
        c.Assert(err, gc.IsNil)
 
44
 
 
45
        args := params.Entities{
 
46
                Entities: []params.Entity{
 
47
                        {Tag: "machine-0"},
 
48
                        {Tag: "machine-1"},
 
49
                        {Tag: "machine-42"},
 
50
                }}
 
51
        result, err := tg.Tools(args)
 
52
        c.Assert(err, gc.IsNil)
 
53
        c.Assert(result.Results, gc.HasLen, 3)
 
54
        c.Assert(result.Results[0].Tools, gc.NotNil)
 
55
        c.Assert(result.Results[0].Tools.Version, gc.DeepEquals, version.Current)
 
56
        c.Assert(result.Results[1].Error, gc.DeepEquals, apiservertesting.ErrUnauthorized)
 
57
        c.Assert(result.Results[2].Error, gc.DeepEquals, apiservertesting.NotFoundError("machine 42"))
 
58
}
 
59
 
 
60
func (s *toolsSuite) TestToolsError(c *gc.C) {
 
61
        getCanRead := func() (common.AuthFunc, error) {
 
62
                return nil, fmt.Errorf("splat")
 
63
        }
 
64
        tg := common.NewToolsGetter(s.State, getCanRead)
 
65
        args := params.Entities{
 
66
                Entities: []params.Entity{{Tag: "machine-42"}},
 
67
        }
 
68
        result, err := tg.Tools(args)
 
69
        c.Assert(err, gc.ErrorMatches, "splat")
 
70
        c.Assert(result.Results, gc.HasLen, 1)
 
71
}