func TestHash2(t *testing.T) { assert := require.New(t) cfg := &config.ContainerConfig{ Id: "docker-volumes", Cmd: "", MigrateVolumes: false, ReloadConfig: false, CreateOnly: true, Service: &project.ServiceConfig{ CapAdd: nil, CapDrop: nil, CpuShares: 0, Command: project.NewCommand(), Detach: "", Dns: project.NewStringorslice(), DnsSearch: project.NewStringorslice(), DomainName: "", Entrypoint: project.NewCommand(), EnvFile: project.NewStringorslice(), Environment: project.NewMaporEqualSlice([]string{}), Hostname: "", Image: "state", Labels: project.NewSliceorMap(map[string]string{ "io.rancher.os.createonly": "true", "io.rancher.os.scope": "system"}), Links: project.NewMaporColonSlice(nil), LogDriver: "json-file", MemLimit: 0, Name: "", Net: "none", Pid: "", Ipc: "", Ports: nil, Privileged: true, Restart: "", ReadOnly: true, StdinOpen: false, Tty: false, User: "", Volumes: []string{ "/var/lib/docker:/var/lib/docker", "/var/lib/rancher/conf:/var/lib/rancher/conf", "/var/lib/system-docker:/var/lib/system-docker"}, VolumesFrom: nil, WorkingDir: "", Expose: nil, ExternalLinks: nil}, } for i := 0; i < 1000; i++ { assert.Equal(getHash(cfg), getHash(cfg), fmt.Sprintf("Failed at iteration: %v", i)) } }
func autoformat(cfg *config.Config) error { if len(cfg.State.Autoformat) == 0 || util.ResolveDevice(cfg.State.Dev) != "" { return nil } AUTOFORMAT := "AUTOFORMAT=" + strings.Join(cfg.State.Autoformat, " ") FORMATZERO := "FORMATZERO=" + fmt.Sprint(cfg.State.FormatZero) cfg.Autoformat["autoformat"].Environment = project.NewMaporEqualSlice([]string{AUTOFORMAT, FORMATZERO}) log.Info("Running Autoformat services") err := docker.RunServices("autoformat", cfg, cfg.Autoformat) return err }
func autoformat(cfg *config.Config) error { if len(cfg.State.Autoformat) == 0 || util.ResolveDevice(cfg.State.Dev) != "" { return nil } var format string outer: for _, dev := range cfg.State.Autoformat { log.Infof("Checking %s to auto-format", dev) if _, err := os.Stat(dev); os.IsNotExist(err) { continue } f, err := os.Open(dev) if err != nil { return err } defer f.Close() buffer := make([]byte, 1048576, 1048576) c, err := f.Read(buffer) if err != nil { return err } if c != 1048576 { log.Infof("%s not right size", dev) continue } boot2docker := false if strings.HasPrefix(string(buffer[:len(boot2dockerMagic)]), boot2dockerMagic) { boot2docker = true } if boot2docker == false { for _, b := range buffer { if b != 0 { log.Infof("%s not empty", dev) continue outer } } } format = dev break } if format != "" { log.Infof("Auto formatting : %s", format) // copy udev := *cfg.BootstrapContainers["udev"] udev.Links = project.NewMaporColonSlice(append(udev.Links.Slice(), "autoformat")) udev.LogDriver = "json-file" err := docker.RunServices("autoformat", cfg, map[string]*project.ServiceConfig{ "autoformat": { Net: "none", Privileged: true, Image: "rancher/os-autoformat:" + config.VERSION, Command: project.NewCommand(format), Labels: project.NewSliceorMap(map[string]string{ config.DETACH: "false", config.SCOPE: config.SYSTEM, }), LogDriver: "json-file", Environment: project.NewMaporEqualSlice([]string{ "MAGIC=" + boot2dockerMagic, }), }, "udev": &udev, }) return err } return nil }