Adding check for missing configuration values
The python-oneviewclient must raise exceptions when 'manager_url' configuration parameter has a null or empty value. Some checks were changed and added to oneview_client.client. Change-Id: I22984cd6757a7816e323bd156eefda086aa06364
This commit is contained in:
parent
ae731b1c16
commit
654fd4db93
@ -55,11 +55,19 @@ class Client(object):
|
|||||||
|
|
||||||
self.session_id = self.get_session()
|
self.session_id = self.get_session()
|
||||||
|
|
||||||
|
def verify_credentials(self):
|
||||||
|
return self._authenticate()
|
||||||
|
|
||||||
def get_session(self):
|
def get_session(self):
|
||||||
response = self._authenticate()
|
response = self._authenticate()
|
||||||
return response.json().get('sessionID')
|
return response.json().get('sessionID')
|
||||||
|
|
||||||
def _authenticate(self):
|
def _authenticate(self):
|
||||||
|
if self.manager_url in ("", None):
|
||||||
|
raise exceptions.OneViewConnectionError(
|
||||||
|
"Can't connect to OneView: 'manager_url' configuration"
|
||||||
|
"parameter is blank")
|
||||||
|
|
||||||
url = '%s/rest/login-sessions' % self.manager_url
|
url = '%s/rest/login-sessions' % self.manager_url
|
||||||
body = {
|
body = {
|
||||||
'userName': self.username,
|
'userName': self.username,
|
||||||
@ -76,7 +84,7 @@ class Client(object):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
verify=verify_ssl)
|
verify=verify_ssl)
|
||||||
|
|
||||||
if r.status_code == 401:
|
if r.status_code == 400:
|
||||||
raise exceptions.OneViewNotAuthorizedException()
|
raise exceptions.OneViewNotAuthorizedException()
|
||||||
else:
|
else:
|
||||||
return r
|
return r
|
||||||
@ -101,7 +109,7 @@ class Client(object):
|
|||||||
def _is_oneview_version_compatible(self):
|
def _is_oneview_version_compatible(self):
|
||||||
versions = self.get_oneview_version()
|
versions = self.get_oneview_version()
|
||||||
v = SUPPORTED_ONEVIEW_VERSION
|
v = SUPPORTED_ONEVIEW_VERSION
|
||||||
min_version_compatible = versions.get('minimumVersion') <= v
|
min_version_compatible = versions.get("minimumVersion") <= v
|
||||||
max_version_compatible = versions.get("currentVersion") >= v
|
max_version_compatible = versions.get("currentVersion") >= v
|
||||||
return min_version_compatible and max_version_compatible
|
return min_version_compatible and max_version_compatible
|
||||||
|
|
||||||
@ -270,15 +278,15 @@ class Client(object):
|
|||||||
if server_hardware_memorymb != node_memorymb:
|
if server_hardware_memorymb != node_memorymb:
|
||||||
message = (
|
message = (
|
||||||
"Node memory_mb is inconsistent with OneView's"
|
"Node memory_mb is inconsistent with OneView's"
|
||||||
" server hardware %(server_hardware_uri)s memoryMb. Node"
|
" server hardware %(server_hardware_uri)s memoryMb."
|
||||||
" validation failed." % {'server_hardware_uri': node_sh_uri}
|
% {'server_hardware_uri': node_sh_uri}
|
||||||
)
|
)
|
||||||
raise exceptions.OneViewInconsistentResource(message)
|
raise exceptions.OneViewInconsistentResource(message)
|
||||||
elif server_hardware_cpus != node_cpus:
|
elif server_hardware_cpus != node_cpus:
|
||||||
message = (
|
message = (
|
||||||
"Node cpus is inconsistent with OneView's"
|
"Node cpus is inconsistent with OneView's"
|
||||||
" server hardware %(server_hardware_uri)s cpus. Node"
|
" server hardware %(server_hardware_uri)s cpus."
|
||||||
" validation failed." % {'server_hardware_uri': node_sh_uri}
|
% {'server_hardware_uri': node_sh_uri}
|
||||||
)
|
)
|
||||||
raise exceptions.OneViewInconsistentResource(message)
|
raise exceptions.OneViewInconsistentResource(message)
|
||||||
|
|
||||||
@ -291,7 +299,7 @@ class Client(object):
|
|||||||
message = (
|
message = (
|
||||||
"Node server_hardware_type_uri is inconsistent"
|
"Node server_hardware_type_uri is inconsistent"
|
||||||
" with OneView's server hardware %(server_hardware_uri)s"
|
" with OneView's server hardware %(server_hardware_uri)s"
|
||||||
" serverHardwareTypeUri. Node validation failed." %
|
" serverHardwareTypeUri." %
|
||||||
{'server_hardware_uri': node_info.get('server_hardware_uri')}
|
{'server_hardware_uri': node_info.get('server_hardware_uri')}
|
||||||
)
|
)
|
||||||
raise exceptions.OneViewInconsistentResource(message)
|
raise exceptions.OneViewInconsistentResource(message)
|
||||||
@ -309,7 +317,7 @@ class Client(object):
|
|||||||
message = (
|
message = (
|
||||||
"Node enclosure_group_uri is inconsistent"
|
"Node enclosure_group_uri is inconsistent"
|
||||||
" with OneView's server hardware %(server_hardware_uri)s"
|
" with OneView's server hardware %(server_hardware_uri)s"
|
||||||
" serverGroupUri. Node validation failed." %
|
" serverGroupUri." %
|
||||||
{'server_hardware_uri': node_info.
|
{'server_hardware_uri': node_info.
|
||||||
get('server_hardware_uri')}
|
get('server_hardware_uri')}
|
||||||
)
|
)
|
||||||
@ -330,7 +338,7 @@ class Client(object):
|
|||||||
if primary_boot_connection is None:
|
if primary_boot_connection is None:
|
||||||
message = (
|
message = (
|
||||||
"No primary boot connection configured for server profile"
|
"No primary boot connection configured for server profile"
|
||||||
" %s Node validation failed." % server_profile_json.get('uri')
|
" %s." % server_profile_json.get('uri')
|
||||||
)
|
)
|
||||||
raise exceptions.OneViewInconsistentResource(message)
|
raise exceptions.OneViewInconsistentResource(message)
|
||||||
|
|
||||||
@ -338,15 +346,17 @@ class Client(object):
|
|||||||
|
|
||||||
is_mac_address_compatible = True
|
is_mac_address_compatible = True
|
||||||
for port in ports:
|
for port in ports:
|
||||||
if port.__dict__.get('_obj_address').lower() != \
|
port_address = port.__dict__.get('_obj_address')
|
||||||
|
if port_address is None:
|
||||||
|
port_address = port.__dict__.get('_address')
|
||||||
|
if port_address.lower() != \
|
||||||
server_profile_mac.lower():
|
server_profile_mac.lower():
|
||||||
is_mac_address_compatible = False
|
is_mac_address_compatible = False
|
||||||
|
|
||||||
if (not is_mac_address_compatible) or len(ports) == 0:
|
if (not is_mac_address_compatible) or len(ports) == 0:
|
||||||
message = (
|
message = (
|
||||||
"The ports of the node are not compatible with its"
|
"The ports of the node are not compatible with its"
|
||||||
" server profile %(server_profile_uri)s. Node validation"
|
" server profile %(server_profile_uri)s." %
|
||||||
" failed." %
|
|
||||||
{'server_profile_uri': server_profile_json.get('uri')}
|
{'server_profile_uri': server_profile_json.get('uri')}
|
||||||
)
|
)
|
||||||
raise exceptions.OneViewInconsistentResource(message)
|
raise exceptions.OneViewInconsistentResource(message)
|
||||||
@ -372,7 +382,7 @@ class Client(object):
|
|||||||
message = (
|
message = (
|
||||||
"Server profile template %(spt_uri)s serverHardwareTypeUri is"
|
"Server profile template %(spt_uri)s serverHardwareTypeUri is"
|
||||||
" inconsistent with server hardware %(server_hardware_uri)s"
|
" inconsistent with server hardware %(server_hardware_uri)s"
|
||||||
" serverHardwareTypeUri. Node validation failed." %
|
" serverHardwareTypeUri." %
|
||||||
{'spt_uri': node_spt_uri,
|
{'spt_uri': node_spt_uri,
|
||||||
'server_hardware_uri': node_info.get('server_hardware_uri')}
|
'server_hardware_uri': node_info.get('server_hardware_uri')}
|
||||||
)
|
)
|
||||||
@ -381,7 +391,7 @@ class Client(object):
|
|||||||
message = (
|
message = (
|
||||||
"Server profile template %(spt_uri)s enclosureGroupUri is"
|
"Server profile template %(spt_uri)s enclosureGroupUri is"
|
||||||
" inconsistent with server hardware %(server_hardware_uri)s"
|
" inconsistent with server hardware %(server_hardware_uri)s"
|
||||||
" serverGroupUri. Node validation failed." %
|
" serverGroupUri." %
|
||||||
{'spt_uri': node_spt_uri,
|
{'spt_uri': node_spt_uri,
|
||||||
'server_hardware_uri': node_info.get('server_hardware_uri')}
|
'server_hardware_uri': node_info.get('server_hardware_uri')}
|
||||||
)
|
)
|
||||||
@ -473,7 +483,9 @@ def _check_request_status(response):
|
|||||||
repeat = False
|
repeat = False
|
||||||
status = response.status_code
|
status = response.status_code
|
||||||
|
|
||||||
if status == 404:
|
if status == 401:
|
||||||
|
raise exceptions.OneViewNotAuthorizedException()
|
||||||
|
elif status == 404:
|
||||||
raise exceptions.OneViewResourceNotFoundError()
|
raise exceptions.OneViewResourceNotFoundError()
|
||||||
elif status in (409,):
|
elif status in (409,):
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
@ -75,7 +75,7 @@ class OneViewClientAuthTestCase(unittest.TestCase):
|
|||||||
@mock.patch.object(requests, 'post')
|
@mock.patch.object(requests, 'post')
|
||||||
def test_authenticate_invalid_credentials(self, mock_post):
|
def test_authenticate_invalid_credentials(self, mock_post):
|
||||||
response = mock_post.return_value
|
response = mock_post.return_value
|
||||||
response.status_code = http_client.UNAUTHORIZED
|
response.status_code = http_client.BAD_REQUEST
|
||||||
mock_post.return_value = response
|
mock_post.return_value = response
|
||||||
|
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
@ -391,7 +391,7 @@ class OneViewClientTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
exc_expected_msg = (
|
exc_expected_msg = (
|
||||||
"Node memory_mb is inconsistent with OneView's server"
|
"Node memory_mb is inconsistent with OneView's server"
|
||||||
" hardware /any_uri memoryMb. Node validation failed."
|
" hardware /any_uri memoryMb."
|
||||||
)
|
)
|
||||||
|
|
||||||
oneview_client = client.Client(self.manager_url,
|
oneview_client = client.Client(self.manager_url,
|
||||||
@ -424,7 +424,7 @@ class OneViewClientTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
exc_expected_msg = (
|
exc_expected_msg = (
|
||||||
"Node cpus is inconsistent with OneView's server"
|
"Node cpus is inconsistent with OneView's server"
|
||||||
" hardware /any_uri cpus. Node validation failed."
|
" hardware /any_uri cpus."
|
||||||
)
|
)
|
||||||
|
|
||||||
oneview_client = client.Client(self.manager_url,
|
oneview_client = client.Client(self.manager_url,
|
||||||
@ -455,7 +455,6 @@ class OneViewClientTestCase(unittest.TestCase):
|
|||||||
exc_expected_msg = (
|
exc_expected_msg = (
|
||||||
"Node server_hardware_type_uri is inconsistent with"
|
"Node server_hardware_type_uri is inconsistent with"
|
||||||
" OneView's server hardware /any_serveruri serverHardwareTypeUri."
|
" OneView's server hardware /any_serveruri serverHardwareTypeUri."
|
||||||
" Node validation failed."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
oneview_client = client.Client(self.manager_url,
|
oneview_client = client.Client(self.manager_url,
|
||||||
@ -481,7 +480,6 @@ class OneViewClientTestCase(unittest.TestCase):
|
|||||||
exc_expected_msg = (
|
exc_expected_msg = (
|
||||||
"Node enclosure_group_uri is inconsistent with"
|
"Node enclosure_group_uri is inconsistent with"
|
||||||
" OneView's server hardware /any_uri serverGroupUri."
|
" OneView's server hardware /any_uri serverGroupUri."
|
||||||
" Node validation failed."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
oneview_client = client.Client(self.manager_url,
|
oneview_client = client.Client(self.manager_url,
|
||||||
@ -510,7 +508,7 @@ class OneViewClientTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
exc_expected_msg = (
|
exc_expected_msg = (
|
||||||
"The ports of the node are not compatible with its"
|
"The ports of the node are not compatible with its"
|
||||||
" server profile /anyuri. Node validation failed."
|
" server profile /anyuri."
|
||||||
)
|
)
|
||||||
|
|
||||||
oneview_client = client.Client(self.manager_url,
|
oneview_client = client.Client(self.manager_url,
|
||||||
@ -541,7 +539,7 @@ class OneViewClientTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
exc_expected_msg = (
|
exc_expected_msg = (
|
||||||
"No primary boot connection configured for server profile"
|
"No primary boot connection configured for server profile"
|
||||||
" /anyuri Node validation failed."
|
" /anyuri."
|
||||||
)
|
)
|
||||||
|
|
||||||
oneview_client = client.Client(self.manager_url,
|
oneview_client = client.Client(self.manager_url,
|
||||||
@ -578,7 +576,7 @@ class OneViewClientTestCase(unittest.TestCase):
|
|||||||
exc_expected_msg = (
|
exc_expected_msg = (
|
||||||
"Server profile template /profile_uri serverHardwareTypeUri is"
|
"Server profile template /profile_uri serverHardwareTypeUri is"
|
||||||
" inconsistent with server hardware /any_uri"
|
" inconsistent with server hardware /any_uri"
|
||||||
" serverHardwareTypeUri. Node validation failed."
|
" serverHardwareTypeUri."
|
||||||
)
|
)
|
||||||
|
|
||||||
oneview_client = client.Client(self.manager_url,
|
oneview_client = client.Client(self.manager_url,
|
||||||
@ -613,7 +611,7 @@ class OneViewClientTestCase(unittest.TestCase):
|
|||||||
exc_expected_msg = (
|
exc_expected_msg = (
|
||||||
"Server profile template /profile_uri enclosureGroupUri is"
|
"Server profile template /profile_uri enclosureGroupUri is"
|
||||||
" inconsistent with server hardware /any_uri"
|
" inconsistent with server hardware /any_uri"
|
||||||
" serverGroupUri. Node validation failed."
|
" serverGroupUri."
|
||||||
)
|
)
|
||||||
|
|
||||||
oneview_client = client.Client(self.manager_url,
|
oneview_client = client.Client(self.manager_url,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user