From aa922d646f3af97b80aae8a75007df4347970fba Mon Sep 17 00:00:00 2001 From: Michele Tartara <mtartara@google.com> Date: Mon, 25 Mar 2013 13:55:31 +0000 Subject: [PATCH] Remove old "reason" implementation Remove the useless parts of the old, partial, implementation of the support for tracking the reason of instances state change, before implementing the new reason trail support, as per the design document. Signed-off-by: Michele Tartara <mtartara@google.com> Reviewed-by: Helga Velroyen <helgav@google.com> --- lib/backend.py | 47 +------------------------- lib/cli.py | 3 +- lib/client/gnt_instance.py | 7 ++-- lib/cmdlib.py | 4 +-- lib/constants.py | 14 -------- lib/opcodes.py | 11 ------ lib/rapi/client.py | 5 +-- lib/rapi/rlib2.py | 4 --- lib/rpc_defs.py | 1 - lib/server/noded.py | 7 +--- src/Ganeti/OpCodes.hs | 1 - src/Ganeti/OpParams.hs | 5 --- src/Ganeti/Types.hs | 10 ------ test/hs/Test/Ganeti/OpCodes.hs | 8 +---- test/py/ganeti.backend_unittest.py | 13 ------- test/py/ganeti.rapi.client_unittest.py | 5 +-- test/py/ganeti.rapi.rlib2_unittest.py | 3 -- 17 files changed, 9 insertions(+), 139 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index 3668d4f64..2c5471b86 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -122,49 +122,6 @@ def GetInstReasonFilename(instance_name): return utils.PathJoin(pathutils.INSTANCE_REASON_DIR, instance_name) -class InstReason(object): - """Class representing the reason for a change of state of a VM. - - It is used to allow an easy serialization of the reason, so that it can be - written on a file. - - """ - def __init__(self, source, text): - """Initialize the class with all the required values. - - @type text: string - @param text: The textual description of the reason for changing state - @type source: string - @param source: The source of the state change (RAPI, CLI, ...) - - """ - self.source = source - self.text = text - - def GetJson(self): - """Get the JSON representation of the InstReason. - - @rtype: string - @return : The JSON representation of the object - - """ - return serializer.DumpJson(dict(source=self.source, text=self.text)) - - def Store(self, instance_name): - """Serialize on a file the reason for the last state change of an instance. - - The exact location of the file depends on the name of the instance and on - the configuration of the Ganeti cluster defined at deploy time. - - @type instance_name: string - @param instance_name: The name of the instance - @rtype: None - - """ - filename = GetInstReasonFilename(instance_name) - utils.WriteFile(filename, data=self.GetJson()) - - def _Fail(msg, *args, **kwargs): """Log an error and the raise an RPCFail exception. @@ -1451,7 +1408,7 @@ def InstanceShutdown(instance, timeout): _RemoveBlockDevLinks(iname, instance.disks) -def InstanceReboot(instance, reboot_type, shutdown_timeout, reason): +def InstanceReboot(instance, reboot_type, shutdown_timeout): """Reboot an instance. @type instance: L{objects.Instance} @@ -1481,14 +1438,12 @@ def InstanceReboot(instance, reboot_type, shutdown_timeout, reason): if reboot_type == constants.INSTANCE_REBOOT_SOFT: try: hyper.RebootInstance(instance) - reason.Store(instance.name) except errors.HypervisorError, err: _Fail("Failed to soft reboot instance %s: %s", instance.name, err) elif reboot_type == constants.INSTANCE_REBOOT_HARD: try: InstanceShutdown(instance, shutdown_timeout) result = StartInstance(instance, False) - reason.Store(instance.name) return result except errors.HypervisorError, err: _Fail("Failed to hard reboot instance %s: %s", instance.name, err) diff --git a/lib/cli.py b/lib/cli.py index 491c0092c..7ff6e6456 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -1406,8 +1406,7 @@ FAILURE_ONLY_OPT = cli_option("--failure-only", default=False, " only (determined by the exit code)")) REASON_OPT = cli_option("--reason", default=None, - help="The reason for executing a VM-state-changing" - " operation") + help="The reason for executing the command") def _PriorityOptionCb(option, _, value, parser): diff --git a/lib/client/gnt_instance.py b/lib/client/gnt_instance.py index aba7e66b0..07db3a62c 100644 --- a/lib/client/gnt_instance.py +++ b/lib/client/gnt_instance.py @@ -630,9 +630,7 @@ def _RebootInstance(name, opts): return opcodes.OpInstanceReboot(instance_name=name, reboot_type=opts.reboot_type, ignore_secondaries=opts.ignore_secondaries, - shutdown_timeout=opts.shutdown_timeout, - reason=(constants.INSTANCE_REASON_SOURCE_CLI, - opts.reason)) + shutdown_timeout=opts.shutdown_timeout) def _ShutdownInstance(name, opts): @@ -1559,8 +1557,7 @@ commands = { [m_force_multi, REBOOT_TYPE_OPT, IGNORE_SECONDARIES_OPT, m_node_opt, m_pri_node_opt, m_sec_node_opt, m_clust_opt, m_inst_opt, SUBMIT_OPT, m_node_tags_opt, m_pri_node_tags_opt, m_sec_node_tags_opt, - m_inst_tags_opt, SHUTDOWN_TIMEOUT_OPT, DRY_RUN_OPT, PRIORITY_OPT, - REASON_OPT], + m_inst_tags_opt, SHUTDOWN_TIMEOUT_OPT, DRY_RUN_OPT, PRIORITY_OPT], "<instance>", "Reboots an instance"), "activate-disks": ( ActivateDisks, ARGS_ONE_INSTANCE, diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 99077d5e3..2c6d216a3 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -7440,7 +7440,6 @@ class LUInstanceReboot(LogicalUnit): instance = self.instance ignore_secondaries = self.op.ignore_secondaries reboot_type = self.op.reboot_type - reason = self.op.reason remote_info = self.rpc.call_instance_info(instance.primary_node, instance.name, @@ -7456,8 +7455,7 @@ class LUInstanceReboot(LogicalUnit): self.cfg.SetDiskID(disk, node_current) result = self.rpc.call_instance_reboot(node_current, instance, reboot_type, - self.op.shutdown_timeout, - reason) + self.op.shutdown_timeout) result.Raise("Could not reboot instance") else: if instance_running: diff --git a/lib/constants.py b/lib/constants.py index 6d781a58e..50b11ba7a 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -2435,19 +2435,5 @@ AUTO_REPAIR_ALL_RESULTS = frozenset([ # The version identifier for builtin data collectors BUILTIN_DATA_COLLECTOR_VERSION = "B" -# The source reasons for the change of state of an instance -INSTANCE_REASON_SOURCE_CLI = "cli" -INSTANCE_REASON_SOURCE_RAPI = "rapi" -INSTANCE_REASON_SOURCE_UNKNOWN = "unknown" - -INSTANCE_REASON_SOURCES = compat.UniqueFrozenset([ - INSTANCE_REASON_SOURCE_CLI, - INSTANCE_REASON_SOURCE_RAPI, - INSTANCE_REASON_SOURCE_UNKNOWN, - ]) - -# The default reasons for the change of state of an instance -INSTANCE_REASON_REBOOT = "reboot" - # Do not re-export imported modules del re, _vcsversion, _autoconf, socket, pathutils, compat diff --git a/lib/opcodes.py b/lib/opcodes.py index 7a48115e2..8bf6c778e 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -184,16 +184,6 @@ _PTargetGroups = \ ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString), "Destination group names or UUIDs (defaults to \"all but current group\")") -# The reason for a state change of an instance -_PReason = \ - ("reason", (constants.INSTANCE_REASON_SOURCE_UNKNOWN, None), - ht.TAnd(ht.TIsLength(2), - ht.TItems([ - ht.TElemOf(constants.INSTANCE_REASON_SOURCES), - ht.TMaybeString, - ])), - "The reason why the state of the instance is changing") - #: OP_ID conversion regular expression _OPID_RE = re.compile("([a-z])([A-Z])") @@ -1465,7 +1455,6 @@ class OpInstanceReboot(OpCode): "Whether to start the instance even if secondary disks are failing"), ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES), "How to reboot instance"), - _PReason, ] OP_RESULT = ht.TNone diff --git a/lib/rapi/client.py b/lib/rapi/client.py index b7600785c..5fc576f88 100644 --- a/lib/rapi/client.py +++ b/lib/rapi/client.py @@ -1001,7 +1001,7 @@ class GanetiRapiClient(object): # pylint: disable=R0904 (GANETI_RAPI_VERSION, instance)), query, None) def RebootInstance(self, instance, reboot_type=None, ignore_secondaries=None, - dry_run=False, reason_text=None): + dry_run=False): """Reboots an instance. @type instance: str @@ -1013,8 +1013,6 @@ class GanetiRapiClient(object): # pylint: disable=R0904 while re-assembling disks (in hard-reboot mode only) @type dry_run: bool @param dry_run: whether to perform a dry run - @type reason_text: string - @param reason_text: the reason for the reboot @rtype: string @return: job id @@ -1024,7 +1022,6 @@ class GanetiRapiClient(object): # pylint: disable=R0904 _AppendIf(query, reboot_type, ("type", reboot_type)) _AppendIf(query, ignore_secondaries is not None, ("ignore_secondaries", ignore_secondaries)) - _AppendIf(query, reason_text, ("reason_text", reason_text)) return self._SendRequest(HTTP_POST, ("/%s/instances/%s/reboot" % diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py index cc8a796b8..d35e3aacb 100644 --- a/lib/rapi/rlib2.py +++ b/lib/rapi/rlib2.py @@ -1040,10 +1040,6 @@ class R_2_instances_name_reboot(baserlib.OpcodeResource): self.queryargs.get("type", [constants.INSTANCE_REBOOT_HARD])[0], "ignore_secondaries": bool(self._checkIntVariable("ignore_secondaries")), "dry_run": self.dryRun(), - "reason": - (constants.INSTANCE_REASON_SOURCE_RAPI, - self._checkStringVariable("reason_text", - default=constants.INSTANCE_REASON_REBOOT)), }) diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py index a9ed9dad1..f5f1c34b2 100644 --- a/lib/rpc_defs.py +++ b/lib/rpc_defs.py @@ -230,7 +230,6 @@ _INSTANCE_CALLS = [ ("inst", ED_INST_DICT, "Instance object"), ("reboot_type", None, None), ("shutdown_timeout", None, None), - ("reason_text", None, "Reason for the reboot"), ], None, None, "Returns the list of running instances on the given nodes"), ("instance_shutdown", SINGLE, None, constants.RPC_TMO_NORMAL, [ ("instance", ED_INST_DICT, "Instance object"), diff --git a/lib/server/noded.py b/lib/server/noded.py index 96ad1acc7..1351b9c90 100644 --- a/lib/server/noded.py +++ b/lib/server/noded.py @@ -650,12 +650,7 @@ class NodeRequestHandler(http.server.HttpServerHandler): instance = objects.Instance.FromDict(params[0]) reboot_type = params[1] shutdown_timeout = params[2] - (reason_source, reason_text) = params[3] - reason_text = _DefaultAlternative(reason_text, - constants.INSTANCE_REASON_REBOOT) - reason = backend.InstReason(reason_source, reason_text) - return backend.InstanceReboot(instance, reboot_type, shutdown_timeout, - reason) + return backend.InstanceReboot(instance, reboot_type, shutdown_timeout) @staticmethod def perspective_instance_balloon_memory(params): diff --git a/src/Ganeti/OpCodes.hs b/src/Ganeti/OpCodes.hs index cf34b2222..6f2844544 100644 --- a/src/Ganeti/OpCodes.hs +++ b/src/Ganeti/OpCodes.hs @@ -345,7 +345,6 @@ $(genOpCode "OpCode" , pShutdownTimeout , pIgnoreSecondaries , pRebootType - , pReason ]) , ("OpInstanceMove", [ pInstanceName diff --git a/src/Ganeti/OpParams.hs b/src/Ganeti/OpParams.hs index 7001f83bf..51d47b252 100644 --- a/src/Ganeti/OpParams.hs +++ b/src/Ganeti/OpParams.hs @@ -236,7 +236,6 @@ module Ganeti.OpParams , pOpPriority , pDependencies , pComment - , pReason , pEnabledDiskTemplates , dOldQuery , dOldQueryNoLocking @@ -1445,10 +1444,6 @@ pDependencies = pComment :: Field pComment = optionalNullSerField $ stringField "comment" --- | The description of the state change reason. -pReason :: Field -pReason = simpleField "reason" [t| (InstReasonSrc, NonEmptyString) |] - -- * Entire opcode parameter list -- | Old-style query opcode, with locking. diff --git a/src/Ganeti/Types.hs b/src/Ganeti/Types.hs index ae402952c..6bd3ade4c 100644 --- a/src/Ganeti/Types.hs +++ b/src/Ganeti/Types.hs @@ -92,7 +92,6 @@ module Ganeti.Types , opStatusToRaw , opStatusFromRaw , ELogType(..) - , InstReasonSrc(..) ) where import Control.Monad (liftM) @@ -486,12 +485,3 @@ $(THH.declareSADT "ELogType" , ("ELogJqueueTest", 'C.elogJqueueTest) ]) $(THH.makeJSONInstance ''ELogType) - --- | Type for the source of the state change of instances. -$(THH.declareSADT "InstReasonSrc" - [ ("IRSCli", 'C.instanceReasonSourceCli) - , ("IRSRapi", 'C.instanceReasonSourceRapi) - ]) -$(THH.makeJSONInstance ''InstReasonSrc) - - diff --git a/test/hs/Test/Ganeti/OpCodes.hs b/test/hs/Test/Ganeti/OpCodes.hs index a37517b93..118374142 100644 --- a/test/hs/Test/Ganeti/OpCodes.hs +++ b/test/hs/Test/Ganeti/OpCodes.hs @@ -69,8 +69,6 @@ $(genArbitrary ''OpCodes.ReplaceDisksMode) $(genArbitrary ''DiskAccess) -$(genArbitrary ''InstReasonSrc) - instance Arbitrary OpCodes.DiskIndex where arbitrary = choose (0, C.maxDisks - 1) >>= OpCodes.mkDiskIndex @@ -241,7 +239,7 @@ instance Arbitrary OpCodes.OpCode where arbitrary <*> arbitrary "OP_INSTANCE_REBOOT" -> OpCodes.OpInstanceReboot <$> genFQDN <*> arbitrary <*> - arbitrary <*> arbitrary <*> ((,) <$> arbitrary <*> genStringNE) + arbitrary <*> arbitrary "OP_INSTANCE_MOVE" -> OpCodes.OpInstanceMove <$> genFQDN <*> arbitrary <*> arbitrary <*> genNodeNameNE <*> arbitrary @@ -398,10 +396,6 @@ genMacPrefix = do octets <- vectorOf 3 $ choose (0::Int, 255) mkNonEmpty . intercalate ":" $ map (printf "%02x") octets --- | Generate a non empty string -genStringNE :: Gen NonEmptyString -genStringNE = genName >>= mkNonEmpty - -- | Arbitrary instance for MetaOpCode, defined here due to TH ordering. $(genArbitrary ''OpCodes.MetaOpCode) diff --git a/test/py/ganeti.backend_unittest.py b/test/py/ganeti.backend_unittest.py index 86f88bc40..4ad743af7 100755 --- a/test/py/ganeti.backend_unittest.py +++ b/test/py/ganeti.backend_unittest.py @@ -538,18 +538,5 @@ class TestGetBlockDevSymlinkPath(unittest.TestCase): self._Test("inst1.example.com", idx) -class TestInstReason(unittest.TestCase): - def testGetJson(self): - reason_text = "OS Update" - reason_source = constants.INSTANCE_REASON_SOURCE_CLI - origDict = dict(text=reason_text, source=reason_source) - - reason = backend.InstReason(reason_source, reason_text) - json = reason.GetJson() - resultDict = serializer.LoadJson(json) - - self.assertEqual(origDict, resultDict) - - if __name__ == "__main__": testutils.GanetiTestProgram() diff --git a/test/py/ganeti.rapi.client_unittest.py b/test/py/ganeti.rapi.client_unittest.py index e78a1d9b6..ab518e5fe 100755 --- a/test/py/ganeti.rapi.client_unittest.py +++ b/test/py/ganeti.rapi.client_unittest.py @@ -594,15 +594,13 @@ class GanetiRapiClientTests(testutils.GanetiTestCase): def testRebootInstance(self): self.rapi.AddResponse("6146") job_id = self.client.RebootInstance("i-bar", reboot_type="hard", - ignore_secondaries=True, dry_run=True, - reason_text="Updates") + ignore_secondaries=True, dry_run=True) self.assertEqual(6146, job_id) self.assertHandler(rlib2.R_2_instances_name_reboot) self.assertItems(["i-bar"]) self.assertDryRun() self.assertQuery("type", ["hard"]) self.assertQuery("ignore_secondaries", ["1"]) - self.assertQuery("reason_text", ["Updates"]) def testRebootInstanceDefaultReason(self): self.rapi.AddResponse("6146") @@ -614,7 +612,6 @@ class GanetiRapiClientTests(testutils.GanetiTestCase): self.assertDryRun() self.assertQuery("type", ["hard"]) self.assertQuery("ignore_secondaries", ["1"]) - self.assertQuery("reason_text", None) def testShutdownInstance(self): self.rapi.AddResponse("1487") diff --git a/test/py/ganeti.rapi.rlib2_unittest.py b/test/py/ganeti.rapi.rlib2_unittest.py index 374f1feb7..d4d36027c 100755 --- a/test/py/ganeti.rapi.rlib2_unittest.py +++ b/test/py/ganeti.rapi.rlib2_unittest.py @@ -370,7 +370,6 @@ class TestInstanceReboot(unittest.TestCase): handler = _CreateHandler(rlib2.R_2_instances_name_reboot, ["inst847"], { "dry-run": ["1"], "ignore_secondaries": ["1"], - "reason_text": ["System update"], }, {}, clfactory) job_id = handler.POST() @@ -384,8 +383,6 @@ class TestInstanceReboot(unittest.TestCase): self.assertEqual(op.reboot_type, constants.INSTANCE_REBOOT_HARD) self.assertTrue(op.ignore_secondaries) self.assertTrue(op.dry_run) - self.assertEqual(op.reason, - (constants.INSTANCE_REASON_SOURCE_RAPI, "System update")) self.assertRaises(IndexError, cl.GetNextSubmittedJob) -- GitLab