Merge lp:~rogpeppe/juju-core/560-utils-apt into lp:~go-bot/juju-core/trunk

Proposed by Roger Peppe
Status: Merged
Approved by: Roger Peppe
Approved revision: no longer in the source branch.
Merged at revision: 2786
Proposed branch: lp:~rogpeppe/juju-core/560-utils-apt
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 885 lines (+177/-131)
19 files modified
agent/mongo/mongo.go (+5/-4)
cmd/jujud/machine_test.go (+3/-3)
cmd/jujud/upgrade_test.go (+2/-2)
container/kvm/initialisation.go (+3/-2)
container/lxc/initialisation.go (+3/-3)
container/lxc/initialisation_test.go (+3/-3)
environs/cloudinit/cloudinit.go (+3/-2)
provider/local/environprovider.go (+2/-1)
provider/local/environprovider_test.go (+3/-3)
provider/local/prereqs.go (+2/-1)
provider/local/prereqs_test.go (+2/-2)
upgrades/rsysloggnutls.go (+2/-4)
utils/apt/apt.go (+37/-46)
utils/apt/apt_test.go (+47/-45)
utils/isubuntu.go (+14/-0)
utils/isubuntu_test.go (+35/-0)
worker/machineenvironmentworker/machineenvironmentworker.go (+3/-2)
worker/machineenvironmentworker/machineenvironmentworker_test.go (+6/-6)
worker/provisioner/container_initialisation_test.go (+2/-2)
To merge this branch: bzr merge lp:~rogpeppe/juju-core/560-utils-apt
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+220792@code.launchpad.net

Commit message

utils/apt: new package

It makes sense on its own, and we want to remove
the osenv dependency from utils.

https://codereview.appspot.com/100730044/

Description of the change

utils/apt: new package

It makes sense on its own, and we want to remove
the osenv dependency from utils.

https://codereview.appspot.com/100730044/

To post a comment you must log in.
Revision history for this message
Roger Peppe (rogpeppe) wrote :

Reviewers: mp+220792_code.launchpad.net,

Message:
Please take a look.

Description:
utils/apt: new package

It makes sense on its own, and we want to remove
the osenv dependency from utils.

https://code.launchpad.net/~rogpeppe/juju-core/560-utils-apt/+merge/220792

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/100730044/

Affected files (+178, -131 lines):
   A [revision details]
   M agent/mongo/mongo.go
   M cmd/jujud/machine_test.go
   M cmd/jujud/upgrade_test.go
   M container/kvm/initialisation.go
   M container/lxc/initialisation.go
   M container/lxc/initialisation_test.go
   M environs/cloudinit/cloudinit.go
   M provider/local/environprovider.go
   M provider/local/environprovider_test.go
   M provider/local/prereqs.go
   M provider/local/prereqs_test.go
   M upgrades/rsysloggnutls.go
   M utils/apt/apt.go
   M utils/apt/apt_test.go
   A utils/isubuntu.go
   A utils/isubuntu_test.go
   M worker/machineenvironmentworker/machineenvironmentworker.go
   M worker/machineenvironmentworker/machineenvironmentworker_test.go
   M worker/provisioner/container_initialisation_test.go

Revision history for this message
Nate Finch (natefinch) wrote :
Revision history for this message
Roger Peppe (rogpeppe) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'agent/mongo/mongo.go'
2--- agent/mongo/mongo.go 2014-05-14 11:38:13 +0000
3+++ agent/mongo/mongo.go 2014-05-23 12:00:33 +0000
4@@ -22,6 +22,7 @@
5 "launchpad.net/juju-core/state/api/params"
6 "launchpad.net/juju-core/upstart"
7 "launchpad.net/juju-core/utils"
8+ "launchpad.net/juju-core/utils/apt"
9 "launchpad.net/juju-core/version"
10 )
11
12@@ -310,10 +311,10 @@
13 }
14 }
15 pkg := packageForSeries(version.Current.Series)
16- cmds := utils.AptGetPreparePackages([]string{pkg}, version.Current.Series)
17+ cmds := apt.GetPreparePackages([]string{pkg}, version.Current.Series)
18 logger.Infof("installing %s", pkg)
19 for _, cmd := range cmds {
20- if err := utils.AptGetInstall(cmd...); err != nil {
21+ if err := apt.GetInstall(cmd...); err != nil {
22 return err
23 }
24 }
25@@ -322,13 +323,13 @@
26
27 func addAptRepository(name string) error {
28 // add-apt-repository requires python-software-properties
29- cmds := utils.AptGetPreparePackages(
30+ cmds := apt.GetPreparePackages(
31 []string{"python-software-properties"},
32 version.Current.Series,
33 )
34 logger.Infof("installing python-software-properties")
35 for _, cmd := range cmds {
36- if err := utils.AptGetInstall(cmd...); err != nil {
37+ if err := apt.GetInstall(cmd...); err != nil {
38 return err
39 }
40 }
41
42=== modified file 'cmd/jujud/machine_test.go'
43--- cmd/jujud/machine_test.go 2014-05-19 13:07:51 +0000
44+++ cmd/jujud/machine_test.go 2014-05-23 12:00:33 +0000
45@@ -39,7 +39,7 @@
46 coretesting "launchpad.net/juju-core/testing"
47 "launchpad.net/juju-core/tools"
48 "launchpad.net/juju-core/upstart"
49- "launchpad.net/juju-core/utils"
50+ "launchpad.net/juju-core/utils/apt"
51 "launchpad.net/juju-core/utils/set"
52 "launchpad.net/juju-core/utils/ssh"
53 sshtesting "launchpad.net/juju-core/utils/ssh/testing"
54@@ -854,7 +854,7 @@
55 func (s *MachineSuite) TestMachineEnvironWorker(c *gc.C) {
56 proxyDir := c.MkDir()
57 s.agentSuite.PatchValue(&machineenvironmentworker.ProxyDirectory, proxyDir)
58- s.agentSuite.PatchValue(&utils.AptConfFile, filepath.Join(proxyDir, "juju-apt-proxy"))
59+ s.agentSuite.PatchValue(&apt.ConfFile, filepath.Join(proxyDir, "juju-apt-proxy"))
60
61 s.primeAgent(c, version.Current, state.JobHostUnits)
62 // Make sure there are some proxy settings to write.
63@@ -875,7 +875,7 @@
64 case <-time.After(coretesting.LongWait):
65 c.Fatalf("timeout while waiting for proxy settings to change")
66 case <-time.After(10 * time.Millisecond):
67- _, err := os.Stat(utils.AptConfFile)
68+ _, err := os.Stat(apt.ConfFile)
69 if os.IsNotExist(err) {
70 continue
71 }
72
73=== modified file 'cmd/jujud/upgrade_test.go'
74--- cmd/jujud/upgrade_test.go 2014-05-16 04:20:04 +0000
75+++ cmd/jujud/upgrade_test.go 2014-05-23 12:00:33 +0000
76@@ -15,7 +15,7 @@
77 "launchpad.net/juju-core/environs/config"
78 "launchpad.net/juju-core/state"
79 coretesting "launchpad.net/juju-core/testing"
80- "launchpad.net/juju-core/utils"
81+ "launchpad.net/juju-core/utils/apt"
82 "launchpad.net/juju-core/version"
83 )
84
85@@ -36,7 +36,7 @@
86
87 // Capture all apt commands.
88 s.aptCmds = nil
89- aptCmds := s.agentSuite.HookCommandOutput(&utils.AptCommandOutput, nil, nil)
90+ aptCmds := s.agentSuite.HookCommandOutput(&apt.CommandOutput, nil, nil)
91 go func() {
92 for cmd := range aptCmds {
93 s.aptCmds = append(s.aptCmds, cmd)
94
95=== modified file 'container/kvm/initialisation.go'
96--- container/kvm/initialisation.go 2014-04-09 08:25:32 +0000
97+++ container/kvm/initialisation.go 2014-05-23 12:00:33 +0000
98@@ -9,6 +9,7 @@
99
100 "launchpad.net/juju-core/container"
101 "launchpad.net/juju-core/utils"
102+ "launchpad.net/juju-core/utils/apt"
103 )
104
105 var requiredPackages = []string{
106@@ -33,7 +34,7 @@
107 }
108
109 func ensureDependencies() error {
110- return utils.AptGetInstall(requiredPackages...)
111+ return apt.GetInstall(requiredPackages...)
112 }
113
114 const kvmNeedsUbuntu = `Sorry, KVM support with the local provider is only supported
115@@ -69,7 +70,7 @@
116 // Check for other packages needed.
117 toInstall := []string{}
118 for _, pkg := range requiredPackages {
119- if !utils.IsPackageInstalled(pkg) {
120+ if !apt.IsPackageInstalled(pkg) {
121 toInstall = append(toInstall, pkg)
122 }
123 }
124
125=== modified file 'container/lxc/initialisation.go'
126--- container/lxc/initialisation.go 2014-05-08 06:58:42 +0000
127+++ container/lxc/initialisation.go 2014-05-23 12:00:33 +0000
128@@ -5,7 +5,7 @@
129
130 import (
131 "launchpad.net/juju-core/container"
132- "launchpad.net/juju-core/utils"
133+ "launchpad.net/juju-core/utils/apt"
134 )
135
136 var requiredPackages = []string{
137@@ -35,9 +35,9 @@
138 // and runs each set of packages through AptGetInstall
139 func ensureDependencies(series string) error {
140 var err error
141- aptGetInstallCommandList := utils.AptGetPreparePackages(requiredPackages, series)
142+ aptGetInstallCommandList := apt.GetPreparePackages(requiredPackages, series)
143 for _, commands := range aptGetInstallCommandList {
144- err = utils.AptGetInstall(commands...)
145+ err = apt.GetInstall(commands...)
146 if err != nil {
147 return err
148 }
149
150=== modified file 'container/lxc/initialisation_test.go'
151--- container/lxc/initialisation_test.go 2014-05-20 04:27:02 +0000
152+++ container/lxc/initialisation_test.go 2014-05-23 12:00:33 +0000
153@@ -7,7 +7,7 @@
154 gc "launchpad.net/gocheck"
155
156 "launchpad.net/juju-core/testing"
157- "launchpad.net/juju-core/utils"
158+ "launchpad.net/juju-core/utils/apt"
159 )
160
161 type InitialiserSuite struct {
162@@ -17,7 +17,7 @@
163 var _ = gc.Suite(&InitialiserSuite{})
164
165 func (s *InitialiserSuite) TestLTSSeriesPackages(c *gc.C) {
166- cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
167+ cmdChan := s.HookCommandOutput(&apt.CommandOutput, []byte{}, nil)
168 container := NewContainerInitialiser("precise")
169 err := container.Initialise()
170 c.Assert(err, gc.IsNil)
171@@ -31,7 +31,7 @@
172 }
173
174 func (s *InitialiserSuite) TestNoSeriesPackages(c *gc.C) {
175- cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
176+ cmdChan := s.HookCommandOutput(&apt.CommandOutput, []byte{}, nil)
177 container := NewContainerInitialiser("")
178 err := container.Initialise()
179 c.Assert(err, gc.IsNil)
180
181=== modified file 'environs/cloudinit/cloudinit.go'
182--- environs/cloudinit/cloudinit.go 2014-05-13 04:50:10 +0000
183+++ environs/cloudinit/cloudinit.go 2014-05-23 12:00:33 +0000
184@@ -27,6 +27,7 @@
185 coretools "launchpad.net/juju-core/tools"
186 "launchpad.net/juju-core/upstart"
187 "launchpad.net/juju-core/utils"
188+ "launchpad.net/juju-core/utils/apt"
189 "launchpad.net/juju-core/version"
190 )
191
192@@ -218,11 +219,11 @@
193
194 // Write out the apt proxy settings
195 if (proxy != osenv.ProxySettings{}) {
196- filename := utils.AptConfFile
197+ filename := apt.ConfFile
198 c.AddBootCmd(fmt.Sprintf(
199 `[ -f %s ] || (printf '%%s\n' %s > %s)`,
200 filename,
201- shquote(utils.AptProxyContent(proxy)),
202+ shquote(apt.ProxyContent(proxy)),
203 filename))
204 }
205 }
206
207=== modified file 'provider/local/environprovider.go'
208--- provider/local/environprovider.go 2014-05-13 08:08:46 +0000
209+++ provider/local/environprovider.go 2014-05-23 12:00:33 +0000
210@@ -18,6 +18,7 @@
211 "launchpad.net/juju-core/juju/osenv"
212 "launchpad.net/juju-core/provider"
213 "launchpad.net/juju-core/utils"
214+ "launchpad.net/juju-core/utils/apt"
215 "launchpad.net/juju-core/version"
216 )
217
218@@ -81,7 +82,7 @@
219 return environ, nil
220 }
221
222-var detectAptProxies = utils.DetectAptProxies
223+var detectAptProxies = apt.DetectProxies
224
225 // Prepare implements environs.EnvironProvider.Prepare.
226 func (p environProvider) Prepare(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
227
228=== modified file 'provider/local/environprovider_test.go'
229--- provider/local/environprovider_test.go 2014-05-16 04:57:59 +0000
230+++ provider/local/environprovider_test.go 2014-05-23 12:00:33 +0000
231@@ -18,7 +18,7 @@
232 "launchpad.net/juju-core/provider"
233 "launchpad.net/juju-core/provider/local"
234 coretesting "launchpad.net/juju-core/testing"
235- "launchpad.net/juju-core/utils"
236+ "launchpad.net/juju-core/utils/apt"
237 )
238
239 type baseProviderSuite struct {
240@@ -54,7 +54,7 @@
241 s.PatchEnvironment("FTP_PROXY", "")
242 s.PatchEnvironment("no_proxy", "")
243 s.PatchEnvironment("NO_PROXY", "")
244- s.HookCommandOutput(&utils.AptCommandOutput, nil, nil)
245+ s.HookCommandOutput(&apt.CommandOutput, nil, nil)
246 s.PatchValue(local.CheckLocalPort, func(port int, desc string) error {
247 return nil
248 })
249@@ -222,7 +222,7 @@
250 restore := testing.PatchEnvironment(key, value)
251 cleanup = append(cleanup, restore)
252 }
253- _, restore := testing.HookCommandOutput(&utils.AptCommandOutput, []byte(test.aptOutput), nil)
254+ _, restore := testing.HookCommandOutput(&apt.CommandOutput, []byte(test.aptOutput), nil)
255 cleanup = append(cleanup, restore)
256 testConfig := baseConfig
257 if test.extraConfig != nil {
258
259=== modified file 'provider/local/prereqs.go'
260--- provider/local/prereqs.go 2014-05-08 07:05:44 +0000
261+++ provider/local/prereqs.go 2014-05-23 12:00:33 +0000
262@@ -12,6 +12,7 @@
263 "launchpad.net/juju-core/container/kvm"
264 "launchpad.net/juju-core/instance"
265 "launchpad.net/juju-core/utils"
266+ "launchpad.net/juju-core/utils/apt"
267 )
268
269 var notLinuxError = errors.New("The local provider is currently only available for Linux")
270@@ -46,7 +47,7 @@
271 var lxclsPath = "lxc-ls"
272
273 // isPackageInstalled is a variable to support testing.
274-var isPackageInstalled = utils.IsPackageInstalled
275+var isPackageInstalled = apt.IsPackageInstalled
276
277 // The operating system the process is running in.
278 // This is a variable only to support unit testing.
279
280=== modified file 'provider/local/prereqs_test.go'
281--- provider/local/prereqs_test.go 2014-05-19 08:16:18 +0000
282+++ provider/local/prereqs_test.go 2014-05-23 12:00:33 +0000
283@@ -13,7 +13,7 @@
284 "launchpad.net/juju-core/agent/mongo"
285 "launchpad.net/juju-core/instance"
286 "launchpad.net/juju-core/testing"
287- "launchpad.net/juju-core/utils"
288+ "launchpad.net/juju-core/utils/apt"
289 )
290
291 type prereqsSuite struct {
292@@ -59,7 +59,7 @@
293 // simulate package installation query responses.
294 err = os.Symlink("/bin/true", filepath.Join(s.tmpdir, "dpkg-query"))
295 c.Assert(err, gc.IsNil)
296- s.PatchValue(&isPackageInstalled, utils.IsPackageInstalled)
297+ s.PatchValue(&isPackageInstalled, apt.IsPackageInstalled)
298 }
299
300 func (*prereqsSuite) TestSupportedOS(c *gc.C) {
301
302=== modified file 'upgrades/rsysloggnutls.go'
303--- upgrades/rsysloggnutls.go 2014-03-18 09:21:53 +0000
304+++ upgrades/rsysloggnutls.go 2014-05-23 12:00:33 +0000
305@@ -3,12 +3,10 @@
306
307 package upgrades
308
309-import (
310- "launchpad.net/juju-core/utils"
311-)
312+import "launchpad.net/juju-core/utils/apt"
313
314 // installRsyslogGnutls installs the rsyslog-gnutls package,
315 // which is required for our rsyslog configuration from 1.18.0.
316 func installRsyslogGnutls(context Context) error {
317- return utils.AptGetInstall("rsyslog-gnutls")
318+ return apt.GetInstall("rsyslog-gnutls")
319 }
320
321=== added directory 'utils/apt'
322=== renamed file 'utils/apt.go' => 'utils/apt/apt.go'
323--- utils/apt.go 2014-05-08 06:58:42 +0000
324+++ utils/apt/apt.go 2014-05-23 12:00:33 +0000
325@@ -1,7 +1,7 @@
326 // Copyright 2012, 2013 Canonical Ltd.
327 // Licensed under the AGPLv3, see LICENCE file for details.
328
329-package utils
330+package apt
331
332 import (
333 "bytes"
334@@ -14,35 +14,36 @@
335 "github.com/juju/loggo"
336
337 "launchpad.net/juju-core/juju/osenv"
338+ "launchpad.net/juju-core/utils"
339 )
340
341 var (
342- aptLogger = loggo.GetLogger("juju.utils.apt")
343- aptProxyRE = regexp.MustCompile(`(?im)^\s*Acquire::(?P<protocol>[a-z]+)::Proxy\s+"(?P<proxy>[^"]+)";\s*$`)
344+ logger = loggo.GetLogger("juju.utils.apt")
345+ proxyRE = regexp.MustCompile(`(?im)^\s*Acquire::(?P<protocol>[a-z]+)::Proxy\s+"(?P<proxy>[^"]+)";\s*$`)
346
347- // AptConfFile is the full file path for the proxy settings that are
348+ // ConfFile is the full file path for the proxy settings that are
349 // written by cloud-init and the machine environ worker.
350- AptConfFile = "/etc/apt/apt.conf.d/42-juju-proxy-settings"
351+ ConfFile = "/etc/apt/apt.conf.d/42-juju-proxy-settings"
352 )
353
354 // Some helpful functions for running apt in a sane way
355
356-// AptCommandOutput calls cmd.Output, this is used as an overloading point so we
357+// CommandOutput calls cmd.Output, this is used as an overloading point so we
358 // can test what *would* be run without actually executing another program
359-var AptCommandOutput = (*exec.Cmd).CombinedOutput
360+var CommandOutput = (*exec.Cmd).CombinedOutput
361
362-// This is the default apt-get command used in cloud-init, the various settings
363+// getCommand is the default apt-get command used in cloud-init, the various settings
364 // mean that apt won't actually block waiting for a prompt from the user.
365-var aptGetCommand = []string{
366+var getCommand = []string{
367 "apt-get", "--option=Dpkg::Options::=--force-confold",
368 "--option=Dpkg::options::=--force-unsafe-io", "--assume-yes", "--quiet",
369 }
370
371-// aptEnvOptions are options we need to pass to apt-get to not have it prompt
372+// getEnvOptions are options we need to pass to apt-get to not have it prompt
373 // the user
374-var aptGetEnvOptions = []string{"DEBIAN_FRONTEND=noninteractive"}
375+var getEnvOptions = []string{"DEBIAN_FRONTEND=noninteractive"}
376
377-// cloudArchivePackages maintaines a list of packages that AptGetPreparePackages
378+// cloudArchivePackages maintaines a list of packages that GetPreparePackages
379 // should reference when determining the --target-release for a given series.
380 // http://reqorts.qa.ubuntu.com/reports/ubuntu-server/cloud-archive/cloud-tools_versions.html
381 var cloudArchivePackages = map[string]bool{
382@@ -83,13 +84,12 @@
383 }
384 }
385
386-// AptGetPreparePackages returns a slice of installCommands. Each item
387-// in the slice is suitable for passing directly to AptGetInstall.
388-//
389-// AptGetPreparePackages will inspect the series passed to it
390-// and properly generate an installCommand entry with a --target-release
391+// GetPreparePackages returns a slice of installCommands. Each item
392+// in the slice is suitable for passing directly to Apt.
393+// It inspects the series passed to it
394+// and properly generates an installCommand entry with a --target-release
395 // should the series be an LTS release with cloud archive packages.
396-func AptGetPreparePackages(packages []string, series string) [][]string {
397+func GetPreparePackages(packages []string, series string) [][]string {
398 var installCommands [][]string
399 if target := targetRelease(series); target == "" {
400 return append(installCommands, packages)
401@@ -120,27 +120,27 @@
402 }
403 }
404
405-// AptGetInstall runs 'apt-get install packages' for the packages listed here
406-func AptGetInstall(packages ...string) error {
407- cmdArgs := append([]string(nil), aptGetCommand...)
408+// GetInstall runs 'apt-get install packages' for the packages listed here
409+func GetInstall(packages ...string) error {
410+ cmdArgs := append([]string(nil), getCommand...)
411 cmdArgs = append(cmdArgs, "install")
412 cmdArgs = append(cmdArgs, packages...)
413- aptLogger.Infof("Running: %s", cmdArgs)
414+ logger.Infof("Running: %s", cmdArgs)
415 cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
416- cmd.Env = append(os.Environ(), aptGetEnvOptions...)
417- out, err := AptCommandOutput(cmd)
418+ cmd.Env = append(os.Environ(), getEnvOptions...)
419+ out, err := CommandOutput(cmd)
420 if err != nil {
421- aptLogger.Errorf("apt-get command failed: %v\nargs: %#v\n%s",
422+ logger.Errorf("apt-get command failed: %v\nargs: %#v\n%s",
423 err, cmdArgs, string(out))
424 return fmt.Errorf("apt-get failed: %v", err)
425 }
426 return nil
427 }
428
429-// AptConfigProxy will consult apt-config about the configured proxy
430+// ConfigProxy will consult apt-config about the configured proxy
431 // settings. If there are no proxy settings configured, an empty string is
432 // returned.
433-func AptConfigProxy() (string, error) {
434+func ConfigProxy() (string, error) {
435 cmdArgs := []string{
436 "apt-config",
437 "dump",
438@@ -149,23 +149,23 @@
439 "Acquire::ftp::Proxy",
440 }
441 cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
442- out, err := AptCommandOutput(cmd)
443+ out, err := CommandOutput(cmd)
444 if err != nil {
445- aptLogger.Errorf("apt-config command failed: %v\nargs: %#v\n%s",
446+ logger.Errorf("apt-config command failed: %v\nargs: %#v\n%s",
447 err, cmdArgs, string(out))
448 return "", fmt.Errorf("apt-config failed: %v", err)
449 }
450- return string(bytes.Join(aptProxyRE.FindAll(out, -1), []byte("\n"))), nil
451+ return string(bytes.Join(proxyRE.FindAll(out, -1), []byte("\n"))), nil
452 }
453
454-// DetectAptProxies will parse the results of AptConfigProxy to return a
455+// DetectProxies will parse the results of ConfigProxy to return a
456 // ProxySettings instance.
457-func DetectAptProxies() (result osenv.ProxySettings, err error) {
458- output, err := AptConfigProxy()
459+func DetectProxies() (result osenv.ProxySettings, err error) {
460+ output, err := ConfigProxy()
461 if err != nil {
462 return result, err
463 }
464- for _, match := range aptProxyRE.FindAllStringSubmatch(output, -1) {
465+ for _, match := range proxyRE.FindAllStringSubmatch(output, -1) {
466 switch match[1] {
467 case "http":
468 result.Http = match[2]
469@@ -178,9 +178,9 @@
470 return result, nil
471 }
472
473-// AptProxyContent produces the format expected by the apt config files
474+// ProxyContent produces the format expected by the apt config files
475 // from the ProxySettings struct.
476-func AptProxyContent(proxy osenv.ProxySettings) string {
477+func ProxyContent(proxy osenv.ProxySettings) string {
478 lines := []string{}
479 addLine := func(proxy, value string) {
480 if value != "" {
481@@ -194,18 +194,9 @@
482 return strings.Join(lines, "\n")
483 }
484
485-// IsUbuntu executes lxb_release to see if the host OS is Ubuntu.
486-func IsUbuntu() bool {
487- out, err := RunCommand("lsb_release", "-i", "-s")
488- if err != nil {
489- return false
490- }
491- return strings.TrimSpace(out) == "Ubuntu"
492-}
493-
494 // IsPackageInstalled uses dpkg-query to determine if the `packageName`
495 // package is installed.
496 func IsPackageInstalled(packageName string) bool {
497- _, err := RunCommand("dpkg-query", "--status", packageName)
498+ _, err := utils.RunCommand("dpkg-query", "--status", packageName)
499 return err == nil
500 }
501
502=== renamed file 'utils/apt_test.go' => 'utils/apt/apt_test.go'
503--- utils/apt_test.go 2014-05-20 04:27:02 +0000
504+++ utils/apt/apt_test.go 2014-05-23 12:00:33 +0000
505@@ -1,19 +1,26 @@
506 // Copyright 2012, 2013 Canonical Ltd.
507 // Licensed under the AGPLv3, see LICENCE file for details.
508
509-package utils_test
510+package apt_test
511
512 import (
513 "fmt"
514+ "io/ioutil"
515+ "path/filepath"
516+ stdtesting "testing"
517
518 jc "github.com/juju/testing/checkers"
519 gc "launchpad.net/gocheck"
520
521 "launchpad.net/juju-core/juju/osenv"
522 "launchpad.net/juju-core/testing"
523- "launchpad.net/juju-core/utils"
524+ "launchpad.net/juju-core/utils/apt"
525 )
526
527+func TestPackage(t *stdtesting.T) {
528+ gc.TestingT(t)
529+}
530+
531 type AptSuite struct {
532 testing.BaseSuite
533 }
534@@ -21,8 +28,8 @@
535 var _ = gc.Suite(&AptSuite{})
536
537 func (s *AptSuite) TestOnePackage(c *gc.C) {
538- cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
539- err := utils.AptGetInstall("test-package")
540+ cmdChan := s.HookCommandOutput(&apt.CommandOutput, []byte{}, nil)
541+ err := apt.GetInstall("test-package")
542 c.Assert(err, gc.IsNil)
543 cmd := <-cmdChan
544 c.Assert(cmd.Args, gc.DeepEquals, []string{
545@@ -34,7 +41,7 @@
546 }
547
548 func (s *AptSuite) TestAptGetPreparePackages(c *gc.C) {
549- packagesList := utils.AptGetPreparePackages([]string{"lxc", "bridge-utils", "git", "mongodb"}, "precise")
550+ packagesList := apt.GetPreparePackages([]string{"lxc", "bridge-utils", "git", "mongodb"}, "precise")
551 c.Assert(packagesList[0], gc.DeepEquals, []string{"--target-release", "precise-updates/cloud-tools", "lxc", "mongodb"})
552 c.Assert(packagesList[1], gc.DeepEquals, []string{"bridge-utils", "git"})
553 }
554@@ -43,8 +50,8 @@
555 const expected = `E: frobnicator failure detected`
556 cmdError := fmt.Errorf("error")
557 cmdExpectedError := fmt.Errorf("apt-get failed: error")
558- cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte(expected), cmdError)
559- err := utils.AptGetInstall("foo")
560+ cmdChan := s.HookCommandOutput(&apt.CommandOutput, []byte(expected), cmdError)
561+ err := apt.GetInstall("foo")
562 c.Assert(err, gc.DeepEquals, cmdExpectedError)
563 cmd := <-cmdChan
564 c.Assert(cmd.Args, gc.DeepEquals, []string{
565@@ -55,8 +62,8 @@
566 }
567
568 func (s *AptSuite) TestConfigProxyEmpty(c *gc.C) {
569- cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
570- out, err := utils.AptConfigProxy()
571+ cmdChan := s.HookCommandOutput(&apt.CommandOutput, []byte{}, nil)
572+ out, err := apt.ConfigProxy()
573 c.Assert(err, gc.IsNil)
574 cmd := <-cmdChan
575 c.Assert(cmd.Args, gc.DeepEquals, []string{
576@@ -69,8 +76,8 @@
577 func (s *AptSuite) TestConfigProxyConfigured(c *gc.C) {
578 const expected = `Acquire::http::Proxy "10.0.3.1:3142";
579 Acquire::https::Proxy "false";`
580- cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte(expected), nil)
581- out, err := utils.AptConfigProxy()
582+ cmdChan := s.HookCommandOutput(&apt.CommandOutput, []byte(expected), nil)
583+ out, err := apt.ConfigProxy()
584 c.Assert(err, gc.IsNil)
585 cmd := <-cmdChan
586 c.Assert(cmd.Args, gc.DeepEquals, []string{
587@@ -87,9 +94,9 @@
588 Acquire::ftp::Proxy "none";
589 Acquire::magic::Proxy "none";
590 `
591- _ = s.HookCommandOutput(&utils.AptCommandOutput, []byte(output), nil)
592+ _ = s.HookCommandOutput(&apt.CommandOutput, []byte(output), nil)
593
594- proxy, err := utils.DetectAptProxies()
595+ proxy, err := apt.DetectProxies()
596 c.Assert(err, gc.IsNil)
597 c.Assert(proxy, gc.DeepEquals, osenv.ProxySettings{
598 Http: "10.0.3.1:3142",
599@@ -99,8 +106,8 @@
600 }
601
602 func (s *AptSuite) TestDetectAptProxyNone(c *gc.C) {
603- _ = s.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
604- proxy, err := utils.DetectAptProxies()
605+ _ = s.HookCommandOutput(&apt.CommandOutput, []byte{}, nil)
606+ proxy, err := apt.DetectProxies()
607 c.Assert(err, gc.IsNil)
608 c.Assert(proxy, gc.DeepEquals, osenv.ProxySettings{})
609 }
610@@ -111,9 +118,9 @@
611 Acquire::ftp::Proxy "here-it-is";
612 Acquire::magic::Proxy "none";
613 `
614- _ = s.HookCommandOutput(&utils.AptCommandOutput, []byte(output), nil)
615+ _ = s.HookCommandOutput(&apt.CommandOutput, []byte(output), nil)
616
617- proxy, err := utils.DetectAptProxies()
618+ proxy, err := apt.DetectProxies()
619 c.Assert(err, gc.IsNil)
620 c.Assert(proxy, gc.DeepEquals, osenv.ProxySettings{
621 Http: "10.0.3.1:3142",
622@@ -122,7 +129,7 @@
623 }
624
625 func (s *AptSuite) TestAptProxyContentEmpty(c *gc.C) {
626- output := utils.AptProxyContent(osenv.ProxySettings{})
627+ output := apt.ProxyContent(osenv.ProxySettings{})
628 c.Assert(output, gc.Equals, "")
629 }
630
631@@ -130,7 +137,7 @@
632 proxy := osenv.ProxySettings{
633 Http: "user@10.0.0.1",
634 }
635- output := utils.AptProxyContent(proxy)
636+ output := apt.ProxyContent(proxy)
637 expected := `Acquire::http::Proxy "user@10.0.0.1";`
638 c.Assert(output, gc.Equals, expected)
639 }
640@@ -141,11 +148,11 @@
641 Https: "https://user@10.0.0.1",
642 Ftp: "ftp://user@10.0.0.1",
643 }
644- output := utils.AptProxyContent(proxy)
645-
646- s.HookCommandOutput(&utils.AptCommandOutput, []byte(output), nil)
647-
648- detected, err := utils.DetectAptProxies()
649+ output := apt.ProxyContent(proxy)
650+
651+ s.HookCommandOutput(&apt.CommandOutput, []byte(output), nil)
652+
653+ detected, err := apt.DetectProxies()
654 c.Assert(err, gc.IsNil)
655 c.Assert(detected, gc.DeepEquals, proxy)
656 }
657@@ -158,8 +165,8 @@
658 expected = `Acquire::http::Proxy "10.0.3.1:3142";
659 Acquire::https::Proxy "false";`
660 )
661- cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte(output), nil)
662- out, err := utils.AptConfigProxy()
663+ cmdChan := s.HookCommandOutput(&apt.CommandOutput, []byte(output), nil)
664+ out, err := apt.ConfigProxy()
665 c.Assert(err, gc.IsNil)
666 cmd := <-cmdChan
667 c.Assert(cmd.Args, gc.DeepEquals, []string{
668@@ -173,8 +180,8 @@
669 const expected = `E: frobnicator failure detected`
670 cmdError := fmt.Errorf("error")
671 cmdExpectedError := fmt.Errorf("apt-config failed: error")
672- cmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte(expected), cmdError)
673- out, err := utils.AptConfigProxy()
674+ cmdChan := s.HookCommandOutput(&apt.CommandOutput, []byte(expected), cmdError)
675+ out, err := apt.ConfigProxy()
676 c.Assert(err, gc.DeepEquals, cmdExpectedError)
677 cmd := <-cmdChan
678 c.Assert(cmd.Args, gc.DeepEquals, []string{
679@@ -184,21 +191,6 @@
680 c.Assert(out, gc.Equals, "")
681 }
682
683-func (s *AptSuite) patchLsbRelease(c *gc.C, name string) {
684- content := fmt.Sprintf("#!/bin/bash --norc\necho %s", name)
685- patchExecutable(s, c.MkDir(), "lsb_release", content)
686-}
687-
688-func (s *AptSuite) TestIsUbuntu(c *gc.C) {
689- s.patchLsbRelease(c, "Ubuntu")
690- c.Assert(utils.IsUbuntu(), jc.IsTrue)
691-}
692-
693-func (s *AptSuite) TestIsNotUbuntu(c *gc.C) {
694- s.patchLsbRelease(c, "Windows NT")
695- c.Assert(utils.IsUbuntu(), jc.IsFalse)
696-}
697-
698 func (s *AptSuite) patchDpkgQuery(c *gc.C, installed bool) {
699 rc := 0
700 if !installed {
701@@ -210,10 +202,20 @@
702
703 func (s *AptSuite) TestIsPackageInstalled(c *gc.C) {
704 s.patchDpkgQuery(c, true)
705- c.Assert(utils.IsPackageInstalled("foo-bar"), jc.IsTrue)
706+ c.Assert(apt.IsPackageInstalled("foo-bar"), jc.IsTrue)
707 }
708
709 func (s *AptSuite) TestIsPackageNotInstalled(c *gc.C) {
710 s.patchDpkgQuery(c, false)
711- c.Assert(utils.IsPackageInstalled("foo-bar"), jc.IsFalse)
712+ c.Assert(apt.IsPackageInstalled("foo-bar"), jc.IsFalse)
713+}
714+
715+type EnvironmentPatcher interface {
716+ PatchEnvironment(name, value string)
717+}
718+
719+func patchExecutable(patcher EnvironmentPatcher, dir, execName, script string) {
720+ patcher.PatchEnvironment("PATH", dir)
721+ filename := filepath.Join(dir, execName)
722+ ioutil.WriteFile(filename, []byte(script), 0755)
723 }
724
725=== added file 'utils/isubuntu.go'
726--- utils/isubuntu.go 1970-01-01 00:00:00 +0000
727+++ utils/isubuntu.go 2014-05-23 12:00:33 +0000
728@@ -0,0 +1,14 @@
729+package utils
730+
731+import (
732+ "strings"
733+)
734+
735+// IsUbuntu executes lxb_release to see if the host OS is Ubuntu.
736+func IsUbuntu() bool {
737+ out, err := RunCommand("lsb_release", "-i", "-s")
738+ if err != nil {
739+ return false
740+ }
741+ return strings.TrimSpace(out) == "Ubuntu"
742+}
743
744=== added file 'utils/isubuntu_test.go'
745--- utils/isubuntu_test.go 1970-01-01 00:00:00 +0000
746+++ utils/isubuntu_test.go 2014-05-23 12:00:33 +0000
747@@ -0,0 +1,35 @@
748+// Copyright 2014 Canonical Ltd.
749+// Licensed under the AGPLv3, see LICENCE file for details.
750+
751+package utils_test
752+
753+import (
754+ "fmt"
755+
756+ jc "github.com/juju/testing/checkers"
757+ gc "launchpad.net/gocheck"
758+
759+ "launchpad.net/juju-core/testing"
760+ "launchpad.net/juju-core/utils"
761+)
762+
763+type IsUbuntuSuite struct {
764+ testing.BaseSuite
765+}
766+
767+var _ = gc.Suite(&IsUbuntuSuite{})
768+
769+func (s *IsUbuntuSuite) patchLsbRelease(c *gc.C, name string) {
770+ content := fmt.Sprintf("#!/bin/bash --norc\necho %s", name)
771+ patchExecutable(s, c.MkDir(), "lsb_release", content)
772+}
773+
774+func (s *IsUbuntuSuite) TestIsUbuntu(c *gc.C) {
775+ s.patchLsbRelease(c, "Ubuntu")
776+ c.Assert(utils.IsUbuntu(), jc.IsTrue)
777+}
778+
779+func (s *IsUbuntuSuite) TestIsNotUbuntu(c *gc.C) {
780+ s.patchLsbRelease(c, "Windows NT")
781+ c.Assert(utils.IsUbuntu(), jc.IsFalse)
782+}
783
784=== modified file 'worker/machineenvironmentworker/machineenvironmentworker.go'
785--- worker/machineenvironmentworker/machineenvironmentworker.go 2014-03-05 19:41:34 +0000
786+++ worker/machineenvironmentworker/machineenvironmentworker.go 2014-05-23 12:00:33 +0000
787@@ -17,6 +17,7 @@
788 "launchpad.net/juju-core/state/api/environment"
789 "launchpad.net/juju-core/state/api/watcher"
790 "launchpad.net/juju-core/utils"
791+ "launchpad.net/juju-core/utils/apt"
792 "launchpad.net/juju-core/utils/exec"
793 "launchpad.net/juju-core/worker"
794 )
795@@ -130,8 +131,8 @@
796 logger.Debugf("new apt proxy settings %#v", aptSettings)
797 w.aptProxy = aptSettings
798 // Always finish with a new line.
799- content := utils.AptProxyContent(w.aptProxy) + "\n"
800- err := ioutil.WriteFile(utils.AptConfFile, []byte(content), 0644)
801+ content := apt.ProxyContent(w.aptProxy) + "\n"
802+ err := ioutil.WriteFile(apt.ConfFile, []byte(content), 0644)
803 if err != nil {
804 // It isn't really fatal, but we should record it.
805 logger.Errorf("error writing apt proxy config file: %v", err)
806
807=== modified file 'worker/machineenvironmentworker/machineenvironmentworker_test.go'
808--- worker/machineenvironmentworker/machineenvironmentworker_test.go 2014-03-17 06:05:54 +0000
809+++ worker/machineenvironmentworker/machineenvironmentworker_test.go 2014-05-23 12:00:33 +0000
810@@ -22,7 +22,7 @@
811 "launchpad.net/juju-core/state/api"
812 "launchpad.net/juju-core/state/api/environment"
813 "launchpad.net/juju-core/testing"
814- "launchpad.net/juju-core/utils"
815+ "launchpad.net/juju-core/utils/apt"
816 "launchpad.net/juju-core/worker"
817 "launchpad.net/juju-core/worker/machineenvironmentworker"
818 )
819@@ -55,7 +55,7 @@
820 s.PatchValue(&machineenvironmentworker.ProxyDirectory, proxyDir)
821 s.started = false
822 s.PatchValue(&machineenvironmentworker.Started, s.setStarted)
823- s.PatchValue(&utils.AptConfFile, path.Join(proxyDir, "juju-apt-proxy"))
824+ s.PatchValue(&apt.ConfFile, path.Join(proxyDir, "juju-apt-proxy"))
825 s.proxyFile = path.Join(proxyDir, machineenvironmentworker.ProxyFile)
826 }
827
828@@ -159,7 +159,7 @@
829
830 s.waitProxySettings(c, proxySettings)
831 s.waitForFile(c, s.proxyFile, proxySettings.AsScriptEnvironment()+"\n")
832- s.waitForFile(c, utils.AptConfFile, utils.AptProxyContent(aptProxySettings)+"\n")
833+ s.waitForFile(c, apt.ConfFile, apt.ProxyContent(aptProxySettings)+"\n")
834 }
835
836 func (s *MachineEnvironmentWatcherSuite) TestRespondsToEvents(c *gc.C) {
837@@ -172,7 +172,7 @@
838
839 s.waitProxySettings(c, proxySettings)
840 s.waitForFile(c, s.proxyFile, proxySettings.AsScriptEnvironment()+"\n")
841- s.waitForFile(c, utils.AptConfFile, utils.AptProxyContent(aptProxySettings)+"\n")
842+ s.waitForFile(c, apt.ConfFile, apt.ProxyContent(aptProxySettings)+"\n")
843 }
844
845 func (s *MachineEnvironmentWatcherSuite) TestInitialStateLocalMachine1(c *gc.C) {
846@@ -184,7 +184,7 @@
847
848 s.waitProxySettings(c, proxySettings)
849 s.waitForFile(c, s.proxyFile, proxySettings.AsScriptEnvironment()+"\n")
850- s.waitForFile(c, utils.AptConfFile, utils.AptProxyContent(aptProxySettings)+"\n")
851+ s.waitForFile(c, apt.ConfFile, apt.ProxyContent(aptProxySettings)+"\n")
852 }
853
854 func (s *MachineEnvironmentWatcherSuite) TestInitialStateLocalMachine0(c *gc.C) {
855@@ -197,7 +197,7 @@
856
857 s.waitProxySettings(c, proxySettings)
858
859- c.Assert(utils.AptConfFile, jc.DoesNotExist)
860+ c.Assert(apt.ConfFile, jc.DoesNotExist)
861 c.Assert(s.proxyFile, jc.DoesNotExist)
862 }
863
864
865=== modified file 'worker/provisioner/container_initialisation_test.go'
866--- worker/provisioner/container_initialisation_test.go 2014-05-13 23:18:30 +0000
867+++ worker/provisioner/container_initialisation_test.go 2014-05-23 12:00:33 +0000
868@@ -17,7 +17,7 @@
869 "launchpad.net/juju-core/state"
870 apiprovisioner "launchpad.net/juju-core/state/api/provisioner"
871 coretesting "launchpad.net/juju-core/testing"
872- "launchpad.net/juju-core/utils"
873+ "launchpad.net/juju-core/utils/apt"
874 "launchpad.net/juju-core/utils/fslock"
875 "launchpad.net/juju-core/version"
876 "launchpad.net/juju-core/worker"
877@@ -54,7 +54,7 @@
878 func (s *ContainerSetupSuite) SetUpTest(c *gc.C) {
879 s.CommonProvisionerSuite.SetUpTest(c)
880 s.CommonProvisionerSuite.setupEnvironmentManager(c)
881- aptCmdChan := s.HookCommandOutput(&utils.AptCommandOutput, []byte{}, nil)
882+ aptCmdChan := s.HookCommandOutput(&apt.CommandOutput, []byte{}, nil)
883 s.aptCmdChan = aptCmdChan
884
885 // Set up provisioner for the state machine.

Subscribers

People subscribed via source and target branches

to status/vote changes: