Add helper function to get nic stat that connected to vswitches
The new function virtual_network_vswitch_query_iuo_stats is used to get all nic stats that connected to all vswitches. Change-Id: Ic1536f379f1c16dfcb21fd2c37c9d1d889aa8a90
This commit is contained in:
parent
8838e435ec
commit
732c635363
@ -369,3 +369,81 @@ def image_performance_query(zhcp_node, inst_list):
|
||||
|
||||
def get_inst_name(instance):
|
||||
return getattr(instance, 'OS-EXT-SRV-ATTR:instance_name', None)
|
||||
|
||||
|
||||
def virutal_network_vswitch_query_iuo_stats(zhcp_node):
|
||||
cmd = ('smcli Virtual_Network_Vswitch_Query_IUO_Stats -T "%s" '
|
||||
'-k "switch_name=*"' % zhcp_node)
|
||||
|
||||
with expect_invalid_xcat_resp_data():
|
||||
resp = xdsh(zhcp_node, cmd)
|
||||
raw_data_list = resp["data"][0]
|
||||
|
||||
while raw_data_list.__contains__(None):
|
||||
raw_data_list.remove(None)
|
||||
|
||||
raw_data = '\n'.join(raw_data_list)
|
||||
rd_list = raw_data.split('\n')
|
||||
|
||||
def _parse_value(data_list, idx, keyword, offset):
|
||||
return idx + offset, data_list[idx].rpartition(keyword)[2].strip()
|
||||
|
||||
vsw_dict = {}
|
||||
with expect_invalid_xcat_resp_data():
|
||||
# vswitch count
|
||||
idx = 0
|
||||
idx, vsw_count = _parse_value(rd_list, idx, 'vswitch count:', 2)
|
||||
vsw_dict['vswitch_count'] = int(vsw_count)
|
||||
|
||||
# deal with each vswitch data
|
||||
vsw_dict['vswitches'] = []
|
||||
for i in range(vsw_dict['vswitch_count']):
|
||||
vsw_data = {}
|
||||
# skip vswitch number
|
||||
idx += 1
|
||||
# vswitch name
|
||||
idx, vsw_name = _parse_value(rd_list, idx, 'vswitch name:', 1)
|
||||
vsw_data['vswitch_name'] = vsw_name
|
||||
# uplink count
|
||||
idx, up_count = _parse_value(rd_list, idx, 'uplink count:', 1)
|
||||
# skip uplink data
|
||||
idx += int(up_count) * 9
|
||||
# skip bridge data
|
||||
idx += 8
|
||||
# nic count
|
||||
vsw_data['nics'] = []
|
||||
idx, nic_count = _parse_value(rd_list, idx, 'nic count:', 1)
|
||||
nic_count = int(nic_count)
|
||||
for j in range(nic_count):
|
||||
nic_data = {}
|
||||
idx, nic_id = _parse_value(rd_list, idx, 'nic_id:', 1)
|
||||
userid, toss, vdev = nic_id.partition(' ')
|
||||
nic_data['userid'] = userid
|
||||
nic_data['vdev'] = vdev
|
||||
idx, nic_data['nic_fr_rx'] = _parse_value(rd_list, idx,
|
||||
'nic_fr_rx:', 1)
|
||||
idx, nic_data['nic_fr_rx_dsc'] = _parse_value(rd_list, idx,
|
||||
'nic_fr_rx_dsc:', 1)
|
||||
idx, nic_data['nic_fr_rx_err'] = _parse_value(rd_list, idx,
|
||||
'nic_fr_rx_err:', 1)
|
||||
idx, nic_data['nic_fr_tx'] = _parse_value(rd_list, idx,
|
||||
'nic_fr_tx:', 1)
|
||||
idx, nic_data['nic_fr_tx_dsc'] = _parse_value(rd_list, idx,
|
||||
'nic_fr_tx_dsc:', 1)
|
||||
idx, nic_data['nic_fr_tx_err'] = _parse_value(rd_list, idx,
|
||||
'nic_fr_tx_err:', 1)
|
||||
idx, nic_data['nic_rx'] = _parse_value(rd_list, idx,
|
||||
'nic_rx:', 1)
|
||||
idx, nic_data['nic_tx'] = _parse_value(rd_list, idx,
|
||||
'nic_tx:', 1)
|
||||
vsw_data['nics'].append(nic_data)
|
||||
# vlan count
|
||||
idx, vlan_count = _parse_value(rd_list, idx, 'vlan count:', 1)
|
||||
# skip vlan data
|
||||
idx += int(vlan_count) * 3
|
||||
# skip the blank line
|
||||
idx += 1
|
||||
|
||||
vsw_dict['vswitches'].append(vsw_data)
|
||||
|
||||
return vsw_dict
|
||||
|
@ -196,6 +196,105 @@ class TestZVMUtils(base.BaseTestCase):
|
||||
self.assertRaises(zvmutils.ZVMException,
|
||||
zvmutils.image_performance_query, 'zhcp', inst_list)
|
||||
|
||||
@mock.patch.object(zvmutils, 'xdsh')
|
||||
def test_virutal_network_vswitch_query_iuo_stats(self, dsh):
|
||||
vsw_data = ['zhcp11: vswitch count: 2\n'
|
||||
'zhcp11: \n'
|
||||
'zhcp11: vswitch number: 1\n'
|
||||
'zhcp11: vswitch name: XCATVSW1\n'
|
||||
'zhcp11: uplink count: 1\n'
|
||||
'zhcp11: uplink_conn: 6240\n'
|
||||
'zhcp11: uplink_fr_rx: 3658251\n'
|
||||
'zhcp11: uplink_fr_rx_dsc: 0\n'
|
||||
'zhcp11: uplink_fr_rx_err: 0\n'
|
||||
'zhcp11: uplink_fr_tx: 4209828\n'
|
||||
'zhcp11: uplink_fr_tx_dsc: 0\n'
|
||||
'zhcp11: uplink_fr_tx_err: 0\n'
|
||||
'zhcp11: uplink_rx: 498914052\n'
|
||||
'zhcp11: uplink_tx: 2615220898\n'
|
||||
'zhcp11: bridge_fr_rx: 0\n'
|
||||
'zhcp11: bridge_fr_rx_dsc: 0\n'
|
||||
'zhcp11: bridge_fr_rx_err: 0\n'
|
||||
'zhcp11: bridge_fr_tx: 0\n'
|
||||
'zhcp11: bridge_fr_tx_dsc: 0\n'
|
||||
'zhcp11: bridge_fr_tx_err: 0\n'
|
||||
'zhcp11: bridge_rx: 0\n'
|
||||
'zhcp11: bridge_tx: 0\n'
|
||||
'zhcp11: nic count: 2\n'
|
||||
'zhcp11: nic_id: INST1 0600\n'
|
||||
'zhcp11: nic_fr_rx: 573952\n'
|
||||
'zhcp11: nic_fr_rx_dsc: 0\n'
|
||||
'zhcp11: nic_fr_rx_err: 0\n'
|
||||
'zhcp11: nic_fr_tx: 548780\n'
|
||||
'zhcp11: nic_fr_tx_dsc: 0\n'
|
||||
'zhcp11: nic_fr_tx_err: 4\n'
|
||||
'zhcp11: nic_rx: 103024058\n'
|
||||
'zhcp11: nic_tx: 102030890\n'
|
||||
'zhcp11: nic_id: INST2 0600\n'
|
||||
'zhcp11: nic_fr_rx: 17493\n'
|
||||
'zhcp11: nic_fr_rx_dsc: 0\n'
|
||||
'zhcp11: nic_fr_rx_err: 0\n'
|
||||
'zhcp11: nic_fr_tx: 16886\n'
|
||||
'zhcp11: nic_fr_tx_dsc: 0\n'
|
||||
'zhcp11: nic_fr_tx_err: 4\n'
|
||||
'zhcp11: nic_rx: 3111714\n'
|
||||
'zhcp11: nic_tx: 3172646\n'
|
||||
'zhcp11: vlan count: 0\n'
|
||||
'zhcp11: \n'
|
||||
'zhcp11: vswitch number: 2\n'
|
||||
'zhcp11: vswitch name: XCATVSW2\n'
|
||||
'zhcp11: uplink count: 1\n'
|
||||
'zhcp11: uplink_conn: 6200\n'
|
||||
'zhcp11: uplink_fr_rx: 1608681\n'
|
||||
'zhcp11: uplink_fr_rx_dsc: 0\n'
|
||||
'zhcp11: uplink_fr_rx_err: 0\n'
|
||||
'zhcp11: uplink_fr_tx: 2120075\n'
|
||||
'zhcp11: uplink_fr_tx_dsc: 0\n'
|
||||
'zhcp11: uplink_fr_tx_err: 0\n'
|
||||
'zhcp11: uplink_rx: 314326223',
|
||||
'zhcp11: uplink_tx: 1503721533\n'
|
||||
'zhcp11: bridge_fr_rx: 0\n'
|
||||
'zhcp11: bridge_fr_rx_dsc: 0\n'
|
||||
'zhcp11: bridge_fr_rx_err: 0\n'
|
||||
'zhcp11: bridge_fr_tx: 0\n'
|
||||
'zhcp11: bridge_fr_tx_dsc: 0\n'
|
||||
'zhcp11: bridge_fr_tx_err: 0\n'
|
||||
'zhcp11: bridge_rx: 0\n'
|
||||
'zhcp11: bridge_tx: 0\n'
|
||||
'zhcp11: nic count: 2\n'
|
||||
'zhcp11: nic_id: INST1 1000\n'
|
||||
'zhcp11: nic_fr_rx: 34958\n'
|
||||
'zhcp11: nic_fr_rx_dsc: 0\n'
|
||||
'zhcp11: nic_fr_rx_err: 0\n'
|
||||
'zhcp11: nic_fr_tx: 16211\n'
|
||||
'zhcp11: nic_fr_tx_dsc: 0\n'
|
||||
'zhcp11: nic_fr_tx_err: 0\n'
|
||||
'zhcp11: nic_rx: 4684435\n'
|
||||
'zhcp11: nic_tx: 3316601\n'
|
||||
'zhcp11: nic_id: INST2 1000\n'
|
||||
'zhcp11: nic_fr_rx: 27211\n'
|
||||
'zhcp11: nic_fr_rx_dsc: 0\n'
|
||||
'zhcp11: nic_fr_rx_err: 0\n'
|
||||
'zhcp11: nic_fr_tx: 12344\n'
|
||||
'zhcp11: nic_fr_tx_dsc: 0\n'
|
||||
'zhcp11: nic_fr_tx_err: 0\n'
|
||||
'zhcp11: nic_rx: 3577163\n'
|
||||
'zhcp11: nic_tx: 2515045\n'
|
||||
'zhcp11: vlan count: 0',
|
||||
None]
|
||||
dsh.return_value = {'data': [vsw_data]}
|
||||
vsw_dict = zvmutils.virutal_network_vswitch_query_iuo_stats('zhcp11')
|
||||
self.assertEqual(2, len(vsw_dict['vswitches']))
|
||||
self.assertEqual('INST1',
|
||||
vsw_dict['vswitches'][0]['nics'][0]['userid'])
|
||||
|
||||
@mock.patch.object(zvmutils, 'xdsh')
|
||||
def test_virutal_network_vswitch_query_iuo_stats_invalid_data(self, dsh):
|
||||
dsh.return_value = ['invalid', 'data']
|
||||
self.assertRaises(zvmutils.ZVMException,
|
||||
zvmutils.virutal_network_vswitch_query_iuo_stats,
|
||||
'zhcp')
|
||||
|
||||
|
||||
class TestCacheData(base.BaseTestCase):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user