~axwalk/juju-core/lp1303195-manual-ubuntuuser-bash

« back to all changes in this revision

Viewing changes to worker/upgrader/upgrader.go

[r=wallyworld] Move tools functionality to environs.tools

This is a refactoring branch to move functionality from
agent.tools to environs.tools, as well as refactor some of the
find tools methods. The work is in preparation for the introduction
of simplestreams tools metadata. Basically, the stuff in environs.tools
now is responsible for building, uploading, and reading tools from
env storage. The stuff in agent.tools is about managing and unpacking
the tools tarballs on disk for the agent. The env stuff to read the
tools will be replaced by simplestreams logic, and the upload tools
will need to update simplestreams metadata. Also, to avoid import
loops in subsequent branches, the core tools structs were moved
to a top level tools package.

https://codereview.appspot.com/13147043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
        "launchpad.net/loggo"
12
12
        "launchpad.net/tomb"
13
13
 
14
 
        "launchpad.net/juju-core/agent/tools"
 
14
        agenttools "launchpad.net/juju-core/agent/tools"
15
15
        "launchpad.net/juju-core/state/api/upgrader"
16
16
        "launchpad.net/juju-core/state/watcher"
 
17
        coretools "launchpad.net/juju-core/tools"
17
18
        "launchpad.net/juju-core/version"
18
19
)
19
20
 
27
28
// an upgrade is ready to be performed and a restart is due.
28
29
type UpgradeReadyError struct {
29
30
        AgentName string
30
 
        OldTools  *tools.Tools
31
 
        NewTools  *tools.Tools
 
31
        OldTools  *coretools.Tools
 
32
        NewTools  *coretools.Tools
32
33
        DataDir   string
33
34
}
34
35
 
40
41
// It should be called just before an agent exits, so that
41
42
// it will restart running the new tools.
42
43
func (e *UpgradeReadyError) ChangeAgentTools() error {
43
 
        tools, err := tools.ChangeAgentTools(e.DataDir, e.AgentName, e.NewTools.Version)
 
44
        tools, err := agenttools.ChangeAgentTools(e.DataDir, e.AgentName, e.NewTools.Version)
44
45
        if err != nil {
45
46
                return err
46
47
        }
97
98
}
98
99
 
99
100
func (u *Upgrader) loop() error {
100
 
        currentTools, err := tools.ReadTools(u.dataDir, version.Current)
 
101
        currentTools, err := agenttools.ReadTools(u.dataDir, version.Current)
101
102
        if err != nil {
102
103
                // Don't abort everything because we can't find the tools directory.
103
104
                // The problem should sort itself out as we will immediately
104
105
                // download some more tools and upgrade.
105
106
                logger.Warningf("cannot read current tools: %v", err)
106
 
                currentTools = &tools.Tools{
 
107
                currentTools = &coretools.Tools{
107
108
                        Version: version.Current,
108
109
                }
109
110
        }
123
124
        // that we attempt an upgrade even if other workers are dying
124
125
        // all around us.
125
126
        var dying <-chan struct{}
126
 
        var wantTools *tools.Tools
 
127
        var wantTools *coretools.Tools
127
128
        for {
128
129
                select {
129
130
                case _, ok := <-changes:
162
163
        }
163
164
}
164
165
 
165
 
func (u *Upgrader) fetchTools(agentTools *tools.Tools) error {
 
166
func (u *Upgrader) fetchTools(agentTools *coretools.Tools) error {
166
167
        logger.Infof("fetching tools from %q", agentTools.URL)
167
168
        resp, err := http.Get(agentTools.URL)
168
169
        if err != nil {
172
173
        if resp.StatusCode != http.StatusOK {
173
174
                return fmt.Errorf("bad HTTP response: %v", resp.Status)
174
175
        }
175
 
        err = tools.UnpackTools(u.dataDir, agentTools, resp.Body)
 
176
        err = agenttools.UnpackTools(u.dataDir, agentTools, resp.Body)
176
177
        if err != nil {
177
178
                return fmt.Errorf("cannot unpack tools: %v", err)
178
179
        }