Skip to content

Commit ba21474

Browse files
committed
Merge branch 'master' into console_auth
2 parents 67629e3 + 45dec1e commit ba21474

File tree

8 files changed

+108
-30
lines changed

8 files changed

+108
-30
lines changed

.idea/libraries/GOPATH__openvdc_.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ Environment Variables:
186186
// Build main binaries
187187
cmd("go", "build", "-i", "./vendor/...")
188188
cmd("go", "build", "-ldflags", LDFLAGS, "-v", "./cmd/openvdc")
189-
cmd("go", "build", "-ldflags", LDFLAGS+"-X 'main.DefaultConfPath=/etc/openvdc/executor.toml'", "-v", "./cmd/openvdc-executor")
189+
cmd("go", "build", "-ldflags", LDFLAGS+
190+
" -X 'main.HostRsaKeyPath=/etc/openvdc/ssh/host_rsa_key'" +
191+
" -X 'main.HostEcdsaKeyPath=/etc/openvdc/ssh/host_ecdsa_key'" +
192+
" -X 'main.HostEd25519KeyPath=/etc/openvdc/ssh/host_ed25519_key'" +
193+
" -X 'main.DefaultConfPath=/etc/openvdc/executor.toml'", "-v", "./cmd/openvdc-executor")
190194
cmd("go", "build", "-ldflags", LDFLAGS+"-X 'main.DefaultConfPath=/etc/openvdc/scheduler.toml'", "-v", "./cmd/openvdc-scheduler")
191195

192196
//Build lxc-template
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"title": "CentOS7",
3+
"template": {
4+
"type": "vm/lxc",
5+
"lxc_template": {
6+
"openvdc": {
7+
"distro": "centos",
8+
"release": "7"
9+
}
10+
}
11+
}
12+
}
13+

ci/citest/acceptance-test/tests/local_image_test.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,54 @@
33
package tests
44

55
import (
6+
"fmt"
7+
"path/filepath"
68
"strings"
79
"testing"
810
"time"
911
)
1012

13+
func init() {
14+
if err := RestoreAssets("/var/tmp", "fixtures"); err != nil {
15+
panic(err)
16+
}
17+
}
18+
1119
func TestLocalImage(t *testing.T) {
1220

21+
stdout, _, err := RunSsh(scheduler_ip, fmt.Sprintf("[ -f /var/www/html/images/centos/7/amd64/meta.tar.xz ] && echo meta.tar.xz found || echo meta.tar.xz not found"))
22+
23+
if err != nil {
24+
t.Error(err)
25+
}
26+
27+
t.Log(stdout.String())
28+
1329
// Use custom lxc-template.
14-
stdout, _ := RunCmdAndReportFail(t, "openvdc", "run", "centos/7/lxc", `{"lxc_template":{"template":"openvdc"}, "node_groups":["linuxbr"]}`)
30+
stdout, _ = RunCmdAndReportFail(t, "openvdc", "run", "/var/tmp/fixtures/lxc2.json", `{"node_groups":["linuxbr"]}`)
1531
instance_id := strings.TrimSpace(stdout.String())
1632

17-
_, _ = RunCmdAndReportFail(t, "openvdc", "show", instance_id)
1833
WaitInstance(t, 10*time.Minute, instance_id, "RUNNING", []string{"QUEUED", "STARTING"})
19-
RunSshWithTimeoutAndReportFail(t, executor_lxc_ip, "sudo lxc-info -n "+instance_id, 10, 5)
34+
35+
configFile := filepath.Join("/var/lib/lxc/", instance_id, "config")
36+
stdout, _, err = RunSsh(executor_lxc_ip, fmt.Sprintf("echo | sudo head -n 1 %s", configFile))
37+
38+
if err != nil {
39+
t.Error(err)
40+
}
41+
if stdout.Len() == 0 {
42+
t.Errorf("Couldn't read %s", configFile)
43+
}
44+
45+
if testing.Verbose() {
46+
t.Log(stdout.String())
47+
}
48+
49+
s := strings.Split(strings.TrimSpace(stdout.String()), "/")
50+
templateUsed := s[len(s)-1]
51+
if templateUsed != "lxc-openvdc" {
52+
t.Errorf("Expected templateUsed to be 'lxc-openvdc', got: %s", templateUsed)
53+
}
2054

2155
_, _ = RunCmdAndReportFail(t, "openvdc", "stop", instance_id)
2256

cmd/lxc-openvdc/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ func PrepareCache() error {
127127

128128
func GenerateConfig() error {
129129
if lxcPath == "" {
130-
return errors.New("lxcPath not set.")
131-
}
130+
return errors.New("lxcPath not set.")
131+
}
132132

133133
lxcCfgPath := filepath.Join(lxcPath, "config")
134134
cfgPath := filepath.Join(containerPath, "config")
@@ -179,7 +179,7 @@ func GetFile(fileName string) error {
179179
}
180180

181181
if res.StatusCode != 200 {
182-
return errors.New(fmt.Sprintf("Http status code: %s", res.StatusCode))
182+
return errors.Errorf("Url: %s Http status code: %s", downloadUrl, res.StatusCode)
183183
}
184184

185185
defer res.Body.Close()

cmd/openvdc-executor/sshd.go

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@ package main
22

33
import (
44
"crypto"
5-
"crypto/ecdsa"
6-
"crypto/elliptic"
7-
"crypto/rand"
8-
"crypto/rsa"
95
"fmt"
106
"io"
117
"net"
12-
138
log "github.com/Sirupsen/logrus"
149
"github.com/axsh/openvdc/hypervisor"
1510
"github.com/axsh/openvdc/model"
1611
"github.com/pkg/errors"
17-
"golang.org/x/crypto/ed25519"
1812
"golang.org/x/crypto/ssh"
13+
"io/ioutil"
1914
"golang.org/x/net/context"
2015
)
2116

@@ -40,31 +35,29 @@ func NewSSHServer(provider hypervisor.HypervisorProvider, ctx context.Context) *
4035

4136
type HostKeyGen func(rand io.Reader) (crypto.Signer, error)
4237

43-
var KeyGenList = []HostKeyGen{
44-
func(rand io.Reader) (crypto.Signer, error) {
45-
_, priv, err := ed25519.GenerateKey(rand)
46-
return priv, err
47-
},
48-
func(rand io.Reader) (crypto.Signer, error) {
49-
return ecdsa.GenerateKey(elliptic.P521(), rand)
50-
},
51-
func(rand io.Reader) (crypto.Signer, error) {
52-
return rsa.GenerateKey(rand, 2048)
53-
},
54-
}
38+
var HostRsaKeyPath string
39+
var HostEcdsaKeyPath string
40+
var HostEd25519KeyPath string
5541

42+
var KeyGenPathList = []string{
43+
HostRsaKeyPath,
44+
HostEcdsaKeyPath,
45+
HostEd25519KeyPath,
46+
}
5647
func (sshd *SSHServer) Setup() error {
5748
if model.GetBackendCtx(sshd.ctx) == nil {
5849
return errors.New("Context does not have model connection")
5950
}
60-
for _, gen := range KeyGenList {
61-
priv, err := gen(rand.Reader)
51+
for _, path := range KeyGenPathList {
52+
// Reading key file
53+
buf, err := ioutil.ReadFile(path)
6254
if err != nil {
63-
return errors.Wrap(err, "Failed to generate host key")
55+
return errors.Wrap(err, path + " doesn't exist")
6456
}
65-
sshSigner, err := ssh.NewSignerFromSigner(priv)
57+
// Check integrity of pem file
58+
sshSigner, err := ssh.ParsePrivateKey(buf)
6659
if err != nil {
67-
return errors.Wrap(err, "Failed to convert to ssh.Signer")
60+
return errors.Wrap(err, path + " is not a valid pem file")
6861
}
6962
sshd.config.AddHostKey(sshSigner)
7063
}

pkg/rhel/openvdc.spec

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ mkdir -p "$RPM_BUILD_ROOT"/opt/axsh/openvdc/bin
5050
mkdir -p "$RPM_BUILD_ROOT"%{_unitdir}
5151
mkdir -p "$RPM_BUILD_ROOT"/etc/openvdc
5252
mkdir -p "$RPM_BUILD_ROOT"/etc/openvdc/scripts
53+
mkdir -p "$RPM_BUILD_ROOT"/etc/openvdc/ssh
5354
mkdir -p "$RPM_BUILD_ROOT"/usr/bin
5455
ln -sf /opt/axsh/openvdc/bin/openvdc "$RPM_BUILD_ROOT"/usr/bin
5556
cp openvdc "$RPM_BUILD_ROOT"/opt/axsh/openvdc/bin
@@ -93,6 +94,12 @@ OpenVDC executor common package.
9394
/opt/axsh/openvdc/share/mesos-slave/attributes.lxc
9495
/opt/axsh/openvdc/share/lxc-templates/lxc-openvdc
9596
%dir /etc/openvdc
97+
%dir /etc/openvdc/ssh
98+
99+
%post executor
100+
test ! -f /etc/openvdc/ssh/host_rsa_key && /usr/bin/ssh-keygen -q -t rsa -f /etc/openvdc/ssh/host_rsa_key -b 4096 -C '' -N '' >&/dev/null;
101+
test ! -f /etc/openvdc/ssh/host_ecdsa_key && /usr/bin/ssh-keygen -q -t ecdsa -f /etc/openvdc/ssh/host_ecdsa_key -C '' -N '' >&/dev/null;
102+
test ! -f /etc/openvdc/ssh/host_ed25519_key && /usr/bin/ssh-keygen -q -t ed25519 -f /etc/openvdc/ssh/host_ed25519_key -C '' -N '' >&/dev/null;
96103

97104
%package executor-null
98105
Summary: OpenVDC executor (null driver)

templates/centos/7/lxc2.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"title": "CentOS7",
3+
"template": {
4+
"type": "vm/lxc",
5+
"lxc_template": {
6+
"openvdc": {
7+
"distro": "centos",
8+
"release": "7"
9+
}
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)