mirror of
https://github.com/rancher/os.git
synced 2025-04-28 11:24:26 +00:00
Support OEM partition and oem-config.yml
This commit is contained in:
parent
cd2829d220
commit
1a95080522
@ -152,7 +152,7 @@ func (c *CloudConfig) Set(key string, value interface{}) (*CloudConfig, error) {
|
||||
}
|
||||
|
||||
func (c *CloudConfig) Save() error {
|
||||
files := append([]string{OsConfigFile}, CloudConfigDirFiles()...)
|
||||
files := append([]string{OsConfigFile, OemConfigFile}, CloudConfigDirFiles()...)
|
||||
files = util.FilterStrings(files, func(x string) bool { return x != CloudConfigPrivateFile })
|
||||
exCfg, err := ChainCfgFuncs(nil,
|
||||
func(_ *CloudConfig) (*CloudConfig, error) {
|
||||
|
@ -18,7 +18,7 @@ var osConfig *CloudConfig
|
||||
|
||||
func NewConfig() *CloudConfig {
|
||||
if osConfig == nil {
|
||||
osConfig, _ = ReadConfig(nil, true, OsConfigFile)
|
||||
osConfig, _ = ReadConfig(nil, true, OsConfigFile, OemConfigFile)
|
||||
}
|
||||
newCfg := *osConfig
|
||||
return &newCfg
|
||||
@ -200,7 +200,7 @@ func amendContainerNames(c *CloudConfig) (*CloudConfig, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func writeToFile(data interface{}, filename string) error {
|
||||
func WriteToFile(data interface{}, filename string) error {
|
||||
content, err := yaml.Marshal(data)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -218,12 +218,12 @@ func saveToDisk(data map[interface{}]interface{}) error {
|
||||
"rancher.docker.server_cert",
|
||||
})
|
||||
|
||||
err := writeToFile(config, CloudConfigFile)
|
||||
err := WriteToFile(config, CloudConfigFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return writeToFile(private, CloudConfigPrivateFile)
|
||||
return WriteToFile(private, CloudConfigPrivateFile)
|
||||
}
|
||||
|
||||
func readConfig(bytes []byte, substituteMetadataVars bool, files ...string) (map[interface{}]interface{}, error) {
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
OEM = "/usr/share/ros/oem"
|
||||
DOCKER_BIN = "/usr/bin/docker"
|
||||
DOCKER_DIST_BIN = "/usr/bin/docker.dist"
|
||||
ROS_BIN = "/usr/bin/ros"
|
||||
@ -40,6 +41,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
OemConfigFile = OEM + "/oem-config.yml"
|
||||
VERSION string
|
||||
)
|
||||
|
||||
@ -111,6 +113,8 @@ type StateConfig struct {
|
||||
Required bool `yaml:"required,omitempty"`
|
||||
Autoformat []string `yaml:"autoformat,omitempty"`
|
||||
FormatZero bool `yaml:"formatzero,omitempty"`
|
||||
OemFsType string `yaml:"oem_fstype,omitempty"`
|
||||
OemDev string `yaml:"oem_dev,omitempty"`
|
||||
}
|
||||
|
||||
type CloudInit struct {
|
||||
|
18
init/init.go
18
init/init.go
@ -111,6 +111,19 @@ func mountState(cfg *config.CloudConfig) error {
|
||||
return mountConfigured("state", cfg.Rancher.State.Dev, cfg.Rancher.State.FsType, STATE)
|
||||
}
|
||||
|
||||
func mountOem(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||
if cfg == nil {
|
||||
var err error
|
||||
if cfg, err = config.LoadConfig(); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
}
|
||||
if err := mountConfigured("oem", cfg.Rancher.State.OemDev, cfg.Rancher.State.OemFsType, config.OEM); err != nil {
|
||||
log.Infof("Not mounting OEM: %v", err)
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func tryMountState(cfg *config.CloudConfig) error {
|
||||
if mountState(cfg) == nil {
|
||||
return nil
|
||||
@ -132,8 +145,10 @@ func tryMountAndBootstrap(cfg *config.CloudConfig) (*config.CloudConfig, error)
|
||||
}
|
||||
|
||||
log.Debugf("Switching to new root at %s %s", STATE, cfg.Rancher.State.Directory)
|
||||
err := switchRoot(STATE, cfg.Rancher.State.Directory, cfg.Rancher.RmUsr)
|
||||
if err := switchRoot(STATE, cfg.Rancher.State.Directory, cfg.Rancher.RmUsr); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
return mountOem(cfg)
|
||||
}
|
||||
|
||||
func getLaunchConfig(cfg *config.CloudConfig, dockerCfg *config.DockerConfig) (*dockerlaunch.Config, []string) {
|
||||
@ -162,6 +177,7 @@ func RunInit() error {
|
||||
func(c *config.CloudConfig) (*config.CloudConfig, error) {
|
||||
return c, dockerlaunch.PrepareFs(&mountConfig)
|
||||
},
|
||||
mountOem,
|
||||
func(_ *config.CloudConfig) (*config.CloudConfig, error) {
|
||||
cfg, err := config.LoadConfig()
|
||||
if err != nil {
|
||||
|
@ -100,6 +100,10 @@ func copyMoveRoot(rootfs string, rmUsr bool) error {
|
||||
}
|
||||
|
||||
func switchRoot(rootfs, subdir string, rmUsr bool) error {
|
||||
if err := syscall.Unmount(config.OEM, 0); err != nil {
|
||||
log.Debugf("Not umounting OEM: %v", err)
|
||||
}
|
||||
|
||||
if subdir != "" {
|
||||
fullRootfs := path.Join(rootfs, subdir)
|
||||
if _, err := os.Stat(fullRootfs); os.IsNotExist(err) {
|
||||
|
@ -58,6 +58,8 @@ rancher:
|
||||
state:
|
||||
fstype: auto
|
||||
dev: LABEL=RANCHER_STATE
|
||||
oem_fstype: auto
|
||||
oem_dev: LABEL=RANCHER_OEM
|
||||
services:
|
||||
acpid:
|
||||
image: rancher/os-acpid:v0.4.3-dev
|
||||
@ -251,7 +253,7 @@ rancher:
|
||||
- /lib/firmware:/lib/firmware
|
||||
- /lib/modules:/lib/modules
|
||||
- /run:/run
|
||||
- /usr/share/ros/os-config.yml:/usr/share/ros/os-config.yml
|
||||
- /usr/share/ros:/usr/share/ros
|
||||
- /var/lib/rancher/conf:/var/lib/rancher/conf
|
||||
- /var/lib/rancher:/var/lib/rancher
|
||||
- /var/log:/var/log
|
||||
|
44
tests/integration/rostest/test_07_oem.py
Normal file
44
tests/integration/rostest/test_07_oem.py
Normal file
@ -0,0 +1,44 @@
|
||||
import time
|
||||
import pytest
|
||||
import rostest.util as u
|
||||
from rostest.util import SSH
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def qemu(request):
|
||||
q = u.run_qemu(request, run_args=['--append', 'rancher.state.dev=x'])
|
||||
u.flush_out(q.stdout)
|
||||
return q
|
||||
|
||||
|
||||
def test_oem(qemu):
|
||||
SSH(qemu).check_call('sudo', 'bash', '-c', '''
|
||||
set -x
|
||||
set -e
|
||||
sudo mkfs.ext4 -L RANCHER_OEM /dev/vda
|
||||
sudo mount /dev/vda /mnt
|
||||
cat > /tmp/oem-config.yml << "EOF"
|
||||
#cloud-config
|
||||
rancher:
|
||||
upgrade:
|
||||
url: 'foo'
|
||||
EOF
|
||||
sudo cp /tmp/oem-config.yml /mnt
|
||||
sudo umount /mnt
|
||||
sudo reboot >/dev/null 2>&1 &'''.strip())
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
SSH(qemu).check_call('bash', '-c', '''
|
||||
set -x
|
||||
if [ ! -e /usr/share/ros/oem/oem-config.yml ]; then
|
||||
echo Failed to find /usr/share/ros/oem/oem-config.yml
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FOO="$(sudo ros config get rancher.upgrade.url)"
|
||||
if [ "$FOO" != "foo" ]; then
|
||||
echo rancher.upgrade.url is not foo
|
||||
exit 1
|
||||
fi
|
||||
'''.strip())
|
Loading…
Reference in New Issue
Block a user