MM-14143 config cleanup final (#10374)
* TestGetLicenseFileFromDisk: avoid using fileutils.FindConfigFile * config: abstract config-related file access, extend memory store * simplify config validate to avoid file knowledge * fix relative file tests * cluster: fix ConfigChanged event The old and new configurations were swapped when notifying the enterprise code of configuration changes, creating needless instability in propagating config updates across a cluster. * config/database: ignore duplicates * test cleanup * remove unnecessary Save() in test
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3716918c57
Коммит
1e462da2d4
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/mattermost/mattermost-server/config"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mattermost/mattermost-server/utils/fileutils"
|
||||
)
|
||||
|
||||
var ConfigCmd = &cobra.Command{
|
||||
@@ -84,33 +83,12 @@ func init() {
|
||||
func configValidateCmdF(command *cobra.Command, args []string) error {
|
||||
utils.TranslationsPreInit()
|
||||
model.AppErrorInit(utils.T)
|
||||
filePath, err := command.Flags().GetString("config")
|
||||
|
||||
_, err := getConfigStore(command)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
filePath = fileutils.FindConfigFile(filePath)
|
||||
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
decoder := json.NewDecoder(file)
|
||||
config := model.Config{}
|
||||
err = decoder.Decode(&config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := file.Stat(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := config.IsValid(); err != nil {
|
||||
return errors.New(utils.T(err.Id))
|
||||
}
|
||||
|
||||
CommandPrettyPrintln("The document is valid")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
@@ -71,7 +74,11 @@ func TestConfigValidate(t *testing.T) {
|
||||
th := Setup()
|
||||
defer th.TearDown()
|
||||
|
||||
assert.Error(t, th.RunCommand(t, "--config", "foo.json", "config", "validate"))
|
||||
tempFile, err := ioutil.TempFile("", "TestConfigValidate")
|
||||
require.NoError(t, err)
|
||||
defer os.Remove(tempFile.Name())
|
||||
|
||||
assert.Error(t, th.RunCommand(t, "--config", tempFile.Name(), "config", "validate"))
|
||||
th.CheckCommand(t, "config", "validate")
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/config"
|
||||
"github.com/mattermost/mattermost-server/manualtesting"
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/web"
|
||||
@@ -31,7 +32,7 @@ func init() {
|
||||
}
|
||||
|
||||
func serverCmdF(command *cobra.Command, args []string) error {
|
||||
config, err := command.Flags().GetString("config")
|
||||
configDSN, err := command.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -40,12 +41,18 @@ func serverCmdF(command *cobra.Command, args []string) error {
|
||||
usedPlatform, _ := command.Flags().GetBool("platform")
|
||||
|
||||
interruptChan := make(chan os.Signal, 1)
|
||||
return runServer(config, disableConfigWatch, usedPlatform, interruptChan)
|
||||
|
||||
configStore, err := config.NewStore(configDSN, !disableConfigWatch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return runServer(configStore, disableConfigWatch, usedPlatform, interruptChan)
|
||||
}
|
||||
|
||||
func runServer(configDSN string, disableConfigWatch bool, usedPlatform bool, interruptChan chan os.Signal) error {
|
||||
func runServer(configStore config.Store, disableConfigWatch bool, usedPlatform bool, interruptChan chan os.Signal) error {
|
||||
options := []app.Option{
|
||||
app.Config(configDSN, !disableConfigWatch),
|
||||
app.ConfigStore(configStore),
|
||||
app.RunJobs,
|
||||
app.JoinCluster,
|
||||
app.StartElasticsearch,
|
||||
|
||||
@@ -10,22 +10,22 @@ import (
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/config"
|
||||
"github.com/mattermost/mattermost-server/jobs"
|
||||
"github.com/mattermost/mattermost-server/utils/fileutils"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type ServerTestHelper struct {
|
||||
configPath string
|
||||
configStore config.Store
|
||||
disableConfigWatch bool
|
||||
interruptChan chan os.Signal
|
||||
originalInterval int
|
||||
}
|
||||
|
||||
func SetupServerTest() *ServerTestHelper {
|
||||
// Build a channel that will be used by the server to receive system signals…
|
||||
// Build a channel that will be used by the server to receive system signals...
|
||||
interruptChan := make(chan os.Signal, 1)
|
||||
// …and sent it immediately a SIGINT value.
|
||||
// ...and sent it immediately a SIGINT value.
|
||||
// This will make the server loop stop as soon as it started successfully.
|
||||
interruptChan <- syscall.SIGINT
|
||||
|
||||
@@ -36,7 +36,6 @@ func SetupServerTest() *ServerTestHelper {
|
||||
jobs.DEFAULT_WATCHER_POLLING_INTERVAL = 200
|
||||
|
||||
th := &ServerTestHelper{
|
||||
configPath: fileutils.FindConfigFile("config.json"),
|
||||
disableConfigWatch: true,
|
||||
interruptChan: interruptChan,
|
||||
originalInterval: originalInterval,
|
||||
@@ -52,24 +51,11 @@ func TestRunServerSuccess(t *testing.T) {
|
||||
th := SetupServerTest()
|
||||
defer th.TearDownServerTest()
|
||||
|
||||
err := runServer(th.configPath, th.disableConfigWatch, false, th.interruptChan)
|
||||
configStore, err := config.NewMemoryStore()
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestRunServerInvalidConfigFile(t *testing.T) {
|
||||
th := SetupServerTest()
|
||||
defer th.TearDownServerTest()
|
||||
|
||||
// Start the server with an unreadable config file
|
||||
unreadableConfigFile, err := ioutil.TempFile("", "mattermost-unreadable-config-file-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
os.Chmod(unreadableConfigFile.Name(), 0200)
|
||||
defer os.Remove(unreadableConfigFile.Name())
|
||||
|
||||
err = runServer(unreadableConfigFile.Name(), th.disableConfigWatch, false, th.interruptChan)
|
||||
require.Error(t, err)
|
||||
err = runServer(configStore, th.disableConfigWatch, false, th.interruptChan)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestRunServerSystemdNotification(t *testing.T) {
|
||||
@@ -113,8 +99,11 @@ func TestRunServerSystemdNotification(t *testing.T) {
|
||||
ch <- string(data)
|
||||
}(socketReader)
|
||||
|
||||
configStore, err := config.NewMemoryStore()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Start and stop the server
|
||||
err = runServer(th.configPath, th.disableConfigWatch, false, th.interruptChan)
|
||||
err = runServer(configStore, th.disableConfigWatch, false, th.interruptChan)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Ensure the notification has been sent on the socket and is correct
|
||||
@@ -131,6 +120,9 @@ func TestRunServerNoSystemd(t *testing.T) {
|
||||
os.Unsetenv("NOTIFY_SOCKET")
|
||||
defer os.Setenv("NOTIFY_SOCKET", originalSocket)
|
||||
|
||||
err := runServer(th.configPath, th.disableConfigWatch, false, th.interruptChan)
|
||||
configStore, err := config.NewMemoryStore()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = runServer(configStore, th.disableConfigWatch, false, th.interruptChan)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user