Commit a82d9394 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Fix style violations in commit 4a90bd4f, small changes

- Commit 4a90bd4f

 contained a rather large number of style violations:
  - Indentation/sequence formatting
  - Wrapping of long lines
  - Docstrings whose first line was wrapped
  - A stray backslash in a docstring
- opcodes: Don't check for list or tuple. None of the other opcodes does
  it explicitely. As long as the length and the items match the value is
  accepted.
- server/noded: “if variable” doesn't test for None, but False
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent d59633a6
......@@ -1452,13 +1452,11 @@ class OpInstanceReboot(OpCode):
("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
"How to reboot instance"),
("reason", (constants.INSTANCE_REASON_SOURCE_UNKNOWN, None),
ht.TAnd(ht.TOr(ht.TList, ht.TTuple),
ht.TIsLength(2),
ht.TAnd(ht.TIsLength(2),
ht.TItems([
ht.TElemOf(constants.INSTANCE_REASON_SOURCES),
ht.TMaybeString,
])
),
ht.TElemOf(constants.INSTANCE_REASON_SOURCES),
ht.TMaybeString,
])),
"The reason why the reboot is happening"),
]
OP_RESULT = ht.TNone
......
......@@ -1040,11 +1040,10 @@ 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),
)
"reason":
(constants.INSTANCE_REASON_SOURCE_RAPI,
self._checkStringVariable("reason_text",
default=constants.INSTANCE_REASON_REBOOT)),
})
......
......@@ -113,12 +113,14 @@ def _DecodeImportExportIO(ieio, ieioargs):
def _DefaultAlternative(value, default):
"""Returns the given value, unless it is None. In that case, returns a
default alternative.
"""Returns value or, if evaluating to False, a default value.
@param value: The value to return if it is not None.
@param default: The value to return as a default alternative.
@return: The given value or the default alternative.\
Returns the given value, unless it evaluates to False. In the latter case the
default value is returned.
@param value: Value to return if it doesn't evaluate to False
@param default: Default value
@return: Given value or the default
"""
if value:
......
......@@ -370,7 +370,7 @@ class TestInstanceReboot(unittest.TestCase):
handler = _CreateHandler(rlib2.R_2_instances_name_reboot, ["inst847"], {
"dry-run": ["1"],
"ignore_secondaries": ["1"],
"reason_text": ["System update"]
"reason_text": ["System update"],
}, {}, clfactory)
job_id = handler.POST()
......@@ -385,9 +385,7 @@ class TestInstanceReboot(unittest.TestCase):
self.assertTrue(op.ignore_secondaries)
self.assertTrue(op.dry_run)
self.assertEqual(op.reason,
(constants.INSTANCE_REASON_SOURCE_RAPI,
"System update",
))
(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