Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Parser for DRBD proc file added
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 37 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Michele Tartara  
View profile  
 More options Nov 16 2012, 3:53 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 09:53:36 +0100
Local: Fri, Nov 16 2012 3:53 am
Subject: [PATCH master 1/4] Parser for DRBD proc file added
A new directory for haskell modules about block devices has been created
The parser is divided in two modules:
* one exports the data types describing the DRBD status
* one exports the parser itself

Signed-off-by: Michele Tartara <mtart...@google.com>
---
 Makefile.am                          |    5 +
 htools/Ganeti/Block/DRBDDataTypes.hs |  165 +++++++++++++++++
 htools/Ganeti/Block/DRBDParser.hs    |  331 ++++++++++++++++++++++++++++++++++
 3 files changed, 501 insertions(+), 0 deletions(-)
 create mode 100644 htools/Ganeti/Block/DRBDDataTypes.hs
 create mode 100644 htools/Ganeti/Block/DRBDParser.hs

diff --git a/Makefile.am b/Makefile.am
index 2ca6ed7..13119f0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -57,6 +57,7 @@ myexeclibdir = $(pkglibdir)
 HTOOLS_DIRS = \
        htools \
        htools/Ganeti \
+       htools/Ganeti/Block \
        htools/Ganeti/Confd \
        htools/Ganeti/HTools \
        htools/Ganeti/HTools/Backend \
@@ -108,6 +109,7 @@ BUILDTIME_DIR_AUTOCREATE = \
        $(APIDOC_DIR) \
        $(APIDOC_HS_DIR) \
        $(APIDOC_HS_DIR)/Ganeti \
+       $(APIDOC_HS_DIR)/Ganeti/Block \
        $(APIDOC_HS_DIR)/Ganeti/Confd \
        $(APIDOC_HS_DIR)/Ganeti/HTools \
        $(APIDOC_HS_DIR)/Ganeti/HTools/Backend \
@@ -424,6 +426,8 @@ HPCEXCL = --exclude Main \
        $(patsubst htools.%,--exclude Test.%,$(subst /,.,$(patsubst %.hs,%, $(HS_LIB_SRCS))))

 HS_LIB_SRCS = \
+       htools/Ganeti/Block/DRBDDataTypes.hs \
+       htools/Ganeti/Block/DRBDParser.hs \
        htools/Ganeti/BasicTypes.hs \
        htools/Ganeti/Common.hs \
        htools/Ganeti/Compat.hs \
@@ -1608,6 +1612,7 @@ hs-apidoc: $(HS_BUILT_SRCS)
        rm -rf $(APIDOC_HS_DIR)/*
        @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/HTools/Backend
        @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/HTools/Program
+       @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/Block
        @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/Confd
        @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/Query
        $(HSCOLOUR) -print-css > $(APIDOC_HS_DIR)/Ganeti/hscolour.css
diff --git a/htools/Ganeti/Block/DRBDDataTypes.hs b/htools/Ganeti/Block/DRBDDataTypes.hs
new file mode 100644
index 0000000..19b7ecf
--- /dev/null
+++ b/htools/Ganeti/Block/DRBDDataTypes.hs
@@ -0,0 +1,165 @@
+{-| DRBD Data Types
+
+This module holds the definition of the data types describing the status of
+DRBD.
+
+-}
+{-
+
+Copyright (C) 2012 Google Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.
+
+-}
+module Ganeti.Block.DRBDDataTypes (DRBDStatus(..),
+                      VersionInfo(..),
+                      DeviceInfo(..),
+                      ConnectionState(..),
+                      LocalRemote(..),
+                      Role(..),
+                      DiskState(..),
+                      PerformanceIndicators(..),
+                      SyncStatus(..),
+                      SizeUnit(..),
+                      Time(..),
+                      TimeUnit(..),
+                      AdditionalInfo(..)) where
+
+-- | Data type contaning all the data about the status of DRBD
+data DRBDStatus = DRBDStatus { versionInfo::VersionInfo,
+                               deviceInfo::[DeviceInfo] } deriving (Eq, Show)
+
+-- | Data type describing the DRBD version
+data VersionInfo = VersionInfo { version::Maybe String,
+                                 api::Maybe String,
+                                 proto::Maybe String,
+                                 srcversion::Maybe String,
+                                 gitHash::Maybe String,
+                                 buildBy::Maybe String } deriving (Eq, Show)
+
+-- | Data type describing a device
+data DeviceInfo = UnconfiguredDevice Int |
+                  DeviceInfo { deviceNumber::Int,
+                               connectionState::ConnectionState,
+                               resourceRoles::LocalRemote Role,
+                               diskStates::LocalRemote DiskState,
+                               replicationProtocol::Char,
+                               ioFlags::String,
+                               performanceIndicators::PerformanceIndicators,
+                               syncStatus::Maybe SyncStatus,
+                               resync::Maybe AdditionalInfo,
+                               actLog::Maybe AdditionalInfo
+                             } deriving (Eq, Show)
+
+-- | Data type describing the state of the connection
+data ConnectionState = StandAlone
+                     | Disconnecting
+                     | Unconnected
+                     | Timeout
+                     | BrokenPipe
+                     | NetworkFailure
+                     | ProtocolError
+                     | TearDown
+                     | WFConnection
+                     | WFReportParams
+                     | Connected
+                     | StartingSyncS
+                     | StartingSyncT
+                     | WFBitMapS
+                     | WFBitMapT
+                     | WFSyncUUID
+                     | SyncSource
+                     | SyncTarget
+                     | PausedSyncS
+                     | PausedSyncT
+                     | VerifyS
+                     | VerifyT
+                     | Unconfigured deriving (Show, Eq)
+
+-- | Algebraic data type describing something that has a local and a remote
+-- value
+data LocalRemote a = LocalRemote { local::a,
+                                   remote::a
+                                 } deriving (Eq, Show)
+
+-- | Data type describing
+data Role = Primary
+          | Secondary
+          | Unknown deriving (Eq, Show)
+
+-- | Data type describing disk states
+data DiskState = Diskless
+               | Attaching
+               | Failed
+               | Negotiating
+               | Inconsistent
+               | Outdated
+               | DUnknown
+               | Consistent
+               | UpToDate deriving (Eq, Show)
+
+-- | Data type containing data about performance indicators
+data PerformanceIndicators = PerformanceIndicators {
+                               networkSend::Int,
+                               networkReceive::Int,
+                               diskWrite::Int,
+                               diskRead::Int,
+                               activityLog::Int,
+                               bitMap::Int,
+                               localCount::Int,
+                               pending::Int,
+                               unacknowledged::Int,
+                               applicationPending::Int,
+                               epochs::Maybe Int,
+                               writeOrder::Maybe Char,
+                               outOfSync::Maybe Int } deriving (Eq, Show)
+
+-- | Data type containing data about the synchronization status of a device
+data SyncStatus = SyncStatus {
+                    percentage::Double,
+                    partialSyncSize::Int,
+                    totalSyncSize::Int,
+                    syncUnit::SizeUnit,
+                    timeToFinish::Time,
+                    speed::Double,
+                    want::Maybe Double,
+                    speedSizeUnit::SizeUnit,
+                    speedTimeUnit::TimeUnit
+                  } deriving (Eq, Show)
+
+-- | Data type describing a size unit for memory
+data SizeUnit = KiloByte | MegaByte deriving (Eq, Show)
+
+-- | Data type describing a time (hh:mm:ss)
+data Time = Time {
+                hour::Integer,
+                min::Integer,
+                sec::Integer
+            } deriving (Eq, Show)
+
+-- | Data type describing a time unit
+data TimeUnit = Second deriving (Eq, Show)
+
+-- | Additional device-specific information produced by drbd <= 8.0
+data AdditionalInfo = AdditionalInfo {
+                partialUsed::Int,
+                totalUsed::Int,
+                hits::Int,
+                misses::Int,
+                starving::Int,
+                dirty::Int,
+                changed::Int
+              } deriving (Eq, Show)
diff --git a/htools/Ganeti/Block/DRBDParser.hs b/htools/Ganeti/Block/DRBDParser.hs
new file mode 100644
index 0000000..9ed805d
--- /dev/null
+++ b/htools/Ganeti/Block/DRBDParser.hs
@@ -0,0 +1,331 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-| DRBD proc file parser
+
+This module holds the definition of the parser that extracts status information
+from the DRBD proc file
+
+-}
+{-
+
+Copyright (C) 2012 Google Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.
+
+-}
+module Ganeti.Block.DRBDParser (drbdStatusParser) where
+
+import Control.Applicative ((<*>), (*>), (<*), (<$>), (<|>), pure, some)
+import qualified
...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "DRBD Parser and tests added" by Michele Tartara
Michele Tartara  
View profile  
 More options Nov 16 2012, 3:53 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 09:53:35 +0100
Local: Fri, Nov 16 2012 3:53 am
Subject: [PATCH master 0/4] DRBD Parser and tests added
This patch set adds the DRBD parser to the ganeti tree.
The parser is, up to now, just used by its unit tests module.
More tests to come soon.
Also, a few utility functions for opening test data files from
Haskell unit tests have been added.

Michele Tartara (4):
  Parser for DRBD proc file added
  Improved TestHelper module docstring
  Utility functions for loading data from test files added
  DRBDParser unit test added

 Makefile.am                           |    7 +
 htest/Test/Ganeti/Block/DRBDParser.hs |  122 ++++++++++++
 htest/Test/Ganeti/TestCommon.hs       |   24 +++
 htest/Test/Ganeti/TestHelper.hs       |    2 +-
 htest/test.hs                         |    2 +
 htools/Ganeti/Block/DRBDDataTypes.hs  |  165 ++++++++++++++++
 htools/Ganeti/Block/DRBDParser.hs     |  331 +++++++++++++++++++++++++++++++++
 7 files changed, 652 insertions(+), 1 deletions(-)
 create mode 100644 htest/Test/Ganeti/Block/DRBDParser.hs
 create mode 100644 htools/Ganeti/Block/DRBDDataTypes.hs
 create mode 100644 htools/Ganeti/Block/DRBDParser.hs

--
1.7.7.3


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Improved TestHelper module docstring" by Michele Tartara
Michele Tartara  
View profile  
 More options Nov 16 2012, 3:53 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 09:53:37 +0100
Local: Fri, Nov 16 2012 3:53 am
Subject: [PATCH master 2/4] Improved TestHelper module docstring
Signed-off-by: Michele Tartara <mtart...@google.com>
---
 htest/Test/Ganeti/TestHelper.hs |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/htest/Test/Ganeti/TestHelper.hs b/htest/Test/Ganeti/TestHelper.hs
index 04eb490..92f5d08 100644
--- a/htest/Test/Ganeti/TestHelper.hs
+++ b/htest/Test/Ganeti/TestHelper.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE TemplateHaskell #-}

-{-| Unittest helpers for Haskell components
+{-| Unittest helpers for TemplateHaskell components

 -}

--
1.7.7.3


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Utility functions for loading data from test files added" by Michele Tartara
Michele Tartara  
View profile  
 More options Nov 16 2012, 3:53 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 09:53:38 +0100
Local: Fri, Nov 16 2012 3:53 am
Subject: [PATCH master 3/4] Utility functions for loading data from test files added
They mimic their python counterparts.

Added functions:
* getSourceDir
* testDataFilename
* readTestData
* readPythonTestData

Signed-off-by: Michele Tartara <mtart...@google.com>
---
 htest/Test/Ganeti/TestCommon.hs |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/htest/Test/Ganeti/TestCommon.hs b/htest/Test/Ganeti/TestCommon.hs
index fdfa7f1..8e8c56b 100644
--- a/htest/Test/Ganeti/TestCommon.hs
+++ b/htest/Test/Ganeti/TestCommon.hs
@@ -217,3 +217,27 @@ testSerialisation a =
 resultProp :: (Show a) => BasicTypes.GenericResult a b -> PropertyM IO b
 resultProp (BasicTypes.Bad err) = stop . failTest $ show err
 resultProp (BasicTypes.Ok  val) = return val
+
+-- | Return the source directory of Ganeti
+getSourceDir :: IO FilePath
+getSourceDir = catchJust (guard . isDoesNotExistError)
+            (getEnv "TOP_SRCDIR")
+            (const (return "."))
+
+-- | Returns the path of a file in the test data directory, given its name
+testDataFilename :: String -> String -> IO FilePath
+testDataFilename datadir name = do
+        src <- getSourceDir
+        return $ src ++ datadir ++ name
+
+-- | Returns the content of the specified python test data file
+readPythonTestData :: String -> IO String
+readPythonTestData filename = do
+    name <- testDataFilename "/test/data/" filename
+    readFile name
+
+-- | Returns the content of the specified haskell test data file
+readTestData :: String -> IO String
+readTestData filename = do
+    name <- testDataFilename "/htest/data/" filename
+    readFile name
--
1.7.7.3


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "DRBDParser unit test added" by Michele Tartara
Michele Tartara  
View profile  
 More options Nov 16 2012, 3:53 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 09:53:39 +0100
Local: Fri, Nov 16 2012 3:53 am
Subject: [PATCH master 4/4] DRBDParser unit test added
Signed-off-by: Michele Tartara <mtart...@google.com>
---
 Makefile.am                           |    2 +
 htest/Test/Ganeti/Block/DRBDParser.hs |  122 +++++++++++++++++++++++++++++++++
 htest/test.hs                         |    2 +
 3 files changed, 126 insertions(+), 0 deletions(-)
 create mode 100644 htest/Test/Ganeti/Block/DRBDParser.hs

diff --git a/Makefile.am b/Makefile.am
index 13119f0..46717c3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -66,6 +66,7 @@ HTOOLS_DIRS = \
        htest \
        htest/Test \
        htest/Test/Ganeti \
+       htest/Test/Ganeti/Block \
        htest/Test/Ganeti/Confd \
        htest/Test/Ganeti/HTools \
        htest/Test/Ganeti/HTools/Backend \
@@ -487,6 +488,7 @@ HS_TEST_SRCS = \
        htest/Test/Ganeti/Common.hs \
        htest/Test/Ganeti/Confd/Utils.hs \
        htest/Test/Ganeti/Daemon.hs \
+       htest/Test/Ganeti/Block/DRBDParser.hs \
        htest/Test/Ganeti/Errors.hs \
        htest/Test/Ganeti/HTools/Backend/Simu.hs \
        htest/Test/Ganeti/HTools/Backend/Text.hs \
diff --git a/htest/Test/Ganeti/Block/DRBDParser.hs b/htest/Test/Ganeti/Block/DRBDParser.hs
new file mode 100644
index 0000000..7f2780d
--- /dev/null
+++ b/htest/Test/Ganeti/Block/DRBDParser.hs
@@ -0,0 +1,122 @@
+{-# LANGUAGE TemplateHaskell #-}
+
+{-| Unittests for Attoparsec support for unicode -}
+
+{-
+
+Copyright (C) 2012 Google Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.
+
+-}
+
+module Test.Ganeti.Block.DRBDParser (testBlock_DRBDParser) where
+
+import Test.HUnit
+
+import Test.Ganeti.TestHelper
+import Test.Ganeti.TestCommon (readPythonTestData)
+
+import qualified Data.Attoparsec.Text as A
+import Data.Text (pack)
+
+import Ganeti.Block.DRBDParser (drbdStatusParser)
+import Ganeti.Block.DRBDDataTypes
+
+case_drbd8 :: Assertion
+case_drbd8 = do
+    fileContent <- readPythonTestData "proc_drbd8.txt"
+    case A.parseOnly drbdStatusParser $ pack fileContent of
+        Left msg -> assertFailure $ "Parsing failed: " ++ msg
+        Right obtained -> assertEqual "drbd8" expected obtained
+    where expected = DRBDStatus (VersionInfo (Just "8.0.12") (Just "86")
+                                    (Just "86") Nothing
+                                    (Just
+                                     "5c9f89594553e32adb87d9638dce591782f947e3")
+                                    (Just "XXX")
+                                )
+                                [DeviceInfo 0 Connected (LocalRemote Primary
+                                                           Secondary)
+                                    (LocalRemote UpToDate UpToDate) 'C' "r---"
+                                    (PerformanceIndicators 4375577 0 4446279 674
+                                        1067 69 0 0 0 0 Nothing Nothing Nothing)
+                                    Nothing
+                                    (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+                                    (Just $ AdditionalInfo 0 257 793749 1067 0 0
+                                                1067
+                                    ),
+                                 DeviceInfo 1 Connected (LocalRemote Secondary
+                                                            Primary)
+                                    (LocalRemote UpToDate UpToDate) 'C' "r---"
+                                    (PerformanceIndicators 738320 0 738320
+                                        554400 67 0 0 0 0 0 Nothing Nothing
+                                        Nothing)
+                                    Nothing
+                                    (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+                                    (Just $ AdditionalInfo 0 257 92464 67 0 0 67
+                                    ),
+                                 UnconfiguredDevice 2,
+                                 DeviceInfo 4 WFConnection (LocalRemote Primary
+                                                                Unknown)
+                                    (LocalRemote UpToDate DUnknown) 'C' "r---"
+                                    (PerformanceIndicators 738320 0 738320
+                                        554400 67 0 0 0 0 0 Nothing Nothing
+                                        Nothing)
+                                    Nothing
+                                    (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+                                    (Just $ AdditionalInfo 0 257 92464 67 0 0 67
+                                    ),
+                                 DeviceInfo 5 Connected (LocalRemote Primary
+                                                            Secondary)
+                                    (LocalRemote UpToDate Diskless) 'C' "r---"
+                                    (PerformanceIndicators 4375581 0 4446283 674
+                                        1069 69 0 0 0 0 Nothing Nothing Nothing)
+                                    Nothing
+                                    (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+                                    (Just $ AdditionalInfo 0 257 793750 1069 0 0
+                                                1069
+                                    ),
+                                 DeviceInfo 6 Connected (LocalRemote Secondary
+                                                            Primary)
+                                    (LocalRemote Diskless UpToDate) 'C'  "r---"
+                                    (PerformanceIndicators 0 4375581 5186925 327
+                                        75 214 0 0 0 0 Nothing Nothing Nothing)
+                                    Nothing
+                                    Nothing
+                                    Nothing,
+                                 DeviceInfo 7 WFConnection (LocalRemote
+                                                                Secondary
+                                                                Unknown)
+                                    (LocalRemote UpToDate DUnknown) 'C' "r---"
+                                    (PerformanceIndicators 0 0 0 0 0 0 0 0 0 0
+                                        Nothing Nothing Nothing)
+                                    Nothing
+                                    (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+                                    (Just $ AdditionalInfo 0 257 0 0 0 0 0),
+                                 DeviceInfo 8 StandAlone (LocalRemote Secondary
+                                                            Unknown)
+                                    (LocalRemote UpToDate DUnknown) ' ' "r---"
+                                    (PerformanceIndicators 0 0 0 0 0 0 0 0 0 0
+                                        Nothing Nothing Nothing)
+                                    Nothing
+                                    (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+                                    (Just $ AdditionalInfo 0 257 0 0 0 0 0)
+                                ]
+
+
+testSuite "Block_DRBDParser"
+          [ 'case_drbd8
+          ]
diff --git a/htest/test.hs b/htest/test.hs
index b41fb99..ee3f5a6 100644
--- a/htest/test.hs
+++ b/htest/test.hs
@@ -32,6 +32,7 @@ import System.Environment (getArgs)
 import Test.Ganeti.TestImports ()
 import Test.Ganeti.Attoparsec
 import Test.Ganeti.BasicTypes
+import Test.Ganeti.Block.DRBDParser
 import Test.Ganeti.Common
 import Test.Ganeti.Confd.Utils
 import Test.Ganeti.Daemon
@@ -79,6 +80,7 @@ allTests =
   , testCommon
   , testConfd_Utils
   , testDaemon
+  , testBlock_DRBDParser
   , testErrors
   , testHTools_Backend_Simu
   , testHTools_Backend_Text
--
1.7.7.3


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Improved TestHelper module docstring" by Iustin Pop
Iustin Pop  
View profile  
 More options Nov 16 2012, 4:59 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 10:59:23 +0100
Local: Fri, Nov 16 2012 4:59 am
Subject: Re: [PATCH master 2/4] Improved TestHelper module docstring

On Fri, Nov 16, 2012 at 09:53:37AM +0100, Michele Tartara wrote:
> Signed-off-by: Michele Tartara <mtart...@google.com>
> ---
>  htest/Test/Ganeti/TestHelper.hs |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

> diff --git a/htest/Test/Ganeti/TestHelper.hs b/htest/Test/Ganeti/TestHelper.hs
> index 04eb490..92f5d08 100644
> --- a/htest/Test/Ganeti/TestHelper.hs
> +++ b/htest/Test/Ganeti/TestHelper.hs
> @@ -1,6 +1,6 @@
>  {-# LANGUAGE TemplateHaskell #-}

> -{-| Unittest helpers for Haskell components
> +{-| Unittest helpers for TemplateHaskell components

LGTM, thanks. I'll add a dot at the end there.

iustin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Utility functions for loading data from test files added" by Iustin Pop
Iustin Pop  
View profile  
 More options Nov 16 2012, 5:01 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 11:01:55 +0100
Local: Fri, Nov 16 2012 5:01 am
Subject: Re: [PATCH master 3/4] Utility functions for loading data from test files added

'.' at end of docstrings; same for the other functions.

For consistency, should this be readHaskellTestData? Just wondering.

iustin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michele Tartara  
View profile  
 More options Nov 16 2012, 7:05 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 13:05:53 +0100
Local: Fri, Nov 16 2012 7:05 am
Subject: Re: [PATCH master 3/4] Utility functions for loading data from test files added

I thought about that, but in the end I preferred to go for a "default
implementation" for the test data specific for the current language and a
"named" implementation for the external language (python).

Also because in my opinion having a single test data directory would make
more sense (data are not language specific) and if they ever end up being
joined, a language-agnostic function to access the data would make more
sense.

Thanks
Michele


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Iustin Pop  
View profile  
 More options Nov 16 2012, 7:15 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 13:15:41 +0100
Local: Fri, Nov 16 2012 7:15 am
Subject: Re: [PATCH master 3/4] Utility functions for loading data from test files added

Ack, makes sense.

> Also because in my opinion having a single test data directory would make
> more sense (data are not language specific) and if they ever end up being
> joined, a language-agnostic function to access the data would make more
> sense.

Hmm. We actually had them (test data) together, but then I split them
for clarity.

Maybe we want to change the tree as follows?

\-pytest
\-hstest
\-test-data

So that the test files are separated, but test data files are common?

iustin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michele Tartara  
View profile  
 More options Nov 16 2012, 7:21 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 13:21:17 +0100
Local: Fri, Nov 16 2012 7:21 am
Subject: Re: [PATCH master 3/4] Utility functions for loading data from test files added

Ok, I'm resending the patch with the docstring's full stops added, and
without changing the function names.

It sounds like the best approach to me.
But that definitely goes in a different patch! :-p

Thanks,
Michele


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michele Tartara  
View profile  
 More options Nov 16 2012, 7:23 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 13:23:02 +0100
Local: Fri, Nov 16 2012 7:23 am
Subject: [PATCH master 3/4] Utility functions for loading data from test files added
They mimic their python counterparts.

Added functions:
* getSourceDir
* testDataFilename
* readTestData
* readPythonTestData

Signed-off-by: Michele Tartara <mtart...@google.com>
---
 htest/Test/Ganeti/TestCommon.hs |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/htest/Test/Ganeti/TestCommon.hs b/htest/Test/Ganeti/TestCommon.hs
index fdfa7f1..c108079 100644
--- a/htest/Test/Ganeti/TestCommon.hs
+++ b/htest/Test/Ganeti/TestCommon.hs
@@ -217,3 +217,27 @@ testSerialisation a =
 resultProp :: (Show a) => BasicTypes.GenericResult a b -> PropertyM IO b
 resultProp (BasicTypes.Bad err) = stop . failTest $ show err
 resultProp (BasicTypes.Ok  val) = return val
+
+-- | Return the source directory of Ganeti.
+getSourceDir :: IO FilePath
+getSourceDir = catchJust (guard . isDoesNotExistError)
+            (getEnv "TOP_SRCDIR")
+            (const (return "."))
+
+-- | Returns the path of a file in the test data directory, given its name.
+testDataFilename :: String -> String -> IO FilePath
+testDataFilename datadir name = do
+        src <- getSourceDir
+        return $ src ++ datadir ++ name
+
+-- | Returns the content of the specified python test data file.
+readPythonTestData :: String -> IO String
+readPythonTestData filename = do
+    name <- testDataFilename "/test/data/" filename
+    readFile name
+
+-- | Returns the content of the specified haskell test data file.
+readTestData :: String -> IO String
+readTestData filename = do
+    name <- testDataFilename "/htest/data/" filename
+    readFile name
--
1.7.7.3


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Iustin Pop  
View profile  
 More options Nov 16 2012, 7:28 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 13:28:02 +0100
Local: Fri, Nov 16 2012 7:28 am
Subject: Re: [PATCH master 3/4] Utility functions for loading data from test files added

Absolutely, was just discussing here as it came up.

thanks,
iustin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Iustin Pop  
View profile  
 More options Nov 16 2012, 7:33 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 13:33:31 +0100
Local: Fri, Nov 16 2012 7:33 am
Subject: Re: [PATCH master 3/4] Utility functions for loading data from test files added

On Fri, Nov 16, 2012 at 01:23:02PM +0100, Michele Tartara wrote:
> They mimic their python counterparts.

> Added functions:
> * getSourceDir
> * testDataFilename
> * readTestData
> * readPythonTestData

> Signed-off-by: Michele Tartara <mtart...@google.com>

LGTM, thanks.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Parser for DRBD proc file added" by Iustin Pop
Iustin Pop  
View profile  
 More options Nov 16 2012, 7:43 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 13:43:28 +0100
Local: Fri, Nov 16 2012 7:43 am
Subject: Re: [PATCH master 1/4] Parser for DRBD proc file added

On Fri, Nov 16, 2012 at 09:53:36AM +0100, Michele Tartara wrote:
> A new directory for haskell modules about block devices has been created
> The parser is divided in two modules:
> * one exports the data types describing the DRBD status
> * one exports the parser itself

> Signed-off-by: Michele Tartara <mtart...@google.com>
> ---
>  Makefile.am                          |    5 +
>  htools/Ganeti/Block/DRBDDataTypes.hs |  165 +++++++++++++++++
>  htools/Ganeti/Block/DRBDParser.hs    |  331 ++++++++++++++++++++++++++++++++++
>  3 files changed, 501 insertions(+), 0 deletions(-)
>  create mode 100644 htools/Ganeti/Block/DRBDDataTypes.hs
>  create mode 100644 htools/Ganeti/Block/DRBDParser.hs

Hi,

You shouldn't do that - I mean, grouping modules based on filenames
rather than structure.

If you need two modules, then these should be:

- Ganeti/Block/Drbd/Types.hs
- Ganeti/Block/Drbd/Parser.hs

(No all uppercase DRBD as well).

Please use, here and in all multi-line declarations below, Haskell-style
indendation - check the other source files. This should be rather:

module Test.Ganeti.TestHelper
  ( testSuite
  , genArbitrary
  , …
   ) where

> +-- | Data type contaning all the data about the status of DRBD
> +data DRBDStatus = DRBDStatus { versionInfo::VersionInfo,
> +                               deviceInfo::[DeviceInfo] } deriving (Eq, Show)

White space around '::'. Deriving should be on its own line. Docstrings
for the actual member types.

Same comment for all these three, and the following ones.

And up to here. Also, don't forget dots at the end of docstrings (but
not in member variable docstrings; check other existing code).

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "DRBDParser unit test added" by Iustin Pop
Iustin Pop  
View profile  
 More options Nov 16 2012, 7:45 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 13:45:18 +0100
Local: Fri, Nov 16 2012 7:45 am
Subject: Re: [PATCH master 4/4] DRBDParser unit test added

Wrong indentation here - 2 spaces, not 4. Possible in the other patches
as well.

Also, I would really prefer if we test all existing test files; we have
multiple ones especially to handle variations in /proc/drbd format.

iustin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Parser for DRBD proc file added" by Michele Tartara
Michele Tartara  
View profile  
 More options Nov 16 2012, 8:42 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 14:42:19 +0100
Local: Fri, Nov 16 2012 8:42 am
Subject: Re: [PATCH master 1/4] Parser for DRBD proc file added

Ok.

Ok, I'll find the proper style guide (if it exists) or I will just look at
the rest of the code.

> > +-- | Data type contaning all the data about the status of DRBD
> > +data DRBDStatus = DRBDStatus { versionInfo::VersionInfo,
> > +                               deviceInfo::[DeviceInfo] } deriving (Eq,
> Show)

> White space around '::'. Deriving should be on its own line. Docstrings
> for the actual member types.

Ok for the spaces and and for "deriving" on its own line.
But what do you mean exactly with "actual member types"? One docstring for
every constructor?

Ok, I'll fix them as I did in the other patch.

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "DRBDParser unit test added" by Michele Tartara
Michele Tartara  
View profile  
 More options Nov 16 2012, 8:45 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 14:45:45 +0100
Local: Fri, Nov 16 2012 8:45 am
Subject: Re: [PATCH master 4/4] DRBDParser unit test added

Ok, I'll fix it.

> Also, I would really prefer if we test all existing test files; we have
> multiple ones especially to handle variations in /proc/drbd format.

This has always been my plan as well :-)
I already wrote some more of them, and I'm writing the others. That's what
I meant with "More tests to come" in the cover letter.
I just wanted to submit something as soon as I could, in order to get
feedback on the coding style, so that I can directly write the rest of the
tests (and of the code, in general) with the correct style, without wasting
time reformatting them afterwards.

Thanks,
Michele


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Parser for DRBD proc file added" by Iustin Pop
Iustin Pop  
View profile  
 More options Nov 16 2012, 8:58 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 14:58:31 +0100
Local: Fri, Nov 16 2012 8:58 am
Subject: Re: [PATCH master 1/4] Parser for DRBD proc file added

http://code.google.com/p/ganeti/wiki/HaskellStyleGuide btw. Not sure if
complete.

> > > +-- | Data type contaning all the data about the status of DRBD
> > > +data DRBDStatus = DRBDStatus { versionInfo::VersionInfo,
> > > +                               deviceInfo::[DeviceInfo] } deriving (Eq,
> > Show)

> > White space around '::'. Deriving should be on its own line. Docstrings
> > for the actual member types.

> Ok for the spaces and and for "deriving" on its own line.
> But what do you mean exactly with "actual member types"? One docstring for
> every constructor?

Yes, for both constructor and record names. Since you have only one
constructor here, we don't need to document it, but we need to document
the record fields:

data DRBDStatus = DRBDStatus
                  { versionInfo :: VersionInfo -- ^ The driver version
                  , deviceInfo  :: [DeviceInfo] -- ^ Per-minor information
                  } deriving (Show, Read, Eq)

Speaking of which. Why is deviceInfo a list? Is the minor index itself
present in DeviceInfo?

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "DRBDParser unit test added" by Iustin Pop
Iustin Pop  
View profile  
 More options Nov 16 2012, 8:59 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 14:58:58 +0100
Local: Fri, Nov 16 2012 8:58 am
Subject: Re: [PATCH master 4/4] DRBDParser unit test added

Oh sorry, I didn't see that (more to come later). Sounds good, thanks!

iustin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Parser for DRBD proc file added" by Michele Tartara
Michele Tartara  
View profile  
 More options Nov 16 2012, 9:26 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 15:26:26 +0100
Local: Fri, Nov 16 2012 9:26 am
Subject: Re: [PATCH master 1/4] Parser for DRBD proc file added

Great! Thanks!

Yes, the minor index is the deviceNumber field of DeviceInfo (probably I
should change the name to minorNumber).
Each "DeviceInfo" represents a single DRBD device, that's why it's a list:
you can have multiple DeviceInfos.
Why by the way makes me think that the deviceInfo field of DRBDStatus
should be renamed to deviceInfos.

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Iustin Pop  
View profile  
 More options Nov 16 2012, 9:30 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 15:30:16 +0100
Local: Fri, Nov 16 2012 9:30 am
Subject: Re: [PATCH master 1/4] Parser for DRBD proc file added

Yes. I also wonder if this shouldn't be a Data.IntMap rather than a
list; well, if we never want to lookup a given device by index, then not
necessarily.

OK, not for now, but let me know when you want to start that, and I
could explain how our TH code is structured.

thanks,
iustin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michele Tartara  
View profile  
 More options Nov 16 2012, 9:33 am
From: Michele Tartara <mtart...@google.com>
Date: Fri, 16 Nov 2012 15:33:40 +0100
Local: Fri, Nov 16 2012 9:33 am
Subject: Re: [PATCH master 1/4] Parser for DRBD proc file added

It might be a good idea. On the other hand, I don't think the list would be
extremely long anyway, so I guess the speedup of not using a list would be
quite negligible.
I will think about it while I restructure the rest of the code according to
your suggestions.

Great, thanks!

Michele


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Iustin Pop  
View profile  
 More options Nov 16 2012, 9:44 am
From: Iustin Pop <ius...@google.com>
Date: Fri, 16 Nov 2012 15:44:19 +0100
Local: Fri, Nov 16 2012 9:44 am
Subject: Re: [PATCH master 1/4] Parser for DRBD proc file added

Oh, speedup was not necessarily my goal. But the fact that a Map
represents the structure of the data better (unique minor indices,
etc.). Whereas a list only says there could be "some" devices.

Anyway, please don't rewrite now, just add a TODO. That's minor point.

thanks,
iustin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michele Tartara  
View profile  
 More options Nov 19 2012, 5:25 am
From: Michele Tartara <mtart...@google.com>
Date: Mon, 19 Nov 2012 11:25:44 +0100
Local: Mon, Nov 19 2012 5:25 am
Subject: [PATCH master 1/2] Parser for DRBD proc file added
A new directory for haskell modules about block devices has been created
The parser is divided in two modules:
* one exports the data types describing the DRBD status
* one exports the parser itself

Signed-off-by: Michele Tartara <mtart...@google.com>
---
 Makefile.am                        |    8 +
 htools/Ganeti/Block/Drbd/Parser.hs |  332 ++++++++++++++++++++++++++++++++++++
 htools/Ganeti/Block/Drbd/Types.hs  |  191 +++++++++++++++++++++
 3 files changed, 531 insertions(+), 0 deletions(-)
 create mode 100644 htools/Ganeti/Block/Drbd/Parser.hs
 create mode 100644 htools/Ganeti/Block/Drbd/Types.hs

diff --git a/Makefile.am b/Makefile.am
index 5ea9925..756b714 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -57,6 +57,8 @@ myexeclibdir = $(pkglibdir)
 HTOOLS_DIRS = \
        htools \
        htools/Ganeti \
+       htools/Ganeti/Block \
+       htools/Ganeti/Block/Drbd \
        htools/Ganeti/Confd \
        htools/Ganeti/HTools \
        htools/Ganeti/HTools/Backend \
@@ -108,6 +110,8 @@ BUILDTIME_DIR_AUTOCREATE = \
        $(APIDOC_DIR) \
        $(APIDOC_HS_DIR) \
        $(APIDOC_HS_DIR)/Ganeti \
+       $(APIDOC_HS_DIR)/Ganeti/Block \
+       $(APIDOC_HS_DIR)/Ganeti/Block/Drbd \
        $(APIDOC_HS_DIR)/Ganeti/Confd \
        $(APIDOC_HS_DIR)/Ganeti/HTools \
        $(APIDOC_HS_DIR)/Ganeti/HTools/Backend \
@@ -426,6 +430,8 @@ HPCEXCL = --exclude Main \
        $(patsubst htools.%,--exclude Test.%,$(subst /,.,$(patsubst %.hs,%, $(HS_LIB_SRCS))))

 HS_LIB_SRCS = \
+       htools/Ganeti/Block/Drbd/Types.hs \
+       htools/Ganeti/Block/Drbd/Parser.hs \
        htools/Ganeti/BasicTypes.hs \
        htools/Ganeti/Common.hs \
        htools/Ganeti/Compat.hs \
@@ -1610,6 +1616,8 @@ hs-apidoc: $(HS_BUILT_SRCS)
        rm -rf $(APIDOC_HS_DIR)/*
        @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/HTools/Backend
        @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/HTools/Program
+       @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/Block
+       @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/Block/Drbd
        @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/Confd
        @mkdir_p@ $(APIDOC_HS_DIR)/Ganeti/Query
        $(HSCOLOUR) -print-css > $(APIDOC_HS_DIR)/Ganeti/hscolour.css
diff --git a/htools/Ganeti/Block/Drbd/Parser.hs b/htools/Ganeti/Block/Drbd/Parser.hs
new file mode 100644
index 0000000..c848b80
--- /dev/null
+++ b/htools/Ganeti/Block/Drbd/Parser.hs
@@ -0,0 +1,332 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-| DRBD proc file parser
+
+This module holds the definition of the parser that extracts status information
+from the DRBD proc file.
+
+-}
+{-
+
+Copyright (C) 2012 Google Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.
+
+-}
+module Ganeti.Block.Drbd.Parser (drbdStatusParser) where
+
+import Control.Applicative ((<*>), (*>), (<*), (<$>), (<|>), pure, some)
+import qualified Data.Attoparsec.Text as A
+import qualified Data.Attoparsec.Combinator as AC
+import Data.Attoparsec.Text (Parser)
+import Data.Text (Text, unpack)
+
+import Ganeti.Block.Drbd.Types
+
+-- | Our own space-skipping function, because A.skipSpace also skips
+-- newline characters. It skips ZERO or more spaces, so it does not fail if
+-- there are no spaces.
+skipSpaces :: Parser ()
+skipSpaces = A.skipWhile A.isHorizontalSpace
+
+-- | Skips spaces and the given string, then executes a parser and
+-- returns its result.
+skipSpacesAndString :: Text -> Parser a -> Parser a
+skipSpacesAndString s parser =
+  skipSpaces
+  *> A.string s
+  *> parser
+
+-- | Takes a parser and returns it with the content wrapped in a Maybe
+-- object. The resulting parser never fails, but contains Nothing if it
+-- couldn't properly parse the string.
+optional :: Parser a -> Parser (Maybe a)
+optional parser = (Just <$> parser) <|> pure Nothing
+
+-- | The parser for a whole DRBD status file.
+drbdStatusParser :: Parser DRBDStatus
+drbdStatusParser =
+  DRBDStatus <$> versionInfoParser
+             <*> deviceParser `AC.manyTill` A.endOfInput
+
+-- | The parser for the version information lines.
+versionInfoParser :: Parser VersionInfo
+versionInfoParser =
+  VersionInfo
+    <$> optional versionP
+    <*> optional apiP
+    <*> optional protoP
+    <*> optional srcVersion
+    <*> (fmap unpack <$> optional gh)
+    <*> (fmap unpack <$> optional builder)
+    where versionP =
+            A.string "version:"
+            *> skipSpaces
+            *> fmap unpack (A.takeWhile $ not . A.isHorizontalSpace)
+          apiP =
+            skipSpacesAndString "(api:" . fmap unpack $ A.takeWhile (/= '/')
+          protoP =
+            A.string "/proto:"
+            *> fmap Data.Text.unpack (A.takeWhile (/= ')'))
+            <* A.takeTill A.isEndOfLine <* A.endOfLine
+          srcVersion =
+            A.string "srcversion:"
+            *> AC.skipMany1 A.space
+            *> fmap unpack (A.takeTill A.isEndOfLine)
+            <* A.endOfLine
+          gh =
+            A.string "GIT-hash:"
+            *> skipSpaces
+            *> A.takeWhile (not . A.isHorizontalSpace)
+          builder =
+            skipSpacesAndString "build by" $
+              skipSpaces
+              *> A.takeTill A.isEndOfLine
+              <* A.endOfLine
+
+-- | The parser for a (multi-line) string representing a device.
+deviceParser :: Parser DeviceInfo
+deviceParser = do
+  deviceNum <- skipSpaces *> A.decimal <* A.char ':'
+  cs <- skipSpacesAndString "cs:" connectionStateParser
+  if cs == Unconfigured
+    then do
+      _ <- additionalEOL
+      return $ UnconfiguredDevice deviceNum
+    else do
+      ro <- skipSpaces *> skipRoleString *> localRemoteParser roleParser
+      ds <- skipSpacesAndString "ds:" $ localRemoteParser diskStateParser
+      replicProtocol <- A.space *> A.anyChar
+      io <- skipSpaces *> ioFlagsParser <* A.endOfLine
+      perfIndicators <- performanceIndicatorsParser
+      syncS <- conditionalSyncStatusParser cs
+      reS <- optional resyncParser
+      act <- optional actLogParser
+      _ <- additionalEOL
+      return $ DeviceInfo deviceNum cs ro ds replicProtocol io perfIndicators
+                          syncS reS act
+
+    where conditionalSyncStatusParser SyncSource = Just <$> syncStatusParser
+          conditionalSyncStatusParser SyncTarget = Just <$> syncStatusParser
+          conditionalSyncStatusParser _ = pure Nothing
+          skipRoleString = A.string "ro:" <|> A.string "st:"
+          resyncParser = skipSpacesAndString "resync:" additionalInfoParser
+          actLogParser = skipSpacesAndString "act_log:" additionalInfoParser
+          additionalEOL = A.skipWhile A.isEndOfLine
+
+-- | The parser for the connection state.
+connectionStateParser :: Parser ConnectionState
+connectionStateParser =
+  standAlone
+  <|> disconnecting
+  <|> unconnected
+  <|> timeout
+  <|> brokenPipe
+  <|> networkFailure
+  <|> protocolError
+  <|> tearDown
+  <|> wfConnection
+  <|> wfReportParams
+  <|> connected
+  <|> startingSyncS
+  <|> startingSyncT
+  <|> wfBitMapS
+  <|> wfBitMapT
+  <|> wfSyncUUID
+  <|> syncSource
+  <|> syncTarget
+  <|> pausedSyncS
+  <|> pausedSyncT
+  <|> verifyS
+  <|> verifyT
+  <|> unconfigured
+    where standAlone = A.string "StandAlone" *> pure StandAlone
+          disconnecting = A.string "Disconnectiog" *> pure Disconnecting
+          unconnected = A.string "Unconnected" *> pure Unconnected
+          timeout = A.string "Timeout" *> pure Timeout
+          brokenPipe = A.string "BrokenPipe" *> pure BrokenPipe
+          networkFailure = A.string "NetworkFailure" *> pure NetworkFailure
+          protocolError = A.string "ProtocolError" *> pure ProtocolError
+          tearDown = A.string "TearDown" *> pure TearDown
+          wfConnection = A.string "WFConnection" *> pure WFConnection
+          wfReportParams = A.string "WFReportParams" *> pure WFReportParams
+          connected = A.string "Connected" *> pure Connected
+          startingSyncS = A.string "StartingSyncS" *> pure StartingSyncS
+          startingSyncT = A.string "StartingSyncT" *> pure StartingSyncT
+          wfBitMapS = A.string "WFBitMapS" *> pure WFBitMapS
+          wfBitMapT = A.string "WFBitMapT" *> pure WFBitMapT
+          wfSyncUUID = A.string "WFSyncUUID" *> pure WFSyncUUID
+          syncSource = A.string "SyncSource" *> pure SyncSource
+          syncTarget = A.string "SyncTarget" *> pure SyncTarget
+          pausedSyncS = A.string "PausedSyncS" *> pure PausedSyncS
+          pausedSyncT = A.string "PausedSyncT" *> pure PausedSyncT
+          verifyS = A.string "VerifyS" *> pure VerifyS
+          verifyT = A.string "VerifyT" *> pure VerifyT
+          unconfigured = A.string "Unconfigured" *> pure Unconfigured
+
+-- | Parser for recognizing strings describing two elements of the same type
+-- separated by a '/'. The first one is considered local, the second remote.
+localRemoteParser :: Parser a -> Parser (LocalRemote a)
+localRemoteParser parser = LocalRemote <$> parser <*> (A.char '/' *> parser)
+
+-- | The parser for resource roles.
+roleParser :: Parser Role
+roleParser =
+  primary
+  <|> secondary
+  <|> unknown
+           where primary = A.string "Primary" *> pure Primary
+                 secondary = A.string "Secondary" *> pure Secondary
+                 unknown = A.string "Unknown" *> pure Unknown
+
+-- | The parser for disk states.
...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "DRBD parser unit tests added" by Michele Tartara
Michele Tartara  
View profile  
 More options Nov 19 2012, 5:26 am
From: Michele Tartara <mtart...@google.com>
Date: Mon, 19 Nov 2012 11:26:55 +0100
Local: Mon, Nov 19 2012 5:26 am
Subject: [PATCH master 2/2] DRBD parser unit tests added
Signed-off-by: Michele Tartara <mtart...@google.com>
---
 Makefile.am                            |    3 +
 htest/Test/Ganeti/Block/Drbd/Parser.hs |  128 ++++++++++++++++++++++++++++++++
 htest/test.hs                          |    2 +
 3 files changed, 133 insertions(+), 0 deletions(-)
 create mode 100644 htest/Test/Ganeti/Block/Drbd/Parser.hs

diff --git a/Makefile.am b/Makefile.am
index 756b714..af4580b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -67,6 +67,8 @@ HTOOLS_DIRS = \
        htest \
        htest/Test \
        htest/Test/Ganeti \
+       htest/Test/Ganeti/Block \
+       htest/Test/Ganeti/Block/Drbd \
        htest/Test/Ganeti/Confd \
        htest/Test/Ganeti/HTools \
        htest/Test/Ganeti/HTools/Backend \
@@ -491,6 +493,7 @@ HS_TEST_SRCS = \
        htest/Test/Ganeti/Common.hs \
        htest/Test/Ganeti/Confd/Utils.hs \
        htest/Test/Ganeti/Daemon.hs \
+       htest/Test/Ganeti/Block/Drbd/Parser.hs \
        htest/Test/Ganeti/Errors.hs \
        htest/Test/Ganeti/HTools/Backend/Simu.hs \
        htest/Test/Ganeti/HTools/Backend/Text.hs \
diff --git a/htest/Test/Ganeti/Block/Drbd/Parser.hs b/htest/Test/Ganeti/Block/Drbd/Parser.hs
new file mode 100644
index 0000000..b02165c
--- /dev/null
+++ b/htest/Test/Ganeti/Block/Drbd/Parser.hs
@@ -0,0 +1,128 @@
+{-# LANGUAGE TemplateHaskell #-}
+
+{-| Unittests for Attoparsec support for unicode -}
+
+{-
+
+Copyright (C) 2012 Google Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.
+
+-}
+
+module Test.Ganeti.Block.Drbd.Parser (testBlock_DRBDParser) where
+
+import Test.HUnit
+
+import Test.Ganeti.TestHelper
+import Test.Ganeti.TestCommon (readPythonTestData)
+
+import qualified Data.Attoparsec.Text as A
+import Data.Text (pack)
+
+import Ganeti.Block.Drbd.Parser (drbdStatusParser)
+import Ganeti.Block.Drbd.Types
+
+-- | Function for testing whether a file is parsed correctly
+testFile :: String -> DRBDStatus -> Assertion
+testFile fileName expectedContent = do
+    fileContent <- readPythonTestData fileName
+    case A.parseOnly drbdStatusParser $ pack fileContent of
+        Left msg -> assertFailure $ "Parsing failed: " ++ msg
+        Right obtained -> assertEqual fileName expectedContent obtained
+
+case_drbd80_emptyline :: Assertion
+case_drbd80_emptyline = testFile "proc_drbd80-emptyline.txt" $
+  DRBDStatus
+    ( VersionInfo Nothing Nothing Nothing Nothing
+        (Just "5c9f89594553e32adb87d9638dce591782f947e3")
+        (Just "r...@node1.example.com, 2009-05-22 12:47:52")
+    )
+    [ DeviceInfo 0 Connected (LocalRemote Primary Secondary)
+        (LocalRemote UpToDate UpToDate) 'C' "r---"
+        (PerformanceIndicators 78728316 0 77675644 1277039 254 270 0 0 0 0 Nothing
+          Nothing Nothing)
+        Nothing
+        (Just $ AdditionalInfo 0 61 65657 135 0 0 135)
+        (Just $ AdditionalInfo 0 257 11378843 254 0 0 254),
+      UnconfiguredDevice 1,
+      UnconfiguredDevice 2,
+      UnconfiguredDevice 5,
+      UnconfiguredDevice 6
+    ]
+
+case_drbd8 :: Assertion
+case_drbd8 = testFile "proc_drbd8.txt" $
+  DRBDStatus
+    ( VersionInfo (Just "8.0.12") (Just "86") (Just "86") Nothing
+        (Just "5c9f89594553e32adb87d9638dce591782f947e3")
+        (Just "XXX")
+    )
+    [ DeviceInfo 0 Connected (LocalRemote Primary Secondary)
+        (LocalRemote UpToDate UpToDate) 'C' "r---"
+        (PerformanceIndicators 4375577 0 4446279 674 1067 69 0 0 0 0 Nothing
+          Nothing Nothing)
+        Nothing
+        (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+        (Just $ AdditionalInfo 0 257 793749 1067 0 0 1067),
+      DeviceInfo 1 Connected (LocalRemote Secondary Primary)
+        (LocalRemote UpToDate UpToDate) 'C' "r---"
+        (PerformanceIndicators 738320 0 738320 554400 67 0 0 0 0 0 Nothing
+          Nothing Nothing)
+        Nothing
+        (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+        (Just $ AdditionalInfo 0 257 92464 67 0 0 67),
+      UnconfiguredDevice 2,
+      DeviceInfo 4 WFConnection (LocalRemote Primary Unknown)
+        (LocalRemote UpToDate DUnknown) 'C' "r---"
+        (PerformanceIndicators 738320 0 738320 554400 67 0 0 0 0 0 Nothing
+          Nothing Nothing)
+        Nothing
+        (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+        (Just $ AdditionalInfo 0 257 92464 67 0 0 67),
+      DeviceInfo 5 Connected (LocalRemote Primary Secondary)
+        (LocalRemote UpToDate Diskless) 'C' "r---"
+        (PerformanceIndicators 4375581 0 4446283 674 1069 69 0 0 0 0 Nothing
+          Nothing Nothing)
+        Nothing
+        (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+        (Just $ AdditionalInfo 0 257 793750 1069 0 0 1069),
+      DeviceInfo 6 Connected (LocalRemote Secondary Primary)
+        (LocalRemote Diskless UpToDate) 'C'  "r---"
+        (PerformanceIndicators 0 4375581 5186925 327 75 214 0 0 0 0 Nothing
+          Nothing Nothing)
+        Nothing
+        Nothing
+        Nothing,
+      DeviceInfo 7 WFConnection (LocalRemote Secondary Unknown)
+        (LocalRemote UpToDate DUnknown) 'C' "r---"
+        (PerformanceIndicators 0 0 0 0 0 0 0 0 0 0 Nothing Nothing Nothing)
+        Nothing
+        (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+        (Just $ AdditionalInfo 0 257 0 0 0 0 0),
+      DeviceInfo 8 StandAlone (LocalRemote Secondary Unknown)
+        (LocalRemote UpToDate DUnknown) ' ' "r---"
+        (PerformanceIndicators 0 0 0 0 0 0 0 0 0 0 Nothing Nothing Nothing)
+        Nothing
+        (Just $ AdditionalInfo 0 61 0 0 0 0 0)
+        (Just $ AdditionalInfo 0 257 0 0 0 0 0)
+    ]
+
+
+testSuite "Block_DRBDParser"
+          [ 'case_drbd80_emptyline,
+            'case_drbd8
+          ]
diff --git a/htest/test.hs b/htest/test.hs
index b41fb99..a3906e9 100644
--- a/htest/test.hs
+++ b/htest/test.hs
@@ -32,6 +32,7 @@ import System.Environment (getArgs)
 import Test.Ganeti.TestImports ()
 import Test.Ganeti.Attoparsec
 import Test.Ganeti.BasicTypes
+import Test.Ganeti.Block.Drbd.Parser
 import Test.Ganeti.Common
 import Test.Ganeti.Confd.Utils
 import Test.Ganeti.Daemon
@@ -79,6 +80,7 @@ allTests =
   , testCommon
   , testConfd_Utils
   , testDaemon
+  , testBlock_DRBDParser
   , testErrors
   , testHTools_Backend_Simu
   , testHTools_Backend_Text
--
1.7.7.3


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 37   Newer >
« Back to Discussions « Newer topic     Older topic »