From ece468e8132fc6bd215830befd97748776ed0974 Mon Sep 17 00:00:00 2001 From: kayrus Date: Wed, 9 Mar 2016 15:11:00 +0100 Subject: [PATCH 01/10] tests: added "fleetctl --tunnel" tests --- functional/fixtures/units/hello@.service | 2 + functional/platform/cluster.go | 2 + functional/platform/nspawn.go | 51 +++++++++++++++++- functional/tunnel_test.go | 68 ++++++++++++++++++++++++ functional/util/config.go | 3 ++ 5 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 functional/fixtures/units/hello@.service create mode 100644 functional/tunnel_test.go diff --git a/functional/fixtures/units/hello@.service b/functional/fixtures/units/hello@.service new file mode 100644 index 000000000..910a8a5b5 --- /dev/null +++ b/functional/fixtures/units/hello@.service @@ -0,0 +1,2 @@ +[Service] +ExecStart=/bin/bash -c "while true; do echo Hello, World %i!; sleep 1; done" diff --git a/functional/platform/cluster.go b/functional/platform/cluster.go index ee47f59cc..d1b87e626 100644 --- a/functional/platform/cluster.go +++ b/functional/platform/cluster.go @@ -35,6 +35,8 @@ type Cluster interface { // client operations Fleetctl(m Member, args ...string) (string, string, error) FleetctlWithInput(m Member, input string, args ...string) (string, string, error) + FleetctlTunnel(m Member, args ...string) (string, string, error) + FleetctlTunnelWithInput(m Member, input string, args ...string) (string, string, error) WaitForNActiveUnits(Member, int) (map[string][]util.UnitState, error) WaitForNMachines(Member, int) ([]string, error) } diff --git a/functional/platform/nspawn.go b/functional/platform/nspawn.go index 3690c7877..a7bbc1717 100644 --- a/functional/platform/nspawn.go +++ b/functional/platform/nspawn.go @@ -39,9 +39,11 @@ const ( ) var fleetdBinPath string +var fleetctlBinPath string func init() { fleetdBinPath = os.Getenv("FLEETD_BIN") + fleetctlBinPath = os.Getenv("FLEETCTL_BIN") if fleetdBinPath == "" { fmt.Println("FLEETD_BIN environment variable must be set") os.Exit(1) @@ -49,6 +51,13 @@ func init() { fmt.Printf("%v\n", err) os.Exit(1) } + if fleetctlBinPath == "" { + fmt.Println("FLEETCTL_BIN environment variable must be set") + os.Exit(1) + } else if _, err := os.Stat(fleetctlBinPath); err != nil { + fmt.Printf("%v\n", err) + os.Exit(1) + } // sanity check etcd availability cmd := exec.Command("etcdctl", "ls") out, err := cmd.CombinedOutput() @@ -104,6 +113,16 @@ func (nc *nspawnCluster) FleetctlWithInput(m Member, input string, args ...strin return util.RunFleetctlWithInput(input, args...) } +func (nc *nspawnCluster) FleetctlTunnel(m Member, args ...string) (string, string, error) { + args = append([]string{"--tunnel=" + m.IP()}, args...) + return util.RunFleetctl(args...) +} + +func (nc *nspawnCluster) FleetctlTunnelWithInput(m Member, input string, args ...string) (string, string, error) { + args = append([]string{"--tunnel=" + m.IP()}, args...) + return util.RunFleetctlWithInput(input, args...) +} + func (nc *nspawnCluster) WaitForNActiveUnits(m Member, count int) (map[string][]util.UnitState, error) { var nactive int states := make(map[string][]util.UnitState) @@ -238,6 +257,16 @@ func (nc *nspawnCluster) insertFleetd(dir string) error { return copyFile(fleetdBinPath, fleetdBinDst, 0755) } +func (nc *nspawnCluster) insertFleetctl(dir string) error { + cmd := fmt.Sprintf("mkdir -p %s/opt/fleet", dir) + if _, _, err := run(cmd); err != nil { + return err + } + + fleetctlBinDst := path.Join(dir, "opt", "fleet", "fleetctl") + return copyFile(fleetctlBinPath, fleetctlBinDst, 0755) +} + func (nc *nspawnCluster) buildConfigDrive(dir, ip string) error { latest := path.Join(dir, "media/configdrive/openstack/latest") userPath := path.Join(latest, "user_data") @@ -303,8 +332,6 @@ func (nc *nspawnCluster) createMember(id string) (m Member, err error) { // minimum requirements for running systemd/coreos in a container fmt.Sprintf("mkdir -p %s/usr", fsdir), fmt.Sprintf("cp /etc/os-release %s/etc", fsdir), - fmt.Sprintf("echo 'core:x:500:500:CoreOS Admin:/home/core:/bin/bash' > %s/etc/passwd", fsdir), - fmt.Sprintf("echo 'core:x:500:' > %s/etc/group", fsdir), fmt.Sprintf("ln -s /proc/self/mounts %s/etc/mtab", fsdir), fmt.Sprintf("ln -s usr/lib64 %s/lib64", fsdir), fmt.Sprintf("ln -s lib64 %s/lib", fsdir), @@ -354,11 +381,31 @@ UseDNS no return } + if err = ioutil.WriteFile(path.Join(fsdir, "/etc/passwd"), []byte("core:x:500:500:CoreOS Admin:/home/core:/bin/bash"), 0644); err != nil { + log.Printf("Failed writing /etc/passwd: %v", err) + return + } + + if err = ioutil.WriteFile(path.Join(fsdir, "/etc/group"), []byte("core:x:500:"), 0644); err != nil { + log.Printf("Failed writing /etc/group: %v", err) + return + } + + if err = ioutil.WriteFile(path.Join(fsdir, "/home/core/.bash_profile"), []byte("export PATH=/opt/fleet:$PATH"), 0644); err != nil { + log.Printf("Failed writing /home/core/.bash_profile: %v", err) + return + } + if err = nc.insertFleetd(fsdir); err != nil { log.Printf("Failed preparing fleetd in filesystem: %v", err) return } + if err = nc.insertFleetctl(fsdir); err != nil { + log.Printf("Failed preparing fleetctl in filesystem: %v", err) + return + } + if err = nc.buildConfigDrive(fsdir, nm.IP()); err != nil { log.Printf("Failed building config drive: %v", err) return diff --git a/functional/tunnel_test.go b/functional/tunnel_test.go new file mode 100644 index 000000000..ae6e8f1d2 --- /dev/null +++ b/functional/tunnel_test.go @@ -0,0 +1,68 @@ +// Copyright 2014 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package functional + +import ( + "fmt" + "io/ioutil" + "os" + "syscall" + "strings" + "testing" + + "github.com/coreos/fleet/functional/platform" +) + +// Start three units using ssh tunnel +func TestTunnelScheduleBatchUnits(t *testing.T) { + cluster, err := platform.NewNspawnCluster("smoke") + if err != nil { + t.Fatal(err) + } + defer cluster.Destroy() + + members, err := platform.CreateNClusterMembers(cluster, 1) + if err != nil { + t.Fatal(err) + } + m0 := members[0] + _, err = cluster.WaitForNMachines(m0, 1) + if err != nil { + t.Fatal(err) + } + + tmp, err := ioutil.TempFile(os.TempDir(), "known-hosts") + if err != nil { + t.Fatal(err) + } + tmp.Close() + defer syscall.Unlink(tmp.Name()) + + khFile := tmp.Name() + + // Launch one unit + if stdout, stderr, err := cluster.FleetctlTunnelWithInput(m0, "yes", "--strict-host-key-checking=true", fmt.Sprintf("--known-hosts-file=%s", khFile), "start", "fixtures/units/hello.service"); err != nil { + t.Fatalf("Unable to submit one unit using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) + } else if strings.Contains(stderr, "Error") { + t.Fatalf("Failed to correctly submit unit using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) + } + + // Launch a batch of units + if stdout, stderr, err := cluster.FleetctlTunnel(m0, "--strict-host-key-checking=true", fmt.Sprintf("--known-hosts-file=%s", khFile), "start", "fixtures/units/hello@1.service", "fixtures/units/hello@1.service", "fixtures/units/hello@3.service"); err != nil { + t.Fatalf("Unable to submit batch of units using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) + } else if strings.Contains(stderr, "Error") { + t.Fatalf("Failed to correctly submit batch of units using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) + } +} diff --git a/functional/util/config.go b/functional/util/config.go index 1c29ab2dc..7063da5cf 100644 --- a/functional/util/config.go +++ b/functional/util/config.go @@ -50,9 +50,12 @@ coreos: Address={{.IP}}/16 - name: fleet.socket command: start + - name: fleet-tcp.socket + command: start content: | [Socket] ListenStream={{printf "%d" .FleetAPIPort}} + Service=fleet.service - name: fleet.service command: start content: | From ea415adbb229624f9f632f7c69a4829036a1a17d Mon Sep 17 00:00:00 2001 From: kayrus Date: Thu, 10 Mar 2016 17:00:06 +0100 Subject: [PATCH 02/10] fleetctl: fixed incorrect "auth-agent-req@openssh.com" behavior fixes: #1425 --- ssh/ssh.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ssh/ssh.go b/ssh/ssh.go index ca02dd949..5d5a73c6d 100644 --- a/ssh/ssh.go +++ b/ssh/ssh.go @@ -30,10 +30,14 @@ import ( type SSHForwardingClient struct { agentForwarding bool *gossh.Client + agentForwardingEnabled bool } func (s *SSHForwardingClient) ForwardAgentAuthentication(session *gossh.Session) error { - if s.agentForwarding { + if s.agentForwarding && !s.agentForwardingEnabled { + // We are allowed to send "auth-agent-req@openssh.com" request only once per channel + // otherwise ssh daemon replies with the "SSH2_MSG_CHANNEL_FAILURE 100" + s.agentForwardingEnabled = true return gosshagent.RequestAgentForwarding(session) } return nil @@ -50,7 +54,7 @@ func newSSHForwardingClient(client *gossh.Client, agentForwarding bool) (*SSHFor return nil, err } - return &SSHForwardingClient{agentForwarding, client}, nil + return &SSHForwardingClient{agentForwarding, client, false}, nil } // makeSession initializes a gossh.Session connected to the invoking process's stdout/stderr/stdout. From 2e4317ae45cf58b200e8d22fac1c9ca87806864c Mon Sep 17 00:00:00 2001 From: kayrus Date: Thu, 10 Mar 2016 17:28:19 +0100 Subject: [PATCH 03/10] tests: updated ssh tests --- functional/tunnel_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/functional/tunnel_test.go b/functional/tunnel_test.go index ae6e8f1d2..aa5bd6c13 100644 --- a/functional/tunnel_test.go +++ b/functional/tunnel_test.go @@ -18,8 +18,8 @@ import ( "fmt" "io/ioutil" "os" - "syscall" "strings" + "syscall" "testing" "github.com/coreos/fleet/functional/platform" @@ -33,12 +33,12 @@ func TestTunnelScheduleBatchUnits(t *testing.T) { } defer cluster.Destroy() - members, err := platform.CreateNClusterMembers(cluster, 1) + members, err := platform.CreateNClusterMembers(cluster, 3) if err != nil { t.Fatal(err) } m0 := members[0] - _, err = cluster.WaitForNMachines(m0, 1) + _, err = cluster.WaitForNMachines(m0, 3) if err != nil { t.Fatal(err) } @@ -60,9 +60,14 @@ func TestTunnelScheduleBatchUnits(t *testing.T) { } // Launch a batch of units - if stdout, stderr, err := cluster.FleetctlTunnel(m0, "--strict-host-key-checking=true", fmt.Sprintf("--known-hosts-file=%s", khFile), "start", "fixtures/units/hello@1.service", "fixtures/units/hello@1.service", "fixtures/units/hello@3.service"); err != nil { + if stdout, stderr, err := cluster.FleetctlTunnel(m0, "--strict-host-key-checking=true", fmt.Sprintf("--known-hosts-file=%s", khFile), "start", "fixtures/units/hello@1.service", "fixtures/units/hello@2.service", "fixtures/units/hello@3.service", "fixtures/units/hello@4.service", "fixtures/units/hello@5.service", "fixtures/units/hello@6.service", "fixtures/units/hello@7.service", "fixtures/units/hello@8.service", "fixtures/units/hello@9.service", "fixtures/units/hello@10.service"); err != nil { t.Fatalf("Unable to submit batch of units using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) } else if strings.Contains(stderr, "Error") { t.Fatalf("Failed to correctly submit batch of units using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) } + + _, err = cluster.WaitForNActiveUnits(m0, 11) + if err != nil { + t.Fatal(err) + } } From 3367bc74d700f4d95fbea9ba957fe2face265a95 Mon Sep 17 00:00:00 2001 From: kayrus Date: Wed, 16 Mar 2016 16:40:33 +0100 Subject: [PATCH 04/10] tests: removed previously declared FleetctlTunnel* functions --- functional/platform/cluster.go | 2 -- functional/platform/nspawn.go | 10 ---------- functional/tunnel_test.go | 6 +++--- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/functional/platform/cluster.go b/functional/platform/cluster.go index d1b87e626..ee47f59cc 100644 --- a/functional/platform/cluster.go +++ b/functional/platform/cluster.go @@ -35,8 +35,6 @@ type Cluster interface { // client operations Fleetctl(m Member, args ...string) (string, string, error) FleetctlWithInput(m Member, input string, args ...string) (string, string, error) - FleetctlTunnel(m Member, args ...string) (string, string, error) - FleetctlTunnelWithInput(m Member, input string, args ...string) (string, string, error) WaitForNActiveUnits(Member, int) (map[string][]util.UnitState, error) WaitForNMachines(Member, int) ([]string, error) } diff --git a/functional/platform/nspawn.go b/functional/platform/nspawn.go index a7bbc1717..f13f025bb 100644 --- a/functional/platform/nspawn.go +++ b/functional/platform/nspawn.go @@ -113,16 +113,6 @@ func (nc *nspawnCluster) FleetctlWithInput(m Member, input string, args ...strin return util.RunFleetctlWithInput(input, args...) } -func (nc *nspawnCluster) FleetctlTunnel(m Member, args ...string) (string, string, error) { - args = append([]string{"--tunnel=" + m.IP()}, args...) - return util.RunFleetctl(args...) -} - -func (nc *nspawnCluster) FleetctlTunnelWithInput(m Member, input string, args ...string) (string, string, error) { - args = append([]string{"--tunnel=" + m.IP()}, args...) - return util.RunFleetctlWithInput(input, args...) -} - func (nc *nspawnCluster) WaitForNActiveUnits(m Member, count int) (map[string][]util.UnitState, error) { var nactive int states := make(map[string][]util.UnitState) diff --git a/functional/tunnel_test.go b/functional/tunnel_test.go index aa5bd6c13..899ad7baa 100644 --- a/functional/tunnel_test.go +++ b/functional/tunnel_test.go @@ -1,4 +1,4 @@ -// Copyright 2014 CoreOS, Inc. +// Copyright 2016 CoreOS, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -53,14 +53,14 @@ func TestTunnelScheduleBatchUnits(t *testing.T) { khFile := tmp.Name() // Launch one unit - if stdout, stderr, err := cluster.FleetctlTunnelWithInput(m0, "yes", "--strict-host-key-checking=true", fmt.Sprintf("--known-hosts-file=%s", khFile), "start", "fixtures/units/hello.service"); err != nil { + if stdout, stderr, err := cluster.FleetctlWithInput(m0, "yes", fmt.Sprintf("--tunnel=%s", m0.IP()), "--strict-host-key-checking=true", fmt.Sprintf("--known-hosts-file=%s", khFile), "start", "fixtures/units/hello.service"); err != nil { t.Fatalf("Unable to submit one unit using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) } else if strings.Contains(stderr, "Error") { t.Fatalf("Failed to correctly submit unit using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) } // Launch a batch of units - if stdout, stderr, err := cluster.FleetctlTunnel(m0, "--strict-host-key-checking=true", fmt.Sprintf("--known-hosts-file=%s", khFile), "start", "fixtures/units/hello@1.service", "fixtures/units/hello@2.service", "fixtures/units/hello@3.service", "fixtures/units/hello@4.service", "fixtures/units/hello@5.service", "fixtures/units/hello@6.service", "fixtures/units/hello@7.service", "fixtures/units/hello@8.service", "fixtures/units/hello@9.service", "fixtures/units/hello@10.service"); err != nil { + if stdout, stderr, err := cluster.Fleetctl(m0, fmt.Sprintf("--tunnel=%s", m0.IP()), "--strict-host-key-checking=true", fmt.Sprintf("--known-hosts-file=%s", khFile), "start", "fixtures/units/hello@1.service", "fixtures/units/hello@2.service", "fixtures/units/hello@3.service", "fixtures/units/hello@4.service", "fixtures/units/hello@5.service", "fixtures/units/hello@6.service", "fixtures/units/hello@7.service", "fixtures/units/hello@8.service", "fixtures/units/hello@9.service", "fixtures/units/hello@10.service"); err != nil { t.Fatalf("Unable to submit batch of units using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) } else if strings.Contains(stderr, "Error") { t.Fatalf("Failed to correctly submit batch of units using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) From 2d184fa83a9058e74992e9db96d26e7087006758 Mon Sep 17 00:00:00 2001 From: kayrus Date: Wed, 16 Mar 2016 17:44:33 +0100 Subject: [PATCH 05/10] tests: implemented insertBin function --- functional/platform/nspawn.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/functional/platform/nspawn.go b/functional/platform/nspawn.go index f13f025bb..b807752d3 100644 --- a/functional/platform/nspawn.go +++ b/functional/platform/nspawn.go @@ -237,24 +237,14 @@ func (nc *nspawnCluster) prepCluster() (err error) { return nil } -func (nc *nspawnCluster) insertFleetd(dir string) error { - cmd := fmt.Sprintf("mkdir -p %s/opt/fleet", dir) +func (nc *nspawnCluster) insertBin(src string, dst string) error { + cmd := fmt.Sprintf("mkdir -p %s/opt/fleet", dst) if _, _, err := run(cmd); err != nil { return err } - fleetdBinDst := path.Join(dir, "opt", "fleet", "fleetd") - return copyFile(fleetdBinPath, fleetdBinDst, 0755) -} - -func (nc *nspawnCluster) insertFleetctl(dir string) error { - cmd := fmt.Sprintf("mkdir -p %s/opt/fleet", dir) - if _, _, err := run(cmd); err != nil { - return err - } - - fleetctlBinDst := path.Join(dir, "opt", "fleet", "fleetctl") - return copyFile(fleetctlBinPath, fleetctlBinDst, 0755) + BinDst := path.Join(dst, "opt", "fleet", path.Base(src)) + return copyFile(src, BinDst, 0755) } func (nc *nspawnCluster) buildConfigDrive(dir, ip string) error { @@ -386,12 +376,12 @@ UseDNS no return } - if err = nc.insertFleetd(fsdir); err != nil { + if err = nc.insertBin(fleetdBinPath, fsdir); err != nil { log.Printf("Failed preparing fleetd in filesystem: %v", err) return } - if err = nc.insertFleetctl(fsdir); err != nil { + if err = nc.insertBin(fleetctlBinPath, fsdir); err != nil { log.Printf("Failed preparing fleetctl in filesystem: %v", err) return } From 586eea8d0e23d8f668378b2b658c3dc7e33891bd Mon Sep 17 00:00:00 2001 From: kayrus Date: Thu, 17 Mar 2016 14:53:56 +0100 Subject: [PATCH 06/10] tests: added handleEndpointFlag function --- functional/platform/nspawn.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/functional/platform/nspawn.go b/functional/platform/nspawn.go index b807752d3..c358d9f84 100644 --- a/functional/platform/nspawn.go +++ b/functional/platform/nspawn.go @@ -103,13 +103,28 @@ func (nc *nspawnCluster) keyspace() string { return fmt.Sprintf("/fleet_functional/%s", nc.name) } +// This function adds --endpoint flag if --tunnel flag is not used +// Usefull for "fleetctl fd-forward" tests +func handleEndpointFlag(m Member, args *[]string) { + result := true + for _, arg := range *args { + if strings.Contains(arg, "-- ") || strings.Contains(arg, "--tunnel") { + result = false + break + } + } + if result { + *args = append([]string{"--endpoint=" + m.Endpoint()}, *args...) + } +} + func (nc *nspawnCluster) Fleetctl(m Member, args ...string) (string, string, error) { - args = append([]string{"--endpoint=" + m.Endpoint()}, args...) + handleEndpointFlag(m, &args) return util.RunFleetctl(args...) } func (nc *nspawnCluster) FleetctlWithInput(m Member, input string, args ...string) (string, string, error) { - args = append([]string{"--endpoint=" + m.Endpoint()}, args...) + handleEndpointFlag(m, &args) return util.RunFleetctlWithInput(input, args...) } From 51fba0bdae40555c8d18920c01fdb7d3da2cf8e7 Mon Sep 17 00:00:00 2001 From: kayrus Date: Thu, 17 Mar 2016 15:31:32 +0100 Subject: [PATCH 07/10] tests: reimplemented "WriteFile" --- functional/platform/nspawn.go | 40 +++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/functional/platform/nspawn.go b/functional/platform/nspawn.go index c358d9f84..9774ebbea 100644 --- a/functional/platform/nspawn.go +++ b/functional/platform/nspawn.go @@ -376,19 +376,33 @@ UseDNS no return } - if err = ioutil.WriteFile(path.Join(fsdir, "/etc/passwd"), []byte("core:x:500:500:CoreOS Admin:/home/core:/bin/bash"), 0644); err != nil { - log.Printf("Failed writing /etc/passwd: %v", err) - return - } - - if err = ioutil.WriteFile(path.Join(fsdir, "/etc/group"), []byte("core:x:500:"), 0644); err != nil { - log.Printf("Failed writing /etc/group: %v", err) - return - } - - if err = ioutil.WriteFile(path.Join(fsdir, "/home/core/.bash_profile"), []byte("export PATH=/opt/fleet:$PATH"), 0644); err != nil { - log.Printf("Failed writing /home/core/.bash_profile: %v", err) - return + filesContents := []struct { + path string + contents string + mode os.FileMode + }{ + { + "/etc/passwd", + "core:x:500:500:CoreOS Admin:/home/core:/bin/bash", + 0644, + }, + { + "/etc/group", + "core:x:500:", + 0644, + }, + { + "/home/core/.bash_profile", + "export PATH=/opt/fleet:$PATH", + 0644, + }, + } + + for _, file := range filesContents { + if err = ioutil.WriteFile(path.Join(fsdir, file.path), []byte(file.contents), file.mode); err != nil { + log.Printf("Failed writing %s: %v", path.Join(fsdir, file.path), err) + return + } } if err = nc.insertBin(fleetdBinPath, fsdir); err != nil { From 3f3daa2466aedc8010b79272d6ca48233d1a0b88 Mon Sep 17 00:00:00 2001 From: kayrus Date: Thu, 17 Mar 2016 16:52:35 +0100 Subject: [PATCH 08/10] tests: use loop to generate units' args slice --- functional/tunnel_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/functional/tunnel_test.go b/functional/tunnel_test.go index 899ad7baa..030ddecea 100644 --- a/functional/tunnel_test.go +++ b/functional/tunnel_test.go @@ -59,8 +59,19 @@ func TestTunnelScheduleBatchUnits(t *testing.T) { t.Fatalf("Failed to correctly submit unit using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) } + // Combine all parameters and units in one args slice + args := []string{ + fmt.Sprintf("--tunnel=%s", m0.IP()), + "--strict-host-key-checking=true", + fmt.Sprintf("--known-hosts-file=%s", khFile), + "start", + } + for i := 1; i <= 10; i++ { + args = append(args, fmt.Sprintf("fixtures/units/hello@%d.service", i)) + } + // Launch a batch of units - if stdout, stderr, err := cluster.Fleetctl(m0, fmt.Sprintf("--tunnel=%s", m0.IP()), "--strict-host-key-checking=true", fmt.Sprintf("--known-hosts-file=%s", khFile), "start", "fixtures/units/hello@1.service", "fixtures/units/hello@2.service", "fixtures/units/hello@3.service", "fixtures/units/hello@4.service", "fixtures/units/hello@5.service", "fixtures/units/hello@6.service", "fixtures/units/hello@7.service", "fixtures/units/hello@8.service", "fixtures/units/hello@9.service", "fixtures/units/hello@10.service"); err != nil { + if stdout, stderr, err := cluster.Fleetctl(m0, args...); err != nil { t.Fatalf("Unable to submit batch of units using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) } else if strings.Contains(stderr, "Error") { t.Fatalf("Failed to correctly submit batch of units using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) From fd6b2f6a921262077012176d462baf8af6d936db Mon Sep 17 00:00:00 2001 From: kayrus Date: Mon, 21 Mar 2016 12:58:44 +0100 Subject: [PATCH 09/10] tests: a couple of tiny improvements * renamed BinDst into binDst * split "Launch one unit" string --- functional/platform/nspawn.go | 4 ++-- functional/tunnel_test.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/functional/platform/nspawn.go b/functional/platform/nspawn.go index 9774ebbea..142c097d8 100644 --- a/functional/platform/nspawn.go +++ b/functional/platform/nspawn.go @@ -258,8 +258,8 @@ func (nc *nspawnCluster) insertBin(src string, dst string) error { return err } - BinDst := path.Join(dst, "opt", "fleet", path.Base(src)) - return copyFile(src, BinDst, 0755) + binDst := path.Join(dst, "opt", "fleet", path.Base(src)) + return copyFile(src, binDst, 0755) } func (nc *nspawnCluster) buildConfigDrive(dir, ip string) error { diff --git a/functional/tunnel_test.go b/functional/tunnel_test.go index 030ddecea..1939f5541 100644 --- a/functional/tunnel_test.go +++ b/functional/tunnel_test.go @@ -53,7 +53,12 @@ func TestTunnelScheduleBatchUnits(t *testing.T) { khFile := tmp.Name() // Launch one unit - if stdout, stderr, err := cluster.FleetctlWithInput(m0, "yes", fmt.Sprintf("--tunnel=%s", m0.IP()), "--strict-host-key-checking=true", fmt.Sprintf("--known-hosts-file=%s", khFile), "start", "fixtures/units/hello.service"); err != nil { + if stdout, stderr, err := cluster.FleetctlWithInput(m0, "yes", + fmt.Sprintf("--tunnel=%s", m0.IP()), + "--strict-host-key-checking=true", + fmt.Sprintf("--known-hosts-file=%s", khFile), + "start", + "fixtures/units/hello.service"); err != nil { t.Fatalf("Unable to submit one unit using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) } else if strings.Contains(stderr, "Error") { t.Fatalf("Failed to correctly submit unit using ssh tunnel: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) From 84c80b44f10d193bb795326495e74cd6ad464b31 Mon Sep 17 00:00:00 2001 From: kayrus Date: Mon, 21 Mar 2016 14:43:20 +0100 Subject: [PATCH 10/10] fleetctl: renamed agentForwardingEnabled into authAgentReqSent --- ssh/ssh.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ssh/ssh.go b/ssh/ssh.go index 5d5a73c6d..b66844912 100644 --- a/ssh/ssh.go +++ b/ssh/ssh.go @@ -30,14 +30,14 @@ import ( type SSHForwardingClient struct { agentForwarding bool *gossh.Client - agentForwardingEnabled bool + authAgentReqSent bool } func (s *SSHForwardingClient) ForwardAgentAuthentication(session *gossh.Session) error { - if s.agentForwarding && !s.agentForwardingEnabled { + if s.agentForwarding && !s.authAgentReqSent { // We are allowed to send "auth-agent-req@openssh.com" request only once per channel // otherwise ssh daemon replies with the "SSH2_MSG_CHANNEL_FAILURE 100" - s.agentForwardingEnabled = true + s.authAgentReqSent = true return gosshagent.RequestAgentForwarding(session) } return nil