1. 20 Nov, 2012 7 commits
    • Iustin Pop's avatar
      Add more basic validation types · edb5a1c8
      Iustin Pop authored
      
      
      This mirrors the ht.py types PositiveInt, NonNegative, etc., except
      that they work at a more generic level (any numeric type, respectively
      any non-empty list).
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarAdeodato Simo <dato@google.com>
      edb5a1c8
    • Michele Tartara's avatar
      Add parser for DRBD /proc file · 3c1915df
      Michele Tartara authored
      
      
      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: default avatarMichele Tartara <mtartara@google.com>
      [iustin@google.com: indentation/alignment fixes]
      Reviewed-by: default avatarIustin Pop <iustin@google.com>
      3c1915df
    • Iustin Pop's avatar
      Properly log errors when setting up daemon FDs · 1a865afe
      Iustin Pop authored
      
      
      While writing the pipe-based reporting and trying various ways to
      break the startup, I fought for a while trying to understand why error
      reporting was _different_ when running the daemon as a user (with no
      rights). It turns out that setupDaemonFDs wants to open the log file
      in append mode way before, so we are not protected by the 'prepare'
      phase.
      
      This patch explicitly runs the 'setupDaemonFDs' function under the
      same handler as the prepare phase, with the only change that here we
      instruct handlePrepErr to not log the message via log*, since logging
      is not yet set up.
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
      1a865afe
    • Iustin Pop's avatar
      Switch opcode data type from normal to record constructors · 8ee2994a
      Iustin Pop authored
      
      
      Currently, the OpCode definitions are using normal constructors:
      
        data OpCode = OpTestDelay Double Bool [String]
                    | OpInstanceFailover String Bool (Maybe String)
                    …
      
      While this works for a few opcodes, it becomes unwieldy when dealing
      with a bigger number of opcode definitions and/or with opcodes having
      many fields.
      
      This patch changes the opcodes to record-based constructors, so that
      we get for free accessor functions:
      
        data OpCode
          = OpTestDelay {
              opDuration :: Double,
              opOnMaster :: Bool,
              opOnNodes :: [String]
            }
            | OpInstanceFailover {
               opInstanceName :: String,
               opIgnoreConsistency :: Bool,
               opTargetNode :: Maybe String
            }
            …
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarAdeodato Simo <dato@google.com>
      8ee2994a
    • Iustin Pop's avatar
      Fix docstrings for the Filter type · 51d991d7
      Iustin Pop authored
      
      
      While looking at the opcode docs and clicking accidentally on the
      filter type, I saw that the haddock formatting is broken due to
      non-escaped use of special chars. Let's convert the ascii-like
      formatting to haddock, and have nicer apidoc.
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
      51d991d7
    • Iustin Pop's avatar
      Split OpCode.hs and add module for opcode parameters · 92f51573
      Iustin Pop authored
      
      
      Due to TemplateHaskell stage restrictions, we can't define parameters
      in the same module as we're using them for TH, so we have to define
      all module parameters in a separate module.
      
      This patch therefore splits OpCodes.hs in two, adding that module and
      moves most code there (types, parameters, etc.). The remaining parts
      in OpCodes.hs, the actual opcode definitions, now use more parameters
      instead of direct field definitions (more will come later)
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarAdeodato Simo <dato@google.com>
      92f51573
    • Iustin Pop's avatar
      Create a new Ganeti/Types.hs module · 5e9deac0
      Iustin Pop authored
      There are already three cases where we copied type definitions between
      the htools-specific types into the main ganeti code. Let's stop doing
      this 
      
       and create a common types module that holds these.
      
      Note that there already exists BasicTypes.hs, but that refers to very
      low-level types, and can't use TH derivation itself.
      
      A side effect of this unification is that there is a small conflict
      between AdminStatus/AdminOffline and InstanceStatus/AdminOffline. As
      such, I renamed AdminOffline and AdminDown to StatusOffline/StatusDown
      in the InstanceStatus type.
      
      The patch also moves the tests related to these types to a new test
      module.
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarAdeodato Simo <dato@google.com>
      5e9deac0
  2. 15 Nov, 2012 1 commit
    • Iustin Pop's avatar
      Cleanup THH function use from built module namespace · 32a569fe
      Iustin Pop authored
      
      
      Currently, THH.hs "injects" into the built code names of library
      functions like Text.JSON.makeObj, Ganeti.JSON.fromObj, etc. built
      directly from strings, via (e.g.)
      
        varE (mkName "makeObj")
      
      This means that the "makeObj" name must exist in the target module,
      i.o.w. must be imported there. This leads to the strange case of
      having to have imports that do not appear at all in the used
      (template) code, but are needed to satisfy this "hidden" dependency;
      look at Ganeti/Jobs.hs before this patch, for example.
      
      This is also not very obvious, because we usually import Text.JSON
      anyway; I only stumbled upon it while doing some cleanup work.
      
      So to clean this up, the current patch changes the THH.hs to use not
      string-derived, but identifier-derived names («'identifier» versus
      «mkName "identifier"»); this is better, as the names must be
      resolvable when compiling THH itself (once), and not when compiling
      the multiple derived modules. As you can see, this allows removal of
      extraneous imports from various modules.
      
      Background information: an `mkName "foo"` results in a name of flavour
      NameS (“An unqualified name; dynamically bound”) or alternatively to a
      qualified name, but still dynamically bound. Whereas what we want is a
      statically bound name: `'foo` results in a NameG flavour, “Global name
      bound outside of the TH AST: An original name”.
      
      One more explanation: the change is similar to going from 'x = eval
      "map"' to 'x = map'; the name is no longer dynamically evaluated, but
      statically when the module is compiled. In our case, previously names
      were bound at target module compile time, now they are bound at THH.hs
      compile time.
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
      32a569fe
  3. 13 Nov, 2012 2 commits
  4. 12 Nov, 2012 14 commits
  5. 08 Nov, 2012 3 commits
  6. 07 Nov, 2012 3 commits
    • Iustin Pop's avatar
      Implement base checkFn/prepFn/execFn model for daemons · 2ac2e420
      Iustin Pop authored
      
      
      This mirrors the code in the Python code base, and is required for
      clean error reporting during startup.
      
      This patch implements the basic infrastructure; the confd daemon is
      not yet modified to take advantage of this, just the types are
      adjusted.
      
      Also, the pipe-based error reporting will go in a future patch, once
      we can actually use that for reporting.
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
      2ac2e420
    • Iustin Pop's avatar
      One more ghc 7.6 fix · 7ae5d703
      Iustin Pop authored
      
      
      This is only in master, so needed to be fixed separately.
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
      7ae5d703
    • Iustin Pop's avatar
      Fix compatibility with newer Haskell libraries · 1251817b
      Iustin Pop authored
      
      
      This small patch fixes compatibility with a few newer Haskell libraries:
      
      - base 4.6, included with ghc 7.6, removed the deprecated 'catch'
        function from Prelude, so our "import Prelude hiding (catch)" is now
        an error; we workaround by using fully-qualified
        Control.Exception.catch name
      
      - containers 0.5 changed the signature of 'deleteFindMax'; we
        workaround by using separate 'findMax' and 'deleteMax'
      
      - QuickCheck 2.5 removed the 'maxDiscards' test parameter, replacing
        it with a much better 'maxDiscardsRatio'; however, until we can
        depend on that, we workaround by just removing it (we don't control
        anymore the maxDiscards, instead leaving it default; for our default
        test size, this is no change, as the default value is already 500,
        which is our default as well) and not printing it anymore
      
      Tested on Squeeze (+extra libs), Wheezy and experimental, which covers
      all supported GHC versions.
      
      Also, merging this in master will be a pain, but unless we want to
      stop supporting 2.6…
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
      1251817b
  7. 06 Nov, 2012 1 commit
  8. 26 Oct, 2012 5 commits
    • Iustin Pop's avatar
      Convert Luxi results to Ganeti errors · 7adb7dff
      Iustin Pop authored
      
      
      This a bit too complex patch converts the result of Luxi calls
      (submitJob, query*, etc.) from Result to ErrorResult. It then
      immediately revers this in the HTools/Backend/Luxi module, where we
      don't need necessarily the full error type (just a nice error
      message), and does the same in Hbal's job execution functions.
      
      While at first sight this doesn't seem to do much, what we get is
      actual error messages from Ganeti, plus improvements to the result
      parsing: instead of "can't parse char", we now get properly (note,
      wrapped manually):
      
        Executing jobset for instances instance1, …
        Job submission error: Failure: the job queue is marked for drain and
          doesn't accept new requests
      
      Or:
      
        Job submission error: Unhandled exception: LuxiError "parsing job
          id: cannot parse string 'a956101'"
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
      7adb7dff
    • Iustin Pop's avatar
      Move htools backends to a separate directory · 879d9290
      Iustin Pop authored
      
      
      Five modules under the HTools/ directories are backend
      implementations, so let's move them to a separate directory, to more
      clearly show the hierarchy. I wanted to do this for a while, but
      merging between branches is always an issue, so let's do it know since
      we have an opportunity.
      
      This patch contains the actual renames, the required changed module
      names, imports, etc., but no other changes.
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
      879d9290
    • Iustin Pop's avatar
      Fix X509CertError definition in Haskell codebase · bca39f5c
      Iustin Pop authored
      
      
      Thanks Dato for catching this.
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
      bca39f5c
    • Iustin Pop's avatar
      Fix a few issues found by newer hlint · 66ad857a
      Iustin Pop authored
      
      
      Testing with a newer hlint found a few minor issues; but all are real,
      valid recommendations:
      
      - don't use "if cond then f x else f y", but "f (if cond then x else y)"
      - "if a then b else True" is equivalent to the simpler "not a || b"
      - and as usual, one more ignore to our "testing basic properties"
        module
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
      66ad857a
    • Iustin Pop's avatar
      Add support for optional fields with null serialised · 9b156883
      Iustin Pop authored
      
      
      This follows a conversation we had for how to deal with
      optional-but-required fields in JSON serialisations: fields which are
      optional (can be either a given type or 'null'), but where the 'null'
      value is required. There are just a few of these in the Python code,
      but we should support them nevertheless.
      
      The patch changes the 'isOptional' attribute from boolean to a custom
      ADT, three-typed. This allows us to keep the same path on load (which
      deals with both cases), but use a custom save path where we explicitly
      save the 'null' value.
      Signed-off-by: default avatarIustin Pop <iustin@google.com>
      Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
      9b156883
  9. 25 Oct, 2012 4 commits