Commit aa922d64 authored by Michele Tartara's avatar Michele Tartara

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: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent c2610080
......@@ -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)
......
......@@ -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):
......
......@@ -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,
......
......@@ -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:
......
......@@ -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
......@@ -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
......
......@@ -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" %
......
......@@ -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)),
})
......
......@@ -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"),
......
......@@ -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):
......
......@@ -345,7 +345,6 @@ $(genOpCode "OpCode"
, pShutdownTimeout
, pIgnoreSecondaries
, pRebootType
, pReason
])
, ("OpInstanceMove",
[ pInstanceName
......
......@@ -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.
......
......@@ -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)
......@@ -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)
......
......@@ -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()
......@@ -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")
......
......@@ -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)
......
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