Commit d31193c3 authored by Jose A. Lopes's avatar Jose A. Lopes
Browse files

Eliminate Haskell constant for opcode names

Modify 'autotools/convert-constants' not to generate the Haskell
constant that holds all opcode names.  By having Haskell generate the
Python opcopdes, it becomes impossible to generate this constant due
to a cyclic dependency.  However, this constant is used only in tests,
therefore, it can be generated from Template Haskell. This patch also
updates the test to execute a Python program to fetch the generated
opcode names instead of relying on the beforementioned constant.
Signed-off-by: default avatarJose A. Lopes <>
Reviewed-by: default avatarGuido Trotter <>
parent 6c2c542e
......@@ -30,7 +30,6 @@ from ganeti import compat
from ganeti import constants
from ganeti import errors
from ganeti import luxi
from ganeti import opcodes
from ganeti import qlang
from ganeti import jstore
......@@ -300,16 +299,6 @@ def Convert(module, prefix):
return "\n".join(lines)
def ConvertMisc():
"""Convert some extra computed-values to Haskell.
lines = [""]
lines.extend(ConvertVariable("opcodes", "OP_IDS",
opcodes.OP_MAPPING.keys(), {}))
return "\n".join(lines)
def main():
print Convert(constants, "")
print Convert(luxi, "luxi")
......@@ -317,7 +306,6 @@ def main():
print Convert(_autoconf, "autoconf")
print Convert(errors, "errors")
print Convert(jstore, "jstore")
print ConvertMisc()
if __name__ == "__main__":
......@@ -441,8 +441,20 @@ prop_serialization = testSerialisation
-- | Check that Python and Haskell defined the same opcode list.
case_AllDefined :: HUnit.Assertion
case_AllDefined = do
let py_ops = sort C.opcodesOpIds
hs_ops = sort OpCodes.allOpIDs
py_stdout <-
runPython "from ganeti import opcodes\n\
\from ganeti import serializer\n\
\import sys\n\
\print serializer.Dump([opid for opid in opcodes.OP_MAPPING])\n" ""
>>= checkPythonResult
py_ops <- case J.decode py_stdout::J.Result [String] of
J.Ok ops -> return ops
J.Error msg ->
HUnit.assertFailure ("Unable to decode opcode names: " ++ msg)
-- this already raised an expection, but we need it
-- for proper types
>> fail "Unable to decode opcode names"
let hs_ops = sort OpCodes.allOpIDs
extra_py = py_ops \\ hs_ops
extra_hs = hs_ops \\ py_ops
HUnit.assertBool ("Missing OpCodes from the Haskell code:\n" ++
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