root / htest / Test / Ganeti / TestHTools.hs @ da1dcce1
History | View | Annotate | Download (4.5 kB)
1 | e1ee7d5a | Iustin Pop | {-# OPTIONS_GHC -fno-warn-orphans #-} |
---|---|---|---|
2 | e1ee7d5a | Iustin Pop | |
3 | e1ee7d5a | Iustin Pop | {-| Common functionality for htools-related unittests. |
4 | e1ee7d5a | Iustin Pop | |
5 | e1ee7d5a | Iustin Pop | -} |
6 | e1ee7d5a | Iustin Pop | |
7 | e1ee7d5a | Iustin Pop | {- |
8 | e1ee7d5a | Iustin Pop | |
9 | e1ee7d5a | Iustin Pop | Copyright (C) 2009, 2010, 2011, 2012 Google Inc. |
10 | e1ee7d5a | Iustin Pop | |
11 | e1ee7d5a | Iustin Pop | This program is free software; you can redistribute it and/or modify |
12 | e1ee7d5a | Iustin Pop | it under the terms of the GNU General Public License as published by |
13 | e1ee7d5a | Iustin Pop | the Free Software Foundation; either version 2 of the License, or |
14 | e1ee7d5a | Iustin Pop | (at your option) any later version. |
15 | e1ee7d5a | Iustin Pop | |
16 | e1ee7d5a | Iustin Pop | This program is distributed in the hope that it will be useful, but |
17 | e1ee7d5a | Iustin Pop | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | e1ee7d5a | Iustin Pop | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 | e1ee7d5a | Iustin Pop | General Public License for more details. |
20 | e1ee7d5a | Iustin Pop | |
21 | e1ee7d5a | Iustin Pop | You should have received a copy of the GNU General Public License |
22 | e1ee7d5a | Iustin Pop | along with this program; if not, write to the Free Software |
23 | e1ee7d5a | Iustin Pop | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
24 | e1ee7d5a | Iustin Pop | 02110-1301, USA. |
25 | e1ee7d5a | Iustin Pop | |
26 | e1ee7d5a | Iustin Pop | -} |
27 | e1ee7d5a | Iustin Pop | |
28 | e1ee7d5a | Iustin Pop | module Test.Ganeti.TestHTools where |
29 | e1ee7d5a | Iustin Pop | |
30 | e1ee7d5a | Iustin Pop | import qualified Data.Map as Map |
31 | e1ee7d5a | Iustin Pop | |
32 | e1ee7d5a | Iustin Pop | import Test.Ganeti.TestCommon |
33 | e1ee7d5a | Iustin Pop | |
34 | e1ee7d5a | Iustin Pop | import qualified Ganeti.Constants as C |
35 | e1ee7d5a | Iustin Pop | import qualified Ganeti.HTools.Container as Container |
36 | e1ee7d5a | Iustin Pop | import qualified Ganeti.HTools.Group as Group |
37 | e1ee7d5a | Iustin Pop | import qualified Ganeti.HTools.Instance as Instance |
38 | e1ee7d5a | Iustin Pop | import qualified Ganeti.HTools.Loader as Loader |
39 | e1ee7d5a | Iustin Pop | import qualified Ganeti.HTools.Node as Node |
40 | e1ee7d5a | Iustin Pop | import qualified Ganeti.HTools.Types as Types |
41 | e1ee7d5a | Iustin Pop | |
42 | e1ee7d5a | Iustin Pop | -- * Helpers |
43 | e1ee7d5a | Iustin Pop | |
44 | e1ee7d5a | Iustin Pop | -- | Null iPolicy, and by null we mean very liberal. |
45 | e1ee7d5a | Iustin Pop | nullIPolicy :: Types.IPolicy |
46 | e1ee7d5a | Iustin Pop | nullIPolicy = Types.IPolicy |
47 | e1ee7d5a | Iustin Pop | { Types.iPolicyMinSpec = Types.ISpec { Types.iSpecMemorySize = 0 |
48 | e1ee7d5a | Iustin Pop | , Types.iSpecCpuCount = 0 |
49 | e1ee7d5a | Iustin Pop | , Types.iSpecDiskSize = 0 |
50 | e1ee7d5a | Iustin Pop | , Types.iSpecDiskCount = 0 |
51 | e1ee7d5a | Iustin Pop | , Types.iSpecNicCount = 0 |
52 | e1ee7d5a | Iustin Pop | , Types.iSpecSpindleUse = 0 |
53 | e1ee7d5a | Iustin Pop | } |
54 | e1ee7d5a | Iustin Pop | , Types.iPolicyMaxSpec = Types.ISpec { Types.iSpecMemorySize = maxBound |
55 | e1ee7d5a | Iustin Pop | , Types.iSpecCpuCount = maxBound |
56 | e1ee7d5a | Iustin Pop | , Types.iSpecDiskSize = maxBound |
57 | e1ee7d5a | Iustin Pop | , Types.iSpecDiskCount = C.maxDisks |
58 | e1ee7d5a | Iustin Pop | , Types.iSpecNicCount = C.maxNics |
59 | e1ee7d5a | Iustin Pop | , Types.iSpecSpindleUse = maxBound |
60 | e1ee7d5a | Iustin Pop | } |
61 | e1ee7d5a | Iustin Pop | , Types.iPolicyStdSpec = Types.ISpec { Types.iSpecMemorySize = Types.unitMem |
62 | e1ee7d5a | Iustin Pop | , Types.iSpecCpuCount = Types.unitCpu |
63 | e1ee7d5a | Iustin Pop | , Types.iSpecDiskSize = Types.unitDsk |
64 | e1ee7d5a | Iustin Pop | , Types.iSpecDiskCount = 1 |
65 | e1ee7d5a | Iustin Pop | , Types.iSpecNicCount = 1 |
66 | e1ee7d5a | Iustin Pop | , Types.iSpecSpindleUse = 1 |
67 | e1ee7d5a | Iustin Pop | } |
68 | e1ee7d5a | Iustin Pop | , Types.iPolicyDiskTemplates = [minBound..maxBound] |
69 | e1ee7d5a | Iustin Pop | , Types.iPolicyVcpuRatio = maxVcpuRatio -- somewhat random value, high |
70 | e1ee7d5a | Iustin Pop | -- enough to not impact us |
71 | e1ee7d5a | Iustin Pop | , Types.iPolicySpindleRatio = maxSpindleRatio |
72 | e1ee7d5a | Iustin Pop | } |
73 | e1ee7d5a | Iustin Pop | |
74 | e1ee7d5a | Iustin Pop | defGroup :: Group.Group |
75 | e1ee7d5a | Iustin Pop | defGroup = flip Group.setIdx 0 $ |
76 | e1ee7d5a | Iustin Pop | Group.create "default" Types.defaultGroupID Types.AllocPreferred |
77 | 659d769d | Dato Simó | nullIPolicy [] |
78 | e1ee7d5a | Iustin Pop | |
79 | e1ee7d5a | Iustin Pop | defGroupList :: Group.List |
80 | e1ee7d5a | Iustin Pop | defGroupList = Container.fromList [(Group.idx defGroup, defGroup)] |
81 | e1ee7d5a | Iustin Pop | |
82 | e1ee7d5a | Iustin Pop | defGroupAssoc :: Map.Map String Types.Gdx |
83 | e1ee7d5a | Iustin Pop | defGroupAssoc = Map.singleton (Group.uuid defGroup) (Group.idx defGroup) |
84 | e1ee7d5a | Iustin Pop | |
85 | e1ee7d5a | Iustin Pop | -- | Create an instance given its spec. |
86 | e1ee7d5a | Iustin Pop | createInstance :: Int -> Int -> Int -> Instance.Instance |
87 | e1ee7d5a | Iustin Pop | createInstance mem dsk vcpus = |
88 | e1ee7d5a | Iustin Pop | Instance.create "inst-unnamed" mem dsk vcpus Types.Running [] True (-1) (-1) |
89 | e1ee7d5a | Iustin Pop | Types.DTDrbd8 1 |
90 | e1ee7d5a | Iustin Pop | |
91 | e1ee7d5a | Iustin Pop | -- | Create a small cluster by repeating a node spec. |
92 | e1ee7d5a | Iustin Pop | makeSmallCluster :: Node.Node -> Int -> Node.List |
93 | e1ee7d5a | Iustin Pop | makeSmallCluster node count = |
94 | e1ee7d5a | Iustin Pop | let origname = Node.name node |
95 | e1ee7d5a | Iustin Pop | origalias = Node.alias node |
96 | e1ee7d5a | Iustin Pop | nodes = map (\idx -> node { Node.name = origname ++ "-" ++ show idx |
97 | e1ee7d5a | Iustin Pop | , Node.alias = origalias ++ "-" ++ show idx }) |
98 | e1ee7d5a | Iustin Pop | [1..count] |
99 | e1ee7d5a | Iustin Pop | fn = flip Node.buildPeers Container.empty |
100 | e1ee7d5a | Iustin Pop | namelst = map (\n -> (Node.name n, fn n)) nodes |
101 | e1ee7d5a | Iustin Pop | (_, nlst) = Loader.assignIndices namelst |
102 | e1ee7d5a | Iustin Pop | in nlst |
103 | e1ee7d5a | Iustin Pop | |
104 | e1ee7d5a | Iustin Pop | -- | Update an instance to be smaller than a node. |
105 | e1ee7d5a | Iustin Pop | setInstanceSmallerThanNode :: Node.Node |
106 | e1ee7d5a | Iustin Pop | -> Instance.Instance -> Instance.Instance |
107 | e1ee7d5a | Iustin Pop | setInstanceSmallerThanNode node inst = |
108 | e1ee7d5a | Iustin Pop | inst { Instance.mem = Node.availMem node `div` 2 |
109 | e1ee7d5a | Iustin Pop | , Instance.dsk = Node.availDisk node `div` 2 |
110 | e1ee7d5a | Iustin Pop | , Instance.vcpus = Node.availCpu node `div` 2 |
111 | e1ee7d5a | Iustin Pop | } |