Commit d22dfef7 authored by Iustin Pop's avatar Iustin Pop

Change behaviour of OpDiagnoseOS w.r.t. 'valid'

This patch changes the behaviour of OpDiagnoseOS with regards to the
'valid' field to be similar to the one for the hidden/blacklisted
fields: unless this field is requested, invalid OSes are filtered out.

The rationale is that, except for the gnt-os info/diagnose, all other
users of this opcode are requesting the valid field just to filter out
invalid OSes, and not for any other use. Thus, changing this behaviour
makes these callers simpler.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 61a14bb3
...@@ -3122,8 +3122,9 @@ class LUDiagnoseOS(NoHooksLU): ...@@ -3122,8 +3122,9 @@ class LUDiagnoseOS(NoHooksLU):
REQ_BGL = False REQ_BGL = False
_HID = "hidden" _HID = "hidden"
_BLK = "blacklisted" _BLK = "blacklisted"
_VLD = "valid"
_FIELDS_STATIC = utils.FieldSet() _FIELDS_STATIC = utils.FieldSet()
_FIELDS_DYNAMIC = utils.FieldSet("name", "valid", "node_status", "variants", _FIELDS_DYNAMIC = utils.FieldSet("name", _VLD, "node_status", "variants",
"parameters", "api_versions", _HID, _BLK) "parameters", "api_versions", _HID, _BLK)
def CheckArguments(self): def CheckArguments(self):
...@@ -3215,13 +3216,14 @@ class LUDiagnoseOS(NoHooksLU): ...@@ -3215,13 +3216,14 @@ class LUDiagnoseOS(NoHooksLU):
is_hid = os_name in cluster.hidden_oss is_hid = os_name in cluster.hidden_oss
is_blk = os_name in cluster.blacklisted_oss is_blk = os_name in cluster.blacklisted_oss
if ((self._HID not in self.op.output_fields and is_hid) or if ((self._HID not in self.op.output_fields and is_hid) or
(self._BLK not in self.op.output_fields and is_blk)): (self._BLK not in self.op.output_fields and is_blk) or
(self._VLD not in self.op.output_fields and not valid)):
continue continue
for field in self.op.output_fields: for field in self.op.output_fields:
if field == "name": if field == "name":
val = os_name val = os_name
elif field == "valid": elif field == self._VLD:
val = valid val = valid
elif field == "node_status": elif field == "node_status":
# this is just a copy of the dict # this is just a copy of the dict
......
...@@ -148,8 +148,7 @@ class R_2_os(baserlib.R_Generic): ...@@ -148,8 +148,7 @@ class R_2_os(baserlib.R_Generic):
""" """
cl = baserlib.GetClient() cl = baserlib.GetClient()
op = opcodes.OpDiagnoseOS(output_fields=["name", "valid", "variants"], op = opcodes.OpDiagnoseOS(output_fields=["name", "variants"], names=[])
names=[])
job_id = baserlib.SubmitJob([op], cl) job_id = baserlib.SubmitJob([op], cl)
# we use custom feedback function, instead of print we log the status # we use custom feedback function, instead of print we log the status
result = cli.PollJob(job_id, cl, feedback_fn=baserlib.FeedbackFn) result = cli.PollJob(job_id, cl, feedback_fn=baserlib.FeedbackFn)
...@@ -159,9 +158,8 @@ class R_2_os(baserlib.R_Generic): ...@@ -159,9 +158,8 @@ class R_2_os(baserlib.R_Generic):
raise http.HttpBadGateway(message="Can't get OS list") raise http.HttpBadGateway(message="Can't get OS list")
os_names = [] os_names = []
for (name, valid, variants) in diagnose_data: for (name, variants) in diagnose_data:
if valid: os_names.extend(cli.CalculateOSNames(name, variants))
os_names.extend(cli.CalculateOSNames(name, variants))
return os_names return os_names
......
...@@ -524,8 +524,7 @@ def ReinstallInstance(opts, args): ...@@ -524,8 +524,7 @@ def ReinstallInstance(opts, args):
# second, if requested, ask for an OS # second, if requested, ask for an OS
if opts.select_os is True: if opts.select_os is True:
op = opcodes.OpDiagnoseOS(output_fields=["name", "valid", "variants"], op = opcodes.OpDiagnoseOS(output_fields=["name", "variants"], names=[])
names=[])
result = SubmitOpCode(op, opts=opts) result = SubmitOpCode(op, opts=opts)
if not result: if not result:
...@@ -535,12 +534,11 @@ def ReinstallInstance(opts, args): ...@@ -535,12 +534,11 @@ def ReinstallInstance(opts, args):
ToStdout("Available OS templates:") ToStdout("Available OS templates:")
number = 0 number = 0
choices = [] choices = []
for (name, valid, variants) in result: for (name, variants) in result:
if valid: for entry in CalculateOSNames(name, variants):
for entry in CalculateOSNames(name, variants): ToStdout("%3s: %s", number, entry)
ToStdout("%3s: %s", number, entry) choices.append(("%s" % number, entry, entry))
choices.append(("%s" % number, entry, entry)) number += 1
number += 1
choices.append(('x', 'exit', 'Exit gnt-instance reinstall')) choices.append(('x', 'exit', 'Exit gnt-instance reinstall'))
selected = AskUser("Enter OS template number (or x to abort):", selected = AskUser("Enter OS template number (or x to abort):",
......
...@@ -44,8 +44,7 @@ def ListOS(opts, args): ...@@ -44,8 +44,7 @@ def ListOS(opts, args):
@return: the desired exit code @return: the desired exit code
""" """
op = opcodes.OpDiagnoseOS(output_fields=["name", "valid", "variants"], op = opcodes.OpDiagnoseOS(output_fields=["name", "variants"], names=[])
names=[])
result = SubmitOpCode(op, opts=opts) result = SubmitOpCode(op, opts=opts)
if not result: if not result:
...@@ -58,9 +57,8 @@ def ListOS(opts, args): ...@@ -58,9 +57,8 @@ def ListOS(opts, args):
headers = None headers = None
os_names = [] os_names = []
for (name, valid, variants) in result: for (name, variants) in result:
if valid: os_names.extend([[n] for n in CalculateOSNames(name, variants)])
os_names.extend([[n] for n in CalculateOSNames(name, variants)])
data = GenerateTable(separator=None, headers=headers, fields=["name"], data = GenerateTable(separator=None, headers=headers, fields=["name"],
data=os_names, units=None) data=os_names, units=None)
......
...@@ -510,16 +510,16 @@ class Burner(object): ...@@ -510,16 +510,16 @@ class Burner(object):
Err(msg, exit_code=err_code) Err(msg, exit_code=err_code)
self.nodes = [data[0] for data in result if not (data[1] or data[2])] self.nodes = [data[0] for data in result if not (data[1] or data[2])]
op_diagnose = opcodes.OpDiagnoseOS(output_fields=["name", "valid", op_diagnose = opcodes.OpDiagnoseOS(output_fields=["name", "variants"],
"variants"], names=[]) names=[])
result = self.ExecOp(True, op_diagnose) result = self.ExecOp(True, op_diagnose)
if not result: if not result:
Err("Can't get the OS list") Err("Can't get the OS list")
found = False found = False
for (name, valid, variants) in result: for (name, variants) in result:
if valid and self.opts.os in cli.CalculateOSNames(name, variants): if self.opts.os in cli.CalculateOSNames(name, variants):
found = True found = True
break break
......
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