From 497beee2dbfa3aeaf2feedf9d4af2b98212ff877 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Sun, 25 Nov 2012 14:28:25 +0100
Subject: [PATCH] Move NICMode from Objects.hs to Types.hs

Also add some unittests for this type.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>
---
 htest/Test/Ganeti/Objects.hs |  2 --
 htest/Test/Ganeti/Types.hs   | 15 +++++++++++++++
 htools/Ganeti/Objects.hs     |  7 -------
 htools/Ganeti/Types.hs       |  9 +++++++++
 4 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/htest/Test/Ganeti/Objects.hs b/htest/Test/Ganeti/Objects.hs
index 941e71c6e..b59cc13de 100644
--- a/htest/Test/Ganeti/Objects.hs
+++ b/htest/Test/Ganeti/Objects.hs
@@ -85,8 +85,6 @@ $(genArbitrary ''PartialBeParams)
 
 $(genArbitrary ''AdminState)
 
-$(genArbitrary ''NICMode)
-
 $(genArbitrary ''PartialNicParams)
 
 $(genArbitrary ''PartialNic)
diff --git a/htest/Test/Ganeti/Types.hs b/htest/Test/Ganeti/Types.hs
index 4bd0acdfd..6a662acc9 100644
--- a/htest/Test/Ganeti/Types.hs
+++ b/htest/Test/Ganeti/Types.hs
@@ -103,6 +103,8 @@ $(genArbitrary ''IAllocatorTestDir)
 
 $(genArbitrary ''IAllocatorMode)
 
+$(genArbitrary ''NICMode)
+
 -- * Properties
 
 prop_AllocPolicy_serialisation :: AllocPolicy -> Property
@@ -231,6 +233,17 @@ case_IAllocatorMode_pyequiv = do
       all_hs_codes = sort $ map Types.iAllocatorModeToRaw [minBound..maxBound]
   assertEqual "for IAllocatorMode equivalence" all_py_codes all_hs_codes
 
+-- | Test 'NICMode' serialisation.
+prop_NICMode_serialisation :: NICMode -> Property
+prop_NICMode_serialisation = testSerialisation
+
+-- | Tests equivalence with Python, based on Constants.hs code.
+case_NICMode_pyequiv :: Assertion
+case_NICMode_pyequiv = do
+  let all_py_codes = sort C.nicValidModes
+      all_hs_codes = sort $ map Types.nICModeToRaw [minBound..maxBound]
+  assertEqual "for NICMode equivalence" all_py_codes all_hs_codes
+
 testSuite "Types"
   [ 'prop_AllocPolicy_serialisation
   , 'prop_DiskTemplate_serialisation
@@ -258,4 +271,6 @@ testSuite "Types"
   , 'prop_IAllocatorTestDir_serialisation
   , 'prop_IAllocatorMode_serialisation
   , 'case_IAllocatorMode_pyequiv
+  , 'prop_NICMode_serialisation
+  , 'case_NICMode_pyequiv
   ]
diff --git a/htools/Ganeti/Objects.hs b/htools/Ganeti/Objects.hs
index f591bb988..54c58a133 100644
--- a/htools/Ganeti/Objects.hs
+++ b/htools/Ganeti/Objects.hs
@@ -33,7 +33,6 @@ module Ganeti.Objects
   , vTypeFromRaw
   , HvParams
   , OsParams
-  , NICMode(..)
   , PartialNicParams(..)
   , FilledNicParams(..)
   , fillNicParams
@@ -168,12 +167,6 @@ roleDescription NRMaster    = "master"
 
 -- * NIC definitions
 
-$(declareSADT "NICMode"
-  [ ("NMBridged", 'C.nicModeBridged)
-  , ("NMRouted",  'C.nicModeRouted)
-  ])
-$(makeJSONInstance ''NICMode)
-
 $(buildParam "Nic" "nicp"
   [ simpleField "mode" [t| NICMode |]
   , simpleField "link" [t| String  |]
diff --git a/htools/Ganeti/Types.hs b/htools/Ganeti/Types.hs
index 659a8045a..824af9c85 100644
--- a/htools/Ganeti/Types.hs
+++ b/htools/Ganeti/Types.hs
@@ -67,6 +67,8 @@ module Ganeti.Types
   , IAllocatorTestDir(..)
   , IAllocatorMode(..)
   , iAllocatorModeToRaw
+  , NICMode(..)
+  , nICModeToRaw
   ) where
 
 import qualified Text.JSON as JSON
@@ -314,3 +316,10 @@ $(THH.declareSADT "IAllocatorMode"
   , ("IAllocatorChangeGroup", 'C.iallocatorModeChgGroup)
   ])
 $(THH.makeJSONInstance ''IAllocatorMode)
+
+-- | Netork mode.
+$(THH.declareSADT "NICMode"
+  [ ("NMBridged", 'C.nicModeBridged)
+  , ("NMRouted",  'C.nicModeRouted)
+  ])
+$(THH.makeJSONInstance ''NICMode)
-- 
GitLab