Since currently for most operations WConfd receives the whole configuration from Python jobs, it makes sense to verify it in every such call. This won't be necessary when WConfd will implement ConfigWriter operations internally.
Also expose the verification function as a RPC call and use it when explicitly verifying the configuration. Later this call will replace the Python verification completely. Signed-off-by: Petr Pudlak <[email protected]> --- lib/config.py | 11 +++++++++++ src/Ganeti/WConfd/Core.hs | 13 +++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/config.py b/lib/config.py index acecc4f..855130a 100644 --- a/lib/config.py +++ b/lib/config.py @@ -945,6 +945,17 @@ class ConfigWriter(object): data = self._ConfigData() cluster = data.cluster + # First call WConfd to perform its checks, if we're not offline + if not self._offline: + try: + self._wconfd.VerifyConfig() + except errors.ConfigVerifyError, err: + try: + for msg in err.args[1]: + result.append(msg) + except IndexError: + pass + # global cluster checks if not cluster.enabled_hypervisors: result.append("enabled hypervisors list doesn't have any entries") diff --git a/src/Ganeti/WConfd/Core.hs b/src/Ganeti/WConfd/Core.hs index 2e339c7..528fb27 100644 --- a/src/Ganeti/WConfd/Core.hs +++ b/src/Ganeti/WConfd/Core.hs @@ -46,6 +46,7 @@ import Ganeti.Locking.Locks ( GanetiLocks(ConfigLock), LockLevel(LevelConfig) , lockLevel, LockLevel, ClientId ) import qualified Ganeti.Locking.Waiting as LW import Ganeti.Objects (ConfigData, DRBDSecret, LogicalVolume) +import qualified Ganeti.WConfd.ConfigVerify as V import Ganeti.WConfd.Language import Ganeti.WConfd.Monad import qualified Ganeti.WConfd.TempRes as T @@ -74,8 +75,15 @@ readConfig ident = checkConfigLock ident L.OwnShared >> CW.readConfig -- | Write the configuration, checking that an exclusive lock is held. -- If not, the call fails. writeConfig :: ClientId -> ConfigData -> WConfdMonad () -writeConfig ident cdata = - checkConfigLock ident L.OwnExclusive >> CW.writeConfig cdata +writeConfig ident cdata = do + checkConfigLock ident L.OwnExclusive + -- V.verifyConfigErr cdata + CW.writeConfig cdata + +-- | Explicitly run verification of the configuration. +-- The caller doesn't need to hold the configuration lock. +verifyConfig :: WConfdMonad () +verifyConfig = CW.readConfig >>= V.verifyConfigErr -- *** Locks on the configuration (only transitional, will be removed later) @@ -253,6 +261,7 @@ exportedFunctions = [ 'echo -- config , 'readConfig , 'writeConfig + , 'verifyConfig , 'lockConfig , 'unlockConfig , 'flushConfig -- 2.0.0.526.g5318336
