mirror of
https://github.com/rancher/os.git
synced 2025-09-17 23:48:09 +00:00
Use the mount command to apply cloud-config mounts
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/coreos/coreos-cloudinit/system"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
rancherConfig "github.com/rancher/os/config"
|
||||
"github.com/rancher/os/docker"
|
||||
"github.com/rancher/os/util"
|
||||
@@ -63,12 +62,13 @@ func ApplyConsole(cfg *rancherConfig.CloudConfig) {
|
||||
|
||||
WriteFiles(cfg, "console")
|
||||
|
||||
for _, configMount := range cfg.Mounts {
|
||||
if len(configMount) != 4 {
|
||||
log.Errorf("Unable to mount %s: must specify exactly four arguments", configMount[1])
|
||||
for _, mount := range cfg.Mounts {
|
||||
if len(mount) != 4 {
|
||||
log.Errorf("Unable to mount %s: must specify exactly four arguments", mount[1])
|
||||
}
|
||||
device := util.ResolveDevice(configMount[0])
|
||||
if configMount[2] == "swap" {
|
||||
device := util.ResolveDevice(mount[0])
|
||||
|
||||
if mount[2] == "swap" {
|
||||
cmd := exec.Command("swapon", device)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
@@ -76,8 +76,17 @@ func ApplyConsole(cfg *rancherConfig.CloudConfig) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := mount.Mount(device, configMount[1], configMount[2], configMount[3]); err != nil {
|
||||
log.Errorf("Unable to mount %s: %v", configMount[1], err)
|
||||
|
||||
cmdArgs := []string{device, mount[1]}
|
||||
if mount[2] != "" {
|
||||
cmdArgs = append(cmdArgs, "-t", mount[2])
|
||||
}
|
||||
if mount[3] != "" {
|
||||
cmdArgs = append(cmdArgs, "-o", mount[3])
|
||||
}
|
||||
cmd := exec.Command("mount", cmdArgs...)
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Errorf("Failed to mount %s: %v", mount[1], err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +0,0 @@
|
||||
#cloud-config
|
||||
write_files:
|
||||
- path: /test
|
||||
content: test
|
||||
- path: /home/rancher/test
|
||||
mounts:
|
||||
- ["/test", "/home/rancher/test", "", "bind"]
|
||||
ssh_authorized_keys:
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF
|
@@ -1,29 +1,12 @@
|
||||
#cloud-config
|
||||
write_files:
|
||||
- path: "/test"
|
||||
permissions: "0644"
|
||||
owner: "root"
|
||||
content: |
|
||||
console content
|
||||
- path: "/test2"
|
||||
container: console
|
||||
permissions: "0644"
|
||||
owner: "root"
|
||||
content: |
|
||||
console content
|
||||
- path: "/test"
|
||||
container: ntp
|
||||
permissions: "0644"
|
||||
owner: "root"
|
||||
content: |
|
||||
ntp content
|
||||
- path: "/test"
|
||||
container: syslog
|
||||
permissions: "0644"
|
||||
owner: "root"
|
||||
content: |
|
||||
syslog content
|
||||
rancher:
|
||||
restart_services: [syslog]
|
||||
- path: /test
|
||||
content: test
|
||||
- path: /home/rancher/test
|
||||
mounts:
|
||||
- ["/test", "/home/rancher/test", "", "bind"]
|
||||
- [/dev/vdb, /home/rancher/a, ext4, ""]
|
||||
- [/dev/vdb, /home/rancher/b, "", ""]
|
||||
- [/dev/vdb, /home/rancher/c, auto, defaults]
|
||||
ssh_authorized_keys:
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF
|
||||
|
30
tests/assets/test_24/cloud-config.yml
Normal file
30
tests/assets/test_24/cloud-config.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
#cloud-config
|
||||
write_files:
|
||||
- path: "/test"
|
||||
permissions: "0644"
|
||||
owner: "root"
|
||||
content: |
|
||||
console content
|
||||
- path: "/test2"
|
||||
container: console
|
||||
permissions: "0644"
|
||||
owner: "root"
|
||||
content: |
|
||||
console content
|
||||
- path: "/test"
|
||||
container: ntp
|
||||
permissions: "0644"
|
||||
owner: "root"
|
||||
content: |
|
||||
ntp content
|
||||
- path: "/test"
|
||||
container: syslog
|
||||
permissions: "0644"
|
||||
owner: "root"
|
||||
content: |
|
||||
syslog content
|
||||
rancher:
|
||||
restart_services: [syslog]
|
||||
ssh_authorized_keys:
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF
|
||||
|
@@ -1,10 +0,0 @@
|
||||
package integration
|
||||
|
||||
import . "gopkg.in/check.v1"
|
||||
|
||||
func (s *QemuSuite) TestCloudConfigMounts(c *C) {
|
||||
err := s.RunQemu("--cloud-config", "./tests/assets/test_16/cloud-config.yml")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
s.CheckCall(c, "cat /home/rancher/test | grep test")
|
||||
}
|
17
tests/mounts_test.go
Normal file
17
tests/mounts_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package integration
|
||||
|
||||
import . "gopkg.in/check.v1"
|
||||
|
||||
func (s *QemuSuite) TestMounts(c *C) {
|
||||
err := s.RunQemu("--cloud-config", "./tests/assets/test_23/cloud-config.yml", "--second-drive")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
s.CheckCall(c, "cat /home/rancher/test | grep test")
|
||||
|
||||
s.CheckCall(c, "mkdir -p /home/rancher/a /home/rancher/b /home/rancher/c")
|
||||
s.CheckCall(c, "sudo mkfs.ext4 /dev/vdb")
|
||||
s.CheckCall(c, "sudo cloud-init-execute")
|
||||
s.CheckCall(c, "mount | grep /home/rancher/a")
|
||||
s.CheckCall(c, "mount | grep /home/rancher/b")
|
||||
s.CheckCall(c, "mount | grep /home/rancher/c")
|
||||
}
|
@@ -3,7 +3,7 @@ package integration
|
||||
import . "gopkg.in/check.v1"
|
||||
|
||||
func (s *QemuSuite) TestWriteFiles(c *C) {
|
||||
err := s.RunQemu("--cloud-config", "./tests/assets/test_23/cloud-config.yml")
|
||||
err := s.RunQemu("--cloud-config", "./tests/assets/test_24/cloud-config.yml")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
s.CheckCall(c, "sudo cat /test | grep 'console content'")
|
||||
|
Reference in New Issue
Block a user