Merge "Numvfs setting during update/upgrade"

This commit is contained in:
Zuul 2019-08-08 10:53:41 +00:00 committed by Gerrit Code Review
commit 367c05c1fa
4 changed files with 67 additions and 13 deletions

View File

@ -102,6 +102,17 @@ def _get_sriov_map():
return sriov_map
def get_numvfs(ifname):
try:
sriov_numvfs_path = os.path.join(_SYS_CLASS_NET, ifname,
"device/sriov_numvfs")
with open(sriov_numvfs_path, 'r') as f:
return int(f.read())
except IOError as exc:
msg = ("Unable to read numvfs for %s" % ifname)
raise SRIOVNumvfsException(msg)
def configure_sriov_pf():
# Create a context for pyudev and observe udev events for network
context = pyudev.Context()
@ -118,8 +129,13 @@ def configure_sriov_pf():
if item['device_type'] == 'pf':
_pf_interface_up(item)
try:
sriov_numvfs_path = ("/sys/class/net/%s/device/sriov_numvfs"
% item['name'])
sriov_numvfs_path = os.path.join(_SYS_CLASS_NET, item['name'],
"device/sriov_numvfs")
curr_numvfs = get_numvfs(item['name'])
if curr_numvfs == item['numvfs']:
logger.info("Numvfs already configured for %s"
% item['name'])
continue
with open(sriov_numvfs_path, 'w') as f:
f.write("%d" % item['numvfs'])
except IOError as exc:

View File

@ -1994,6 +1994,10 @@ class TestIfcfgNetConfigApply(base.TestCase):
self.assertEqual(_ROUTES, route_data)
def test_sriov_pf_network_apply(self):
def get_numvfs_stub(pf_name):
return 0
self.stub_out('os_net_config.sriov_config.get_numvfs',
get_numvfs_stub)
route1 = objects.Route('192.168.1.1', default=True,
route_options="metric 10")
route2 = objects.Route('192.168.1.1', '172.19.0.0/24')

View File

@ -119,6 +119,10 @@ class TestUtils(base.TestCase):
shutil.rmtree(tmpdir)
def test_update_sriov_pf_map_new(self):
def get_numvfs_stub(pf_name):
return 0
self.stub_out('os_net_config.sriov_config.get_numvfs',
get_numvfs_stub)
utils.update_sriov_pf_map('eth1', 10, False)
contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
sriov_pf_map = yaml.safe_load(contents) if contents else []
@ -127,7 +131,32 @@ class TestUtils(base.TestCase):
'name': 'eth1', 'numvfs': 10}]
self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
def test_update_sriov_pf_map_with_same_numvfs(self):
def get_numvfs_stub(pf_name):
return 10
self.stub_out('os_net_config.sriov_config.get_numvfs',
get_numvfs_stub)
utils.update_sriov_pf_map('eth1', 10, False)
contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
sriov_pf_map = yaml.safe_load(contents) if contents else []
self.assertEqual(1, len(sriov_pf_map))
test_sriov_pf_map = [{'device_type': 'pf', 'link_mode': 'legacy',
'name': 'eth1', 'numvfs': 10}]
self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
def test_update_sriov_pf_map_with_diff_numvfs(self):
def get_numvfs_stub(pf_name):
return 12
self.stub_out('os_net_config.sriov_config.get_numvfs',
get_numvfs_stub)
self.assertRaises(sriov_config.SRIOVNumvfsException,
utils.update_sriov_pf_map, 'eth1', 10, False)
def test_update_sriov_pf_map_new_with_promisc(self):
def get_numvfs_stub(pf_name):
return 0
self.stub_out('os_net_config.sriov_config.get_numvfs',
get_numvfs_stub)
utils.update_sriov_pf_map('eth1', 10, False, promisc='off')
contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
sriov_pf_map = yaml.safe_load(contents) if contents else []
@ -137,27 +166,28 @@ class TestUtils(base.TestCase):
self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
def test_update_sriov_pf_map_exist(self):
def get_numvfs_stub(pf_name):
return 10
self.stub_out('os_net_config.sriov_config.get_numvfs',
get_numvfs_stub)
pf_initial = [{'device_type': 'pf', 'link_mode': 'legacy',
'name': 'eth1', 'numvfs': 10}]
utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)
utils.update_sriov_pf_map('eth1', 20, False)
pf_final = [{'device_type': 'pf', 'link_mode': 'legacy',
'name': 'eth1', 'numvfs': 20}]
contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
pf_map = yaml.safe_load(contents) if contents else []
self.assertEqual(1, len(pf_map))
self.assertListEqual(pf_final, pf_map)
self.assertRaises(sriov_config.SRIOVNumvfsException,
utils.update_sriov_pf_map, 'eth1', 20, False)
def test_update_sriov_pf_map_exist_with_promisc(self):
def get_numvfs_stub(pf_name):
return 10
self.stub_out('os_net_config.sriov_config.get_numvfs',
get_numvfs_stub)
pf_initial = [{'device_type': 'pf', 'link_mode': 'legacy',
'name': 'eth1', 'numvfs': 10, 'promisc': 'on'}]
utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)
utils.update_sriov_pf_map('eth1', 20, False)
utils.update_sriov_pf_map('eth1', 10, False, promisc='off')
pf_final = [{'device_type': 'pf', 'link_mode': 'legacy',
'name': 'eth1', 'numvfs': 20, 'promisc': 'on'}]
'name': 'eth1', 'numvfs': 10, 'promisc': 'off'}]
contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)
pf_map = yaml.safe_load(contents) if contents else []

View File

@ -417,6 +417,10 @@ def _get_dpdk_mac_address(name):
def update_sriov_pf_map(ifname, numvfs, noop, promisc=None,
link_mode='legacy'):
if not noop:
cur_numvfs = sriov_config.get_numvfs(ifname)
if cur_numvfs > 0 and cur_numvfs != numvfs:
msg = ("Can't change the numvfs for %s" % ifname)
raise sriov_config.SRIOVNumvfsException(msg)
sriov_map = _get_sriov_map()
for item in sriov_map:
if item['device_type'] == 'pf' and item['name'] == ifname: