Bugfix+removing invalid tests+functional at gate

A bug has been introduced on the code along with ClientV2.
`get_server_profile_template` was calling the manager of server_profile instead
of server_profile_template. This wasn't seen because functional tests for
Client(v1) were wrong and useless. Tests fixed for the case above and I changed
.testr.conf to run funcional tests on py34 and py27 gates since they're mocked
at the limits of the system anyway.

Change-Id: Iea97095dbf34267a053dafbee0ebcd56ec55db13
This commit is contained in:
Thiago Paiva 2016-06-01 17:06:04 -03:00 committed by Gabriel Bezerra
parent 814be3229b
commit b49a1fe73a
4 changed files with 87 additions and 157 deletions

View File

@ -2,6 +2,6 @@
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} -m subunit.run discover -t ./ ${TESTS_DIR:-./oneview_client/tests/unit} $LISTOPT $IDOPTION ${PYTHON:-python} -m subunit.run discover -t ./ ${TESTS_DIR:-./oneview_client/tests} $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE test_id_option=--load-list $IDFILE
test_list_option=--list test_list_option=--list

View File

@ -348,7 +348,7 @@ class Client(BaseClient):
def get_server_profile_template(self, node_info): def get_server_profile_template(self, node_info):
uuid = node_info['server_profile_template_uri'].split("/")[-1] uuid = node_info['server_profile_template_uri'].split("/")[-1]
return self._server_profile.get(uuid) return self._server_profile_template.get(uuid)
def get_server_profile_template_by_uuid(self, uuid): def get_server_profile_template_by_uuid(self, uuid):
return self._server_profile_template.get(uuid) return self._server_profile_template.get(uuid)

View File

@ -47,28 +47,7 @@ class OneViewClientTestCase(unittest.TestCase):
self.password = 'password' self.password = 'password'
@mock.patch.object(requests, 'get', autospec=True) @mock.patch.object(requests, 'get', autospec=True)
def test_server_hardware_list(self, mock_get, mock__authenticate): def test_get_server_hardware(self, mock_get, mock__authenticate):
oneview_client = client.Client(self.manager_url,
self.username,
self.password)
response = mock_get.return_value
response.status_code = http_client.OK
response.json = mock.MagicMock(
return_value=fixtures.SERVER_HARDWARE_LIST_JSON
)
mock_get.return_value = response
server_hardware_list = oneview_client._server_hardware.list()
mock_get.assert_called_once_with(
url='https://1.2.3.4/rest/server-hardware/',
headers=mock.ANY,
verify=True
)
for sh in server_hardware_list:
self.assertIsInstance(sh, models.ServerHardware)
@mock.patch.object(requests, 'get', autospec=True)
def test_server_hardware_get(self, mock_get, mock__authenticate):
oneview_client = client.Client(self.manager_url, oneview_client = client.Client(self.manager_url,
self.username, self.username,
self.password) self.password)
@ -79,7 +58,12 @@ class OneViewClientTestCase(unittest.TestCase):
) )
mock_get.return_value = response mock_get.return_value = response
sh = oneview_client._server_hardware.get('aaaa-bbbb-cccc') node_info = {
'server_hardware_uri': '/rest/server-hardware/aaaa-bbbb-cccc'
}
sh = oneview_client.get_server_hardware(node_info)
mock_get.assert_called_once_with( mock_get.assert_called_once_with(
url='https://1.2.3.4/rest/server-hardware/aaaa-bbbb-cccc', url='https://1.2.3.4/rest/server-hardware/aaaa-bbbb-cccc',
headers=mock.ANY, headers=mock.ANY,
@ -88,7 +72,7 @@ class OneViewClientTestCase(unittest.TestCase):
self.assertIsInstance(sh, models.ServerHardware) self.assertIsInstance(sh, models.ServerHardware)
@mock.patch.object(requests, 'get', autospec=True) @mock.patch.object(requests, 'get', autospec=True)
def test_server_hardware_get_not_found(self, mock_get, mock__authenticate): def test_get_server_hardware_not_found(self, mock_get, mock__authenticate):
oneview_client = client.Client(self.manager_url, oneview_client = client.Client(self.manager_url,
self.username, self.username,
self.password) self.password)
@ -96,59 +80,18 @@ class OneViewClientTestCase(unittest.TestCase):
response.status_code = http_client.NOT_FOUND response.status_code = http_client.NOT_FOUND
mock_get.return_value = response mock_get.return_value = response
node_info = {
'server_hardware_uri': '/rest/server-hardware/aaaa-bbbb-cccc'
}
self.assertRaises( self.assertRaises(
exceptions.OneViewResourceNotFoundError, exceptions.OneViewResourceNotFoundError,
oneview_client._server_hardware.get, oneview_client.get_server_hardware,
'aaaa-bbbb-cccc' node_info
)
def test_server_hardware_create(self, mock__authenticate):
oneview_client = client.Client(self.manager_url,
self.username,
self.password)
self.assertRaises(
NotImplementedError,
oneview_client._server_hardware.create,
name='something',
description='somethingelse',
something=0
)
def test_server_hardware_delete(self, mock__authenticate):
oneview_client = client.Client(self.manager_url,
self.username,
self.password)
self.assertRaises(
NotImplementedError,
oneview_client._server_hardware.delete,
'aaaa-bbbb-cccc'
) )
@mock.patch.object(requests, 'get', autospec=True) @mock.patch.object(requests, 'get', autospec=True)
def test_server_profile_template_list(self, mock_get, mock__authenticate): def test_get_server_profile_template(self, mock_get, mock__authenticate):
oneview_client = client.Client(self.manager_url,
self.username,
self.password)
response = mock_get.return_value
response.status_code = http_client.OK
response.json = mock.MagicMock(
return_value=fixtures.SERVER_PROFILE_TEMPLATE_LIST_JSON
)
mock_get.return_value = response
server_profile_template_list = (
oneview_client._server_profile_template.list()
)
mock_get.assert_called_once_with(
url='https://1.2.3.4/rest/server-profile-templates/',
headers=mock.ANY,
verify=True
)
for spt in server_profile_template_list:
self.assertIsInstance(spt, models.ServerProfileTemplate)
@mock.patch.object(requests, 'get', autospec=True)
def test_server_profile_template_get(self, mock_get, mock__authenticate):
oneview_client = client.Client(self.manager_url, oneview_client = client.Client(self.manager_url,
self.username, self.username,
self.password) self.password)
@ -159,7 +102,12 @@ class OneViewClientTestCase(unittest.TestCase):
) )
mock_get.return_value = response mock_get.return_value = response
spt = oneview_client._server_profile_template.get('aaaa-bbbb-cccc') node_info = {
'server_profile_template_uri':
'/rest/server-profile-templates/aaaa-bbbb-cccc'
}
spt = oneview_client.get_server_profile_template(node_info)
mock_get.assert_called_once_with( mock_get.assert_called_once_with(
url='https://1.2.3.4/rest/server-profile-templates/aaaa-bbbb-cccc', url='https://1.2.3.4/rest/server-profile-templates/aaaa-bbbb-cccc',
headers=mock.ANY, headers=mock.ANY,
@ -177,75 +125,85 @@ class OneViewClientTestCase(unittest.TestCase):
response.status_code = http_client.NOT_FOUND response.status_code = http_client.NOT_FOUND
mock_get.return_value = response mock_get.return_value = response
node_info = {
'server_profile_template_uri':
'/rest/server-profile-templates/aaaa-bbbb-cccc'
}
self.assertRaises( self.assertRaises(
exceptions.OneViewResourceNotFoundError, exceptions.OneViewResourceNotFoundError,
oneview_client._server_profile_template.get, oneview_client.get_server_profile_template,
'aaaa-bbbb-cccc' node_info
)
def test_server_profile_template_create(self, mock__authenticate):
oneview_client = client.Client(self.manager_url,
self.username,
self.password)
self.assertRaises(
NotImplementedError,
oneview_client._server_profile_template.create,
name='something',
description='somethingelse',
something=0
)
def test_server_profile_template_delete(self, mock__authenticate):
oneview_client = client.Client(self.manager_url,
self.username,
self.password)
self.assertRaises(
NotImplementedError,
oneview_client._server_profile_template.delete,
'aaaa-bbbb-cccc'
) )
@mock.patch.object(requests, 'get', autospec=True) @mock.patch.object(requests, 'get', autospec=True)
def test_server_profile_list(self, mock_get, mock__authenticate): def test_get_server_profile_from_hardware(self, mock_get,
mock__authenticate):
oneview_client = client.Client(self.manager_url, oneview_client = client.Client(self.manager_url,
self.username, self.username,
self.password) self.password)
response = mock_get.return_value hardware = mock.MagicMock()
response.status_code = http_client.OK hardware.status_code = http_client.OK
response.json = mock.MagicMock( hardware.json = mock.MagicMock(
return_value=fixtures.SERVER_PROFILE_LIST_JSON return_value=fixtures.SERVER_HARDWARE_LIST_JSON['members'][0]
) )
mock_get.return_value = response profile = mock.MagicMock()
profile.status_code = http_client.OK
server_profile_list = oneview_client._server_profile.list() profile.json = mock.MagicMock(
mock_get.assert_called_once_with(
url='https://1.2.3.4/rest/server-profiles/',
headers=mock.ANY,
verify=True
)
for sp in server_profile_list:
self.assertIsInstance(sp, models.ServerProfile)
@mock.patch.object(requests, 'get', autospec=True)
def test_server_profile_get(self, mock_get, mock__authenticate):
oneview_client = client.Client(self.manager_url,
self.username,
self.password)
response = mock_get.return_value
response.status_code = http_client.OK
response.json = mock.MagicMock(
return_value=fixtures.SERVER_PROFILE_JSON return_value=fixtures.SERVER_PROFILE_JSON
) )
mock_get.return_value = response mock_get.side_effect = [hardware, profile]
sp = oneview_client._server_profile.get('aaaa-bbbb-cccc') node_info = {
mock_get.assert_called_once_with( 'server_hardware_uri':
url='https://1.2.3.4/rest/server-profiles/aaaa-bbbb-cccc', '/rest/server-hardware/30303437-3933-4753-4831-31315835524E'
headers=mock.ANY, }
verify=True
sp = oneview_client.get_server_profile_from_hardware(node_info)
mock_get.assert_has_calls(
[mock.call(
url='https://1.2.3.4/rest/server-hardware/30303437-3933-4753-4'
'831-31315835524E',
headers=mock.ANY,
verify=True,
), mock.call(
url='https://1.2.3.4/rest/server-profiles/f2160e28-8107-45f9-b'
'4b2-3119a622a3a1',
headers=mock.ANY,
verify=True,
)]
) )
self.assertIsInstance(sp, models.ServerProfile) self.assertIsInstance(sp, models.ServerProfile)
@mock.patch.object(requests, 'get', autospec=True)
def test_get_server_profile_from_hardware_no_profile(self, mock_get,
mock__authenticate):
oneview_client = client.Client(self.manager_url,
self.username,
self.password)
hardware = mock.MagicMock()
hardware.status_code = http_client.OK
hardware.json = mock.MagicMock(
return_value=fixtures.SERVER_HARDWARE_JSON
)
profile = mock.MagicMock()
profile.status_code = http_client.OK
profile.json = mock.MagicMock(
return_value=fixtures.SERVER_PROFILE_JSON
)
mock_get.side_effect = [hardware, profile]
node_info = {
'server_hardware_uri':
'/rest/server-hardware/30303437-3933-4753-4831-31315835524E'
}
self.assertRaises(
exceptions.OneViewServerProfileAssociatedError,
oneview_client.get_server_profile_from_hardware,
node_info
)
@mock.patch.object(requests, 'get', autospec=True) @mock.patch.object(requests, 'get', autospec=True)
def test_server_profile_get_not_found(self, mock_get, mock__authenticate): def test_server_profile_get_not_found(self, mock_get, mock__authenticate):
oneview_client = client.Client(self.manager_url, oneview_client = client.Client(self.manager_url,
@ -261,28 +219,6 @@ class OneViewClientTestCase(unittest.TestCase):
'aaaa-bbbb-cccc' 'aaaa-bbbb-cccc'
) )
def test_server_profile_create(self, mock__authenticate):
oneview_client = client.Client(self.manager_url,
self.username,
self.password)
self.assertRaises(
NotImplementedError,
oneview_client._server_profile.create,
name='something',
description='somethingelse',
something=0
)
def test_server_profile_delete(self, mock__authenticate):
oneview_client = client.Client(self.manager_url,
self.username,
self.password)
self.assertRaises(
NotImplementedError,
oneview_client._server_profile.delete,
'aaaa-bbbb-cccc'
)
@mock.patch.object(client.ClientV2, '_authenticate', autospec=True) @mock.patch.object(client.ClientV2, '_authenticate', autospec=True)
class OneViewClientV2TestCase(unittest.TestCase): class OneViewClientV2TestCase(unittest.TestCase):

View File

@ -28,12 +28,6 @@ commands = oslo_debug_helper {posargs}
[flake8] [flake8]
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools
[testenv:functional]
setenv = TESTS_DIR=./oneview_client/tests/functional
LANGUAGE=en_US
show-source = True show-source = True
ignore = E123,E125 ignore = E123,E125
builtins = _ builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build