Commit a56d29a6 authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Merge branch 'stable-2.10' into stable-2.11



* stable-2.10
  Fixed typos
  Pass correct params in move-instance
  In CanTieredAlloc test set IPolicy
  Make genInstanceMaybeBiggerThanNode honor policy lower bound
  Also export a null ISpec
  Support instance generation within ranges
  Add a function to leave the list monad

Conflicts:
	src/Ganeti/BasicTypes.hs (take all the imports)
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parents 51e9eef6 a7f867a3
...@@ -122,7 +122,7 @@ command. ...@@ -122,7 +122,7 @@ command.
The NICs of the instances can be specified via the ``--net`` The NICs of the instances can be specified via the ``--net``
option. By default, one NIC is created for the instance, with a option. By default, one NIC is created for the instance, with a
random MAC, and set up according the the cluster level NIC random MAC, and set up according to the cluster level NIC
parameters. Each NIC can take these parameters (all optional): parameters. Each NIC can take these parameters (all optional):
mac mac
...@@ -137,7 +137,7 @@ ip ...@@ -137,7 +137,7 @@ ip
passed in the **network** parameter if this NIC is meant to be passed in the **network** parameter if this NIC is meant to be
connected to the said network. ``--no-conflicts-check`` can be used connected to the said network. ``--no-conflicts-check`` can be used
to override this check. The special value **pool** causes Ganeti to to override this check. The special value **pool** causes Ganeti to
select an IP from the the network the NIC is or will be connected to. select an IP from the network the NIC is or will be connected to.
One can pick an externally reserved IP of a network along with One can pick an externally reserved IP of a network along with
``--no-conflict-check``. Note that this IP cannot be assigned to ``--no-conflict-check``. Note that this IP cannot be assigned to
any other instance until it gets released. any other instance until it gets released.
......
...@@ -53,6 +53,7 @@ module Ganeti.BasicTypes ...@@ -53,6 +53,7 @@ module Ganeti.BasicTypes
, handleErrorT , handleErrorT
, iterateOk , iterateOk
, select , select
, runListHead
, LookupResult(..) , LookupResult(..)
, MatchPriority(..) , MatchPriority(..)
, lookupName , lookupName
...@@ -278,6 +279,12 @@ select :: a -- ^ default result ...@@ -278,6 +279,12 @@ select :: a -- ^ default result
-> a -- ^ first result which has a True condition, or default -> a -- ^ first result which has a True condition, or default
select def = maybe def snd . find fst select def = maybe def snd . find fst
-- | Apply a function to the first element of a list, return the default
-- value, if the list is empty. This is just a convenient combination of
-- maybe and listToMaybe.
runListHead :: a -> (b -> a) -> [b] -> a
runListHead a f = maybe a f . listToMaybe
-- * Lookup of partial names functionality -- * Lookup of partial names functionality
-- | The priority of a match in a lookup result. -- | The priority of a match in a lookup result.
......
...@@ -39,6 +39,7 @@ module Test.Ganeti.HTools.Cluster (testHTools_Cluster) where ...@@ -39,6 +39,7 @@ module Test.Ganeti.HTools.Cluster (testHTools_Cluster) where
import Test.QuickCheck hiding (Result) import Test.QuickCheck hiding (Result)
import Control.Monad (liftM)
import qualified Data.IntMap as IntMap import qualified Data.IntMap as IntMap
import Data.Maybe import Data.Maybe
...@@ -168,7 +169,8 @@ prop_Alloc_sane inst = ...@@ -168,7 +169,8 @@ prop_Alloc_sane inst =
prop_CanTieredAlloc :: Property prop_CanTieredAlloc :: Property
prop_CanTieredAlloc = prop_CanTieredAlloc =
forAll (choose (2, 5)) $ \count -> forAll (choose (2, 5)) $ \count ->
forAll (genOnlineNode `suchThat` isNodeBig 4) $ \node -> forAll (liftM (Node.setPolicy Types.defIPolicy)
(genOnlineNode `suchThat` isNodeBig 4)) $ \node ->
forAll (genInstanceMaybeBiggerThanNode node) $ \inst -> forAll (genInstanceMaybeBiggerThanNode node) $ \inst ->
let nl = makeSmallCluster node count let nl = makeSmallCluster node count
il = Container.empty il = Container.empty
......
...@@ -48,6 +48,7 @@ import Control.Applicative ((<$>)) ...@@ -48,6 +48,7 @@ import Control.Applicative ((<$>))
import Control.Monad (liftM) import Control.Monad (liftM)
import Test.QuickCheck hiding (Result) import Test.QuickCheck hiding (Result)
import Test.Ganeti.TestHTools (nullISpec)
import Test.Ganeti.TestHelper import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon import Test.Ganeti.TestCommon
import Test.Ganeti.HTools.Types () import Test.Ganeti.HTools.Types ()
...@@ -61,25 +62,32 @@ import qualified Ganeti.HTools.Types as Types ...@@ -61,25 +62,32 @@ import qualified Ganeti.HTools.Types as Types
-- * Arbitrary instances -- * Arbitrary instances
-- | Generates a random instance with maximum disk/mem/cpu values. -- | Generates a random instance with maximum and minimum disk/mem/cpu values.
genInstanceSmallerThan :: Int -> Int -> Int -> Maybe Int -> genInstanceWithin :: Int -> Int -> Int -> Int
Gen Instance.Instance -> Int -> Int -> Int -> Maybe Int
genInstanceSmallerThan lim_mem lim_dsk lim_cpu lim_spin = do -> Gen Instance.Instance
genInstanceWithin min_mem min_dsk min_cpu min_spin
max_mem max_dsk max_cpu max_spin = do
name <- genFQDN name <- genFQDN
mem <- choose (0, lim_mem) mem <- choose (min_mem, max_mem)
dsk <- choose (0, lim_dsk) dsk <- choose (min_dsk, max_dsk)
run_st <- arbitrary run_st <- arbitrary
pn <- arbitrary pn <- arbitrary
sn <- arbitrary sn <- arbitrary
vcpus <- choose (0, lim_cpu) vcpus <- choose (min_cpu, max_cpu)
dt <- arbitrary dt <- arbitrary
spindles <- case lim_spin of spindles <- case max_spin of
Nothing -> genMaybe $ choose (0, maxSpindles) Nothing -> genMaybe $ choose (min_spin, maxSpindles)
Just ls -> liftM Just $ choose (0, ls) Just ls -> liftM Just $ choose (min_spin, ls)
let disk = Instance.Disk dsk spindles let disk = Instance.Disk dsk spindles
return $ Instance.create return $ Instance.create
name mem dsk [disk] vcpus run_st [] True pn sn dt 1 [] name mem dsk [disk] vcpus run_st [] True pn sn dt 1 []
-- | Generate an instance with maximum disk/mem/cpu values.
genInstanceSmallerThan :: Int -> Int -> Int -> Maybe Int
-> Gen Instance.Instance
genInstanceSmallerThan = genInstanceWithin 0 0 0 0
-- | Generates an instance smaller than a node. -- | Generates an instance smaller than a node.
genInstanceSmallerThanNode :: Node.Node -> Gen Instance.Instance genInstanceSmallerThanNode :: Node.Node -> Gen Instance.Instance
genInstanceSmallerThanNode node = genInstanceSmallerThanNode node =
...@@ -91,12 +99,20 @@ genInstanceSmallerThanNode node = ...@@ -91,12 +99,20 @@ genInstanceSmallerThanNode node =
else Nothing) else Nothing)
-- | Generates an instance possibly bigger than a node. -- | Generates an instance possibly bigger than a node.
-- In any case, that instance will be bigger than the node's ipolicy's lower
-- bound.
genInstanceMaybeBiggerThanNode :: Node.Node -> Gen Instance.Instance genInstanceMaybeBiggerThanNode :: Node.Node -> Gen Instance.Instance
genInstanceMaybeBiggerThanNode node = genInstanceMaybeBiggerThanNode node =
genInstanceSmallerThan (Node.availMem node + Types.unitMem * 2) let minISpec = runListHead nullISpec Types.minMaxISpecsMinSpec
(Node.availDisk node + Types.unitDsk * 3) . Types.iPolicyMinMaxISpecs $ Node.iPolicy node
(Node.availCpu node + Types.unitCpu * 4) in genInstanceWithin (Types.iSpecMemorySize minISpec)
(if Node.exclStorage node (Types.iSpecDiskSize minISpec)
(Types.iSpecCpuCount minISpec)
(Types.iSpecSpindleUse minISpec)
(Node.availMem node + Types.unitMem * 2)
(Node.availDisk node + Types.unitDsk * 3)
(Node.availCpu node + Types.unitCpu * 4)
(if Node.exclStorage node
then Just $ Node.fSpindles node + then Just $ Node.fSpindles node +
Types.unitSpindle * 5 Types.unitSpindle * 5
else Nothing) else Nothing)
......
...@@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
module Test.Ganeti.TestHTools module Test.Ganeti.TestHTools
( nullIPolicy ( nullIPolicy
, nullISpec
, defGroup , defGroup
, defGroupList , defGroupList
, defGroupAssoc , defGroupAssoc
...@@ -58,17 +59,21 @@ import qualified Ganeti.HTools.Types as Types ...@@ -58,17 +59,21 @@ import qualified Ganeti.HTools.Types as Types
-- * Helpers -- * Helpers
-- | An ISpec with 0 resources.
nullISpec :: Types.ISpec
nullISpec = Types.ISpec { Types.iSpecMemorySize = 0
, Types.iSpecCpuCount = 0
, Types.iSpecDiskSize = 0
, Types.iSpecDiskCount = 0
, Types.iSpecNicCount = 0
, Types.iSpecSpindleUse = 0
}
-- | Null iPolicy, and by null we mean very liberal. -- | Null iPolicy, and by null we mean very liberal.
nullIPolicy :: Types.IPolicy nullIPolicy :: Types.IPolicy
nullIPolicy = Types.IPolicy nullIPolicy = Types.IPolicy
{ Types.iPolicyMinMaxISpecs = [Types.MinMaxISpecs { Types.iPolicyMinMaxISpecs = [Types.MinMaxISpecs
{ Types.minMaxISpecsMinSpec = Types.ISpec { Types.iSpecMemorySize = 0 { Types.minMaxISpecsMinSpec = nullISpec
, Types.iSpecCpuCount = 0
, Types.iSpecDiskSize = 0
, Types.iSpecDiskCount = 0
, Types.iSpecNicCount = 0
, Types.iSpecSpindleUse = 0
}
, Types.minMaxISpecsMaxSpec = Types.ISpec , Types.minMaxISpecsMaxSpec = Types.ISpec
{ Types.iSpecMemorySize = maxBound { Types.iSpecMemorySize = maxBound
, Types.iSpecCpuCount = maxBound , Types.iSpecCpuCount = maxBound
......
...@@ -461,7 +461,7 @@ class MoveDestExecutor(object): ...@@ -461,7 +461,7 @@ class MoveDestExecutor(object):
mrt.move.dest_disk_template, mrt.move.dest_disk_template,
mrt.src_instinfo, mrt.src_expinfo, mrt.src_instinfo, mrt.src_expinfo,
mrt.move.hvparams, mrt.move.beparams, mrt.move.hvparams, mrt.move.beparams,
mrt.move.beparams, mrt.move.nics) mrt.move.osparams, mrt.move.nics)
mrt.PollJob(dest_client, job_id, mrt.PollJob(dest_client, job_id,
remote_import_fn=compat.partial(self._SetImportInfo, mrt)) remote_import_fn=compat.partial(self._SetImportInfo, mrt))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment