Fixing URL of index variable and refactoring

This patch fixes the problem related to the URL of the server
 profile template, that was not the same as used in REST API of
 OneView. Also, some refactoring in the client.py module,
 methods *by_uuid, that could be simplified.

Change-Id: I943d1444c9a0315ff1061f20432d7255df75e468
Closes-Bug: #1549994
This commit is contained in:
Caio Oliveira 2016-02-26 16:11:08 +00:00
parent 174e9390e4
commit f4816b6837
2 changed files with 5 additions and 9 deletions

View File

@ -40,7 +40,7 @@ MOMENTARY_PRESS = 'MomentaryPress'
PRESS_AND_HOLD = 'PressAndHold'
SERVER_HARDWARE_PREFIX_URI = '/rest/server-hardware/'
SERVER_PROFILE_TEMPLATE_PREFIX_URI = '/rest/server-profile-template/'
SERVER_PROFILE_TEMPLATE_PREFIX_URI = '/rest/server-profile-templates/'
class Client(object):
@ -179,9 +179,7 @@ class Client(object):
# --- ManagementDriver ---
def get_server_hardware(self, node_info):
INDEX_BEGIN_UUID = len(SERVER_HARDWARE_PREFIX_URI) - 1
server_hardware_uri = node_info['server_hardware_uri']
uuid = server_hardware_uri[INDEX_BEGIN_UUID:]
uuid = node_info['server_hardware_uri'].split("/")[-1]
return self.get_server_hardware_by_uuid(uuid)
@ -219,9 +217,7 @@ class Client(object):
return ServerProfile.from_json(server_profile_json)
def get_server_profile_template(self, node_info):
INDEX_BEGIN_UUID = len(SERVER_PROFILE_TEMPLATE_PREFIX_URI) - 1
server_hardware_uri = node_info['server_profile_template_uri']
uuid = server_hardware_uri[INDEX_BEGIN_UUID:]
uuid = node_info['server_profile_template_uri'].split("/")[-1]
return self.get_server_profile_template_by_uuid(uuid)

View File

@ -534,7 +534,7 @@ class OneViewClientTestCase(unittest.TestCase):
self, mock__prepare_do_request, mock__authenticate
):
mock__prepare_do_request.return_value = {
"uri": "/rest/server-profile-template/123"
"uri": "/rest/server-profile-templates/123"
}
uuid = 123
oneview_client = client.Client(self.manager_url,
@ -542,7 +542,7 @@ class OneViewClientTestCase(unittest.TestCase):
self.password)
oneview_client.get_server_profile_template_by_uuid(uuid)
mock__prepare_do_request.assert_called_once_with(
oneview_client, uri="/rest/server-profile-template/123"
oneview_client, uri="/rest/server-profile-templates/123"
)
@mock.patch.object(client.Client, '_prepare_and_do_request', autospec=True)