| 1 |
{-# LANGUAGE TemplateHaskell #-} |
| 2 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
| 3 |
|
| 4 |
{-| Unittests for ganeti-htools. |
| 5 |
|
| 6 |
-} |
| 7 |
|
| 8 |
{- |
| 9 |
|
| 10 |
Copyright (C) 2009, 2010, 2011, 2012, 2013 Google Inc. |
| 11 |
All rights reserved. |
| 12 |
|
| 13 |
Redistribution and use in source and binary forms, with or without |
| 14 |
modification, are permitted provided that the following conditions are |
| 15 |
met: |
| 16 |
|
| 17 |
1. Redistributions of source code must retain the above copyright notice, |
| 18 |
this list of conditions and the following disclaimer. |
| 19 |
|
| 20 |
2. Redistributions in binary form must reproduce the above copyright |
| 21 |
notice, this list of conditions and the following disclaimer in the |
| 22 |
documentation and/or other materials provided with the distribution. |
| 23 |
|
| 24 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 25 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 26 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 27 |
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 28 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 29 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 30 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 31 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 32 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 33 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 34 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 |
|
| 36 |
-} |
| 37 |
|
| 38 |
module Test.Ganeti.OpCodes |
| 39 |
( testOpCodes |
| 40 |
, OpCodes.OpCode(..) |
| 41 |
) where |
| 42 |
|
| 43 |
import Test.HUnit as HUnit |
| 44 |
import Test.QuickCheck as QuickCheck |
| 45 |
|
| 46 |
import Control.Monad |
| 47 |
import Data.Char |
| 48 |
import Data.List |
| 49 |
import Data.Ratio ((%)) |
| 50 |
import qualified Data.Map as Map |
| 51 |
import qualified Text.JSON as J |
| 52 |
import Text.Printf (printf) |
| 53 |
|
| 54 |
import Test.Ganeti.Objects () |
| 55 |
import Test.Ganeti.Query.Language () |
| 56 |
import Test.Ganeti.TestHelper |
| 57 |
import Test.Ganeti.TestCommon |
| 58 |
import Test.Ganeti.Types (genReasonTrail) |
| 59 |
|
| 60 |
import Ganeti.BasicTypes |
| 61 |
import qualified Ganeti.Constants as C |
| 62 |
import qualified Ganeti.ConstantUtils as CU |
| 63 |
import qualified Ganeti.OpCodes as OpCodes |
| 64 |
import Ganeti.Types |
| 65 |
import Ganeti.OpParams |
| 66 |
import Ganeti.JSON |
| 67 |
|
| 68 |
{-# ANN module "HLint: ignore Use camelCase" #-} |
| 69 |
|
| 70 |
-- * Arbitrary instances |
| 71 |
|
| 72 |
arbitraryOpTagsGet :: Gen OpCodes.OpCode |
| 73 |
arbitraryOpTagsGet = do |
| 74 |
kind <- arbitrary |
| 75 |
OpCodes.OpTagsSet kind <$> genTags <*> genOpCodesTagName kind |
| 76 |
|
| 77 |
arbitraryOpTagsSet :: Gen OpCodes.OpCode |
| 78 |
arbitraryOpTagsSet = do |
| 79 |
kind <- arbitrary |
| 80 |
OpCodes.OpTagsSet kind <$> genTags <*> genOpCodesTagName kind |
| 81 |
|
| 82 |
arbitraryOpTagsDel :: Gen OpCodes.OpCode |
| 83 |
arbitraryOpTagsDel = do |
| 84 |
kind <- arbitrary |
| 85 |
OpCodes.OpTagsDel kind <$> genTags <*> genOpCodesTagName kind |
| 86 |
|
| 87 |
$(genArbitrary ''OpCodes.ReplaceDisksMode) |
| 88 |
|
| 89 |
$(genArbitrary ''DiskAccess) |
| 90 |
|
| 91 |
instance Arbitrary OpCodes.DiskIndex where |
| 92 |
arbitrary = choose (0, C.maxDisks - 1) >>= OpCodes.mkDiskIndex |
| 93 |
|
| 94 |
instance Arbitrary INicParams where |
| 95 |
arbitrary = INicParams <$> genMaybe genNameNE <*> genMaybe genName <*> |
| 96 |
genMaybe genNameNE <*> genMaybe genNameNE <*> |
| 97 |
genMaybe genNameNE <*> genMaybe genName <*> |
| 98 |
genMaybe genNameNE <*> genMaybe genNameNE |
| 99 |
|
| 100 |
instance Arbitrary IDiskParams where |
| 101 |
arbitrary = IDiskParams <$> arbitrary <*> arbitrary <*> |
| 102 |
genMaybe genNameNE <*> genMaybe genNameNE <*> |
| 103 |
genMaybe genNameNE <*> genMaybe genNameNE <*> |
| 104 |
genMaybe genNameNE <*> arbitrary <*> |
| 105 |
genMaybe genNameNE <*> genAndRestArguments |
| 106 |
|
| 107 |
instance Arbitrary RecreateDisksInfo where |
| 108 |
arbitrary = oneof [ pure RecreateDisksAll |
| 109 |
, RecreateDisksIndices <$> arbitrary |
| 110 |
, RecreateDisksParams <$> arbitrary |
| 111 |
] |
| 112 |
|
| 113 |
instance Arbitrary DdmOldChanges where |
| 114 |
arbitrary = oneof [ DdmOldIndex <$> arbitrary |
| 115 |
, DdmOldMod <$> arbitrary |
| 116 |
] |
| 117 |
|
| 118 |
instance (Arbitrary a) => Arbitrary (SetParamsMods a) where |
| 119 |
arbitrary = oneof [ pure SetParamsEmpty |
| 120 |
, SetParamsDeprecated <$> arbitrary |
| 121 |
, SetParamsNew <$> arbitrary |
| 122 |
] |
| 123 |
|
| 124 |
instance Arbitrary ExportTarget where |
| 125 |
arbitrary = oneof [ ExportTargetLocal <$> genNodeNameNE |
| 126 |
, ExportTargetRemote <$> pure [] |
| 127 |
] |
| 128 |
|
| 129 |
arbitraryDataCollector :: Gen (GenericContainer String Bool) |
| 130 |
arbitraryDataCollector = do |
| 131 |
els <- listOf . elements $ CU.toList C.dataCollectorNames |
| 132 |
activation <- vector $ length els |
| 133 |
return . GenericContainer . Map.fromList $ zip els activation |
| 134 |
|
| 135 |
arbitraryDataCollectorInterval :: Gen (Maybe (GenericContainer String Int)) |
| 136 |
arbitraryDataCollectorInterval = do |
| 137 |
els <- listOf . elements $ CU.toList C.dataCollectorNames |
| 138 |
intervals <- vector $ length els |
| 139 |
genMaybe . return . containerFromList $ zip els intervals |
| 140 |
|
| 141 |
{- | |
| 142 |
Choose numbers across orders of magnitudes |
| 143 |
in order to detect inconsistencies |
| 144 |
in the choice between fix point and scientific formatting. |
| 145 |
Also choose equally between finite and periodic decimal fractions. |
| 146 |
-} |
| 147 |
arbitraryDuration :: Gen Double |
| 148 |
arbitraryDuration = |
| 149 |
oneof $ |
| 150 |
(do mantissa <- choose (0, 1000) |
| 151 |
expon <- choose (0,12::Int) |
| 152 |
return $ fromRational $ mantissa % 10^expon) : |
| 153 |
(do numerator <- choose (0, 1000) |
| 154 |
denominator <- choose (1, 1000) |
| 155 |
expon <- choose (-40,4::Int) |
| 156 |
return $ fromRational (numerator % denominator) * 2^^expon) : |
| 157 |
[] |
| 158 |
|
| 159 |
instance Arbitrary OpCodes.OpCode where |
| 160 |
arbitrary = do |
| 161 |
op_id <- elements OpCodes.allOpIDs |
| 162 |
case op_id of |
| 163 |
"OP_TEST_DELAY" -> |
| 164 |
OpCodes.OpTestDelay <$> arbitraryDuration <*> arbitrary <*> |
| 165 |
genNodeNamesNE <*> return Nothing <*> arbitrary <*> arbitrary <*> |
| 166 |
arbitrary |
| 167 |
"OP_INSTANCE_REPLACE_DISKS" -> |
| 168 |
OpCodes.OpInstanceReplaceDisks <$> genFQDN <*> return Nothing <*> |
| 169 |
arbitrary <*> arbitrary <*> arbitrary <*> genDiskIndices <*> |
| 170 |
genMaybe genNodeNameNE <*> return Nothing <*> genMaybe genNameNE |
| 171 |
"OP_INSTANCE_FAILOVER" -> |
| 172 |
OpCodes.OpInstanceFailover <$> genFQDN <*> return Nothing <*> |
| 173 |
arbitrary <*> arbitrary <*> genMaybe genNodeNameNE <*> |
| 174 |
return Nothing <*> arbitrary <*> arbitrary <*> genMaybe genNameNE |
| 175 |
"OP_INSTANCE_MIGRATE" -> |
| 176 |
OpCodes.OpInstanceMigrate <$> genFQDN <*> return Nothing <*> |
| 177 |
arbitrary <*> arbitrary <*> genMaybe genNodeNameNE <*> |
| 178 |
return Nothing <*> arbitrary <*> arbitrary <*> arbitrary <*> |
| 179 |
genMaybe genNameNE <*> arbitrary <*> arbitrary |
| 180 |
"OP_TAGS_GET" -> |
| 181 |
arbitraryOpTagsGet |
| 182 |
"OP_TAGS_SEARCH" -> |
| 183 |
OpCodes.OpTagsSearch <$> genNameNE |
| 184 |
"OP_TAGS_SET" -> |
| 185 |
arbitraryOpTagsSet |
| 186 |
"OP_TAGS_DEL" -> |
| 187 |
arbitraryOpTagsDel |
| 188 |
"OP_CLUSTER_POST_INIT" -> pure OpCodes.OpClusterPostInit |
| 189 |
"OP_CLUSTER_RENEW_CRYPTO" -> OpCodes.OpClusterRenewCrypto |
| 190 |
<$> arbitrary -- Node SSL certificates |
| 191 |
<*> arbitrary -- renew_ssh_keys |
| 192 |
<*> arbitrary -- ssh_key_type |
| 193 |
<*> arbitrary -- ssh_key_bits |
| 194 |
<*> arbitrary -- verbose |
| 195 |
<*> arbitrary -- debug |
| 196 |
"OP_CLUSTER_DESTROY" -> pure OpCodes.OpClusterDestroy |
| 197 |
"OP_CLUSTER_QUERY" -> pure OpCodes.OpClusterQuery |
| 198 |
"OP_CLUSTER_VERIFY" -> |
| 199 |
OpCodes.OpClusterVerify <$> arbitrary <*> arbitrary <*> |
| 200 |
genListSet Nothing <*> genListSet Nothing <*> arbitrary <*> |
| 201 |
genMaybe genNameNE <*> arbitrary |
| 202 |
"OP_CLUSTER_VERIFY_CONFIG" -> |
| 203 |
OpCodes.OpClusterVerifyConfig <$> arbitrary <*> arbitrary <*> |
| 204 |
genListSet Nothing <*> arbitrary |
| 205 |
"OP_CLUSTER_VERIFY_GROUP" -> |
| 206 |
OpCodes.OpClusterVerifyGroup <$> genNameNE <*> arbitrary <*> |
| 207 |
arbitrary <*> genListSet Nothing <*> genListSet Nothing <*> |
| 208 |
arbitrary <*> arbitrary |
| 209 |
"OP_CLUSTER_VERIFY_DISKS" -> |
| 210 |
OpCodes.OpClusterVerifyDisks <$> genMaybe genNameNE <*> arbitrary |
| 211 |
"OP_GROUP_VERIFY_DISKS" -> |
| 212 |
OpCodes.OpGroupVerifyDisks <$> genNameNE <*> arbitrary |
| 213 |
"OP_CLUSTER_REPAIR_DISK_SIZES" -> |
| 214 |
OpCodes.OpClusterRepairDiskSizes <$> genNodeNamesNE |
| 215 |
"OP_CLUSTER_CONFIG_QUERY" -> |
| 216 |
OpCodes.OpClusterConfigQuery <$> genFieldsNE |
| 217 |
"OP_CLUSTER_RENAME" -> |
| 218 |
OpCodes.OpClusterRename <$> genNameNE |
| 219 |
"OP_CLUSTER_SET_PARAMS" -> |
| 220 |
OpCodes.OpClusterSetParams |
| 221 |
<$> arbitrary -- force |
| 222 |
<*> emptyMUD -- hv_state |
| 223 |
<*> emptyMUD -- disk_state |
| 224 |
<*> genMaybe genName -- vg_name |
| 225 |
<*> genMaybe arbitrary -- enabled_hypervisors |
| 226 |
<*> genMaybe genEmptyContainer -- hvparams |
| 227 |
<*> emptyMUD -- beparams |
| 228 |
<*> genMaybe genEmptyContainer -- os_hvp |
| 229 |
<*> genMaybe genEmptyContainer -- osparams |
| 230 |
<*> genMaybe genEmptyContainer -- osparams_private_cluster |
| 231 |
<*> genMaybe genEmptyContainer -- diskparams |
| 232 |
<*> genMaybe arbitrary -- candidate_pool_size |
| 233 |
<*> genMaybe arbitrary -- max_running_jobs |
| 234 |
<*> genMaybe arbitrary -- max_tracked_jobs |
| 235 |
<*> arbitrary -- uid_pool |
| 236 |
<*> arbitrary -- add_uids |
| 237 |
<*> arbitrary -- remove_uids |
| 238 |
<*> arbitrary -- maintain_node_health |
| 239 |
<*> arbitrary -- prealloc_wipe_disks |
| 240 |
<*> arbitrary -- nicparams |
| 241 |
<*> emptyMUD -- ndparams |
| 242 |
<*> emptyMUD -- ipolicy |
| 243 |
<*> genMaybe genPrintableAsciiString |
| 244 |
-- drbd_helper |
| 245 |
<*> genMaybe genPrintableAsciiString |
| 246 |
-- default_iallocator |
| 247 |
<*> emptyMUD -- default_iallocator_params |
| 248 |
<*> genMaybe genMacPrefix -- mac_prefix |
| 249 |
<*> genMaybe genPrintableAsciiString |
| 250 |
-- master_netdev |
| 251 |
<*> arbitrary -- master_netmask |
| 252 |
<*> genMaybe (listOf genPrintableAsciiStringNE) |
| 253 |
-- reserved_lvs |
| 254 |
<*> genMaybe (listOf ((,) <$> arbitrary |
| 255 |
<*> genPrintableAsciiStringNE)) |
| 256 |
-- hidden_os |
| 257 |
<*> genMaybe (listOf ((,) <$> arbitrary |
| 258 |
<*> genPrintableAsciiStringNE)) |
| 259 |
-- blacklisted_os |
| 260 |
<*> arbitrary -- use_external_mip_script |
| 261 |
<*> arbitrary -- enabled_disk_templates |
| 262 |
<*> arbitrary -- modify_etc_hosts |
| 263 |
<*> genMaybe genName -- file_storage_dir |
| 264 |
<*> genMaybe genName -- shared_file_storage_dir |
| 265 |
<*> genMaybe genName -- gluster_file_storage_dir |
| 266 |
<*> genMaybe genPrintableAsciiString |
| 267 |
-- install_image |
| 268 |
<*> genMaybe genPrintableAsciiString |
| 269 |
-- instance_communication_network |
| 270 |
<*> genMaybe genPrintableAsciiString |
| 271 |
-- zeroing_image |
| 272 |
<*> genMaybe (listOf genPrintableAsciiStringNE) |
| 273 |
-- compression_tools |
| 274 |
<*> arbitrary -- enabled_user_shutdown |
| 275 |
<*> genMaybe arbitraryDataCollector -- enabled_data_collectors |
| 276 |
<*> arbitraryDataCollectorInterval -- data_collector_interval |
| 277 |
"OP_CLUSTER_REDIST_CONF" -> pure OpCodes.OpClusterRedistConf |
| 278 |
"OP_CLUSTER_ACTIVATE_MASTER_IP" -> |
| 279 |
pure OpCodes.OpClusterActivateMasterIp |
| 280 |
"OP_CLUSTER_DEACTIVATE_MASTER_IP" -> |
| 281 |
pure OpCodes.OpClusterDeactivateMasterIp |
| 282 |
"OP_QUERY" -> |
| 283 |
OpCodes.OpQuery <$> arbitrary <*> arbitrary <*> genNamesNE <*> |
| 284 |
pure Nothing |
| 285 |
"OP_QUERY_FIELDS" -> |
| 286 |
OpCodes.OpQueryFields <$> arbitrary <*> genMaybe genNamesNE |
| 287 |
"OP_OOB_COMMAND" -> |
| 288 |
OpCodes.OpOobCommand <$> genNodeNamesNE <*> return Nothing <*> |
| 289 |
arbitrary <*> arbitrary <*> arbitrary <*> |
| 290 |
(arbitrary `suchThat` (>0)) |
| 291 |
"OP_NODE_REMOVE" -> |
| 292 |
OpCodes.OpNodeRemove <$> genNodeNameNE <*> return Nothing |
| 293 |
"OP_NODE_ADD" -> |
| 294 |
OpCodes.OpNodeAdd <$> genNodeNameNE <*> emptyMUD <*> emptyMUD <*> |
| 295 |
genMaybe genNameNE <*> genMaybe genNameNE <*> arbitrary <*> |
| 296 |
genMaybe genNameNE <*> arbitrary <*> arbitrary <*> emptyMUD <*> |
| 297 |
arbitrary |
| 298 |
"OP_NODE_QUERYVOLS" -> |
| 299 |
OpCodes.OpNodeQueryvols <$> genNamesNE <*> genNodeNamesNE |
| 300 |
"OP_NODE_QUERY_STORAGE" -> |
| 301 |
OpCodes.OpNodeQueryStorage <$> genNamesNE <*> arbitrary <*> |
| 302 |
genNodeNamesNE <*> genMaybe genNameNE |
| 303 |
"OP_NODE_MODIFY_STORAGE" -> |
| 304 |
OpCodes.OpNodeModifyStorage <$> genNodeNameNE <*> return Nothing <*> |
| 305 |
arbitrary <*> genMaybe genNameNE <*> pure emptyJSObject |
| 306 |
"OP_REPAIR_NODE_STORAGE" -> |
| 307 |
OpCodes.OpRepairNodeStorage <$> genNodeNameNE <*> return Nothing <*> |
| 308 |
arbitrary <*> genMaybe genNameNE <*> arbitrary |
| 309 |
"OP_NODE_SET_PARAMS" -> |
| 310 |
OpCodes.OpNodeSetParams <$> genNodeNameNE <*> return Nothing <*> |
| 311 |
arbitrary <*> emptyMUD <*> emptyMUD <*> arbitrary <*> arbitrary <*> |
| 312 |
arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> |
| 313 |
genMaybe genNameNE <*> emptyMUD <*> arbitrary |
| 314 |
"OP_NODE_POWERCYCLE" -> |
| 315 |
OpCodes.OpNodePowercycle <$> genNodeNameNE <*> return Nothing <*> |
| 316 |
arbitrary |
| 317 |
"OP_NODE_MIGRATE" -> |
| 318 |
OpCodes.OpNodeMigrate <$> genNodeNameNE <*> return Nothing <*> |
| 319 |
arbitrary <*> arbitrary <*> genMaybe genNodeNameNE <*> |
| 320 |
return Nothing <*> arbitrary <*> arbitrary <*> genMaybe genNameNE |
| 321 |
"OP_NODE_EVACUATE" -> |
| 322 |
OpCodes.OpNodeEvacuate <$> arbitrary <*> genNodeNameNE <*> |
| 323 |
return Nothing <*> genMaybe genNodeNameNE <*> return Nothing <*> |
| 324 |
genMaybe genNameNE <*> arbitrary <*> arbitrary |
| 325 |
"OP_INSTANCE_CREATE" -> |
| 326 |
OpCodes.OpInstanceCreate |
| 327 |
<$> genFQDN -- instance_name |
| 328 |
<*> arbitrary -- force_variant |
| 329 |
<*> arbitrary -- wait_for_sync |
| 330 |
<*> arbitrary -- name_check |
| 331 |
<*> arbitrary -- ignore_ipolicy |
| 332 |
<*> arbitrary -- opportunistic_locking |
| 333 |
<*> pure emptyJSObject -- beparams |
| 334 |
<*> arbitrary -- disks |
| 335 |
<*> arbitrary -- disk_template |
| 336 |
<*> genMaybe genNameNE -- group_name |
| 337 |
<*> arbitrary -- file_driver |
| 338 |
<*> genMaybe genNameNE -- file_storage_dir |
| 339 |
<*> pure emptyJSObject -- hvparams |
| 340 |
<*> arbitrary -- hypervisor |
| 341 |
<*> genMaybe genNameNE -- iallocator |
| 342 |
<*> arbitrary -- identify_defaults |
| 343 |
<*> arbitrary -- ip_check |
| 344 |
<*> arbitrary -- conflicts_check |
| 345 |
<*> arbitrary -- mode |
| 346 |
<*> arbitrary -- nics |
| 347 |
<*> arbitrary -- no_install |
| 348 |
<*> pure emptyJSObject -- osparams |
| 349 |
<*> genMaybe arbitraryPrivateJSObj -- osparams_private |
| 350 |
<*> genMaybe arbitrarySecretJSObj -- osparams_secret |
| 351 |
<*> genMaybe genNameNE -- os_type |
| 352 |
<*> genMaybe genNodeNameNE -- pnode |
| 353 |
<*> return Nothing -- pnode_uuid |
| 354 |
<*> genMaybe genNodeNameNE -- snode |
| 355 |
<*> return Nothing -- snode_uuid |
| 356 |
<*> genMaybe (pure []) -- source_handshake |
| 357 |
<*> genMaybe genNodeNameNE -- source_instance_name |
| 358 |
<*> arbitrary -- source_shutdown_timeout |
| 359 |
<*> genMaybe genNodeNameNE -- source_x509_ca |
| 360 |
<*> return Nothing -- src_node |
| 361 |
<*> genMaybe genNodeNameNE -- src_node_uuid |
| 362 |
<*> genMaybe genNameNE -- src_path |
| 363 |
<*> genPrintableAsciiString -- compress |
| 364 |
<*> arbitrary -- start |
| 365 |
<*> arbitrary -- forthcoming |
| 366 |
<*> arbitrary -- commit |
| 367 |
<*> (genTags >>= mapM mkNonEmpty) -- tags |
| 368 |
<*> arbitrary -- instance_communication |
| 369 |
<*> arbitrary -- helper_startup_timeout |
| 370 |
<*> arbitrary -- helper_shutdown_timeout |
| 371 |
"OP_INSTANCE_MULTI_ALLOC" -> |
| 372 |
OpCodes.OpInstanceMultiAlloc <$> arbitrary <*> genMaybe genNameNE <*> |
| 373 |
pure [] |
| 374 |
"OP_INSTANCE_REINSTALL" -> |
| 375 |
OpCodes.OpInstanceReinstall <$> genFQDN <*> return Nothing <*> |
| 376 |
arbitrary <*> genMaybe genNameNE <*> genMaybe (pure emptyJSObject) |
| 377 |
<*> genMaybe arbitraryPrivateJSObj <*> genMaybe arbitrarySecretJSObj |
| 378 |
"OP_INSTANCE_REMOVE" -> |
| 379 |
OpCodes.OpInstanceRemove <$> genFQDN <*> return Nothing <*> |
| 380 |
arbitrary <*> arbitrary |
| 381 |
"OP_INSTANCE_RENAME" -> |
| 382 |
OpCodes.OpInstanceRename <$> genFQDN <*> return Nothing <*> |
| 383 |
genNodeNameNE <*> arbitrary <*> arbitrary |
| 384 |
"OP_INSTANCE_STARTUP" -> |
| 385 |
OpCodes.OpInstanceStartup <$> |
| 386 |
genFQDN <*> -- instance_name |
| 387 |
return Nothing <*> -- instance_uuid |
| 388 |
arbitrary <*> -- force |
| 389 |
arbitrary <*> -- ignore_offline_nodes |
| 390 |
pure emptyJSObject <*> -- hvparams |
| 391 |
pure emptyJSObject <*> -- beparams |
| 392 |
arbitrary <*> -- no_remember |
| 393 |
arbitrary <*> -- startup_paused |
| 394 |
arbitrary -- shutdown_timeout |
| 395 |
"OP_INSTANCE_SHUTDOWN" -> |
| 396 |
OpCodes.OpInstanceShutdown <$> genFQDN <*> return Nothing <*> |
| 397 |
arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary |
| 398 |
"OP_INSTANCE_REBOOT" -> |
| 399 |
OpCodes.OpInstanceReboot <$> genFQDN <*> return Nothing <*> |
| 400 |
arbitrary <*> arbitrary <*> arbitrary |
| 401 |
"OP_INSTANCE_MOVE" -> |
| 402 |
OpCodes.OpInstanceMove <$> genFQDN <*> return Nothing <*> |
| 403 |
arbitrary <*> arbitrary <*> genNodeNameNE <*> return Nothing <*> |
| 404 |
genPrintableAsciiString <*> arbitrary |
| 405 |
"OP_INSTANCE_CONSOLE" -> OpCodes.OpInstanceConsole <$> genFQDN <*> |
| 406 |
return Nothing |
| 407 |
"OP_INSTANCE_ACTIVATE_DISKS" -> |
| 408 |
OpCodes.OpInstanceActivateDisks <$> genFQDN <*> return Nothing <*> |
| 409 |
arbitrary <*> arbitrary |
| 410 |
"OP_INSTANCE_DEACTIVATE_DISKS" -> |
| 411 |
OpCodes.OpInstanceDeactivateDisks <$> genFQDN <*> return Nothing <*> |
| 412 |
arbitrary |
| 413 |
"OP_INSTANCE_RECREATE_DISKS" -> |
| 414 |
OpCodes.OpInstanceRecreateDisks <$> genFQDN <*> return Nothing <*> |
| 415 |
arbitrary <*> genNodeNamesNE <*> return Nothing <*> |
| 416 |
genMaybe genNameNE |
| 417 |
"OP_INSTANCE_QUERY_DATA" -> |
| 418 |
OpCodes.OpInstanceQueryData <$> arbitrary <*> |
| 419 |
genNodeNamesNE <*> arbitrary |
| 420 |
"OP_INSTANCE_SET_PARAMS" -> |
| 421 |
OpCodes.OpInstanceSetParams |
| 422 |
<$> genFQDN -- instance_name |
| 423 |
<*> return Nothing -- instance_uuid |
| 424 |
<*> arbitrary -- force |
| 425 |
<*> arbitrary -- force_variant |
| 426 |
<*> arbitrary -- ignore_ipolicy |
| 427 |
<*> arbitrary -- nics |
| 428 |
<*> arbitrary -- disks |
| 429 |
<*> pure emptyJSObject -- beparams |
| 430 |
<*> arbitrary -- runtime_mem |
| 431 |
<*> pure emptyJSObject -- hvparams |
| 432 |
<*> arbitrary -- disk_template |
| 433 |
<*> pure emptyJSObject -- ext_params |
| 434 |
<*> arbitrary -- file_driver |
| 435 |
<*> genMaybe genNameNE -- file_storage_dir |
| 436 |
<*> genMaybe genNodeNameNE -- pnode |
| 437 |
<*> return Nothing -- pnode_uuid |
| 438 |
<*> genMaybe genNodeNameNE -- remote_node |
| 439 |
<*> return Nothing -- remote_node_uuid |
| 440 |
<*> genMaybe genNameNE -- iallocator |
| 441 |
<*> genMaybe genNameNE -- os_name |
| 442 |
<*> pure emptyJSObject -- osparams |
| 443 |
<*> genMaybe arbitraryPrivateJSObj -- osparams_private |
| 444 |
<*> arbitrary -- wait_for_sync |
| 445 |
<*> arbitrary -- offline |
| 446 |
<*> arbitrary -- conflicts_check |
| 447 |
<*> arbitrary -- hotplug |
| 448 |
<*> arbitrary -- instance_communication |
| 449 |
"OP_INSTANCE_GROW_DISK" -> |
| 450 |
OpCodes.OpInstanceGrowDisk <$> genFQDN <*> return Nothing <*> |
| 451 |
arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary |
| 452 |
"OP_INSTANCE_CHANGE_GROUP" -> |
| 453 |
OpCodes.OpInstanceChangeGroup <$> genFQDN <*> return Nothing <*> |
| 454 |
arbitrary <*> genMaybe genNameNE <*> |
| 455 |
genMaybe (resize maxNodes (listOf genNameNE)) |
| 456 |
"OP_GROUP_ADD" -> |
| 457 |
OpCodes.OpGroupAdd <$> genNameNE <*> arbitrary <*> |
| 458 |
emptyMUD <*> genMaybe genEmptyContainer <*> |
| 459 |
emptyMUD <*> emptyMUD <*> emptyMUD |
| 460 |
"OP_GROUP_ASSIGN_NODES" -> |
| 461 |
OpCodes.OpGroupAssignNodes <$> genNameNE <*> arbitrary <*> |
| 462 |
genNodeNamesNE <*> return Nothing |
| 463 |
"OP_GROUP_SET_PARAMS" -> |
| 464 |
OpCodes.OpGroupSetParams <$> genNameNE <*> arbitrary <*> |
| 465 |
emptyMUD <*> genMaybe genEmptyContainer <*> |
| 466 |
emptyMUD <*> emptyMUD <*> emptyMUD |
| 467 |
"OP_GROUP_REMOVE" -> |
| 468 |
OpCodes.OpGroupRemove <$> genNameNE |
| 469 |
"OP_GROUP_RENAME" -> |
| 470 |
OpCodes.OpGroupRename <$> genNameNE <*> genNameNE |
| 471 |
"OP_GROUP_EVACUATE" -> |
| 472 |
OpCodes.OpGroupEvacuate <$> genNameNE <*> arbitrary <*> |
| 473 |
genMaybe genNameNE <*> genMaybe genNamesNE <*> arbitrary <*> arbitrary |
| 474 |
"OP_OS_DIAGNOSE" -> |
| 475 |
OpCodes.OpOsDiagnose <$> genFieldsNE <*> genNamesNE |
| 476 |
"OP_EXT_STORAGE_DIAGNOSE" -> |
| 477 |
OpCodes.OpOsDiagnose <$> genFieldsNE <*> genNamesNE |
| 478 |
"OP_BACKUP_PREPARE" -> |
| 479 |
OpCodes.OpBackupPrepare <$> genFQDN <*> return Nothing <*> arbitrary |
| 480 |
"OP_BACKUP_EXPORT" -> |
| 481 |
OpCodes.OpBackupExport |
| 482 |
<$> genFQDN -- instance_name |
| 483 |
<*> return Nothing -- instance_uuid |
| 484 |
<*> genPrintableAsciiString -- compress |
| 485 |
<*> arbitrary -- shutdown_timeout |
| 486 |
<*> arbitrary -- target_node |
| 487 |
<*> return Nothing -- target_node_uuid |
| 488 |
<*> arbitrary -- shutdown |
| 489 |
<*> arbitrary -- remove_instance |
| 490 |
<*> arbitrary -- ignore_remove_failures |
| 491 |
<*> arbitrary -- mode |
| 492 |
<*> genMaybe (pure []) -- x509_key_name |
| 493 |
<*> genMaybe genNameNE -- destination_x509_ca |
| 494 |
<*> arbitrary -- zero_free_space |
| 495 |
<*> arbitrary -- zeroing_timeout_fixed |
| 496 |
<*> arbitrary -- zeroing_timeout_per_mib |
| 497 |
<*> arbitrary -- long_sleep |
| 498 |
"OP_BACKUP_REMOVE" -> |
| 499 |
OpCodes.OpBackupRemove <$> genFQDN <*> return Nothing |
| 500 |
"OP_TEST_ALLOCATOR" -> |
| 501 |
OpCodes.OpTestAllocator <$> arbitrary <*> arbitrary <*> |
| 502 |
genNameNE <*> genMaybe (pure []) <*> genMaybe (pure []) <*> |
| 503 |
arbitrary <*> genMaybe genNameNE <*> |
| 504 |
(genTags >>= mapM mkNonEmpty) <*> |
| 505 |
arbitrary <*> arbitrary <*> genMaybe genNameNE <*> |
| 506 |
arbitrary <*> genMaybe genNodeNamesNE <*> arbitrary <*> |
| 507 |
genMaybe genNamesNE <*> arbitrary <*> arbitrary <*> |
| 508 |
genMaybe genNameNE |
| 509 |
"OP_TEST_JQUEUE" -> |
| 510 |
OpCodes.OpTestJqueue <$> arbitrary <*> arbitrary <*> |
| 511 |
resize 20 (listOf genFQDN) <*> arbitrary |
| 512 |
"OP_TEST_OS_PARAMS" -> |
| 513 |
OpCodes.OpTestOsParams <$> genMaybe arbitrarySecretJSObj |
| 514 |
"OP_TEST_DUMMY" -> |
| 515 |
OpCodes.OpTestDummy <$> pure J.JSNull <*> pure J.JSNull <*> |
| 516 |
pure J.JSNull <*> pure J.JSNull |
| 517 |
"OP_NETWORK_ADD" -> |
| 518 |
OpCodes.OpNetworkAdd <$> genNameNE <*> genIPv4Network <*> |
| 519 |
genMaybe genIPv4Address <*> pure Nothing <*> pure Nothing <*> |
| 520 |
genMaybe genMacPrefix <*> genMaybe (listOf genIPv4Address) <*> |
| 521 |
arbitrary <*> (genTags >>= mapM mkNonEmpty) |
| 522 |
"OP_NETWORK_REMOVE" -> |
| 523 |
OpCodes.OpNetworkRemove <$> genNameNE <*> arbitrary |
| 524 |
"OP_NETWORK_RENAME" -> |
| 525 |
OpCodes.OpNetworkRename <$> genNameNE <*> genNameNE |
| 526 |
"OP_NETWORK_SET_PARAMS" -> |
| 527 |
OpCodes.OpNetworkSetParams <$> genNameNE <*> |
| 528 |
genMaybe genIPv4Address <*> pure Nothing <*> pure Nothing <*> |
| 529 |
genMaybe genMacPrefix <*> genMaybe (listOf genIPv4Address) <*> |
| 530 |
genMaybe (listOf genIPv4Address) |
| 531 |
"OP_NETWORK_CONNECT" -> |
| 532 |
OpCodes.OpNetworkConnect <$> genNameNE <*> genNameNE <*> |
| 533 |
arbitrary <*> genNameNE <*> genPrintableAsciiString <*> arbitrary |
| 534 |
"OP_NETWORK_DISCONNECT" -> |
| 535 |
OpCodes.OpNetworkDisconnect <$> genNameNE <*> genNameNE |
| 536 |
"OP_RESTRICTED_COMMAND" -> |
| 537 |
OpCodes.OpRestrictedCommand <$> arbitrary <*> genNodeNamesNE <*> |
| 538 |
return Nothing <*> genNameNE |
| 539 |
_ -> fail $ "Undefined arbitrary for opcode " ++ op_id |
| 540 |
|
| 541 |
instance Arbitrary OpCodes.CommonOpParams where |
| 542 |
arbitrary = OpCodes.CommonOpParams <$> arbitrary <*> arbitrary <*> |
| 543 |
arbitrary <*> resize 5 arbitrary <*> genMaybe genName <*> |
| 544 |
genReasonTrail |
| 545 |
|
| 546 |
-- * Helper functions |
| 547 |
|
| 548 |
-- | Empty JSObject. |
| 549 |
emptyJSObject :: J.JSObject J.JSValue |
| 550 |
emptyJSObject = J.toJSObject [] |
| 551 |
|
| 552 |
-- | Empty maybe unchecked dictionary. |
| 553 |
emptyMUD :: Gen (Maybe (J.JSObject J.JSValue)) |
| 554 |
emptyMUD = genMaybe $ pure emptyJSObject |
| 555 |
|
| 556 |
-- | Generates an empty container. |
| 557 |
genEmptyContainer :: (Ord a) => Gen (GenericContainer a b) |
| 558 |
genEmptyContainer = pure . GenericContainer $ Map.fromList [] |
| 559 |
|
| 560 |
-- | Generates list of disk indices. |
| 561 |
genDiskIndices :: Gen [DiskIndex] |
| 562 |
genDiskIndices = do |
| 563 |
cnt <- choose (0, C.maxDisks) |
| 564 |
genUniquesList cnt arbitrary |
| 565 |
|
| 566 |
-- | Generates a list of node names. |
| 567 |
genNodeNames :: Gen [String] |
| 568 |
genNodeNames = resize maxNodes (listOf genFQDN) |
| 569 |
|
| 570 |
-- | Generates a list of node names in non-empty string type. |
| 571 |
genNodeNamesNE :: Gen [NonEmptyString] |
| 572 |
genNodeNamesNE = genNodeNames >>= mapM mkNonEmpty |
| 573 |
|
| 574 |
-- | Gets a node name in non-empty type. |
| 575 |
genNodeNameNE :: Gen NonEmptyString |
| 576 |
genNodeNameNE = genFQDN >>= mkNonEmpty |
| 577 |
|
| 578 |
-- | Gets a name (non-fqdn) in non-empty type. |
| 579 |
genNameNE :: Gen NonEmptyString |
| 580 |
genNameNE = genName >>= mkNonEmpty |
| 581 |
|
| 582 |
-- | Gets a list of names (non-fqdn) in non-empty type. |
| 583 |
genNamesNE :: Gen [NonEmptyString] |
| 584 |
genNamesNE = resize maxNodes (listOf genNameNE) |
| 585 |
|
| 586 |
-- | Returns a list of non-empty fields. |
| 587 |
genFieldsNE :: Gen [NonEmptyString] |
| 588 |
genFieldsNE = genFields >>= mapM mkNonEmpty |
| 589 |
|
| 590 |
-- | Generate a 3-byte MAC prefix. |
| 591 |
genMacPrefix :: Gen NonEmptyString |
| 592 |
genMacPrefix = do |
| 593 |
octets <- vectorOf 3 $ choose (0::Int, 255) |
| 594 |
mkNonEmpty . intercalate ":" $ map (printf "%02x") octets |
| 595 |
|
| 596 |
-- | JSObject of arbitrary data. |
| 597 |
-- |
| 598 |
-- Since JSValue does not implement Arbitrary, I'll simply generate |
| 599 |
-- (String, String) objects. |
| 600 |
arbitraryPrivateJSObj :: Gen (J.JSObject (Private J.JSValue)) |
| 601 |
arbitraryPrivateJSObj = |
| 602 |
constructor <$> (fromNonEmpty <$> genNameNE) |
| 603 |
<*> (fromNonEmpty <$> genNameNE) |
| 604 |
where constructor k v = showPrivateJSObject [(k, v)] |
| 605 |
|
| 606 |
-- | JSObject of arbitrary secret data. |
| 607 |
arbitrarySecretJSObj :: Gen (J.JSObject (Secret J.JSValue)) |
| 608 |
arbitrarySecretJSObj = |
| 609 |
constructor <$> (fromNonEmpty <$> genNameNE) |
| 610 |
<*> (fromNonEmpty <$> genNameNE) |
| 611 |
where constructor k v = showSecretJSObject [(k, v)] |
| 612 |
|
| 613 |
-- | Arbitrary instance for MetaOpCode, defined here due to TH ordering. |
| 614 |
$(genArbitrary ''OpCodes.MetaOpCode) |
| 615 |
|
| 616 |
-- | Small helper to check for a failed JSON deserialisation |
| 617 |
isJsonError :: J.Result a -> Bool |
| 618 |
isJsonError (J.Error _) = True |
| 619 |
isJsonError _ = False |
| 620 |
|
| 621 |
-- * Test cases |
| 622 |
|
| 623 |
-- | Check that opcode serialization is idempotent. |
| 624 |
prop_serialization :: OpCodes.OpCode -> Property |
| 625 |
prop_serialization = testSerialisation |
| 626 |
|
| 627 |
-- | Check that Python and Haskell defined the same opcode list. |
| 628 |
case_AllDefined :: HUnit.Assertion |
| 629 |
case_AllDefined = do |
| 630 |
py_stdout <- |
| 631 |
runPython "from ganeti import opcodes\n\ |
| 632 |
\from ganeti import serializer\n\ |
| 633 |
\import sys\n\ |
| 634 |
\sys.stdout.buffer.write(\ |
| 635 |
\ serializer.Dump([opid for opid in opcodes.OP_MAPPING]))" |
| 636 |
"" |
| 637 |
>>= checkPythonResult |
| 638 |
py_ops <- case J.decode py_stdout::J.Result [String] of |
| 639 |
J.Ok ops -> return ops |
| 640 |
J.Error msg -> |
| 641 |
HUnit.assertFailure ("Unable to decode opcode names: " ++ msg) |
| 642 |
-- this already raised an expection, but we need it |
| 643 |
-- for proper types |
| 644 |
>> fail "Unable to decode opcode names" |
| 645 |
let hs_ops = sort OpCodes.allOpIDs |
| 646 |
extra_py = py_ops \\ hs_ops |
| 647 |
extra_hs = hs_ops \\ py_ops |
| 648 |
HUnit.assertBool ("Missing OpCodes from the Haskell code:\n" ++ |
| 649 |
unlines extra_py) (null extra_py) |
| 650 |
HUnit.assertBool ("Extra OpCodes in the Haskell code:\n" ++ |
| 651 |
unlines extra_hs) (null extra_hs) |
| 652 |
|
| 653 |
-- | Custom HUnit test case that forks a Python process and checks |
| 654 |
-- correspondence between Haskell-generated OpCodes and their Python |
| 655 |
-- decoded, validated and re-encoded version. |
| 656 |
-- |
| 657 |
-- Note that we have a strange beast here: since launching Python is |
| 658 |
-- expensive, we don't do this via a usual QuickProperty, since that's |
| 659 |
-- slow (I've tested it, and it's indeed quite slow). Rather, we use a |
| 660 |
-- single HUnit assertion, and in it we manually use QuickCheck to |
| 661 |
-- generate 500 opcodes times the number of defined opcodes, which |
| 662 |
-- then we pass in bulk to Python. The drawbacks to this method are |
| 663 |
-- two fold: we cannot control the number of generated opcodes, since |
| 664 |
-- HUnit assertions don't get access to the test options, and for the |
| 665 |
-- same reason we can't run a repeatable seed. We should probably find |
| 666 |
-- a better way to do this, for example by having a |
| 667 |
-- separately-launched Python process (if not running the tests would |
| 668 |
-- be skipped). |
| 669 |
case_py_compat_types :: HUnit.Assertion |
| 670 |
case_py_compat_types = do |
| 671 |
let num_opcodes = length OpCodes.allOpIDs * 100 |
| 672 |
opcodes <- genSample (vectorOf num_opcodes |
| 673 |
(arbitrary::Gen OpCodes.MetaOpCode)) |
| 674 |
let with_sum = map (\o -> (OpCodes.opSummary $ |
| 675 |
OpCodes.metaOpCode o, o)) opcodes |
| 676 |
serialized = J.encode opcodes |
| 677 |
-- check for non-ASCII fields, usually due to 'arbitrary :: String' |
| 678 |
mapM_ (\op -> when (any (not . isAscii) (J.encode op)) . |
| 679 |
HUnit.assertFailure $ |
| 680 |
"OpCode has non-ASCII fields: " ++ show op |
| 681 |
) opcodes |
| 682 |
py_stdout <- |
| 683 |
runPython "from ganeti import opcodes\n\ |
| 684 |
\from ganeti import serializer\n\ |
| 685 |
\import sys\n\ |
| 686 |
\op_data = serializer.Load(sys.stdin.read())\n\ |
| 687 |
\decoded = [opcodes.OpCode.LoadOpCode(o) for o in op_data]\n\ |
| 688 |
\for op in decoded:\n\ |
| 689 |
\ op.Validate(True)\n\ |
| 690 |
\encoded = [(op.Summary(), op.__getstate__())\n\ |
| 691 |
\ for op in decoded]\n\ |
| 692 |
\sys.stdout.buffer.write(serializer.Dump(\ |
| 693 |
\ encoded,\ |
| 694 |
\ private_encoder=serializer.EncodeWithPrivateFields))" |
| 695 |
serialized |
| 696 |
>>= checkPythonResult |
| 697 |
let deserialised = |
| 698 |
J.decode py_stdout::J.Result [(String, OpCodes.MetaOpCode)] |
| 699 |
decoded <- case deserialised of |
| 700 |
J.Ok ops -> return ops |
| 701 |
J.Error msg -> |
| 702 |
HUnit.assertFailure ("Unable to decode opcodes: " ++ msg) |
| 703 |
-- this already raised an expection, but we need it |
| 704 |
-- for proper types |
| 705 |
>> fail "Unable to decode opcodes" |
| 706 |
HUnit.assertEqual "Mismatch in number of returned opcodes" |
| 707 |
(length decoded) (length with_sum) |
| 708 |
mapM_ (uncurry (HUnit.assertEqual "Different result after encoding/decoding") |
| 709 |
) $ zip with_sum decoded |
| 710 |
|
| 711 |
-- | Custom HUnit test case that forks a Python process and checks |
| 712 |
-- correspondence between Haskell OpCodes fields and their Python |
| 713 |
-- equivalent. |
| 714 |
case_py_compat_fields :: HUnit.Assertion |
| 715 |
case_py_compat_fields = do |
| 716 |
let hs_fields = sort $ map (\op_id -> (op_id, OpCodes.allOpFields op_id)) |
| 717 |
OpCodes.allOpIDs |
| 718 |
py_stdout <- |
| 719 |
runPython "from ganeti import opcodes\n\ |
| 720 |
\import sys\n\ |
| 721 |
\from ganeti import serializer\n\ |
| 722 |
\fields = [(k, sorted([p[0] for p in v.OP_PARAMS]))\n\ |
| 723 |
\ for k, v in opcodes.OP_MAPPING.items()]\n\ |
| 724 |
\sys.stdout.buffer.write(serializer.Dump(fields))" "" |
| 725 |
>>= checkPythonResult |
| 726 |
let deserialised = J.decode py_stdout::J.Result [(String, [String])] |
| 727 |
py_fields <- case deserialised of |
| 728 |
J.Ok v -> return $ sort v |
| 729 |
J.Error msg -> |
| 730 |
HUnit.assertFailure ("Unable to decode op fields: " ++ msg) |
| 731 |
-- this already raised an expection, but we need it |
| 732 |
-- for proper types |
| 733 |
>> fail "Unable to decode op fields" |
| 734 |
HUnit.assertEqual "Mismatch in number of returned opcodes" |
| 735 |
(length hs_fields) (length py_fields) |
| 736 |
HUnit.assertEqual "Mismatch in defined OP_IDs" |
| 737 |
(map fst hs_fields) (map fst py_fields) |
| 738 |
mapM_ (\((py_id, py_flds), (hs_id, hs_flds)) -> do |
| 739 |
HUnit.assertEqual "Mismatch in OP_ID" py_id hs_id |
| 740 |
HUnit.assertEqual ("Mismatch in fields for " ++ hs_id) |
| 741 |
py_flds hs_flds |
| 742 |
) $ zip hs_fields py_fields |
| 743 |
|
| 744 |
-- | Checks that setOpComment works correctly. |
| 745 |
prop_setOpComment :: OpCodes.MetaOpCode -> String -> Property |
| 746 |
prop_setOpComment op comment = |
| 747 |
let (OpCodes.MetaOpCode common _) = OpCodes.setOpComment comment op |
| 748 |
in OpCodes.opComment common ==? Just comment |
| 749 |
|
| 750 |
-- | Tests wrong (negative) disk index. |
| 751 |
prop_mkDiskIndex_fail :: QuickCheck.Positive Int -> Property |
| 752 |
prop_mkDiskIndex_fail (Positive i) = |
| 753 |
case mkDiskIndex (negate i) of |
| 754 |
Bad msg -> counterexample "error message " $ |
| 755 |
"Invalid value" `isPrefixOf` msg |
| 756 |
Ok v -> failTest $ "Succeeded to build disk index '" ++ show v ++ |
| 757 |
"' from negative value " ++ show (negate i) |
| 758 |
|
| 759 |
-- | Tests a few invalid 'readRecreateDisks' cases. |
| 760 |
case_readRecreateDisks_fail :: Assertion |
| 761 |
case_readRecreateDisks_fail = do |
| 762 |
assertBool "null" $ |
| 763 |
isJsonError (J.readJSON J.JSNull::J.Result RecreateDisksInfo) |
| 764 |
assertBool "string" $ |
| 765 |
isJsonError (J.readJSON (J.showJSON "abc")::J.Result RecreateDisksInfo) |
| 766 |
|
| 767 |
-- | Tests a few invalid 'readDdmOldChanges' cases. |
| 768 |
case_readDdmOldChanges_fail :: Assertion |
| 769 |
case_readDdmOldChanges_fail = do |
| 770 |
assertBool "null" $ |
| 771 |
isJsonError (J.readJSON J.JSNull::J.Result DdmOldChanges) |
| 772 |
assertBool "string" $ |
| 773 |
isJsonError (J.readJSON (J.showJSON "abc")::J.Result DdmOldChanges) |
| 774 |
|
| 775 |
-- | Tests a few invalid 'readExportTarget' cases. |
| 776 |
case_readExportTarget_fail :: Assertion |
| 777 |
case_readExportTarget_fail = do |
| 778 |
assertBool "null" $ |
| 779 |
isJsonError (J.readJSON J.JSNull::J.Result ExportTarget) |
| 780 |
assertBool "int" $ |
| 781 |
isJsonError (J.readJSON (J.showJSON (5::Int))::J.Result ExportTarget) |
| 782 |
|
| 783 |
testSuite "OpCodes" |
| 784 |
[ 'prop_serialization |
| 785 |
, 'case_AllDefined |
| 786 |
, 'case_py_compat_types |
| 787 |
, 'case_py_compat_fields |
| 788 |
, 'prop_setOpComment |
| 789 |
, 'prop_mkDiskIndex_fail |
| 790 |
, 'case_readRecreateDisks_fail |
| 791 |
, 'case_readDdmOldChanges_fail |
| 792 |
, 'case_readExportTarget_fail |
| 793 |
] |