Update readme, add some tests

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2022-07-05 17:48:25 +00:00
parent 42249ede0b
commit 87c77f6966
4 changed files with 46 additions and 2 deletions

View file

@ -17,9 +17,16 @@ git clone https://github.com/cloudbase/garm
cd garm
go install ./...
```
You should now have both ```garm``` and ```garm-cli``` in your ```$GOPATH/bin``` folder.
If you have docker/podman installed, you can also build statically linked binaries by running:
```bash
make
```
The ```garm``` and ```garm-cli``` binaries will be built and copied to the ```bin/``` folder in your current working directory.
## Install the service
Add a new system user:
@ -31,12 +38,20 @@ useradd --shell /usr/bin/false \
--no-create-home garm
```
Copy the binary from your ```$GOPATH``` to somewhere in the system ```$PATH```:
The ```lxd``` group is only needed if you have a local LXD install and want to connect to the unix socket to use it. If you're connecting to a remote LXD server over TCP, you can skip adding the ```garm``` user to the ```lxd``` group.
Copy the binary to somewhere in the system ```$PATH```:
```bash
sudo cp $(go env GOPATH)/bin/garm /usr/local/bin/garm
```
Or if you built garm using ```make```:
```bash
sudo cp ./bin/garm /usr/local/bin/garm
```
Create the config folder:
```bash

View file

@ -165,6 +165,12 @@ func (d *Default) Validate() error {
return fmt.Errorf("missing callback_url")
}
if d.ConfigDir != "" {
if _, err := os.Stat(d.ConfigDir); err != nil {
return errors.Wrap(err, "accessing config dir")
}
}
return nil
}

1
config/config_test.go Normal file
View file

@ -0,0 +1 @@
package config

View file

@ -1,6 +1,7 @@
package config
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -72,6 +73,14 @@ func TestExternal(t *testing.T) {
},
errString: "path to provider dir must be absolute",
},
{
name: "Provider executable not found",
cfg: External{
ConfigFile: "",
ProviderDir: "/tmp",
},
errString: "checking provider executable: stat /tmp/garm-external-provider: no such file or directory",
},
}
for _, tc := range tests {
@ -86,3 +95,16 @@ func TestExternal(t *testing.T) {
})
}
}
func TestProviderExecutableIsExecutable(t *testing.T) {
cfg := getDefaultExternalConfig(t)
execPath, err := cfg.ExecutablePath()
assert.Nil(t, err)
err = os.Chmod(execPath, 0o644)
assert.Nil(t, err)
err = cfg.Validate()
assert.NotNil(t, err)
assert.EqualError(t, err, fmt.Sprintf("external provider binary %s is not executable", execPath))
}