Skip to content

Commit

Permalink
Merge pull request #676 from lluiscampos/enable-dbus-by-default
Browse files Browse the repository at this point in the history
When available, enable D-Bus interface by default
  • Loading branch information
lluiscampos committed Dec 1, 2020
2 parents d6f6e64 + f8310e5 commit 0215e9c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
7 changes: 7 additions & 0 deletions conf/config.go
Expand Up @@ -20,6 +20,7 @@ import (
"strings"

"github.com/mendersoftware/mender/client"
"github.com/mendersoftware/mender/dbus"
"github.com/mendersoftware/mender/installer"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -121,6 +122,12 @@ func LoadConfig(mainConfigFile string, fallbackConfigFile string) (*MenderConfig
var filesLoadedCount int
config := NewMenderConfig()

// If DBus is compiled in, enable it by default
_, err := dbus.GetDBusAPI()
if err == nil {
config.DBus.Enabled = true
}

if loadErr := loadConfigFile(fallbackConfigFile, config, &filesLoadedCount); loadErr != nil {
return nil, loadErr
}
Expand Down
36 changes: 35 additions & 1 deletion conf/config_test.go
Expand Up @@ -75,6 +75,13 @@ var testDBusConfig = `{
}
}`

var testDBusConfigDisabled = `{
"ServerURL": "mender.io",
"DBus": {
"Enabled": false
}
}`

func Test_readConfigFile_noFile_returnsError(t *testing.T) {
err := readConfigFile(nil, "non-existing-file")
assert.Error(t, err)
Expand Down Expand Up @@ -110,6 +117,9 @@ func validateConfiguration(t *testing.T, actual *MenderConfig) {
UpdateLogPath: "/var/lib/mender/log/deployment.log",
DeviceTypeFile: "/var/lib/mender/test_device_type",
Servers: []client.MenderServer{{ServerURL: "mender.io"}},
DBus: DBusConfig{
Enabled: true,
},
}
if !assert.True(t, reflect.DeepEqual(actual, expectedConfig)) {
t.Logf("got: %+v", actual)
Expand Down Expand Up @@ -192,12 +202,36 @@ func TestDBusConfig(t *testing.T) { // create a temporary mender.conf file
confFile.WriteString(testDBusConfig)
conf, err := LoadConfig(confPath, "does-not-exist.config")
assert.NoError(t, err)
conf.Validate()
err = conf.Validate()
assert.NoError(t, err)
assert.Equal(t, true, conf.DBus.Enabled)

}

func TestDbusEnabledDefault(t *testing.T) {
conf, err := LoadConfig("does-not-exist", "also-does-not-exist")
assert.NoError(t, err)
err = conf.Validate()
assert.NoError(t, err)
assert.IsType(t, &MenderConfig{}, conf)
assert.True(t, conf.DBus.Enabled)
}

func TestDBusConfigDisabled(t *testing.T) { // create a temporary mender.conf file
tdir, _ := ioutil.TempDir("", "mendertest")
confPath := path.Join(tdir, "mender.conf")
confFile, err := os.Create(confPath)
defer os.RemoveAll(tdir)
assert.NoError(t, err)

confFile.WriteString(testDBusConfigDisabled)
conf, err := LoadConfig(confPath, "does-not-exist")
assert.NoError(t, err)
conf.Validate()
assert.NoError(t, err)
assert.False(t, conf.DBus.Enabled)
}

func TestConfigurationMergeSettings(t *testing.T) {
var mainConfigJson = `{
"RootfsPartA": "Eggplant",
Expand Down

0 comments on commit 0215e9c

Please sign in to comment.