Merge "Disallow with sriov_numvfs is 0 or less when creating vf interface"

This commit is contained in:
Zuul 2022-08-04 15:44:49 +00:00 committed by Gerrit Code Review
commit 986c61d0f8
2 changed files with 12 additions and 0 deletions

View File

@ -1418,6 +1418,8 @@ def _check_interface_data(op, interface, ihost, existing_interface,
msg = _("VF interfaces must be created over an interface of class"
" %s" % constants.INTERFACE_CLASS_PCI_SRIOV)
raise wsme.exc.ClientSideError(msg)
if interface['sriov_numvfs'] <= 0:
raise wsme.exc.ClientSideError(_("Value for number of SR-IOV VFs must be > 0."))
avail_vfs = lower_iface['sriov_numvfs'] - 1
for i in lower_iface['used_by']:
if i != interface['ifname']:

View File

@ -1564,6 +1564,16 @@ class TestPostMixin(object):
self._create_vf('vf1', lower_iface=lower_iface,
host=self.worker, sriov_numvfs=4, expect_errors=True)
# Expected message:
# Value for number of SR-IOV VFs must be > 0.
def test_create_vf_interface_numvfs_less_than_zero(self):
self._create_ethernet('mgmt', constants.NETWORK_TYPE_MGMT,
host=self.worker)
port, lower_iface = self._create_sriov(
'sriov', host=self.worker, sriov_numvfs=4)
self._create_vf('vf1', lower_iface=lower_iface,
host=self.worker, sriov_numvfs=-1, expect_errors=True)
# Expected message:
# The number of virtual functions _ must be less than or equal to the
# available VFs _ available on the underlying interface _