Commit 7c670076 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Add instance query field for OS parameters



These were not available as a query field before. Update unittests
and description text for the other “..params” fields.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 65a884ef
...@@ -1259,6 +1259,7 @@ class InstanceQueryData: ...@@ -1259,6 +1259,7 @@ class InstanceQueryData:
# Used for individual rows # Used for individual rows
self.inst_hvparams = None self.inst_hvparams = None
self.inst_beparams = None self.inst_beparams = None
self.inst_osparams = None
self.inst_nicparams = None self.inst_nicparams = None
def __iter__(self): def __iter__(self):
...@@ -1271,6 +1272,7 @@ class InstanceQueryData: ...@@ -1271,6 +1272,7 @@ class InstanceQueryData:
for inst in self.instances: for inst in self.instances:
self.inst_hvparams = self.cluster.FillHV(inst, skip_globals=True) self.inst_hvparams = self.cluster.FillHV(inst, skip_globals=True)
self.inst_beparams = self.cluster.FillBE(inst) self.inst_beparams = self.cluster.FillBE(inst)
self.inst_osparams = self.cluster.SimpleFillOS(inst.os, inst.osparams)
self.inst_nicparams = [self.cluster.SimpleFillNIC(nic.nicparams) self.inst_nicparams = [self.cluster.SimpleFillNIC(nic.nicparams)
for nic in inst.nics] for nic in inst.nics]
...@@ -1636,11 +1638,14 @@ def _GetInstanceParameterFields(): ...@@ -1636,11 +1638,14 @@ def _GetInstanceParameterFields():
fields = [ fields = [
# Filled parameters # Filled parameters
(_MakeField("hvparams", "HypervisorParameters", QFT_OTHER, (_MakeField("hvparams", "HypervisorParameters", QFT_OTHER,
"Hypervisor parameters"), "Hypervisor parameters (merged)"),
IQ_CONFIG, 0, lambda ctx, _: ctx.inst_hvparams), IQ_CONFIG, 0, lambda ctx, _: ctx.inst_hvparams),
(_MakeField("beparams", "BackendParameters", QFT_OTHER, (_MakeField("beparams", "BackendParameters", QFT_OTHER,
"Backend parameters"), "Backend parameters (merged)"),
IQ_CONFIG, 0, lambda ctx, _: ctx.inst_beparams), IQ_CONFIG, 0, lambda ctx, _: ctx.inst_beparams),
(_MakeField("osparams", "OpSysParameters", QFT_OTHER,
"Operating system parameters (merged)"),
IQ_CONFIG, 0, lambda ctx, _: ctx.inst_osparams),
# Unfilled parameters # Unfilled parameters
(_MakeField("custom_hvparams", "CustomHypervisorParameters", QFT_OTHER, (_MakeField("custom_hvparams", "CustomHypervisorParameters", QFT_OTHER,
...@@ -1649,6 +1654,9 @@ def _GetInstanceParameterFields(): ...@@ -1649,6 +1654,9 @@ def _GetInstanceParameterFields():
(_MakeField("custom_beparams", "CustomBackendParameters", QFT_OTHER, (_MakeField("custom_beparams", "CustomBackendParameters", QFT_OTHER,
"Custom backend parameters",), "Custom backend parameters",),
IQ_CONFIG, 0, _GetItemAttr("beparams")), IQ_CONFIG, 0, _GetItemAttr("beparams")),
(_MakeField("custom_osparams", "CustomOpSysParameters", QFT_OTHER,
"Custom operating system parameters",),
IQ_CONFIG, 0, _GetItemAttr("osparams")),
(_MakeField("custom_nicparams", "CustomNicParameters", QFT_OTHER, (_MakeField("custom_nicparams", "CustomNicParameters", QFT_OTHER,
"Custom network interface parameters"), "Custom network interface parameters"),
IQ_CONFIG, 0, lambda ctx, inst: [nic.nicparams for nic in inst.nics]), IQ_CONFIG, 0, lambda ctx, inst: [nic.nicparams for nic in inst.nics]),
......
...@@ -564,16 +564,20 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -564,16 +564,20 @@ class TestInstanceQuery(unittest.TestCase):
}, },
nicparams={ nicparams={
constants.PP_DEFAULT: constants.NICC_DEFAULTS, constants.PP_DEFAULT: constants.NICC_DEFAULTS,
}) },
os_hvp={},
osparams={})
instances = [ instances = [
objects.Instance(name="inst1", hvparams={}, beparams={}, nics=[]), objects.Instance(name="inst1", hvparams={}, beparams={}, osparams={},
objects.Instance(name="inst2", hvparams={}, nics=[], nics=[], os="deb1"),
objects.Instance(name="inst2", hvparams={}, nics=[], osparams={},
os="foomoo",
beparams={ beparams={
constants.BE_MEMORY: 512, constants.BE_MEMORY: 512,
}), }),
objects.Instance(name="inst3", hvparams={}, beparams={}, objects.Instance(name="inst3", hvparams={}, beparams={}, osparams={},
nics=[objects.NIC(ip="192.0.2.99", nicparams={})]), os="dos", nics=[objects.NIC(ip="192.0.2.99", nicparams={})]),
] ]
iqd = query.InstanceQueryData(instances, cluster, None, [], [], {}, iqd = query.InstanceQueryData(instances, cluster, None, [], [], {},
...@@ -617,7 +621,12 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -617,7 +621,12 @@ class TestInstanceQuery(unittest.TestCase):
constants.PP_DEFAULT: constants.NICC_DEFAULTS, constants.PP_DEFAULT: constants.NICC_DEFAULTS,
}, },
os_hvp={}, os_hvp={},
tcpudp_port_pool=set()) tcpudp_port_pool=set(),
osparams={
"deb99": {
"clean_install": "yes",
},
})
offline_nodes = ["nodeoff1", "nodeoff2"] offline_nodes = ["nodeoff1", "nodeoff2"]
bad_nodes = ["nodebad1", "nodebad2", "nodebad3"] + offline_nodes bad_nodes = ["nodebad1", "nodebad2", "nodebad3"] + offline_nodes
...@@ -630,7 +639,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -630,7 +639,8 @@ class TestInstanceQuery(unittest.TestCase):
admin_up=True, hypervisor=constants.HT_XEN_PVM, os="linux1", admin_up=True, hypervisor=constants.HT_XEN_PVM, os="linux1",
primary_node="node1", primary_node="node1",
disk_template=constants.DT_PLAIN, disk_template=constants.DT_PLAIN,
disks=[]), disks=[],
osparams={}),
objects.Instance(name="inst2", hvparams={}, nics=[], objects.Instance(name="inst2", hvparams={}, nics=[],
uuid="73a0f8a7-068c-4630-ada2-c3440015ab1a", uuid="73a0f8a7-068c-4630-ada2-c3440015ab1a",
ctime=1291211000, mtime=1291211077, serial_no=1, ctime=1291211000, mtime=1291211077, serial_no=1,
...@@ -640,7 +650,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -640,7 +650,8 @@ class TestInstanceQuery(unittest.TestCase):
disks=[], disks=[],
beparams={ beparams={
constants.BE_MEMORY: 512, constants.BE_MEMORY: 512,
}), },
osparams={}),
objects.Instance(name="inst3", hvparams={}, beparams={}, objects.Instance(name="inst3", hvparams={}, beparams={},
uuid="11ec8dff-fb61-4850-bfe0-baa1803ff280", uuid="11ec8dff-fb61-4850-bfe0-baa1803ff280",
ctime=1291011000, mtime=1291013000, serial_no=1923, ctime=1291011000, mtime=1291013000, serial_no=1923,
...@@ -654,7 +665,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -654,7 +665,8 @@ class TestInstanceQuery(unittest.TestCase):
constants.NIC_LINK: constants.DEFAULT_BRIDGE, constants.NIC_LINK: constants.DEFAULT_BRIDGE,
}), }),
objects.NIC(ip=None, mac=macs.pop(), nicparams={}), objects.NIC(ip=None, mac=macs.pop(), nicparams={}),
]), ],
osparams={}),
objects.Instance(name="inst4", hvparams={}, beparams={}, objects.Instance(name="inst4", hvparams={}, beparams={},
uuid="68dab168-3ef5-4c9d-b4d3-801e0672068c", uuid="68dab168-3ef5-4c9d-b4d3-801e0672068c",
ctime=1291244390, mtime=1291244395, serial_no=25, ctime=1291244390, mtime=1291244395, serial_no=25,
...@@ -677,7 +689,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -677,7 +689,8 @@ class TestInstanceQuery(unittest.TestCase):
constants.NIC_MODE: constants.NIC_MODE_BRIDGED, constants.NIC_MODE: constants.NIC_MODE_BRIDGED,
constants.NIC_LINK: "eth123", constants.NIC_LINK: "eth123",
}), }),
]), ],
osparams={}),
objects.Instance(name="inst5", hvparams={}, nics=[], objects.Instance(name="inst5", hvparams={}, nics=[],
uuid="0e3dca12-5b42-4e24-98a2-415267545bd0", uuid="0e3dca12-5b42-4e24-98a2-415267545bd0",
ctime=1231211000, mtime=1261200000, serial_no=3, ctime=1231211000, mtime=1261200000, serial_no=3,
...@@ -687,7 +700,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -687,7 +700,8 @@ class TestInstanceQuery(unittest.TestCase):
disks=[], disks=[],
beparams={ beparams={
constants.BE_MEMORY: 512, constants.BE_MEMORY: 512,
}), },
osparams={}),
objects.Instance(name="inst6", hvparams={}, nics=[], objects.Instance(name="inst6", hvparams={}, nics=[],
uuid="72de6580-c8d5-4661-b902-38b5785bb8b3", uuid="72de6580-c8d5-4661-b902-38b5785bb8b3",
ctime=7513, mtime=11501, serial_no=13390, ctime=7513, mtime=11501, serial_no=13390,
...@@ -697,6 +711,9 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -697,6 +711,9 @@ class TestInstanceQuery(unittest.TestCase):
disks=[], disks=[],
beparams={ beparams={
constants.BE_MEMORY: 768, constants.BE_MEMORY: 768,
},
osparams={
"clean_install": "no",
}), }),
objects.Instance(name="inst7", hvparams={}, nics=[], objects.Instance(name="inst7", hvparams={}, nics=[],
uuid="ceec5dc4-b729-4f42-ae28-69b3cd24920e", uuid="ceec5dc4-b729-4f42-ae28-69b3cd24920e",
...@@ -705,7 +722,8 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -705,7 +722,8 @@ class TestInstanceQuery(unittest.TestCase):
primary_node="node6", primary_node="node6",
disk_template=constants.DT_DISKLESS, disk_template=constants.DT_DISKLESS,
disks=[], disks=[],
beparams={}), beparams={},
osparams={}),
] ]
assert not utils.FindDuplicates(inst.name for inst in instances) assert not utils.FindDuplicates(inst.name for inst in instances)
...@@ -826,6 +844,18 @@ class TestInstanceQuery(unittest.TestCase): ...@@ -826,6 +844,18 @@ class TestInstanceQuery(unittest.TestCase):
exp = (constants.RS_NORMAL, inst.name in live_data) exp = (constants.RS_NORMAL, inst.name in live_data)
self.assertEqual(row[fieldidx["oper_state"]], exp) self.assertEqual(row[fieldidx["oper_state"]], exp)
cust_exp = (constants.RS_NORMAL, {})
if inst.os == "deb99":
if inst.name == "inst6":
exp = (constants.RS_NORMAL, {"clean_install": "no"})
cust_exp = exp
else:
exp = (constants.RS_NORMAL, {"clean_install": "yes"})
else:
exp = (constants.RS_NORMAL, {})
self.assertEqual(row[fieldidx["osparams"]], exp)
self.assertEqual(row[fieldidx["custom_osparams"]], cust_exp)
usage = disk_usage[inst.name] usage = disk_usage[inst.name]
if usage is None: if usage is None:
usage = 0 usage = 0
......
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