Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
6f925722
Commit
6f925722
authored
Nov 28, 2016
by
Random-Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ssh related functions into ssh.go.
parent
2708f5c7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
69 deletions
+99
-69
BUILD
test/e2e_node/remote/BUILD
+4
-1
remote.go
test/e2e_node/remote/remote.go
+0
-68
ssh.go
test/e2e_node/remote/ssh.go
+95
-0
No files found.
test/e2e_node/remote/BUILD
View file @
6f925722
...
@@ -12,7 +12,10 @@ load(
...
@@ -12,7 +12,10 @@ load(
go_library(
go_library(
name = "go_default_library",
name = "go_default_library",
srcs = ["remote.go"],
srcs = [
"remote.go",
"ssh.go",
],
tags = ["automanaged"],
tags = ["automanaged"],
deps = [
deps = [
"//pkg/util/errors:go_default_library",
"//pkg/util/errors:go_default_library",
...
...
test/e2e_node/remote/remote.go
View file @
6f925722
...
@@ -22,10 +22,8 @@ import (
...
@@ -22,10 +22,8 @@ import (
"io/ioutil"
"io/ioutil"
"os"
"os"
"os/exec"
"os/exec"
"os/user"
"path/filepath"
"path/filepath"
"strings"
"strings"
"sync"
"time"
"time"
"github.com/golang/glog"
"github.com/golang/glog"
...
@@ -33,13 +31,9 @@ import (
...
@@ -33,13 +31,9 @@ import (
"k8s.io/kubernetes/test/e2e_node/builder"
"k8s.io/kubernetes/test/e2e_node/builder"
)
)
var
sshOptions
=
flag
.
String
(
"ssh-options"
,
""
,
"Commandline options passed to ssh."
)
var
sshEnv
=
flag
.
String
(
"ssh-env"
,
""
,
"Use predefined ssh options for environment. Options: gce"
)
var
testTimeoutSeconds
=
flag
.
Duration
(
"test-timeout"
,
45
*
time
.
Minute
,
"How long (in golang duration format) to wait for ginkgo tests to complete."
)
var
testTimeoutSeconds
=
flag
.
Duration
(
"test-timeout"
,
45
*
time
.
Minute
,
"How long (in golang duration format) to wait for ginkgo tests to complete."
)
var
resultsDir
=
flag
.
String
(
"results-dir"
,
"/tmp/"
,
"Directory to scp test results to."
)
var
resultsDir
=
flag
.
String
(
"results-dir"
,
"/tmp/"
,
"Directory to scp test results to."
)
var
sshOptionsMap
map
[
string
]
string
const
(
const
(
archiveName
=
"e2e_node_test.tar.gz"
archiveName
=
"e2e_node_test.tar.gz"
CNIRelease
=
"07a8a28637e97b22eb8dfe710eeae1344f69d16e"
CNIRelease
=
"07a8a28637e97b22eb8dfe710eeae1344f69d16e"
...
@@ -48,36 +42,6 @@ const (
...
@@ -48,36 +42,6 @@ const (
var
CNIURL
=
fmt
.
Sprintf
(
"https://storage.googleapis.com/kubernetes-release/network-plugins/cni-%s.tar.gz"
,
CNIRelease
)
var
CNIURL
=
fmt
.
Sprintf
(
"https://storage.googleapis.com/kubernetes-release/network-plugins/cni-%s.tar.gz"
,
CNIRelease
)
var
hostnameIpOverrides
=
struct
{
sync
.
RWMutex
m
map
[
string
]
string
}{
m
:
make
(
map
[
string
]
string
)}
func
init
()
{
usr
,
err
:=
user
.
Current
()
if
err
!=
nil
{
glog
.
Fatal
(
err
)
}
sshOptionsMap
=
map
[
string
]
string
{
"gce"
:
fmt
.
Sprintf
(
"-i %s/.ssh/google_compute_engine -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o CheckHostIP=no -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o LogLevel=ERROR"
,
usr
.
HomeDir
),
}
}
func
AddHostnameIp
(
hostname
,
ip
string
)
{
hostnameIpOverrides
.
Lock
()
defer
hostnameIpOverrides
.
Unlock
()
hostnameIpOverrides
.
m
[
hostname
]
=
ip
}
func
GetHostnameOrIp
(
hostname
string
)
string
{
hostnameIpOverrides
.
RLock
()
defer
hostnameIpOverrides
.
RUnlock
()
if
ip
,
found
:=
hostnameIpOverrides
.
m
[
hostname
];
found
{
return
ip
}
return
hostname
}
// CreateTestArchive builds the local source and creates a tar archive e2e_node_test.tar.gz containing
// CreateTestArchive builds the local source and creates a tar archive e2e_node_test.tar.gz containing
// the binaries k8s required for node e2e tests
// the binaries k8s required for node e2e tests
func
CreateTestArchive
()
(
string
,
error
)
{
func
CreateTestArchive
()
(
string
,
error
)
{
...
@@ -361,35 +325,3 @@ func WriteLog(host, filename, content string) error {
...
@@ -361,35 +325,3 @@ func WriteLog(host, filename, content string) error {
_
,
err
=
f
.
WriteString
(
content
)
_
,
err
=
f
.
WriteString
(
content
)
return
err
return
err
}
}
// getSSHCommand handles proper quoting so that multiple commands are executed in the same shell over ssh
func
getSSHCommand
(
sep
string
,
args
...
string
)
string
{
return
fmt
.
Sprintf
(
"'%s'"
,
strings
.
Join
(
args
,
sep
))
}
// SSH executes ssh command with runSSHCommand as root. The `sudo` makes sure that all commands
// are executed by root, so that there won't be permission mismatch between different commands.
func
SSH
(
host
string
,
cmd
...
string
)
(
string
,
error
)
{
return
runSSHCommand
(
"ssh"
,
append
([]
string
{
GetHostnameOrIp
(
host
),
"--"
,
"sudo"
},
cmd
...
)
...
)
}
// SSHNoSudo executes ssh command with runSSHCommand as normal user. Sometimes we need this,
// for example creating a directory that we'll copy files there with scp.
func
SSHNoSudo
(
host
string
,
cmd
...
string
)
(
string
,
error
)
{
return
runSSHCommand
(
"ssh"
,
append
([]
string
{
GetHostnameOrIp
(
host
),
"--"
},
cmd
...
)
...
)
}
// runSSHCommand executes the ssh or scp command, adding the flag provided --ssh-options
func
runSSHCommand
(
cmd
string
,
args
...
string
)
(
string
,
error
)
{
if
env
,
found
:=
sshOptionsMap
[
*
sshEnv
];
found
{
args
=
append
(
strings
.
Split
(
env
,
" "
),
args
...
)
}
if
*
sshOptions
!=
""
{
args
=
append
(
strings
.
Split
(
*
sshOptions
,
" "
),
args
...
)
}
output
,
err
:=
exec
.
Command
(
cmd
,
args
...
)
.
CombinedOutput
()
if
err
!=
nil
{
return
string
(
output
),
fmt
.
Errorf
(
"command [%s %s] failed with error: %v"
,
cmd
,
strings
.
Join
(
args
,
" "
),
err
)
}
return
string
(
output
),
nil
}
test/e2e_node/remote/ssh.go
0 → 100644
View file @
6f925722
/*
Copyright 2016 The Kubernetes Authors.
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
remote
import
(
"flag"
"fmt"
"os/exec"
"os/user"
"strings"
"sync"
"github.com/golang/glog"
)
var
sshOptions
=
flag
.
String
(
"ssh-options"
,
""
,
"Commandline options passed to ssh."
)
var
sshEnv
=
flag
.
String
(
"ssh-env"
,
""
,
"Use predefined ssh options for environment. Options: gce"
)
var
sshOptionsMap
map
[
string
]
string
func
init
()
{
usr
,
err
:=
user
.
Current
()
if
err
!=
nil
{
glog
.
Fatal
(
err
)
}
sshOptionsMap
=
map
[
string
]
string
{
"gce"
:
fmt
.
Sprintf
(
"-i %s/.ssh/google_compute_engine -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o CheckHostIP=no -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o LogLevel=ERROR"
,
usr
.
HomeDir
),
}
}
var
hostnameIpOverrides
=
struct
{
sync
.
RWMutex
m
map
[
string
]
string
}{
m
:
make
(
map
[
string
]
string
)}
func
AddHostnameIp
(
hostname
,
ip
string
)
{
hostnameIpOverrides
.
Lock
()
defer
hostnameIpOverrides
.
Unlock
()
hostnameIpOverrides
.
m
[
hostname
]
=
ip
}
func
GetHostnameOrIp
(
hostname
string
)
string
{
hostnameIpOverrides
.
RLock
()
defer
hostnameIpOverrides
.
RUnlock
()
if
ip
,
found
:=
hostnameIpOverrides
.
m
[
hostname
];
found
{
return
ip
}
return
hostname
}
// getSSHCommand handles proper quoting so that multiple commands are executed in the same shell over ssh
func
getSSHCommand
(
sep
string
,
args
...
string
)
string
{
return
fmt
.
Sprintf
(
"'%s'"
,
strings
.
Join
(
args
,
sep
))
}
// SSH executes ssh command with runSSHCommand as root. The `sudo` makes sure that all commands
// are executed by root, so that there won't be permission mismatch between different commands.
func
SSH
(
host
string
,
cmd
...
string
)
(
string
,
error
)
{
return
runSSHCommand
(
"ssh"
,
append
([]
string
{
GetHostnameOrIp
(
host
),
"--"
,
"sudo"
},
cmd
...
)
...
)
}
// SSHNoSudo executes ssh command with runSSHCommand as normal user. Sometimes we need this,
// for example creating a directory that we'll copy files there with scp.
func
SSHNoSudo
(
host
string
,
cmd
...
string
)
(
string
,
error
)
{
return
runSSHCommand
(
"ssh"
,
append
([]
string
{
GetHostnameOrIp
(
host
),
"--"
},
cmd
...
)
...
)
}
// runSSHCommand executes the ssh or scp command, adding the flag provided --ssh-options
func
runSSHCommand
(
cmd
string
,
args
...
string
)
(
string
,
error
)
{
if
env
,
found
:=
sshOptionsMap
[
*
sshEnv
];
found
{
args
=
append
(
strings
.
Split
(
env
,
" "
),
args
...
)
}
if
*
sshOptions
!=
""
{
args
=
append
(
strings
.
Split
(
*
sshOptions
,
" "
),
args
...
)
}
output
,
err
:=
exec
.
Command
(
cmd
,
args
...
)
.
CombinedOutput
()
if
err
!=
nil
{
return
string
(
output
),
fmt
.
Errorf
(
"command [%s %s] failed with error: %v"
,
cmd
,
strings
.
Join
(
args
,
" "
),
err
)
}
return
string
(
output
),
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment