SysInv: Host Add MAC Address Message

host-add command error message is not clear when user provides no
MAC Address of the host mgmt interface, it is a [REQUIRED] parameter.

Tested with a Controller Storage Configuration:

$ system host-list
+----+--------------+-------------+----------------+-------------+
| id | hostname     | personality | administrative | operational |
+----+--------------+-------------+----------------+-------------+
| 5  | None         | None        | locked         | disabled    |
+----+--------------+-------------+----------------+-------------+

$ system host-add -n compute-0 -p worker
Host-add Rejected: Must provide MAC Address of the host mgmt interface

$ system host-add -n compute-1 -p worker -m 52:54:00:59:02:9
Host-add Rejected: Must provide a valid format of a MAC Address

$ system host-add -n compute-1 -p worker -m 52:54:00:59:02:95
+---------------------+--------------------------------------+
| Property            | Value                                |
+---------------------+--------------------------------------+
| hostname            | compute-1                            |
| mgmt_ip             | 192.168.204.10                       |
| mgmt_mac            | 52:54:00:59:02:95                    |
| personality         | worker                               |
+---------------------+--------------------------------------+

Closes-Bug: 1828247

Change-Id: I086df1d0c716992808e10b0fa627109dff0294ad
Cc: John Kung <john.kung@windriver.com>
Signed-off-by: Abraham Arce <abraham.arce.moreno@intel.com>
This commit is contained in:
Abraham Arce 2019-08-06 11:48:52 -05:00
parent ef2574478e
commit 46dbbd2cc3
3 changed files with 59 additions and 0 deletions

View File

@ -1314,6 +1314,17 @@ class HostController(rest.RestController):
else:
self._validate_hostname(ihost_dict['hostname'], personality)
mgmt_mac = ihost_dict.get('mgmt_mac')
if not mgmt_mac:
raise wsme.exc.ClientSideError(_(
"Host-add Rejected: Must provide MAC Address of "
"the host mgmt interface"))
else:
if not cutils.is_valid_mac(mgmt_mac):
raise wsme.exc.ClientSideError(_(
"Host-add Rejected: Must provide a valid format "
"of a MAC Address"))
HostController._personality_license_check(personality)
def _do_post(self, ihost_dict):

View File

@ -464,6 +464,42 @@ class TestPost(TestHost):
self.post_json, '/ihosts', ndict,
headers={'User-Agent': 'sysinv-test'})
def test_create_ihost_missing_mgmt_mac(self):
# Test creation of a second node with missing management MAC
self._configure_networks()
# Create controller-0
self._create_controller_0()
ndict = dbutils.post_get_test_ihost(hostname='controller-1',
personality='controller',
subfunctions=None,
mgmt_mac=None,
mgmt_ip=None,
serialid='serial2',
bm_ip="128.224.150.195")
self.assertRaises(webtest.app.AppError,
self.post_json, '/ihosts', ndict,
headers={'User-Agent': 'sysinv-test'})
def test_create_ihost_invalid_mgmt_mac_format(self):
# Test creation of a second node with an invalid management MAC format
self._configure_networks()
# Create controller-0
self._create_controller_0()
ndict = dbutils.post_get_test_ihost(hostname='controller-1',
personality='controller',
subfunctions=None,
mgmt_mac='52:54:00:59:02:9',
mgmt_ip=None,
serialid='serial2',
bm_ip="128.224.150.195")
self.assertRaises(webtest.app.AppError,
self.post_json, '/ihosts', ndict,
headers={'User-Agent': 'sysinv-test'})
class TestDelete(TestHost):

View File

@ -86,6 +86,18 @@ class ManagerTestCase(base.DbTestCase):
res = self.dbapi.ihost_get_list()
self.assertEqual(len(res), 0)
def test_create_ihost_with_invalid_mac(self):
ihost_dict = {'mgmt_mac': '52:54:00:59:02:9'}
self.assertRaises(exception.SysinvException,
self.service.create_ihost,
self.context,
ihost_dict)
# verify create did not happen
res = self.dbapi.ihost_get_list()
self.assertEqual(len(res), 0)
def test_create_ihost_without_ip(self):
ihost_dict = {'mgmt_mac': '00:11:22:33:44:55'}