Validation failing with 2 connections
The `validate_spt_boot_connections` were throwing exception when encoutered a NotBootable connection even when the Primary is present. This patch solves that and adds tests to ensure the behavior expected from this validation. Change-Id: Ic00205bfc69818e68c61aab207a6900a55b493be
This commit is contained in:
parent
0455e167d6
commit
07caa4279c
@ -642,12 +642,13 @@ class Client(BaseClient):
|
||||
|
||||
for connection in server_profile_template.connections:
|
||||
boot = connection.get('boot')
|
||||
if boot is not None and boot.get('priority').lower() != 'primary':
|
||||
message = (
|
||||
"No primary boot connection configured for server profile"
|
||||
" template %s." % server_profile_template.uri
|
||||
)
|
||||
raise exceptions.OneViewInconsistentResource(message)
|
||||
if boot and boot.get('priority').lower() == 'primary':
|
||||
return
|
||||
message = (
|
||||
"No primary boot connection configured for server profile"
|
||||
" template %s." % server_profile_template.uri
|
||||
)
|
||||
raise exceptions.OneViewInconsistentResource(message)
|
||||
|
||||
|
||||
def _check_request_status(response):
|
||||
|
@ -3563,7 +3563,21 @@ SERVER_PROFILE_TEMPLATE_LIST_JSON = {
|
||||
"forceInstallFirmware": False,
|
||||
"firmwareBaselineUri": None
|
||||
},
|
||||
"connections": [],
|
||||
"connections": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "encl1-blade1",
|
||||
"functionType": "Ethernet",
|
||||
"networkUri": "/rest/ethernet-networks/b4a0663d-9160-4566-"
|
||||
"96b3-1b00745c8115",
|
||||
"portId": "Flb 1:1-a",
|
||||
"requestedVFs": "Auto",
|
||||
"requestedMbps": "2500",
|
||||
"boot": {
|
||||
"priority": "NotBootable"
|
||||
}
|
||||
}
|
||||
],
|
||||
"bootMode": None,
|
||||
"boot": {
|
||||
"manageBoot": True,
|
||||
@ -3628,6 +3642,19 @@ SERVER_PROFILE_TEMPLATE_LIST_JSON = {
|
||||
"boot": {
|
||||
"priority": "Primary"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "internal-net-dcs-connection",
|
||||
"functionType": "Ethernet",
|
||||
"networkUri": "/rest/ethernet-networks/b4a0663d-9160-4566-"
|
||||
"96b3-1b00745c8115",
|
||||
"portId": "Flb 1:1-a",
|
||||
"requestedVFs": "Auto",
|
||||
"requestedMbps": "2500",
|
||||
"boot": {
|
||||
"priority": "NotBootable"
|
||||
}
|
||||
}
|
||||
],
|
||||
"bootMode": None,
|
||||
@ -3691,10 +3718,24 @@ SERVER_PROFILE_TEMPLATE_LIST_JSON = {
|
||||
"portId": "Flb 1:1-a",
|
||||
"requestedVFs": "Auto",
|
||||
"requestedMbps": "2500",
|
||||
"boot": {
|
||||
"priority": "NotBootable"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "internal-net-dcs-connection",
|
||||
"functionType": "Ethernet",
|
||||
"networkUri": "/rest/ethernet-networks/b4a0663d-9160-4566-"
|
||||
"96b3-1b00745c8115",
|
||||
"portId": "Flb 1:1-a",
|
||||
"requestedVFs": "Auto",
|
||||
"requestedMbps": "2500",
|
||||
"boot": {
|
||||
"priority": "Primary"
|
||||
}
|
||||
}
|
||||
|
||||
],
|
||||
"bootMode": None,
|
||||
"boot": {
|
||||
@ -3758,7 +3799,20 @@ SERVER_PROFILE_TEMPLATE_LIST_JSON = {
|
||||
"requestedVFs": "Auto",
|
||||
"requestedMbps": "2500",
|
||||
"boot": {
|
||||
"priority": "Primary"
|
||||
"priority": "NotBootable"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Devstack-blade7",
|
||||
"functionType": "Ethernet",
|
||||
"networkUri": "/rest/ethernet-networks/f676ffc9-d2c3-499e-"
|
||||
"b616-265708f34216",
|
||||
"portId": "Flb 1:1-a",
|
||||
"requestedVFs": "Auto",
|
||||
"requestedMbps": "2500",
|
||||
"boot": {
|
||||
"priority": "NotBootable"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -24,6 +24,7 @@ from oneview_client import client
|
||||
from oneview_client import exceptions
|
||||
from oneview_client import models
|
||||
from oneview_client.tests import fixtures
|
||||
from oneview_client import utils
|
||||
|
||||
|
||||
@mock.patch.object(client.Client, '_authenticate', autospec=True)
|
||||
@ -241,6 +242,51 @@ class OneViewClientTestCase(unittest.TestCase):
|
||||
verify=True
|
||||
)
|
||||
|
||||
@mock.patch.object(requests, 'get', autospec=True)
|
||||
def test_validate_spt_boot_connections(self, mock_get, mock__authenticate):
|
||||
oneview_client = client.Client(self.manager_url,
|
||||
self.username,
|
||||
self.password)
|
||||
|
||||
passes = [
|
||||
# Single connection, Primary
|
||||
fixtures.SERVER_PROFILE_TEMPLATE_LIST_JSON.get('members')[0],
|
||||
# Two connections, Primary first
|
||||
fixtures.SERVER_PROFILE_TEMPLATE_LIST_JSON.get('members')[2],
|
||||
# Two connections, Primary second
|
||||
fixtures.SERVER_PROFILE_TEMPLATE_LIST_JSON.get('members')[3],
|
||||
]
|
||||
fails = [
|
||||
# Single connection, no primary
|
||||
fixtures.SERVER_PROFILE_TEMPLATE_LIST_JSON.get('members')[1],
|
||||
# Two connections, any primary
|
||||
fixtures.SERVER_PROFILE_TEMPLATE_LIST_JSON.get('members')[4],
|
||||
# No connections
|
||||
fixtures.SERVER_PROFILE_TEMPLATE_LIST_JSON.get('members')[9],
|
||||
]
|
||||
for spt in passes:
|
||||
response = mock_get.return_value
|
||||
response.status_code = http_client.OK
|
||||
response.json = mock.MagicMock(
|
||||
return_value=spt
|
||||
)
|
||||
mock_get.return_value = response
|
||||
oneview_client.validate_spt_boot_connections(
|
||||
utils.get_uuid_from_uri(spt.get('uri'))
|
||||
)
|
||||
for spt in fails:
|
||||
response = mock_get.return_value
|
||||
response.status_code = http_client.OK
|
||||
response.json = mock.MagicMock(
|
||||
return_value=spt
|
||||
)
|
||||
mock_get.return_value = response
|
||||
self.assertRaises(
|
||||
exceptions.OneViewInconsistentResource,
|
||||
oneview_client.validate_spt_boot_connections,
|
||||
utils.get_uuid_from_uri(spt.get('uri'))
|
||||
)
|
||||
|
||||
|
||||
@mock.patch.object(client.ClientV2, '_authenticate', autospec=True)
|
||||
class OneViewClientV2TestCase(unittest.TestCase):
|
||||
|
@ -821,7 +821,7 @@ class OneViewClientTestCase(unittest.TestCase):
|
||||
|
||||
@mock.patch.object(client.Client, 'get_server_profile_template_by_uuid',
|
||||
autospec=True)
|
||||
def test_validate_spt_boot_connections_no_primary_boot_connection(
|
||||
def test_validate_spt_boot_connections(
|
||||
self, mock_server_template
|
||||
):
|
||||
server_hardware_mock = models.ServerHardware()
|
||||
@ -832,6 +832,7 @@ class OneViewClientTestCase(unittest.TestCase):
|
||||
setattr(profile_template_mock, "server_hardware_type_uri", "/sht_uri")
|
||||
setattr(profile_template_mock, "enclosure_group_uri", "/eg_uri")
|
||||
|
||||
# Negative scenario
|
||||
profile_template_mock_connections = [
|
||||
{'boot': {'priority': u'NotBootable'},
|
||||
'mac': u'56:88:7B:C0:00:0B'}
|
||||
@ -856,6 +857,55 @@ class OneViewClientTestCase(unittest.TestCase):
|
||||
server_profile_template_uuid
|
||||
)
|
||||
|
||||
# Positive scenario
|
||||
profile_template_mock_connections = [
|
||||
{'boot': {'priority': u'Primary'},
|
||||
'mac': u'56:88:7B:C0:00:0B'}
|
||||
]
|
||||
setattr(profile_template_mock,
|
||||
"connections",
|
||||
profile_template_mock_connections)
|
||||
|
||||
mock_server_template.return_value = profile_template_mock
|
||||
|
||||
self.oneview_client.validate_spt_boot_connections(
|
||||
server_profile_template_uuid
|
||||
)
|
||||
|
||||
# More than one connection, Primary first
|
||||
profile_template_mock_connections = [
|
||||
{'boot': {'priority': u'Primary'},
|
||||
'mac': u'56:88:7B:C0:00:0B'},
|
||||
{'boot': {'priority': u'NotBootable'},
|
||||
'mac': u'56:88:7B:C0:00:0C'}
|
||||
]
|
||||
setattr(profile_template_mock,
|
||||
"connections",
|
||||
profile_template_mock_connections)
|
||||
|
||||
mock_server_template.return_value = profile_template_mock
|
||||
|
||||
self.oneview_client.validate_spt_boot_connections(
|
||||
server_profile_template_uuid
|
||||
)
|
||||
|
||||
# More than one connection, Primary NOT first
|
||||
profile_template_mock_connections = [
|
||||
{'boot': {'priority': u'NotBootable'},
|
||||
'mac': u'56:88:7B:C0:00:0B'},
|
||||
{'boot': {'priority': u'Primary'},
|
||||
'mac': u'56:88:7B:C0:00:0C'}
|
||||
]
|
||||
setattr(profile_template_mock,
|
||||
"connections",
|
||||
profile_template_mock_connections)
|
||||
|
||||
mock_server_template.return_value = profile_template_mock
|
||||
|
||||
self.oneview_client.validate_spt_boot_connections(
|
||||
server_profile_template_uuid
|
||||
)
|
||||
|
||||
@mock.patch.object(client.Client, 'get_oneview_version')
|
||||
def test_verify_oneview_version(self, mock_get_oneview_version):
|
||||
mock_get_oneview_version.return_value = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user