Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 5 | "os" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 6 | "os/exec" |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 7 | "strings" |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 8 | "text/template" |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 9 | |
| 10 | "github.com/edwarnicke/exechelper" |
| 11 | ) |
| 12 | |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 13 | const ( |
| 14 | logDir string = "/tmp/hs-test/" |
| 15 | ) |
| 16 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 17 | var ( |
| 18 | workDir, _ = os.Getwd() |
| 19 | ) |
| 20 | |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 21 | type Volume struct { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 22 | hostDir string |
| 23 | containerDir string |
| 24 | isDefaultWorkDir bool |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | type Container struct { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 28 | suite *HstSuite |
Filip Tehlar | 3f95143 | 2023-01-13 21:33:43 +0100 | [diff] [blame] | 29 | isOptional bool |
| 30 | name string |
| 31 | image string |
Filip Tehlar | 3f95143 | 2023-01-13 21:33:43 +0100 | [diff] [blame] | 32 | extraRunningArgs string |
| 33 | volumes map[string]Volume |
| 34 | envVars map[string]string |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 35 | vppInstance *VppInstance |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 38 | func newContainer(yamlInput ContainerConfig) (*Container, error) { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 39 | containerName := yamlInput["name"].(string) |
| 40 | if len(containerName) == 0 { |
| 41 | err := fmt.Errorf("container name must not be blank") |
| 42 | return nil, err |
| 43 | } |
| 44 | |
| 45 | var container = new(Container) |
| 46 | container.volumes = make(map[string]Volume) |
| 47 | container.envVars = make(map[string]string) |
| 48 | container.name = containerName |
| 49 | |
| 50 | if image, ok := yamlInput["image"]; ok { |
| 51 | container.image = image.(string) |
| 52 | } else { |
| 53 | container.image = "hs-test/vpp" |
| 54 | } |
| 55 | |
Filip Tehlar | 3f95143 | 2023-01-13 21:33:43 +0100 | [diff] [blame] | 56 | if args, ok := yamlInput["extra-args"]; ok { |
| 57 | container.extraRunningArgs = args.(string) |
| 58 | } else { |
| 59 | container.extraRunningArgs = "" |
| 60 | } |
| 61 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 62 | if isOptional, ok := yamlInput["is-optional"]; ok { |
| 63 | container.isOptional = isOptional.(bool) |
| 64 | } else { |
| 65 | container.isOptional = false |
| 66 | } |
| 67 | |
| 68 | if _, ok := yamlInput["volumes"]; ok { |
Filip Tehlar | f3ee2b6 | 2023-01-09 12:07:09 +0100 | [diff] [blame] | 69 | r := strings.NewReplacer("$HST_DIR", workDir) |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 70 | for _, volu := range yamlInput["volumes"].([]interface{}) { |
| 71 | volumeMap := volu.(ContainerConfig) |
| 72 | hostDir := r.Replace(volumeMap["host-dir"].(string)) |
| 73 | containerDir := volumeMap["container-dir"].(string) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 74 | isDefaultWorkDir := false |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 75 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 76 | if isDefault, ok := volumeMap["is-default-work-dir"]; ok { |
| 77 | isDefaultWorkDir = isDefault.(bool) |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 80 | container.addVolume(hostDir, containerDir, isDefaultWorkDir) |
| 81 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
| 85 | if _, ok := yamlInput["vars"]; ok { |
| 86 | for _, envVar := range yamlInput["vars"].([]interface{}) { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 87 | envVarMap := envVar.(ContainerConfig) |
| 88 | name := envVarMap["name"].(string) |
| 89 | value := envVarMap["value"].(string) |
| 90 | container.addEnvVar(name, value) |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | return container, nil |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 96 | func (c *Container) getWorkDirVolume() (res Volume, exists bool) { |
| 97 | for _, v := range c.volumes { |
| 98 | if v.isDefaultWorkDir { |
| 99 | res = v |
| 100 | exists = true |
| 101 | return |
| 102 | } |
| 103 | } |
| 104 | return |
| 105 | } |
| 106 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 107 | func (c *Container) getHostWorkDir() (res string) { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 108 | if v, ok := c.getWorkDirVolume(); ok { |
| 109 | res = v.hostDir |
| 110 | } |
| 111 | return |
| 112 | } |
| 113 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 114 | func (c *Container) getContainerWorkDir() (res string) { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 115 | if v, ok := c.getWorkDirVolume(); ok { |
| 116 | res = v.containerDir |
| 117 | } |
| 118 | return |
| 119 | } |
| 120 | |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 121 | func (c *Container) getContainerArguments() string { |
| 122 | args := "--cap-add=all --privileged --network host --rm" |
| 123 | args += c.getVolumesAsCliOption() |
| 124 | args += c.getEnvVarsAsCliOption() |
| 125 | args += " --name " + c.name + " " + c.image |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 126 | args += " " + c.extraRunningArgs |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 127 | return args |
| 128 | } |
| 129 | |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 130 | func (c *Container) create() error { |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 131 | cmd := "docker create " + c.getContainerArguments() |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 132 | c.suite.log(cmd) |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 133 | return exechelper.Run(cmd) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 136 | func (c *Container) start() error { |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 137 | cmd := "docker start " + c.name |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 138 | c.suite.log(cmd) |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 139 | return exechelper.Run(cmd) |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | func (c *Container) run() error { |
| 143 | if c.name == "" { |
| 144 | return fmt.Errorf("run container failed: name is blank") |
| 145 | } |
| 146 | |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame] | 147 | cmd := "docker run -d " + c.getContainerArguments() |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 148 | c.suite.log(cmd) |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 149 | err := exechelper.Run(cmd) |
| 150 | if err != nil { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 151 | return fmt.Errorf("container run failed: %s", err) |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | return nil |
| 155 | } |
| 156 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 157 | func (c *Container) addVolume(hostDir string, containerDir string, isDefaultWorkDir bool) { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 158 | var volume Volume |
| 159 | volume.hostDir = hostDir |
| 160 | volume.containerDir = containerDir |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 161 | volume.isDefaultWorkDir = isDefaultWorkDir |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 162 | c.volumes[hostDir] = volume |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 165 | func (c *Container) getVolumesAsCliOption() string { |
| 166 | cliOption := "" |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 167 | |
| 168 | if len(c.volumes) > 0 { |
| 169 | for _, volume := range c.volumes { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 170 | cliOption += fmt.Sprintf(" -v %s:%s", volume.hostDir, volume.containerDir) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 174 | return cliOption |
| 175 | } |
| 176 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 177 | func (c *Container) addEnvVar(name string, value string) { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 178 | c.envVars[name] = value |
| 179 | } |
| 180 | |
| 181 | func (c *Container) getEnvVarsAsCliOption() string { |
| 182 | cliOption := "" |
| 183 | if len(c.envVars) == 0 { |
| 184 | return cliOption |
| 185 | } |
| 186 | |
| 187 | for name, value := range c.envVars { |
| 188 | cliOption += fmt.Sprintf(" -e %s=%s", name, value) |
| 189 | } |
| 190 | return cliOption |
| 191 | } |
| 192 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 193 | func (c *Container) newVppInstance(additionalConfig ...Stanza) (*VppInstance, error) { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 194 | vpp := new(VppInstance) |
| 195 | vpp.container = c |
Maros Ondrejicka | 7d7ab10 | 2023-02-14 12:56:49 +0100 | [diff] [blame] | 196 | |
| 197 | if len(additionalConfig) > 0 { |
| 198 | vpp.additionalConfig = additionalConfig[0] |
| 199 | } |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 200 | |
| 201 | c.vppInstance = vpp |
| 202 | |
| 203 | return vpp, nil |
| 204 | } |
| 205 | |
| 206 | func (c *Container) copy(sourceFileName string, targetFileName string) error { |
| 207 | cmd := exec.Command("docker", "cp", sourceFileName, c.name+":"+targetFileName) |
| 208 | return cmd.Run() |
| 209 | } |
| 210 | |
| 211 | func (c *Container) createFile(destFileName string, content string) error { |
| 212 | f, err := os.CreateTemp("/tmp", "hst-config") |
| 213 | if err != nil { |
| 214 | return err |
| 215 | } |
| 216 | defer os.Remove(f.Name()) |
| 217 | |
| 218 | if _, err := f.Write([]byte(content)); err != nil { |
| 219 | return err |
| 220 | } |
| 221 | if err := f.Close(); err != nil { |
| 222 | return err |
| 223 | } |
| 224 | c.copy(f.Name(), destFileName) |
| 225 | return nil |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | * Executes in detached mode so that the started application can continue to run |
| 230 | * without blocking execution of test |
| 231 | */ |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 232 | func (c *Container) execServer(command string, arguments ...any) { |
| 233 | serverCommand := fmt.Sprintf(command, arguments...) |
| 234 | containerExecCommand := "docker exec -d" + c.getEnvVarsAsCliOption() + |
| 235 | " " + c.name + " " + serverCommand |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 236 | c.suite.T().Helper() |
| 237 | c.suite.log(containerExecCommand) |
| 238 | c.suite.assertNil(exechelper.Run(containerExecCommand)) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 239 | } |
| 240 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 241 | func (c *Container) exec(command string, arguments ...any) string { |
| 242 | cliCommand := fmt.Sprintf(command, arguments...) |
| 243 | containerExecCommand := "docker exec" + c.getEnvVarsAsCliOption() + |
| 244 | " " + c.name + " " + cliCommand |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 245 | c.suite.T().Helper() |
| 246 | c.suite.log(containerExecCommand) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 247 | byteOutput, err := exechelper.CombinedOutput(containerExecCommand) |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 248 | c.suite.assertNil(err) |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 249 | return string(byteOutput) |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 250 | } |
| 251 | |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 252 | func (c *Container) getLogDirPath() string { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 253 | testId := c.suite.getTestId() |
| 254 | testName := c.suite.T().Name() |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 255 | logDirPath := logDir + testName + "/" + testId + "/" |
| 256 | |
| 257 | cmd := exec.Command("mkdir", "-p", logDirPath) |
| 258 | if err := cmd.Run(); err != nil { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 259 | c.suite.T().Fatalf("mkdir error: %v", err) |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | return logDirPath |
| 263 | } |
| 264 | |
| 265 | func (c *Container) saveLogs() { |
| 266 | cmd := exec.Command("docker", "inspect", "--format='{{.State.Status}}'", c.name) |
| 267 | if output, _ := cmd.CombinedOutput(); !strings.Contains(string(output), "running") { |
| 268 | return |
| 269 | } |
| 270 | |
| 271 | testLogFilePath := c.getLogDirPath() + "container-" + c.name + ".log" |
| 272 | |
| 273 | cmd = exec.Command("docker", "logs", "--details", "-t", c.name) |
| 274 | output, err := cmd.CombinedOutput() |
| 275 | if err != nil { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 276 | c.suite.T().Fatalf("fetching logs error: %v", err) |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | f, err := os.Create(testLogFilePath) |
| 280 | if err != nil { |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 281 | c.suite.T().Fatalf("file create error: %v", err) |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 282 | } |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 283 | fmt.Fprint(f, string(output)) |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 284 | f.Close() |
| 285 | } |
| 286 | |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 287 | func (c *Container) log() string { |
| 288 | cmd := "docker logs " + c.name |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 289 | c.suite.log(cmd) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 290 | o, err := exechelper.CombinedOutput(cmd) |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 291 | c.suite.assertNil(err) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 292 | return string(o) |
| 293 | } |
| 294 | |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 295 | func (c *Container) stop() error { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 296 | if c.vppInstance != nil && c.vppInstance.apiChannel != nil { |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 297 | c.vppInstance.saveLogs() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 298 | c.vppInstance.disconnect() |
| 299 | } |
| 300 | c.vppInstance = nil |
Maros Ondrejicka | a2d5262 | 2023-02-24 11:26:39 +0100 | [diff] [blame] | 301 | c.saveLogs() |
Florin Coras | f4fe016 | 2023-01-17 13:02:51 -0800 | [diff] [blame] | 302 | return exechelper.Run("docker stop " + c.name + " -t 0") |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 303 | } |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 304 | |
| 305 | func (c *Container) createConfig(targetConfigName string, templateName string, values any) { |
| 306 | template := template.Must(template.ParseFiles(templateName)) |
| 307 | |
| 308 | f, err := os.CreateTemp("/tmp/hs-test/", "hst-config") |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 309 | c.suite.assertNil(err) |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 310 | defer os.Remove(f.Name()) |
| 311 | |
| 312 | err = template.Execute(f, values) |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 313 | c.suite.assertNil(err) |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 314 | |
| 315 | err = f.Close() |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 316 | c.suite.assertNil(err) |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 317 | |
| 318 | c.copy(f.Name(), targetConfigName) |
| 319 | } |
Maros Ondrejicka | f4ddf16 | 2023-03-08 16:01:43 +0100 | [diff] [blame] | 320 | |
| 321 | func init() { |
| 322 | cmd := exec.Command("mkdir", "-p", logDir) |
| 323 | if err := cmd.Run(); err != nil { |
| 324 | panic(err) |
| 325 | } |
| 326 | } |