LGTM
On Wed, Apr 9, 2014 at 12:51 PM, Klaus Aehlig <[email protected]> wrote: > ...so that we can notify owners when their pending request got granted. > > Signed-off-by: Klaus Aehlig <[email protected]> > --- > lib/config.py | 4 ++-- > src/Ganeti/Locking/Locks.hs | 14 +++++++++----- > test/hs/Test/Ganeti/Locking/Locks.hs | 7 ++++++- > 3 files changed, 17 insertions(+), 8 deletions(-) > > diff --git a/lib/config.py b/lib/config.py > index 81df350..b86df08 100644 > --- a/lib/config.py > +++ b/lib/config.py > @@ -71,10 +71,10 @@ def GetWConfdContext(ec_id, livelock): > """ > if ec_id is None: > return (threading.current_thread().getName(), > - livelock.lockfile.name) > + livelock.lockfile.name, os.getpid()) > else: > return (ec_id, > - livelock.lockfile.name) > + livelock.lockfile.name, os.getpid()) > > > def GetConfig(ec_id, livelock, **kwargs): > diff --git a/src/Ganeti/Locking/Locks.hs b/src/Ganeti/Locking/Locks.hs > index 72c777e..4be5bea 100644 > --- a/src/Ganeti/Locking/Locks.hs > +++ b/src/Ganeti/Locking/Locks.hs > @@ -38,10 +38,11 @@ module Ganeti.Locking.Locks > ) where > > import Control.Applicative ((<$>), (<*>), pure) > -import Control.Monad ((>=>)) > +import Control.Monad ((>=>), liftM) > import Control.Monad.Base (MonadBase, liftBase) > import Control.Monad.Error (MonadError, catchError) > import Data.List (stripPrefix) > +import System.Posix.Types (ProcessID) > import qualified Text.JSON as J > > > @@ -202,8 +203,8 @@ instance J.JSON ClientType where > readJSON (J.JSString s) = J.Ok . ClientOther $ J.fromJSString s > readJSON jids = J.readJSON jids >>= \jid -> J.Ok (ClientJob jid) > > --- | A client is identified as a job id, thread id and path to its process > --- identifier file. > +-- | A client is identified as a job id, thread id, a path to its process > +-- identifier file, and its process id. > -- > -- The JobId isn't enough to identify a client as the master daemon > -- also handles client calls that aren't jobs, but which use the > configuration. > @@ -211,17 +212,20 @@ instance J.JSON ClientType where > data ClientId = ClientId > { ciIdentifier :: ClientType > , ciLockFile :: FilePath > + , ciPid :: ProcessID > } > deriving (Ord, Eq, Show) > > -- | Obtain the ClientID from its JSON representation. > clientIdFromJSON :: J.JSValue -> J.Result ClientId > -clientIdFromJSON (J.JSArray [clienttp, J.JSString lf]) = > +clientIdFromJSON (J.JSArray [clienttp, J.JSString lf, pid]) = > ClientId <$> J.readJSON clienttp <*> pure (J.fromJSString lf) > + <*> liftM fromIntegral (J.readJSON pid :: J.Result Integer) > clientIdFromJSON x = J.Error $ "malformed client id: " ++ show x > > instance J.JSON ClientId where > - showJSON (ClientId client lf) = J.showJSON (client, lf) > + showJSON (ClientId client lf pid) > + = J.showJSON (client, lf, fromIntegral pid :: Integer) > readJSON = clientIdFromJSON > > -- | The type of lock Allocations in Ganeti. In Ganeti, the owner of > diff --git a/test/hs/Test/Ganeti/Locking/Locks.hs > b/test/hs/Test/Ganeti/Locking/Locks.hs > index d4b8829..bd12c53 100644 > --- a/test/hs/Test/Ganeti/Locking/Locks.hs > +++ b/test/hs/Test/Ganeti/Locking/Locks.hs > @@ -29,6 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, > Boston, MA > module Test.Ganeti.Locking.Locks (testLocking_Locks) where > > import Control.Applicative ((<$>), (<*>), liftA2) > +import Control.Monad (liftM) > +import System.Posix.Types (CPid) > > import Test.QuickCheck > import Text.JSON > @@ -100,8 +102,11 @@ prop_ReadShow_ClientType :: Property > prop_ReadShow_ClientType = forAll (arbitrary :: Gen ClientType) $ \a -> > readJSON (showJSON a) ==? Ok a > > +instance Arbitrary CPid where > + arbitrary = liftM fromIntegral (arbitrary :: Gen Integer) > + > instance Arbitrary ClientId where > - arbitrary = ClientId <$> arbitrary <*> arbitrary > + arbitrary = ClientId <$> arbitrary <*> arbitrary <*> arbitrary > > -- | Verify that readJSON . showJSON = Ok for ClientId > prop_ReadShow_ClientId :: Property > -- > 1.9.1.423.g4596e3a > >
