Merge lp:~axwalk/juju-core/ssh-disable-proxy into lp:~go-bot/juju-core/trunk

Proposed by Andrew Wilkins
Status: Merged
Approved by: Andrew Wilkins
Approved revision: no longer in the source branch.
Merged at revision: 2450
Proposed branch: lp:~axwalk/juju-core/ssh-disable-proxy
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 352 lines (+72/-149)
4 files modified
cmd/juju/scp.go (+1/-9)
cmd/juju/scp_test.go (+58/-56)
cmd/juju/ssh.go (+11/-74)
cmd/juju/ssh_test.go (+2/-10)
To merge this branch: bzr merge lp:~axwalk/juju-core/ssh-disable-proxy
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+211853@code.launchpad.net

Commit message

cmd/juju: revert proxy changes in CLI

I'm reverting the changes to the CLI only,
as juju ssh support for the local provider
regressed (broken if machine 0 doesn't have
an SSH server available.)

We'll keep the API and utils/ssh changes
needed to re-enable this after 1.18 is
released.

https://codereview.appspot.com/78070043/

Description of the change

cmd/juju: revert proxy changes in CLI

I'm reverting the changes to the CLI only,
as juju ssh support for the local provider
regressed (broken if machine 0 doesn't have
an SSH server available.)

We'll keep the API and utils/ssh changes
needed to re-enable this after 1.18 is
released.

https://codereview.appspot.com/78070043/

To post a comment you must log in.
Revision history for this message
Andrew Wilkins (axwalk) wrote :

Reviewers: mp+211853_code.launchpad.net,

Message:
Please take a look.

Description:
cmd/juju: revert proxy changes in CLI

I'm reverting the changes to the CLI only,
as juju ssh support for the local provider
regressed (broken if machine 0 doesn't have
an SSH server available.)

We'll keep the API and utils/ssh changes
needed to re-enable this after 1.18 is
released.

https://code.launchpad.net/~axwalk/juju-core/ssh-disable-proxy/+merge/211853

(do not edit description out of merge proposal)

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

Affected files (+74, -149 lines):
   A [revision details]
   M cmd/juju/scp.go
   M cmd/juju/scp_test.go
   M cmd/juju/ssh.go
   M cmd/juju/ssh_test.go

Revision history for this message
Tim Penhey (thumper) wrote :

On 2014/03/20 02:35:16, axw wrote:
> Please take a look.

LGTM

https://codereview.appspot.com/78070043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/juju/scp.go'
2--- cmd/juju/scp.go 2014-03-19 03:18:41 +0000
3+++ cmd/juju/scp.go 2014-03-20 02:33:00 +0000
4@@ -106,13 +106,5 @@
5 targets = append(targets, arg)
6 }
7 }
8-
9- var options *ssh.Options
10- if c.proxy {
11- options = new(ssh.Options)
12- if err := c.setProxyCommand(options); err != nil {
13- return err
14- }
15- }
16- return ssh.Copy(targets, extraArgs, options)
17+ return ssh.Copy(targets, extraArgs, nil)
18 }
19
20=== modified file 'cmd/juju/scp_test.go'
21--- cmd/juju/scp_test.go 2014-03-19 03:18:41 +0000
22+++ cmd/juju/scp_test.go 2014-03-20 02:33:00 +0000
23@@ -27,64 +27,67 @@
24 about string
25 args []string
26 result string
27- proxy bool
28 error string
29 }{
30 {
31- about: "scp from machine 0 to current dir",
32- args: []string{"0:foo", "."},
33- result: commonArgsNoProxy + "ubuntu@dummyenv-0.dns:foo .\n",
34- },
35- {
36- about: "scp from machine 0 to current dir with extra args",
37- args: []string{"0:foo", ".", "-rv -o SomeOption"},
38- result: commonArgsNoProxy + "-rv -o SomeOption ubuntu@dummyenv-0.dns:foo .\n",
39- },
40- {
41- about: "scp from current dir to machine 0",
42- args: []string{"foo", "0:"},
43- result: commonArgsNoProxy + "foo ubuntu@dummyenv-0.dns:\n",
44- },
45- {
46- about: "scp from current dir to machine 0 with extra args",
47- args: []string{"foo", "0:", "-r -v"},
48- result: commonArgsNoProxy + "-r -v foo ubuntu@dummyenv-0.dns:\n",
49- },
50- {
51- about: "scp from machine 0 to unit mysql/0",
52- args: []string{"0:foo", "mysql/0:/foo"},
53- result: commonArgsNoProxy + "ubuntu@dummyenv-0.dns:foo ubuntu@dummyenv-0.dns:/foo\n",
54- },
55- {
56- about: "scp from machine 0 to unit mysql/0 and extra args",
57- args: []string{"0:foo", "mysql/0:/foo", "-q"},
58- result: commonArgsNoProxy + "-q ubuntu@dummyenv-0.dns:foo ubuntu@dummyenv-0.dns:/foo\n",
59- },
60- {
61- about: "scp from machine 0 to unit mysql/0 and extra args before",
62- args: []string{"-q", "-r", "0:foo", "mysql/0:/foo"},
63- error: `unexpected argument "-q"; extra arguments must be last`,
64- },
65- {
66- about: "scp two local files to unit mysql/0",
67- args: []string{"file1", "file2", "mysql/0:/foo/"},
68- result: commonArgsNoProxy + "file1 file2 ubuntu@dummyenv-0.dns:/foo/\n",
69- },
70- {
71- about: "scp from unit mongodb/1 to unit mongodb/0 and multiple extra args",
72- args: []string{"mongodb/1:foo", "mongodb/0:", "-r -v -q -l5"},
73- result: commonArgsNoProxy + "-r -v -q -l5 ubuntu@dummyenv-2.dns:foo ubuntu@dummyenv-1.dns:\n",
74- },
75- {
76- about: "scp works with IPv6 addresses",
77- args: []string{"ipv6-svc/0:foo", "bar"},
78- result: commonArgsNoProxy + `ubuntu@\[2001:db8::\]:foo bar` + "\n",
79- },
80- {
81- about: "scp from machine 0 to unit mysql/0 with proxy",
82- args: []string{"0:foo", "mysql/0:/foo"},
83- result: commonArgs + "ubuntu@dummyenv-0.dns:foo ubuntu@dummyenv-0.dns:/foo\n",
84- proxy: true,
85+ "scp from machine 0 to current dir",
86+ []string{"0:foo", "."},
87+ commonArgs + "ubuntu@dummyenv-0.dns:foo .\n",
88+ "",
89+ },
90+ {
91+ "scp from machine 0 to current dir with extra args",
92+ []string{"0:foo", ".", "-rv -o SomeOption"},
93+ commonArgs + "-rv -o SomeOption ubuntu@dummyenv-0.dns:foo .\n",
94+ "",
95+ },
96+ {
97+ "scp from current dir to machine 0",
98+ []string{"foo", "0:"},
99+ commonArgs + "foo ubuntu@dummyenv-0.dns:\n",
100+ "",
101+ },
102+ {
103+ "scp from current dir to machine 0 with extra args",
104+ []string{"foo", "0:", "-r -v"},
105+ commonArgs + "-r -v foo ubuntu@dummyenv-0.dns:\n",
106+ "",
107+ },
108+ {
109+ "scp from machine 0 to unit mysql/0",
110+ []string{"0:foo", "mysql/0:/foo"},
111+ commonArgs + "ubuntu@dummyenv-0.dns:foo ubuntu@dummyenv-0.dns:/foo\n",
112+ "",
113+ },
114+ {
115+ "scp from machine 0 to unit mysql/0 and extra args",
116+ []string{"0:foo", "mysql/0:/foo", "-q"},
117+ commonArgs + "-q ubuntu@dummyenv-0.dns:foo ubuntu@dummyenv-0.dns:/foo\n",
118+ "",
119+ },
120+ {
121+ "scp from machine 0 to unit mysql/0 and extra args before",
122+ []string{"-q", "-r", "0:foo", "mysql/0:/foo"},
123+ "",
124+ `unexpected argument "-q"; extra arguments must be last`,
125+ },
126+ {
127+ "scp two local files to unit mysql/0",
128+ []string{"file1", "file2", "mysql/0:/foo/"},
129+ commonArgs + "file1 file2 ubuntu@dummyenv-0.dns:/foo/\n",
130+ "",
131+ },
132+ {
133+ "scp from unit mongodb/1 to unit mongodb/0 and multiple extra args",
134+ []string{"mongodb/1:foo", "mongodb/0:", "-r -v -q -l5"},
135+ commonArgs + "-r -v -q -l5 ubuntu@dummyenv-2.dns:foo ubuntu@dummyenv-1.dns:\n",
136+ "",
137+ },
138+ {
139+ "scp works with IPv6 addresses",
140+ []string{"ipv6-svc/0:foo", "bar"},
141+ commonArgs + `ubuntu@\[2001:db8::\]:foo bar` + "\n",
142+ "",
143 },
144 }
145
146@@ -119,7 +122,6 @@
147 c.Logf("test %d: %s -> %s\n", i, t.about, t.args)
148 ctx := coretesting.Context(c)
149 scpcmd := &SCPCommand{}
150- scpcmd.proxy = t.proxy
151
152 err := scpcmd.Init(t.args)
153 c.Check(err, gc.IsNil)
154
155=== modified file 'cmd/juju/ssh.go'
156--- cmd/juju/ssh.go 2014-03-19 03:18:41 +0000
157+++ cmd/juju/ssh.go 2014-03-20 02:33:00 +0000
158@@ -6,13 +6,8 @@
159 import (
160 "errors"
161 "fmt"
162- "net"
163- "os"
164- "os/exec"
165 "time"
166
167- "launchpad.net/gnuflag"
168-
169 "launchpad.net/juju-core/cmd"
170 "launchpad.net/juju-core/instance"
171 "launchpad.net/juju-core/juju"
172@@ -31,34 +26,13 @@
173 // SSHCommon provides common methods for SSHCommand, SCPCommand and DebugHooksCommand.
174 type SSHCommon struct {
175 cmd.EnvCommandBase
176- proxy bool
177 Target string
178 Args []string
179 apiClient *api.Client
180- apiAddr string
181 // Only used for compatibility with 1.16
182 rawConn *juju.Conn
183 }
184
185-func (c *SSHCommon) SetFlags(f *gnuflag.FlagSet) {
186- c.EnvCommandBase.SetFlags(f)
187- f.BoolVar(&c.proxy, "proxy", true, "proxy through the API server")
188-}
189-
190-// setProxyCommand sets the proxy command option.
191-func (c *SSHCommon) setProxyCommand(options *ssh.Options) error {
192- apiServerHost, _, err := net.SplitHostPort(c.apiAddr)
193- if err != nil {
194- return fmt.Errorf("failed to get proxy address: %v", err)
195- }
196- juju, err := getJujuExecutable()
197- if err != nil {
198- return fmt.Errorf("failed to get juju executable path: %v", err)
199- }
200- options.SetProxyCommand(juju, "ssh", "--proxy=false", apiServerHost, "-T", "nc -q0 %h %p")
201- return nil
202-}
203-
204 const sshDoc = `
205 Launch an ssh shell on the machine identified by the <target> parameter.
206 <target> can be either a machine id as listed by "juju status" in the
207@@ -101,12 +75,6 @@
208 return nil
209 }
210
211-// getJujuExecutable returns the path to the juju
212-// executable, or an error if it could not be found.
213-var getJujuExecutable = func() (string, error) {
214- return exec.LookPath(os.Args[0])
215-}
216-
217 // Run resolves c.Target to a machine, to the address of a i
218 // machine or unit forks ssh passing any arguments provided.
219 func (c *SSHCommand) Run(ctx *cmd.Context) error {
220@@ -124,11 +92,6 @@
221 }
222 var options ssh.Options
223 options.EnablePTY()
224- if c.proxy {
225- if err := c.setProxyCommand(&options); err != nil {
226- return err
227- }
228- }
229 cmd := ssh.Command("ubuntu@"+host, c.Args, &options)
230 cmd.Stdin = ctx.Stdin
231 cmd.Stdout = ctx.Stdout
232@@ -139,13 +102,9 @@
233 // initAPIClient initialises the API connection.
234 // It is the caller's responsibility to close the connection.
235 func (c *SSHCommon) initAPIClient() (*api.Client, error) {
236- st, err := juju.NewAPIFromName(c.EnvName)
237- if err != nil {
238- return nil, err
239- }
240- c.apiClient = st.Client()
241- c.apiAddr = st.Addr()
242- return c.apiClient, nil
243+ var err error
244+ c.apiClient, err = juju.NewAPIClientFromName(c.EnvName)
245+ return c.apiClient, err
246 }
247
248 // attemptStarter is an interface corresponding to utils.AttemptStrategy
249@@ -199,15 +158,9 @@
250 if err != nil {
251 return "", err
252 }
253- var addr string
254- if c.proxy {
255- if addr = instance.SelectInternalAddress(machine.Addresses(), false); addr == "" {
256- return "", fmt.Errorf("machine %q has no internal address", machine)
257- }
258- } else {
259- if addr = instance.SelectPublicAddress(machine.Addresses()); addr == "" {
260- return "", fmt.Errorf("machine %q has no public address", machine)
261- }
262+ addr := instance.SelectPublicAddress(machine.Addresses())
263+ if addr == "" {
264+ return "", fmt.Errorf("machine %q has no public address", machine)
265 }
266 return addr, nil
267 }
268@@ -218,16 +171,9 @@
269 if err != nil {
270 return "", err
271 }
272- var addr string
273- var ok bool
274- if c.proxy {
275- if addr, ok = unit.PrivateAddress(); !ok {
276- return "", fmt.Errorf("unit %q has no internal address", unit)
277- }
278- } else {
279- if addr, ok = unit.PublicAddress(); !ok {
280- return "", fmt.Errorf("unit %q has no public address", unit)
281- }
282+ addr, ok := unit.PublicAddress()
283+ if !ok {
284+ return "", fmt.Errorf("unit %q has no public address", unit)
285 }
286 return addr, nil
287 }
288@@ -235,11 +181,6 @@
289 }
290
291 func (c *SSHCommon) hostFromTarget(target string) (string, error) {
292- // If the target is neither a machine nor a unit,
293- // assume it's a hostname and try it directly.
294- if !names.IsMachine(target) && !names.IsUnit(target) {
295- return target, nil
296- }
297 var addr string
298 var err error
299 var useStateConn bool
300@@ -248,13 +189,9 @@
301 // a loop.
302 for a := sshHostFromTargetAttemptStrategy.Start(); a.Next(); {
303 if !useStateConn {
304- if c.proxy {
305- addr, err = c.apiClient.PrivateAddress(target)
306- } else {
307- addr, err = c.apiClient.PublicAddress(target)
308- }
309+ addr, err = c.apiClient.PublicAddress(target)
310 if params.IsCodeNotImplemented(err) {
311- logger.Infof("API server does not support Client.PrivateAddress falling back to 1.16 compatibility mode (direct DB access)")
312+ logger.Infof("API server does not support Client.PublicAddress falling back to 1.16 compatibility mode (direct DB access)")
313 useStateConn = true
314 }
315 }
316
317=== modified file 'cmd/juju/ssh_test.go'
318--- cmd/juju/ssh_test.go 2014-03-19 03:18:41 +0000
319+++ cmd/juju/ssh_test.go 2014-03-20 02:33:00 +0000
320@@ -39,7 +39,6 @@
321
322 func (s *SSHCommonSuite) SetUpTest(c *gc.C) {
323 s.JujuConnSuite.SetUpTest(c)
324- s.PatchValue(&getJujuExecutable, func() (string, error) { return "juju", nil })
325
326 s.bin = c.MkDir()
327 s.PatchEnvPathPrepend(s.bin)
328@@ -54,10 +53,8 @@
329 }
330
331 const (
332- commonArgsNoProxy = `-o StrictHostKeyChecking no -o PasswordAuthentication no `
333- commonArgs = `-o StrictHostKeyChecking no -o ProxyCommand juju ssh --proxy=false 127.0.0.1 -T "nc -q0 %h %p" -o PasswordAuthentication no `
334- sshArgs = commonArgs + `-t -t `
335- sshArgsNoProxy = commonArgsNoProxy + `-t -t `
336+ commonArgs = `-o StrictHostKeyChecking no -o PasswordAuthentication no `
337+ sshArgs = commonArgs + `-t -t `
338 )
339
340 var sshTests = []struct {
341@@ -85,11 +82,6 @@
342 []string{"ssh", "mongodb/1", "ls", "/"},
343 sshArgs + "ubuntu@dummyenv-2.dns ls /\n",
344 },
345- {
346- "connect to unit mysql/0 without proxy",
347- []string{"ssh", "--proxy=false", "mysql/0"},
348- sshArgsNoProxy + "ubuntu@dummyenv-0.dns\n",
349- },
350 }
351
352 func (s *SSHSuite) TestSSHCommand(c *gc.C) {

Subscribers

People subscribed via source and target branches

to status/vote changes: