1
0
mirror of https://github.com/rancher/os.git synced 2025-08-16 22:08:26 +00:00

My first pass at fixing the b2d autoformat

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit 2017-01-20 17:02:48 +10:00
parent 1c5d41a56e
commit a4e77692c4
6 changed files with 33 additions and 5 deletions

View File

@ -15,12 +15,15 @@ import (
)
func bootstrapAction(c *cli.Context) error {
log.Debugf("bootstrapAction")
if err := UdevSettle(); err != nil {
log.Errorf("Failed to run udev settle: %v", err)
}
log.Debugf("bootstrapAction: loadingConfig")
cfg := config.LoadConfig()
log.Debugf("bootstrapAction: MdadmScan(%v)", cfg.Rancher.State.MdadmScan)
if cfg.Rancher.State.MdadmScan {
if err := mdadmScan(); err != nil {
log.Errorf("Failed to run mdadm scan: %v", err)
@ -28,12 +31,14 @@ func bootstrapAction(c *cli.Context) error {
}
stateScript := cfg.Rancher.State.Script
log.Debugf("bootstrapAction: stateScript(%v)", stateScript)
if stateScript != "" {
if err := runStateScript(stateScript); err != nil {
log.Errorf("Failed to run state script: %v", err)
}
}
log.Debugf("bootstrapAction: RunCommandSequence(%v)", cfg.Bootcmd)
util.RunCommandSequence(cfg.Bootcmd)
if cfg.Rancher.State.Dev != "" && cfg.Rancher.State.Wait {
@ -41,12 +46,14 @@ func bootstrapAction(c *cli.Context) error {
}
autoformatDevices := cfg.Rancher.State.Autoformat
log.Debugf("bootstrapAction: Autoformat(%v)", cfg.Rancher.State.Autoformat)
if len(autoformatDevices) > 0 {
if err := autoformat(autoformatDevices); err != nil {
log.Errorf("Failed to run autoformat: %v", err)
}
}
log.Debugf("bootstrapAction: udev settle2")
if err := UdevSettle(); err != nil {
log.Errorf("Failed to run udev settle: %v", err)
}

View File

@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"path"
"path/filepath"
"sort"
"strings"
@ -171,7 +172,7 @@ func readCmdline() map[interface{}]interface{} {
return nil
}
log.Debugf("Config cmdline %s", cmdLine)
//log.Debugf("Config cmdline %s", cmdLine)
cmdLineObj := parseCmdline(strings.TrimSpace(util.UnescapeKernelParams(string(cmdLine))))
@ -219,6 +220,10 @@ func WriteToFile(data interface{}, filename string) error {
return err
}
if err := os.MkdirAll(filepath.Dir(filename), os.ModeDir|0755); err != nil {
return err
}
return util.WriteFileAtomic(filename, content, 400)
}

View File

@ -12,6 +12,8 @@ import (
func bootstrapServices(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if util.ResolveDevice(cfg.Rancher.State.Dev) != "" && len(cfg.Bootcmd) == 0 {
log.Info("NOT Running Bootstrap")
return cfg, nil
}
log.Info("Running Bootstrap")
@ -56,6 +58,8 @@ func stopDocker(c chan interface{}) error {
func bootstrap(cfg *config.CloudConfig) error {
log.Info("Launching Bootstrap Docker")
log.Infof("bootstrap container: Autoformat(%v)", cfg.Rancher.State.Autoformat)
c, err := startDocker(cfg)
if err != nil {
return err

View File

@ -267,7 +267,17 @@ func RunInit() error {
}
}
return cfg, nil
// save here so the bootstrap service can see it (when booting from iso, its very early)
if boot2DockerEnvironment {
if err := config.Set("rancher.state.dev", cfg.Rancher.State.Dev); err != nil {
log.Errorf("Failed to update rancher.state.dev: %v", err)
}
if err := config.Set("rancher.state.autoformat", cfg.Rancher.State.Autoformat); err != nil {
log.Errorf("Failed to update rancher.state.autoformat: %v", err)
}
}
return config.LoadConfig(), nil
},
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
var err error
@ -278,9 +288,6 @@ func RunInit() error {
return cfg, nil
},
func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if err := os.MkdirAll(config.CloudConfigDir, os.ModeDir|0755); err != nil {
log.Error(err)
}
cfg.Rancher.CloudInit.Datasources = config.LoadConfigWithPrefix(state).Rancher.CloudInit.Datasources
if err := config.Set("rancher.cloud_init.datasources", cfg.Rancher.CloudInit.Datasources); err != nil {

View File

@ -32,6 +32,7 @@ rancher:
- /lib/firmware:/lib/firmware
- /usr/bin/ros:/usr/bin/ros:ro
- /usr/share/ros:/usr/share/ros:ro
- /var/lib/rancher:/var/lib/rancher:ro
cloud_init_services:
cloud-init:
image: {{.OS_REPO}}/os-base:{{.VERSION}}{{.SUFFIX}}

View File

@ -2,6 +2,8 @@ package integration
import . "gopkg.in/check.v1"
// NOTE: the boot2docker magic string/tar file is also used by Docker-machine
func (s *QemuSuite) TestBoot2DockerState(c *C) {
s.RunQemu(c, "--fresh", "--b2d")
s.CheckCall(c, "blkid | grep B2D_STATE")
@ -12,6 +14,8 @@ func (s *QemuSuite) TestBoot2DockerState(c *C) {
func (s *QemuSuite) TestIsoBoot2DockerState(c *C) {
s.RunQemu(c, "--fresh", "--b2d", "--iso")
s.CheckCall(c, "blkid | grep B2D_STATE")
s.CheckCall(c, "sudo ros config get rancher.state.dev | grep LABEL=B2D_STATE")
s.CheckCall(c, "sudo ros config get rancher.state.autoformat | grep vda")
// And once I make run create a tar file, check that its untarred in the docker user's home dir
// And confirm if it should add to the dir, or replace, i can't remember
}