From d9037ebf371e024cc31d3792b3f07e90a1c38ec2 Mon Sep 17 00:00:00 2001 From: Lisa Velden <velden@google.com> Date: Fri, 3 Jul 2015 13:37:38 +0200 Subject: [PATCH] Add new command gnt-debug test-osparams which takes secret parameters with --os-secret-parameters and writes them to stdout. This command can be used to test the transmission of secret parameters. Signed-off-by: Lisa Velden <velden@google.com> Reviewed-by: Hrvoje Ribicic <riba@google.com> --- lib/client/gnt_debug.py | 14 ++++++++++++++ lib/cmdlib/__init__.py | 1 + lib/cmdlib/test.py | 17 +++++++++++++++++ man/gnt-debug.rst | 7 +++++++ src/Ganeti/Hs2Py/OpDoc.hs | 4 ++++ src/Ganeti/OpCodes.hs | 6 ++++++ 6 files changed, 49 insertions(+) diff --git a/lib/client/gnt_debug.py b/lib/client/gnt_debug.py index d05fbc232..48a557f4c 100644 --- a/lib/client/gnt_debug.py +++ b/lib/client/gnt_debug.py @@ -583,6 +583,16 @@ def TestJobqueue(opts, _): return 0 +def TestOsParams(opts, _): + """Set secret os parameters. + + """ + op = opcodes.OpTestOsParams(osparams_secret=opts.osparams_secret) + SubmitOrSend(op, opts) + + return 0 + + def ListLocks(opts, args): # pylint: disable=W0613 """List all locks. @@ -785,6 +795,10 @@ commands = { "test-jobqueue": ( TestJobqueue, ARGS_NONE, [PRIORITY_OPT], "", "Test a few aspects of the job queue"), + "test-osparams": ( + TestOsParams, ARGS_NONE, [OSPARAMS_SECRET_OPT] + SUBMIT_OPTS, + "[--os-parameters-secret <params>]", + "Test secret os parameter transmission"), "locks": ( ListLocks, ARGS_NONE, [NOHDR_OPT, SEP_OPT, FIELDS_OPT, INTERVAL_OPT, VERBOSE_OPT], diff --git a/lib/cmdlib/__init__.py b/lib/cmdlib/__init__.py index ee024177b..5fd9b8dfc 100644 --- a/lib/cmdlib/__init__.py +++ b/lib/cmdlib/__init__.py @@ -128,6 +128,7 @@ from ganeti.cmdlib.misc import \ LUExtStorageDiagnose, \ LURestrictedCommand from ganeti.cmdlib.test import \ + LUTestOsParams, \ LUTestDelay, \ LUTestJqueue, \ LUTestAllocator diff --git a/lib/cmdlib/test.py b/lib/cmdlib/test.py index 5ec7c924f..167be3dab 100644 --- a/lib/cmdlib/test.py +++ b/lib/cmdlib/test.py @@ -353,6 +353,23 @@ class LUTestJqueue(NoHooksLU): return True +class LUTestOsParams(NoHooksLU): + """Utility LU to test secret OS parameter transmission. + + """ + REQ_BGL = False + + def ExpandNames(self): + self.needed_locks = {} + + def Exec(self, feedback_fn): + if self.op.osparams_secret: + msg = "Secret OS parameters: %s" % self.op.osparams_secret.Unprivate() + feedback_fn(msg) + else: + raise errors.OpExecError("Opcode needs secret parameters") + + class LUTestAllocator(NoHooksLU): """Run allocator tests. diff --git a/man/gnt-debug.rst b/man/gnt-debug.rst index 6614c12fd..e934d0e84 100644 --- a/man/gnt-debug.rst +++ b/man/gnt-debug.rst @@ -99,6 +99,13 @@ TEST-JOBQUEUE Executes a few tests on the job queue. This command might generate failed jobs deliberately. +TEST_OSPARAMS +~~~~~~~~~~~~~ + +**test-osparams** {--os-parameters-secret *param*=*value*... } + +Tests secret os parameter transmission. + LOCKS ~~~~~ diff --git a/src/Ganeti/Hs2Py/OpDoc.hs b/src/Ganeti/Hs2Py/OpDoc.hs index 82aba2f14..aee68db64 100644 --- a/src/Ganeti/Hs2Py/OpDoc.hs +++ b/src/Ganeti/Hs2Py/OpDoc.hs @@ -465,6 +465,10 @@ opTestJqueue :: String opTestJqueue = "Utility opcode to test some aspects of the job queue." +opTestOsParams :: String +opTestOsParams = + "Utility opcode to test secret os parameter transmission." + opTestDummy :: String opTestDummy = "Utility opcode used by unittests." diff --git a/src/Ganeti/OpCodes.hs b/src/Ganeti/OpCodes.hs index 271b40997..209943d53 100644 --- a/src/Ganeti/OpCodes.hs +++ b/src/Ganeti/OpCodes.hs @@ -903,6 +903,12 @@ $(genOpCode "OpCode" , pJQueueFail ], []) + , ("OpTestOsParams", + [t| () |], + OpDoc.opTestOsParams, + [ pInstOsParamsSecret + ], + []) , ("OpTestDummy", [t| () |], OpDoc.opTestDummy, -- GitLab