Skip to content

Commit 45dec1e

Browse files
author
Masahiro Fujiwara
authored
Merge pull request #180 from axsh/template-misc
Template misc
2 parents dae64a7 + 9a1e2af commit 45dec1e

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed
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()

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)