Merge lp:~thumper/juju-core/really-unit-agent-proxy-settings into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 2252
Proposed branch: lp:~thumper/juju-core/really-unit-agent-proxy-settings
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 477 lines (+203/-29)
8 files modified
environs/cloudinit/cloudinit.go (+1/-1)
juju/osenv/proxy.go (+23/-5)
juju/osenv/proxy_test.go (+39/-6)
worker/uniter/context.go (+7/-1)
worker/uniter/context_test.go (+26/-15)
worker/uniter/export_test.go (+10/-0)
worker/uniter/uniter.go (+57/-1)
worker/uniter/uniter_test.go (+40/-0)
To merge this branch: bzr merge lp:~thumper/juju-core/really-unit-agent-proxy-settings
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+202971@code.launchpad.net

This proposal supersedes a proposal from 2014-01-23.

Commit message

Make the uniter pass on proxy settings

The uniter watches for environment changes and updates
the package proxy settings when they change. These
are used by the Context to specify the environment
for the hook execution.

https://codereview.appspot.com/53240044/

Description of the change

Make the uniter pass on proxy settings

The uniter watches for environment changes and updates
the package proxy settings when they change. These
are used by the Context to specify the environment
for the hook execution.

https://codereview.appspot.com/53240044/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal

Reviewers: mp+202788_code.launchpad.net,

Message:
Please take a look.

Description:
Make the uniter pass on proxy settings

The uniter watches for environment changes and updates
the package proxy settings when they change. These
are used by the Context to specify the environment
for the hook execution.

https://code.launchpad.net/~thumper/juju-core/really-unit-agent-proxy-settings/+merge/202788

Requires:
https://code.launchpad.net/~thumper/juju-core/unit-agent-proxy-settings/+merge/202780

(do not edit description out of merge proposal)

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

Affected files (+184, -21 lines):
   A [revision details]
   M environs/cloudinit/cloudinit.go
   M juju/osenv/proxy.go
   M juju/osenv/proxy_test.go
   M worker/uniter/context.go
   M worker/uniter/context_test.go
   M worker/uniter/export_test.go
   A worker/uniter/proxy.go
   M worker/uniter/uniter.go
   M worker/uniter/uniter_test.go

Revision history for this message
Ian Booth (wallyworld) wrote : Posted in a previous version of this proposal

New to lose the global proxy vars. But bigger issue is a missing end-end
test to ensure we can make a change it state and it is propagated
through and used next time a hook is run.

https://codereview.appspot.com/53240044/diff/1/worker/uniter/proxy.go
File worker/uniter/proxy.go (right):

https://codereview.appspot.com/53240044/diff/1/worker/uniter/proxy.go#newcode16
worker/uniter/proxy.go:16: proxyMutex sync.Mutex
Please move these from being global to attrs on Uniter

https://codereview.appspot.com/53240044/diff/1/worker/uniter/proxy.go#newcode26
worker/uniter/proxy.go:26: func UpdatePackageProxy(cfg *config.Config) {
This could then be moved as well.

https://codereview.appspot.com/53240044/

Revision history for this message
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal

On 2014/01/23 21:27:37, wallyworld wrote:
> New to lose the global proxy vars. But bigger issue is a missing
end-end test to
> ensure we can make a change it state and it is propagated through and
used next
> time a hook is run.

This is now there.

> https://codereview.appspot.com/53240044/diff/1/worker/uniter/proxy.go
> File worker/uniter/proxy.go (right):

https://codereview.appspot.com/53240044/diff/1/worker/uniter/proxy.go#newcode16
> worker/uniter/proxy.go:16: proxyMutex sync.Mutex
> Please move these from being global to attrs on Uniter

Done.

https://codereview.appspot.com/53240044/diff/1/worker/uniter/proxy.go#newcode26
> worker/uniter/proxy.go:26: func UpdatePackageProxy(cfg *config.Config)
{
> This could then be moved as well.

Yes.

https://codereview.appspot.com/53240044/

Revision history for this message
Ian Booth (wallyworld) wrote : Posted in a previous version of this proposal
Revision history for this message
Go Bot (go-bot) wrote : Posted in a previous version of this proposal
Download full text (58.1 KiB)

The attempt to merge lp:~thumper/juju-core/really-unit-agent-proxy-settings into lp:juju-core failed. Below is the output from the failed tests.

ok launchpad.net/juju-core/agent 1.224s
ok launchpad.net/juju-core/agent/tools 0.278s
ok launchpad.net/juju-core/bzr 7.319s
ok launchpad.net/juju-core/cert 3.295s
ok launchpad.net/juju-core/charm 0.635s
? launchpad.net/juju-core/charm/hooks [no test files]
? launchpad.net/juju-core/charm/testing [no test files]
ok launchpad.net/juju-core/cloudinit 0.033s
ok launchpad.net/juju-core/cloudinit/sshinit 1.205s
ok launchpad.net/juju-core/cmd 0.250s
ok launchpad.net/juju-core/cmd/charm-admin 0.836s
? launchpad.net/juju-core/cmd/charmd [no test files]
? launchpad.net/juju-core/cmd/charmload [no test files]
ok launchpad.net/juju-core/cmd/juju 238.379s

----------------------------------------------------------------------
FAIL: machine_test.go:329: MachineSuite.TestManageEnvironRunsAddressUpdater

[LOG] 24.63087 DEBUG juju.environs.configstore Making /tmp/gocheck-5486140987150761883/50/home/ubuntu/.juju/environments
[LOG] 24.72452 DEBUG juju.environs.tools reading v1.* tools
[LOG] 24.72458 INFO juju environs/testing: uploading FAKE tools 1.17.1-precise-amd64
[LOG] 24.73101 DEBUG juju.environs.tools no architecture specified when finding tools, looking for any
[LOG] 24.73104 DEBUG juju.environs.tools no series specified when finding tools, looking for any
[LOG] 24.73110 DEBUG juju.environs.simplestreams fetchData failed for "http://127.0.0.1:46087/dummyenv/private/tools/streams/v1/index.sjson": file "tools/streams/v1/index.sjson" not found not found
[LOG] 24.73112 DEBUG juju.environs.simplestreams cannot load index "http://127.0.0.1:46087/dummyenv/private/tools/streams/v1/index.sjson": invalid URL "http://127.0.0.1:46087/dummyenv/private/tools/streams/v1/index.sjson" not found
[LOG] 24.73117 DEBUG juju.environs.simplestreams fetchData failed for "http://127.0.0.1:46087/dummyenv/private/tools/streams/v1/index.json": file "tools/streams/v1/index.json" not found not found
[LOG] 24.73119 DEBUG juju.environs.simplestreams cannot load index "http://127.0.0.1:46087/dummyenv/private/tools/streams/v1/index.json": invalid URL "http://127.0.0.1:46087/dummyenv/private/tools/streams/v1/index.json" not found
[LOG] 24.73146 INFO juju.environs.tools Writing tools/streams/v1/index.json
[LOG] 24.73151 INFO juju.environs.tools Writing tools/streams/v1/com.ubuntu.juju:released:tools.json
[LOG] 24.73166 INFO juju.environs.bootstrap bootstrapping environment "dummyenv"
[LOG] 24.73169 DEBUG juju.environs.bootstrap looking for bootstrap tools: series="precise", arch=<nil>, version=1.17.1
[LOG] 24.73170 INFO juju.environs.tools reading tools with major.minor version 1.17
[LOG] 24.73171 INFO juju.environs.tools filtering tools by version: 1.17.1
[LOG] 24.73172 INFO juju.environs.tools filtering tools by series: precise
[LOG] 24.73174 DEBUG juju.environs.tools no architecture specified when finding tools, looking for any
[LOG] 24.73178 DEBUG juju.environs.simplestreams fetchData failed for "http://127.0.0.1:46087/dummyenv/private/tools/streams/v1/index.sjson": file "tools/streams/v1/index.sjson" not foun...

Revision history for this message
Go Bot (go-bot) wrote : Posted in a previous version of this proposal
Download full text (8.7 KiB)

The attempt to merge lp:~thumper/juju-core/really-unit-agent-proxy-settings into lp:juju-core failed. Below is the output from the failed tests.

ok launchpad.net/juju-core/agent 1.290s
ok launchpad.net/juju-core/agent/tools 0.238s
ok launchpad.net/juju-core/bzr 7.480s
ok launchpad.net/juju-core/cert 3.550s
ok launchpad.net/juju-core/charm 0.589s
? launchpad.net/juju-core/charm/hooks [no test files]
? launchpad.net/juju-core/charm/testing [no test files]
ok launchpad.net/juju-core/cloudinit 0.033s
ok launchpad.net/juju-core/cloudinit/sshinit 1.098s
ok launchpad.net/juju-core/cmd 0.238s
ok launchpad.net/juju-core/cmd/charm-admin 0.871s
? launchpad.net/juju-core/cmd/charmd [no test files]
? launchpad.net/juju-core/cmd/charmload [no test files]
ok launchpad.net/juju-core/cmd/juju 231.336s
ok launchpad.net/juju-core/cmd/jujud 60.567s
ok launchpad.net/juju-core/cmd/plugins/juju-metadata 11.837s
? launchpad.net/juju-core/cmd/plugins/juju-restore [no test files]
ok launchpad.net/juju-core/constraints 0.027s
ok launchpad.net/juju-core/container 0.037s
ok launchpad.net/juju-core/container/factory 0.052s
ok launchpad.net/juju-core/container/kvm 0.362s
ok launchpad.net/juju-core/container/kvm/mock 0.053s
? launchpad.net/juju-core/container/kvm/testing [no test files]
ok launchpad.net/juju-core/container/lxc 0.336s
? launchpad.net/juju-core/container/lxc/mock [no test files]
? launchpad.net/juju-core/container/lxc/testing [no test files]
? launchpad.net/juju-core/container/testing [no test files]
ok launchpad.net/juju-core/downloader 5.305s
ok launchpad.net/juju-core/environs 3.017s
ok launchpad.net/juju-core/environs/bootstrap 4.732s
ok launchpad.net/juju-core/environs/cloudinit 0.684s
ok launchpad.net/juju-core/environs/config 4.156s
ok launchpad.net/juju-core/environs/configstore 0.042s
ok launchpad.net/juju-core/environs/filestorage 0.032s
ok launchpad.net/juju-core/environs/httpstorage 0.901s
ok launchpad.net/juju-core/environs/imagemetadata 0.505s
? launchpad.net/juju-core/environs/imagemetadata/testing [no test files]
ok launchpad.net/juju-core/environs/instances 0.058s
ok launchpad.net/juju-core/environs/jujutest 0.256s
ok launchpad.net/juju-core/environs/manual 8.317s
ok launchpad.net/juju-core/environs/simplestreams 0.329s
? launchpad.net/juju-core/environs/simplestreams/testing [no test files]
ok launchpad.net/juju-core/environs/sshstorage 1.224s
ok launchpad.net/juju-core/environs/storage 1.296s
ok launchpad.net/juju-core/environs/sync 34.005s
ok launchpad.net/juju-core/environs/testing 0.201s
ok launchpad.net/juju-core/environs/tools 6.938s
? launchpad.net/juju-core/environs/tools/testing [no test files]
ok launchpad.net/juju-core/errors 0.016s
ok launchpad.net/juju-core/instance 0.024s
? launchpad.net/juju-core/instance/testing [no test files]
ok launchpad.net/juju-core/juju 23.811s
ok launchpad.net/juju-core/juju/osenv 0.020s
? launchpad.net/juju-core/juju/testing [no test files]
ok launchpad.net/juju-core/log 0.015s
ok launchpad.net/juju-core/log/syslog 0.047s
ok launchpad.net/juju-core/names 0.027s
? launchpa...

Read more...

Revision history for this message
Go Bot (go-bot) wrote : Posted in a previous version of this proposal
Revision history for this message
Go Bot (go-bot) wrote :

Attempt to merge into lp:juju-core failed due to conflicts:

text conflict in environs/cloudinit/cloudinit.go

Revision history for this message
Go Bot (go-bot) wrote :
Download full text (56.9 KiB)

The attempt to merge lp:~thumper/juju-core/really-unit-agent-proxy-settings into lp:juju-core failed. Below is the output from the failed tests.

ok launchpad.net/juju-core/agent 0.842s
ok launchpad.net/juju-core/agent/tools 0.279s
ok launchpad.net/juju-core/bzr 7.425s
ok launchpad.net/juju-core/cert 3.696s
ok launchpad.net/juju-core/charm 0.623s
? launchpad.net/juju-core/charm/hooks [no test files]
? launchpad.net/juju-core/charm/testing [no test files]
ok launchpad.net/juju-core/cloudinit 0.031s
ok launchpad.net/juju-core/cloudinit/sshinit 1.133s
ok launchpad.net/juju-core/cmd 0.232s
ok launchpad.net/juju-core/cmd/charm-admin 0.868s
? launchpad.net/juju-core/cmd/charmd [no test files]
? launchpad.net/juju-core/cmd/charmload [no test files]
ok launchpad.net/juju-core/cmd/juju 232.189s

----------------------------------------------------------------------
FAIL: machine_test.go:278: MachineSuite.TestManageEnviron

[LOG] 48.23366 DEBUG juju.environs.configstore Making /tmp/gocheck-2970700287221458280/43/home/ubuntu/.juju/environments
[LOG] 48.31803 DEBUG juju.environs.tools reading v1.* tools
[LOG] 48.31805 INFO juju environs/testing: uploading FAKE tools 1.17.1-precise-amd64
[LOG] 48.31889 DEBUG juju.environs.tools no architecture specified when finding tools, looking for any
[LOG] 48.31891 DEBUG juju.environs.tools no series specified when finding tools, looking for any
[LOG] 48.31898 DEBUG juju.environs.simplestreams fetchData failed for "http://127.0.0.1:52216/dummyenv/private/tools/streams/v1/index.sjson": file "tools/streams/v1/index.sjson" not found not found
[LOG] 48.31899 DEBUG juju.environs.simplestreams cannot load index "http://127.0.0.1:52216/dummyenv/private/tools/streams/v1/index.sjson": invalid URL "http://127.0.0.1:52216/dummyenv/private/tools/streams/v1/index.sjson" not found
[LOG] 48.31907 DEBUG juju.environs.simplestreams fetchData failed for "http://127.0.0.1:52216/dummyenv/private/tools/streams/v1/index.json": file "tools/streams/v1/index.json" not found not found
[LOG] 48.31911 DEBUG juju.environs.simplestreams cannot load index "http://127.0.0.1:52216/dummyenv/private/tools/streams/v1/index.json": invalid URL "http://127.0.0.1:52216/dummyenv/private/tools/streams/v1/index.json" not found
[LOG] 48.31935 INFO juju.environs.tools Writing tools/streams/v1/index.json
[LOG] 48.31941 INFO juju.environs.tools Writing tools/streams/v1/com.ubuntu.juju:released:tools.json
[LOG] 48.31955 INFO juju.environs.bootstrap bootstrapping environment "dummyenv"
[LOG] 48.31957 DEBUG juju.environs.bootstrap looking for bootstrap tools: series="precise", arch=<nil>, version=1.17.1
[LOG] 48.31959 INFO juju.environs.tools reading tools with major.minor version 1.17
[LOG] 48.31960 INFO juju.environs.tools filtering tools by version: 1.17.1
[LOG] 48.31961 INFO juju.environs.tools filtering tools by series: precise
[LOG] 48.31966 DEBUG juju.environs.tools no architecture specified when finding tools, looking for any
[LOG] 48.31966 DEBUG juju.environs.simplestreams fetchData failed for "http://127.0.0.1:52216/dummyenv/private/tools/streams/v1/index.sjson": file "tools/streams/v1/index.sjson" not found not found
[LOG] ...

Revision history for this message
Go Bot (go-bot) wrote :
Download full text (8.7 KiB)

The attempt to merge lp:~thumper/juju-core/really-unit-agent-proxy-settings into lp:juju-core failed. Below is the output from the failed tests.

ok launchpad.net/juju-core/agent 1.330s
ok launchpad.net/juju-core/agent/tools 0.247s
ok launchpad.net/juju-core/bzr 7.485s
ok launchpad.net/juju-core/cert 3.562s
ok launchpad.net/juju-core/charm 0.592s
? launchpad.net/juju-core/charm/hooks [no test files]
? launchpad.net/juju-core/charm/testing [no test files]
ok launchpad.net/juju-core/cloudinit 0.032s
ok launchpad.net/juju-core/cloudinit/sshinit 1.035s
ok launchpad.net/juju-core/cmd 0.228s
ok launchpad.net/juju-core/cmd/charm-admin 0.852s
? launchpad.net/juju-core/cmd/charmd [no test files]
? launchpad.net/juju-core/cmd/charmload [no test files]
ok launchpad.net/juju-core/cmd/juju 240.691s
ok launchpad.net/juju-core/cmd/jujud 60.651s
ok launchpad.net/juju-core/cmd/plugins/juju-metadata 11.419s
? launchpad.net/juju-core/cmd/plugins/juju-restore [no test files]
ok launchpad.net/juju-core/constraints 0.026s
ok launchpad.net/juju-core/container 0.036s
ok launchpad.net/juju-core/container/factory 0.056s
ok launchpad.net/juju-core/container/kvm 0.291s
ok launchpad.net/juju-core/container/kvm/mock 0.055s
? launchpad.net/juju-core/container/kvm/testing [no test files]
ok launchpad.net/juju-core/container/lxc 0.332s
? launchpad.net/juju-core/container/lxc/mock [no test files]
? launchpad.net/juju-core/container/lxc/testing [no test files]
? launchpad.net/juju-core/container/testing [no test files]
ok launchpad.net/juju-core/downloader 5.321s
ok launchpad.net/juju-core/environs 3.196s
ok launchpad.net/juju-core/environs/bootstrap 4.532s
ok launchpad.net/juju-core/environs/cloudinit 0.626s
ok launchpad.net/juju-core/environs/config 3.564s
ok launchpad.net/juju-core/environs/configstore 0.040s
ok launchpad.net/juju-core/environs/filestorage 0.032s
ok launchpad.net/juju-core/environs/httpstorage 1.061s
ok launchpad.net/juju-core/environs/imagemetadata 0.517s
? launchpad.net/juju-core/environs/imagemetadata/testing [no test files]
ok launchpad.net/juju-core/environs/instances 0.060s
ok launchpad.net/juju-core/environs/jujutest 0.218s
ok launchpad.net/juju-core/environs/manual 11.327s
ok launchpad.net/juju-core/environs/simplestreams 0.365s
? launchpad.net/juju-core/environs/simplestreams/testing [no test files]
ok launchpad.net/juju-core/environs/sshstorage 1.180s
ok launchpad.net/juju-core/environs/storage 1.123s
ok launchpad.net/juju-core/environs/sync 33.293s
ok launchpad.net/juju-core/environs/testing 0.206s
ok launchpad.net/juju-core/environs/tools 6.856s
? launchpad.net/juju-core/environs/tools/testing [no test files]
ok launchpad.net/juju-core/errors 0.018s
ok launchpad.net/juju-core/instance 0.024s
? launchpad.net/juju-core/instance/testing [no test files]
ok launchpad.net/juju-core/juju 22.405s
ok launchpad.net/juju-core/juju/osenv 0.020s
? launchpad.net/juju-core/juju/testing [no test files]
ok launchpad.net/juju-core/log 0.016s
ok launchpad.net/juju-core/log/syslog 0.025s
ok launchpad.net/juju-core/names 0.027s
? launchp...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'environs/cloudinit/cloudinit.go'
2--- environs/cloudinit/cloudinit.go 2014-01-23 21:20:27 +0000
3+++ environs/cloudinit/cloudinit.go 2014-01-24 01:06:43 +0000
4@@ -271,7 +271,7 @@
5 c.AddScripts(
6 fmt.Sprintf(
7 `[ -e /home/ubuntu ] && (printf '%%s\n' %s > /home/ubuntu/.juju-proxy && chown ubuntu:ubuntu /home/ubuntu/.juju-proxy)`,
8- shquote(cfg.ProxySettings.AsEnvironmentValues())))
9+ shquote(cfg.ProxySettings.AsScriptEnvironment())))
10 }
11
12 c.AddScripts(
13
14=== modified file 'juju/osenv/proxy.go'
15--- juju/osenv/proxy.go 2014-01-21 22:45:47 +0000
16+++ juju/osenv/proxy.go 2014-01-24 01:06:43 +0000
17@@ -34,11 +34,10 @@
18 }
19 }
20
21-// AsEnvironmentValues returns a potentially multi-line
22-// string in a format that specifies key=value lines.
23-// There are two lines for each non-empty proxy value,
24-// one lower-case and one upper-case.
25-func (s *ProxySettings) AsEnvironmentValues() string {
26+// AsScriptEnvironment returns a potentially multi-line string in a format
27+// that specifies exported key=value lines. There are two lines for each non-
28+// empty proxy value, one lower-case and one upper-case.
29+func (s *ProxySettings) AsScriptEnvironment() string {
30 lines := []string{}
31 addLine := func(proxy, value string) {
32 if value != "" {
33@@ -53,3 +52,22 @@
34 addLine("ftp_proxy", s.Ftp)
35 return strings.Join(lines, "\n")
36 }
37+
38+// AsEnvironmentValues returns a slice of strings of the format "key=value"
39+// suitable to be used in a command environment. There are two values for each
40+// non-empty proxy value, one lower-case and one upper-case.
41+func (s *ProxySettings) AsEnvironmentValues() []string {
42+ lines := []string{}
43+ addLine := func(proxy, value string) {
44+ if value != "" {
45+ lines = append(
46+ lines,
47+ fmt.Sprintf("%s=%s", proxy, value),
48+ fmt.Sprintf("%s=%s", strings.ToUpper(proxy), value))
49+ }
50+ }
51+ addLine("http_proxy", s.Http)
52+ addLine("https_proxy", s.Https)
53+ addLine("ftp_proxy", s.Ftp)
54+ return lines
55+}
56
57=== modified file 'juju/osenv/proxy_test.go'
58--- juju/osenv/proxy_test.go 2014-01-21 22:45:47 +0000
59+++ juju/osenv/proxy_test.go 2014-01-24 01:06:43 +0000
60@@ -88,22 +88,22 @@
61 })
62 }
63
64-func (s *proxySuite) TestAsEnvironmentValuesEmpty(c *gc.C) {
65+func (s *proxySuite) TestAsScriptEnvironmentEmpty(c *gc.C) {
66 proxies := osenv.ProxySettings{}
67- c.Assert(proxies.AsEnvironmentValues(), gc.Equals, "")
68+ c.Assert(proxies.AsScriptEnvironment(), gc.Equals, "")
69 }
70
71-func (s *proxySuite) TestAsEnvironmentValuesOneValue(c *gc.C) {
72+func (s *proxySuite) TestAsScriptEnvironmentOneValue(c *gc.C) {
73 proxies := osenv.ProxySettings{
74 Http: "some-value",
75 }
76 expected := `
77 export http_proxy=some-value
78 export HTTP_PROXY=some-value`[1:]
79- c.Assert(proxies.AsEnvironmentValues(), gc.Equals, expected)
80+ c.Assert(proxies.AsScriptEnvironment(), gc.Equals, expected)
81 }
82
83-func (s *proxySuite) TestAsEnvironmentValuesAllValue(c *gc.C) {
84+func (s *proxySuite) TestAsScriptEnvironmentAllValue(c *gc.C) {
85 proxies := osenv.ProxySettings{
86 Http: "some-value",
87 Https: "special",
88@@ -116,5 +116,38 @@
89 export HTTPS_PROXY=special
90 export ftp_proxy=who uses this?
91 export FTP_PROXY=who uses this?`[1:]
92- c.Assert(proxies.AsEnvironmentValues(), gc.Equals, expected)
93+ c.Assert(proxies.AsScriptEnvironment(), gc.Equals, expected)
94+}
95+
96+func (s *proxySuite) TestAsEnvironmentValuesEmpty(c *gc.C) {
97+ proxies := osenv.ProxySettings{}
98+ c.Assert(proxies.AsEnvironmentValues(), gc.HasLen, 0)
99+}
100+
101+func (s *proxySuite) TestAsEnvironmentValuesOneValue(c *gc.C) {
102+ proxies := osenv.ProxySettings{
103+ Http: "some-value",
104+ }
105+ expected := []string{
106+ "http_proxy=some-value",
107+ "HTTP_PROXY=some-value",
108+ }
109+ c.Assert(proxies.AsEnvironmentValues(), gc.DeepEquals, expected)
110+}
111+
112+func (s *proxySuite) TestAsEnvironmentValuesAllValue(c *gc.C) {
113+ proxies := osenv.ProxySettings{
114+ Http: "some-value",
115+ Https: "special",
116+ Ftp: "who uses this?",
117+ }
118+ expected := []string{
119+ "http_proxy=some-value",
120+ "HTTP_PROXY=some-value",
121+ "https_proxy=special",
122+ "HTTPS_PROXY=special",
123+ "ftp_proxy=who uses this?",
124+ "FTP_PROXY=who uses this?",
125+ }
126+ c.Assert(proxies.AsEnvironmentValues(), gc.DeepEquals, expected)
127 }
128
129=== modified file 'worker/uniter/context.go'
130--- worker/uniter/context.go 2014-01-17 00:58:55 +0000
131+++ worker/uniter/context.go 2014-01-24 01:06:43 +0000
132@@ -18,6 +18,7 @@
133 "launchpad.net/loggo"
134
135 "launchpad.net/juju-core/charm"
136+ "launchpad.net/juju-core/juju/osenv"
137 "launchpad.net/juju-core/state/api/params"
138 "launchpad.net/juju-core/state/api/uniter"
139 utilexec "launchpad.net/juju-core/utils/exec"
140@@ -78,11 +79,14 @@
141
142 // serviceOwner contains the owner of the service
143 serviceOwner string
144+
145+ // proxySettings are the current proxy settings that the uniter knows about
146+ proxySettings osenv.ProxySettings
147 }
148
149 func NewHookContext(unit *uniter.Unit, id, uuid string, relationId int,
150 remoteUnitName string, relations map[int]*ContextRelation,
151- apiAddrs []string, serviceOwner string) (*HookContext, error) {
152+ apiAddrs []string, serviceOwner string, proxySettings osenv.ProxySettings) (*HookContext, error) {
153 ctx := &HookContext{
154 unit: unit,
155 id: id,
156@@ -92,6 +96,7 @@
157 relations: relations,
158 apiAddrs: apiAddrs,
159 serviceOwner: serviceOwner,
160+ proxySettings: proxySettings,
161 }
162 // Get and cache the addresses.
163 var err error
164@@ -187,6 +192,7 @@
165 name, _ := ctx.RemoteUnitName()
166 vars = append(vars, "JUJU_REMOTE_UNIT="+name)
167 }
168+ vars = append(vars, ctx.proxySettings.AsEnvironmentValues()...)
169 return vars
170 }
171
172
173=== modified file 'worker/uniter/context_test.go'
174--- worker/uniter/context_test.go 2013-12-18 13:33:12 +0000
175+++ worker/uniter/context_test.go 2014-01-24 01:06:43 +0000
176@@ -14,6 +14,7 @@
177 gc "launchpad.net/gocheck"
178
179 "launchpad.net/juju-core/charm"
180+ "launchpad.net/juju-core/juju/osenv"
181 "launchpad.net/juju-core/juju/testing"
182 "launchpad.net/juju-core/state"
183 "launchpad.net/juju-core/state/api"
184@@ -25,6 +26,8 @@
185 "launchpad.net/juju-core/worker/uniter/jujuc"
186 )
187
188+var noProxies = osenv.ProxySettings{}
189+
190 type RunHookSuite struct {
191 HookContextSuite
192 }
193@@ -123,12 +126,13 @@
194 var expectedApiAddrs = strings.Join(apiAddrs, " ")
195
196 var runHookTests = []struct {
197- summary string
198- relid int
199- remote string
200- spec hookSpec
201- err string
202- env map[string]string
203+ summary string
204+ relid int
205+ remote string
206+ spec hookSpec
207+ err string
208+ env map[string]string
209+ proxySettings osenv.ProxySettings
210 }{
211 {
212 summary: "missing hook is not an error",
213@@ -170,12 +174,19 @@
214 stdout: strings.Repeat("a", lineBufferSize+10),
215 },
216 }, {
217- summary: "check shell environment for non-relation hook context",
218- relid: -1,
219- spec: hookSpec{perm: 0700},
220+ summary: "check shell environment for non-relation hook context",
221+ relid: -1,
222+ spec: hookSpec{perm: 0700},
223+ proxySettings: osenv.ProxySettings{Http: "http", Https: "https", Ftp: "ftp"},
224 env: map[string]string{
225 "JUJU_UNIT_NAME": "u/0",
226 "JUJU_API_ADDRESSES": expectedApiAddrs,
227+ "http_proxy": "http",
228+ "HTTP_PROXY": "http",
229+ "https_proxy": "https",
230+ "HTTPS_PROXY": "https",
231+ "ftp_proxy": "ftp",
232+ "FTP_PROXY": "ftp",
233 },
234 }, {
235 summary: "check shell environment for relation-broken hook context",
236@@ -208,7 +219,7 @@
237 c.Assert(err, gc.IsNil)
238 for i, t := range runHookTests {
239 c.Logf("\ntest %d: %s; perm %v", i, t.summary, t.spec.perm)
240- ctx := s.getHookContext(c, uuid.String(), t.relid, t.remote)
241+ ctx := s.getHookContext(c, uuid.String(), t.relid, t.remote, t.proxySettings)
242 var charmDir, outPath string
243 var hookExists bool
244 if t.spec.perm == 0 {
245@@ -260,7 +271,7 @@
246 // Create a charm with a breaking hook.
247 uuid, err := utils.NewUUID()
248 c.Assert(err, gc.IsNil)
249- ctx := s.getHookContext(c, uuid.String(), -1, "")
250+ ctx := s.getHookContext(c, uuid.String(), -1, "", noProxies)
251 charmDir, _ := makeCharm(c, hookSpec{
252 name: "something-happened",
253 perm: 0700,
254@@ -550,7 +561,7 @@
255 remoteName string) jujuc.Context {
256 uuid, err := utils.NewUUID()
257 c.Assert(err, gc.IsNil)
258- return s.HookContextSuite.getHookContext(c, uuid.String(), relId, remoteName)
259+ return s.HookContextSuite.getHookContext(c, uuid.String(), relId, remoteName, noProxies)
260 }
261
262 func (s *InterfaceSuite) TestUtils(c *gc.C) {
263@@ -694,13 +705,13 @@
264 }
265
266 func (s *HookContextSuite) getHookContext(c *gc.C, uuid string, relid int,
267- remote string) *uniter.HookContext {
268+ remote string, proxies osenv.ProxySettings) *uniter.HookContext {
269 if relid != -1 {
270 _, found := s.relctxs[relid]
271 c.Assert(found, gc.Equals, true)
272 }
273 context, err := uniter.NewHookContext(s.apiUnit, "TestCtx", uuid, relid, remote,
274- s.relctxs, apiAddrs, "test-owner")
275+ s.relctxs, apiAddrs, "test-owner", proxies)
276 c.Assert(err, gc.IsNil)
277 return context
278 }
279@@ -730,7 +741,7 @@
280 func (s *RunCommandSuite) getHookContext(c *gc.C) *uniter.HookContext {
281 uuid, err := utils.NewUUID()
282 c.Assert(err, gc.IsNil)
283- return s.HookContextSuite.getHookContext(c, uuid.String(), -1, "")
284+ return s.HookContextSuite.getHookContext(c, uuid.String(), -1, "", noProxies)
285 }
286
287 func (s *RunCommandSuite) TestRunCommandsHasEnvironSet(c *gc.C) {
288
289=== modified file 'worker/uniter/export_test.go'
290--- worker/uniter/export_test.go 2013-12-12 05:20:07 +0000
291+++ worker/uniter/export_test.go 2014-01-24 01:06:43 +0000
292@@ -3,6 +3,16 @@
293
294 package uniter
295
296+import (
297+ "launchpad.net/juju-core/juju/osenv"
298+)
299+
300 func SetUniterObserver(u *Uniter, observer UniterExecutionObserver) {
301 u.observer = observer
302 }
303+
304+func (u *Uniter) GetProxyValues() osenv.ProxySettings {
305+ u.proxyMutex.Lock()
306+ defer u.proxyMutex.Unlock()
307+ return u.proxy
308+}
309
310=== modified file 'worker/uniter/uniter.go'
311--- worker/uniter/uniter.go 2014-01-15 01:15:23 +0000
312+++ worker/uniter/uniter.go 2014-01-24 01:06:43 +0000
313@@ -10,6 +10,7 @@
314 "os"
315 "path/filepath"
316 "strings"
317+ "sync"
318 "time"
319
320 "launchpad.net/loggo"
321@@ -19,8 +20,11 @@
322 corecharm "launchpad.net/juju-core/charm"
323 "launchpad.net/juju-core/charm/hooks"
324 "launchpad.net/juju-core/cmd"
325+ "launchpad.net/juju-core/environs/config"
326+ "launchpad.net/juju-core/juju/osenv"
327 "launchpad.net/juju-core/state/api/params"
328 "launchpad.net/juju-core/state/api/uniter"
329+ apiwatcher "launchpad.net/juju-core/state/api/watcher"
330 "launchpad.net/juju-core/state/watcher"
331 "launchpad.net/juju-core/utils"
332 "launchpad.net/juju-core/utils/exec"
333@@ -76,6 +80,9 @@
334 hookLock *fslock.Lock
335 runListener *RunListener
336
337+ proxy osenv.ProxySettings
338+ proxyMutex sync.Mutex
339+
340 ranConfigChanged bool
341 // The execution observer is only used in tests at this stage. Should this
342 // need to be extended, perhaps a list of observers would be needed.
343@@ -104,6 +111,13 @@
344 defer u.runListener.Close()
345 logger.Infof("unit %q started", u.unit)
346
347+ environWatcher, err := u.st.WatchForEnvironConfigChanges()
348+ if err != nil {
349+ return err
350+ }
351+ defer watcher.Stop(environWatcher, &u.tomb)
352+ u.watchForProxyChanges(environWatcher)
353+
354 // Start filtering state change events for consumption by modes.
355 u.f, err = newFilter(u.st, unitTag)
356 if err != nil {
357@@ -322,8 +336,13 @@
358 ctxRelations[id] = r.Context()
359 }
360
361+ u.proxyMutex.Lock()
362+ defer u.proxyMutex.Unlock()
363+
364+ // Make a copy of the proxy settings.
365+ proxySettings := u.proxy
366 return NewHookContext(u.unit, hctxId, u.uuid, relationId, remoteUnitName,
367- ctxRelations, apiAddrs, ownerTag)
368+ ctxRelations, apiAddrs, ownerTag, proxySettings)
369 }
370
371 func (u *Uniter) acquireHookLock(message string) (err error) {
372@@ -664,3 +683,40 @@
373 }
374 }
375 }
376+
377+// updatePackageProxy updates the package proxy settings from the
378+// environment.
379+func (u *Uniter) updatePackageProxy(cfg *config.Config) {
380+ u.proxyMutex.Lock()
381+ defer u.proxyMutex.Unlock()
382+
383+ newSettings := cfg.ProxySettings()
384+ if u.proxy != newSettings {
385+ u.proxy = newSettings
386+ logger.Debugf("Updated proxy settings: %#v", u.proxy)
387+ }
388+}
389+
390+// watchForProxyChanges kicks off a go routine to listen to the watcher and
391+// update the proxy settings.
392+func (u *Uniter) watchForProxyChanges(environWatcher apiwatcher.NotifyWatcher) {
393+ go func() {
394+ for {
395+ select {
396+ case <-u.tomb.Dying():
397+ return
398+ case _, ok := <-environWatcher.Changes():
399+ logger.Debugf("new environment change")
400+ if !ok {
401+ return
402+ }
403+ environConfig, err := u.st.EnvironConfig()
404+ if err != nil {
405+ logger.Errorf("cannot load environment configuration: %v", err)
406+ } else {
407+ u.updatePackageProxy(environConfig)
408+ }
409+ }
410+ }
411+ }()
412+}
413
414=== modified file 'worker/uniter/uniter_test.go'
415--- worker/uniter/uniter_test.go 2014-01-15 01:15:23 +0000
416+++ worker/uniter/uniter_test.go 2014-01-24 01:06:43 +0000
417@@ -26,6 +26,7 @@
418 "launchpad.net/juju-core/agent/tools"
419 "launchpad.net/juju-core/charm"
420 "launchpad.net/juju-core/errors"
421+ "launchpad.net/juju-core/juju/osenv"
422 "launchpad.net/juju-core/juju/testing"
423 "launchpad.net/juju-core/state"
424 "launchpad.net/juju-core/state/api"
425@@ -871,6 +872,22 @@
426 "user-admin\nprivate.dummy.address.example.com\npublic.dummy.address.example.com\n",
427 },
428 ), ut(
429+ "run commands: proxy settings set",
430+ quickStartRelation{},
431+ setProxySettings{Http: "http", Https: "https", Ftp: "ftp"},
432+ runCommands{
433+ fmt.Sprintf("echo $http_proxy > %s", testFile("proxy.output")),
434+ fmt.Sprintf("echo $HTTP_PROXY >> %s", testFile("proxy.output")),
435+ fmt.Sprintf("echo $https_proxy >> %s", testFile("proxy.output")),
436+ fmt.Sprintf("echo $HTTPS_PROXY >> %s", testFile("proxy.output")),
437+ fmt.Sprintf("echo $ftp_proxy >> %s", testFile("proxy.output")),
438+ fmt.Sprintf("echo $FTP_PROXY >> %s", testFile("proxy.output")),
439+ },
440+ verifyFile{
441+ testFile("proxy.output"),
442+ "http\nhttp\nhttps\nhttps\nftp\nftp\n",
443+ },
444+ ), ut(
445 "run commands: async using rpc client",
446 quickStart{},
447 asyncRunCommands{echoUnitNameToFile("run.output")},
448@@ -1940,6 +1957,29 @@
449 c.Assert(lock.IsLocked(), jc.IsTrue)
450 }}
451
452+type setProxySettings osenv.ProxySettings
453+
454+func (s setProxySettings) step(c *gc.C, ctx *context) {
455+ old, err := ctx.st.EnvironConfig()
456+ c.Assert(err, gc.IsNil)
457+ cfg, err := old.Apply(map[string]interface{}{
458+ "http-proxy": s.Http,
459+ "https-proxy": s.Https,
460+ "ftp-proxy": s.Ftp,
461+ })
462+ c.Assert(err, gc.IsNil)
463+ err = ctx.st.SetEnvironConfig(cfg, old)
464+ c.Assert(err, gc.IsNil)
465+ // wait for the new values...
466+ expected := (osenv.ProxySettings)(s)
467+ for attempt := coretesting.LongAttempt.Start(); attempt.Next(); {
468+ if ctx.uniter.GetProxyValues() == expected {
469+ return
470+ }
471+ }
472+ c.Fatal("settings didn't get noticed by the uniter")
473+}
474+
475 type runCommands []string
476
477 func (cmds runCommands) step(c *gc.C, ctx *context) {

Subscribers

People subscribed via source and target branches

to status/vote changes: