Revision 7dbe4c72

b/src/Ganeti/HTools/CLI.hs
52 52
  , oExInst
53 53
  , oExTags
54 54
  , oExecJobs
55
  , oForce
55 56
  , oGroup
56 57
  , oIAllocSrc
57 58
  , oInstMoves
......
117 118
  , optExInst      :: [String]       -- ^ Instances to be excluded
118 119
  , optExTags      :: Maybe [String] -- ^ Tags to use for exclusion
119 120
  , optExecJobs    :: Bool           -- ^ Execute the commands via Luxi
121
  , optForce       :: Bool           -- ^ Force the execution
120 122
  , optGroup       :: Maybe GroupID  -- ^ The UUID of the group to process
121 123
  , optIAllocSrc   :: Maybe FilePath -- ^ The iallocation spec
122 124
  , optSelInst     :: [String]       -- ^ Instances to be excluded
......
163 165
  , optExInst      = []
164 166
  , optExTags      = Nothing
165 167
  , optExecJobs    = False
168
  , optForce       = False
166 169
  , optGroup       = Nothing
167 170
  , optIAllocSrc   = Nothing
168 171
  , optSelInst     = []
......
319 322
   \ it for data gathering)",
320 323
   OptComplNone)
321 324

  
325
oForce :: OptType
326
oForce =
327
  (Option "f" ["force"]
328
   (NoArg (\ opts -> Ok opts {optForce = True}))
329
   "force the execution of this program, even if warnings would\
330
   \ otherwise prevent it",
331
   OptComplNone)
332

  
322 333
oGroup :: OptType
323 334
oGroup =
324 335
  (Option "G" ["group"]
b/src/Ganeti/HTools/Program/Hroller.hs
61 61
    , oNoHeaders
62 62
    , oSaveCluster
63 63
    , oGroup
64
    , oForce
64 65
    ]
65 66

  
66 67
-- | The list of arguments supported by the program.
......
112 113
  unless (null args) $ exitErr "This program doesn't take any arguments."
113 114

  
114 115
  let verbose = optVerbose opts
116
      maybeExit = if optForce opts then warn else exitErr
115 117

  
116 118
  -- Load cluster data. The last two arguments, cluster tags and ipolicy, are
117 119
  -- currently not used by this tool.
118 120
  ini_cdata@(ClusterData gl fixed_nl ilf _ _) <- loadExternalData opts
119 121

  
122
  let master_names = map Node.name . filter Node.isMaster . IntMap.elems $
123
                     fixed_nl
124
  case master_names of
125
    [] -> maybeExit "No master node found (maybe not supported by backend)."
126
    [ _ ] -> return ()
127
    _ -> exitErr $ "Found more than one master node: " ++  show master_names
128

  
120 129
  nlf <- setNodeStatus opts fixed_nl
121 130

  
122 131
  maybeSaveData (optSaveCluster opts) "original" "before hroller run" ini_cdata
b/src/Ganeti/Utils.hs
49 49
  , getCurrentTimeUSec
50 50
  , clockTimeToString
51 51
  , chompPrefix
52
  , warn
52 53
  , wrap
53 54
  , trim
54 55
  , defaultHead
......
247 248
exitUnless :: Bool -> String -> IO ()
248 249
exitUnless cond = exitWhen (not cond)
249 250

  
251
-- | Print a warning, but do not exit.
252
warn :: String -> IO ()
253
warn = hPutStrLn stderr . (++) "Warning: "
254

  
250 255
-- | Helper for 'niceSort'. Computes the key element for a given string.
251 256
extractKey :: [Either Integer String]  -- ^ Current (partial) key, reversed
252 257
           -> String                   -- ^ Remaining string
b/test/hs/shelltests/htools-invalid.test
52 52
Error: This program doesn't take any arguments.
53 53
>>>=1
54 54

  
55
# hroller fails to build a graph for an empty cluster
55
# hroller should notice the absence of a master node
56 56
./test/hs/hroller -t$TESTDATA_DIR/empty-cluster.data
57
>>>2
58
Error: Cannot create node graph
57
>>>2/Error: No master node found/
58
>>>=1
59

  
60
# hroller fails to build a graph for an empty cluster
61
./test/hs/hroller -f -t$TESTDATA_DIR/empty-cluster.data
62
>>>2/Error: Cannot create node graph/
59 63
>>>=1
60 64

  
61 65
# hbal doesn't accept invalid priority
b/test/hs/shelltests/htools-single-group.test
28 28
>>> /HCHECK_INIT_CLUSTER_NEED_REBALANCE=0/
29 29
>>>= 0
30 30

  
31
# FIXME: remove option -f once the text backend supports indicating
32
#        the master node
31 33
# hroller should be able to print the solution
32
./test/hs/hroller -t$T/simu-onegroup.tiered
34
./test/hs/hroller -f -t$T/simu-onegroup.tiered
33 35
>>>= 0
34 36

  
35 37
# hroller should be able to print the solution, in verbose mode as well
36
./test/hs/hroller -t$T/simu-onegroup.tiered -v -v
38
./test/hs/hroller -f -t$T/simu-onegroup.tiered -v -v
37 39
>>>= 0

Also available in: Unified diff