diff --git a/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/interface.py b/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/interface.py index 70753d2055..0f9e1094a9 100644 --- a/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/interface.py +++ b/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/interface.py @@ -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']: diff --git a/sysinv/sysinv/sysinv/sysinv/tests/api/test_interface.py b/sysinv/sysinv/sysinv/sysinv/tests/api/test_interface.py index 66b48aa75d..913f861603 100644 --- a/sysinv/sysinv/sysinv/sysinv/tests/api/test_interface.py +++ b/sysinv/sysinv/sysinv/sysinv/tests/api/test_interface.py @@ -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 _