diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ff7c6b8c..317d8f86a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 8.0.0 +#### Notes +Extends support of the SDK to OneView REST API version 4600 (OneView v8.0.0) +#### Major changes +Added support for San Manager resources + # 7.2.0 #### Notes Extends support of the SDK to OneView REST API version 4400 (OneView v7.2.0) diff --git a/examples/san_managers.py b/examples/san_managers.py index e9c31dc88..4c45f134f 100644 --- a/examples/san_managers.py +++ b/examples/san_managers.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ### -# (C) Copyright [2019] Hewlett Packard Enterprise Development LP +# (C) Copyright [2022] Hewlett Packard Enterprise Development LP # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ from hpeOneView.oneview_client import OneViewClient # This example has options pre-defined for 'Brocade Network Advisor' and 'Cisco' type SAN Managers -PROVIDER_NAME = 'Cisco' +PROVIDER_NAME = 'Brocade FOS Switch' config = { "ip": "", @@ -34,44 +34,60 @@ # # To run this sample you must define the following resources for a Brocade Network Advisor manager_host = '' manager_port = '' -manager_username = '' +manager_username = '' manager_password = '' # Try load config from a file (if there is a config file) config = try_load_from_file(config) oneview_client = OneViewClient(config) +san_providers = oneview_client.san_providers +san_managers = oneview_client.san_managers + # Print default connection info for Brocade Network Advisor print("\nGet {} default connection info:".format(PROVIDER_NAME)) -default_info = oneview_client.san_managers.get_default_connection_info(PROVIDER_NAME) +default_info = san_providers.get_default_connection_info(PROVIDER_NAME) +print(default_info) for property in default_info: print(" '{name}' - '{value}'".format(**property)) # Add a Brocade Network Advisor -provider_uri = oneview_client.san_managers.get_provider_uri(PROVIDER_NAME) +provider_uri = san_providers.get_provider_uri(PROVIDER_NAME) options_for_brocade = { 'providerDisplayName': PROVIDER_NAME, 'connectionInfo': [ { - 'name': 'Host', - 'value': manager_host + "name": "Host", + "displayName": "Host", + "required": True, + "value": manager_host, + "valueType": "String", + "valueFormat": "IPAddressOrHostname" }, { - 'name': 'Port', - 'value': manager_port + "name": "Username", + "displayName": "Username", + "required": True, + "value": manager_username, + "valueType": "String", + "valueFormat": "None" }, { - 'name': 'Username', - 'value': manager_username + "name": "Password", + "displayName": "Password", + "required": True, + "value": manager_password, + "valueType": "String", + "valueFormat": "SecuritySensitive" }, { - 'name': 'Password', - 'value': manager_password - }, - { - 'name': 'UseSsl', - 'value': True + "name": "UseHttps", + "displayName": "UseHttps", + "required": True, + "value": True, + "valueType": "Boolean", + "valueFormat": "None" } ] } @@ -146,10 +162,10 @@ ] } -if PROVIDER_NAME == 'Brocade Network Advisor': - san_manager = oneview_client.san_managers.add(options_for_brocade, provider_uri) +if PROVIDER_NAME == 'Brocade FOS Switch': + san_manager = san_providers.add(options_for_brocade, provider_uri) elif PROVIDER_NAME == 'Cisco': - san_manager = oneview_client.san_managers.add(options_for_cisco, provider_uri) + san_manager = san_providers.add(options_for_cisco, provider_uri) else: provider_error_msg = 'Options for the "%s" provider not pre-added to this example file. Validate ' provider_error_msg < 'and or create options for that provider and remove this exception.' % PROVIDER_NAME @@ -161,22 +177,23 @@ info = { 'refreshState': "RefreshPending" } -san_manager = oneview_client.san_managers.update(resource=info, id_or_uri=san_manager['uri']) +san_manager = san_managers.update(resource=info, id_or_uri=san_manager['uri']) print(" 'refreshState' successfully updated to '{refreshState}'".format(**san_manager)) print("\nGet SAN manager by uri") -san_manager_byuri = oneview_client.san_managers.get(san_manager['uri']) -print(" Found '{name}' at uri: {uri}".format(**san_manager_byuri)) +san_manager_byuri = san_managers.get_by_uri(san_manager['uri']) + +print(" Found '{name}' at uri: {uri}".format(**san_manager_byuri.data)) print("\nGet all SAN managers") -san_managers = oneview_client.san_managers.get_all() -for manager in san_managers: +san_manager_all = san_managers.get_all() +for manager in san_manager_all: print(" '{name}' at uri: {uri}".format(**manager)) print("\nGet a SAN Manager by name") -san_managers_by_name = oneview_client.san_managers.get_by_name(manager_host) +san_managers_by_name = san_managers.get_by_name(manager_host) pprint(san_managers_by_name) print("\nDelete the SAN Manager previously created...") -oneview_client.san_managers.remove(san_manager) +san_managers_by_name.remove() print("The SAN Manager was deleted successfully.") diff --git a/hpeOneView/oneview_client.py b/hpeOneView/oneview_client.py index 1bfa0f7af..33d6cb581 100755 --- a/hpeOneView/oneview_client.py +++ b/hpeOneView/oneview_client.py @@ -24,6 +24,7 @@ from future import standard_library + standard_library.install_aliases() import json @@ -68,6 +69,7 @@ from hpeOneView.resources.facilities.datacenters import Datacenters from hpeOneView.resources.fc_sans.managed_sans import ManagedSANs from hpeOneView.resources.fc_sans.san_managers import SanManagers +from hpeOneView.resources.fc_sans.san_providers import SanProviders from hpeOneView.resources.fc_sans.endpoints import Endpoints from hpeOneView.resources.networking.logical_interconnects import LogicalInterconnects from hpeOneView.resources.networking.logical_interconnect_groups import LogicalInterconnectGroups @@ -170,6 +172,7 @@ def __init__(self, config, sessionID=None): self.__roles = None self.__datacenters = None self.__san_managers = None + self.__san_providers = None self.__endpoints = None self.__logical_interconnects = None self.__sas_logical_interconnects = None @@ -792,14 +795,12 @@ def racks(self): @property def san_managers(self): """ - Gets the SanManagers API client. + Gets the Repositories API client. Returns: - SanManagers: + Repositories: """ - if not self.__san_managers: - self.__san_managers = SanManagers(self.__connection) - return self.__san_managers + return SanManagers(self.__connection) @property def endpoints(self): @@ -1287,3 +1288,13 @@ def repositories(self): Repositories: """ return Repositories(self.__connection) + + @property + def san_providers(self): + """ + Gets the Repositories API client. + + Returns: + Repositories: + """ + return SanProviders(self.__connection) diff --git a/hpeOneView/resources/fc_sans/san_managers.py b/hpeOneView/resources/fc_sans/san_managers.py index 4ced09bfd..ec586cb2e 100644 --- a/hpeOneView/resources/fc_sans/san_managers.py +++ b/hpeOneView/resources/fc_sans/san_managers.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ### -# (C) Copyright [2019] Hewlett Packard Enterprise Development LP +# (C) Copyright [2022] Hewlett Packard Enterprise Development LP # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,26 +25,22 @@ standard_library.install_aliases() -from hpeOneView.resources.resource import ResourceClient +from hpeOneView.resources.resource import Resource -class SanManagers(object): +class SanManagers(Resource): """ SAN Managers API client. """ URI = '/rest/fc-sans/device-managers' - PROVIDER_URI = '/rest/fc-sans/providers' - def __init__(self, con): - self._connection = con - self._client = ResourceClient(con, self.URI) - self._provider_client = ResourceClient(con, self.PROVIDER_URI) + def __init__(self, connection, data=None): + super(SanManagers, self).__init__(connection, data) - def get_all(self, start=0, count=-1, query='', sort=''): + def get_all(self, start=0, count=-1, filter='', sort='', query=''): """ Retrieves the list of registered SAN Managers. - Args: start: The first item to return, using 0-based indexing. @@ -53,6 +49,9 @@ def get_all(self, start=0, count=-1, query='', sort=''): The number of resources to return. A count of -1 requests all items. The actual number of items in the response may differ from the requested count if the sum of start and count exceed the total number of items. + filter (list or str): + A general filter/query string to narrow the list of items returned. The + default is no filter; all resources are returned. query: A general query string to narrow the list of resources returned. The default is no query - all resources are returned. @@ -64,19 +63,7 @@ def get_all(self, start=0, count=-1, query='', sort=''): list: A list of SAN managers. """ - return self._client.get_all(start=start, count=count, query=query, sort=sort) - - def get(self, id_or_uri): - """ - Retrieves a single registered SAN Manager by ID or URI. - - Args: - id_or_uri: Can be either the SAN Manager resource ID or URI. - - Returns: - dict: The SAN Manager resource. - """ - return self._client.get(id_or_uri=id_or_uri) + return self._helper.get_all(start=start, count=count, filter=filter, sort=sort, query=query,) def update(self, resource, id_or_uri): """ @@ -89,68 +76,26 @@ def update(self, resource, id_or_uri): Returns: dict: The device manager resource. """ - return self._client.update(resource=resource, uri=id_or_uri) - def add(self, resource, provider_uri_or_id, timeout=-1): - """ - Adds a Device Manager under the specified provider. - - Args: - resource (dict): Object to add. - provider_uri_or_id: ID or URI of provider. - timeout: - Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation - in OneView, just stop waiting for its completion. - - Returns: - dict: Added SAN Manager. - """ - uri = self._provider_client.build_uri(provider_uri_or_id) + "/device-managers" - return self._client.create(resource=resource, uri=uri, timeout=timeout) + return self._helper.update(resource=resource, uri=id_or_uri) - def get_provider_uri(self, provider_display_name): + def remove(self, force=False, timeout=-1): """ - Gets uri for a specific provider. + Removes the SAN Manager from OneView. Args: - provider_display_name: Display name of the provider. - - Returns: - uri - """ - providers = self._provider_client.get_by('displayName', provider_display_name) - return providers[0]['uri'] if providers else None - - def get_default_connection_info(self, provider_name): - """ - Gets default connection info for a specific provider. - - Args: - provider_name: Name of the provider. - - Returns: - dict: Default connection information. - """ - provider = self._provider_client.get_by_name(provider_name) - if provider: - return provider['defaultConnectionInfo'] - else: - return {} - - def remove(self, resource, timeout=-1): - """ - Removes a registered SAN Manager. - - Args: - resource (dict): Object to delete. + force (bool): + If set to true, the operation completes despite any problems with + network connectivity or errors on the resource itself. The default is false. timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation in OneView; it just stops waiting for its completion. Returns: - bool: Indicates if the resource was successfully removed. + dict: Details of associated resource. """ - return self._client.delete(resource, timeout=timeout) + headers = {'If-Match': '*'} + return self.delete(force=force, timeout=timeout, custom_headers=headers) def get_by_name(self, name): """ @@ -160,11 +105,12 @@ def get_by_name(self, name): name: Name of the SAN Manager Returns: - dict: SAN Manager. + SAN Manager. """ - san_managers = self._client.get_all() + san_managers = self.get_all() result = [x for x in san_managers if x['name'] == name] - return result[0] if result else None + + return self.new(self._connection, result[0])if result else None def get_by_provider_display_name(self, provider_display_name): """ @@ -174,8 +120,8 @@ def get_by_provider_display_name(self, provider_display_name): provider_display_name: Name of the Provider Display Name Returns: - dict: SAN Manager. + SAN Manager. """ - san_managers = self._client.get_all() + san_managers = self.get_all() result = [x for x in san_managers if x['providerDisplayName'] == provider_display_name] - return result[0] if result else None + return self.new(self._connection, result[0])if result else None diff --git a/hpeOneView/resources/fc_sans/san_providers.py b/hpeOneView/resources/fc_sans/san_providers.py new file mode 100644 index 000000000..cad3e7ee0 --- /dev/null +++ b/hpeOneView/resources/fc_sans/san_providers.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +### +# (C) Copyright [2022] Hewlett Packard Enterprise Development LP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +### + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +from future import standard_library + +standard_library.install_aliases() + + +from hpeOneView.resources.resource import Resource + + +class SanProviders(Resource): + """ + SAN Managers API client. + + """ + + URI = '/rest/fc-sans/providers' + + def __init__(self, connection, data=None): + super(SanProviders, self).__init__(connection, data) + + def add(self, resource, provider_uri_or_id, timeout=-1): + """ + Adds a Device Manager under the specified provider. + + Args: + resource (dict): Object to add. + provider_uri_or_id: ID or URI of provider. + timeout: + Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation + in OneView, just stop waiting for its completion. + + Returns: + dict: Added SAN Manager. + """ + uri = provider_uri_or_id + "/device-managers" + + return self._helper.create(data=resource, uri=uri, timeout=timeout) + + def get_provider_uri(self, provider_display_name): + """ + Gets uri for a specific provider. + + Args: + provider_display_name: Display name of the provider. + + Returns: + uri + """ + providers = self.get_by_field('displayName', provider_display_name) + return providers.data['uri'] if providers else None + + def get_default_connection_info(self, provider_name): + """ + Gets default connection info for a specific provider. + + Args: + provider_name: Name of the provider. + + Returns: + dict: Default connection information. + """ + provider = self.get_by_field('displayName', provider_name) + + if provider: + return provider.data['defaultConnectionInfo'] + else: + return {} diff --git a/tests/unit/resources/fc_sans/test_san_managers.py b/tests/unit/resources/fc_sans/test_san_managers.py index a08477a1a..c1b39a8ad 100644 --- a/tests/unit/resources/fc_sans/test_san_managers.py +++ b/tests/unit/resources/fc_sans/test_san_managers.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ### -# (C) Copyright [2020] Hewlett Packard Enterprise Development LP +# (C) Copyright [2022] Hewlett Packard Enterprise Development LP # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,204 +20,86 @@ import mock from hpeOneView.connection import connection -from hpeOneView.resources.resource import ResourceClient from hpeOneView.resources.fc_sans.san_managers import SanManagers +from hpeOneView.resources.resource import ResourceHelper TIMEOUT = -1 -PROVIDERS = [ - { - "uri": "/rest/fc-sans/providers/0aa1f4e1-3b5e-4233-af1a-f849dc64da69", - "name": "Brocade San Plugin", - "displayName": "Brocade Network Advisor", - "sanType": "Fabric" - }, - { - "uri": "/rest/fc-sans/providers/848c191d-c995-4cd5-a7ba-e627435dd5f2", - "name": "Cisco San Plugin", - "displayName": "Cisco", - "sanType": "Fabric" - }, - { - "uri": "/rest/fc-sans/providers/5c5c67f5-0f8f-4c85-a54f-f26b1f1332c7", - "name": "Direct Attach SAN Plugin", - "displayName": "HPE", - "sanType": "Fabric" - } -] - class SanManagersTest(TestCase): def setUp(self): - host = '127.0.0.1' - http_connection = connection(host, 800) - self._resource = SanManagers(http_connection) + self.host = '127.0.0.1' + self.connection = connection(self.host, 800) + self._san_manager = SanManagers(self.connection) + self.uri = "/rest/fc-sans/device-managers/1234-5678" + self._san_manager.data = {"uri": self.uri} - @mock.patch.object(ResourceClient, 'get_all') + @mock.patch.object(ResourceHelper, 'get_all') def test_get_all(self, mock_get_all): query_filter = "name EQ 'TestName'" sort = 'name:ascending' + query = 'query' - self._resource.get_all(start=2, count=500, query=query_filter, sort=sort) - mock_get_all.assert_called_once_with(start=2, count=500, query=query_filter, sort=sort) - - @mock.patch.object(ResourceClient, 'get') - def test_get_by_id(self, mock_get): - id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" - - self._resource.get(id) - mock_get.assert_called_once_with(id_or_uri=id) - - @mock.patch.object(ResourceClient, 'create') - def test_add_withId(self, mock_create): - resource = { - "connectionInfo": [ - { - "name": "Host", - "value": "brocade-device-manager.domain.com" - }, - { - "name": "Port", - "value": 5989 - }, - { - "name": "Username", - "value": "Administrator" - }, - { - "name": "Password", - "value": "password" - }, - { - "name": "UseSsl", - "value": True - } - ] - } + self._san_manager.get_all(start=2, count=500, filter=query_filter, query=query, sort=sort) + mock_get_all.assert_called_once_with(start=2, count=500, filter=query_filter, query=query, sort=sort) - provider_id = "534-345-345-55" - rest_uri = "/rest/fc-sans/providers/534-345-345-55/device-managers" - - self._resource.add(resource, provider_uri_or_id=provider_id, timeout=TIMEOUT) - mock_create.assert_called_once_with(resource=resource, uri=rest_uri, timeout=TIMEOUT) - - @mock.patch.object(ResourceClient, 'create') - def test_add_withUri(self, mock_create): - resource = { - "connectionInfo": [ - { - "name": "Host", - "value": "brocade-device-manager.domain.com" - }, - { - "name": "Port", - "value": 5989 - }, - { - "name": "Username", - "value": "Administrator" - }, - { - "name": "Password", - "value": "password" - }, - { - "name": "UseSsl", - "value": True - } - ] + @mock.patch.object(ResourceHelper, 'update') + def test_update_a_registered_device_manager(self, mock_update): + uri_rest_call = self.uri + info = { + 'refreshState': "RefreshPending" } - provider_uri = "/rest/fc-sans/providers/534-345-345-55" - rest_uri = "/rest/fc-sans/providers/534-345-345-55/device-managers" - - self._resource.add(resource, provider_uri_or_id=provider_uri, timeout=TIMEOUT) - mock_create.assert_called_once_with(resource=resource, uri=rest_uri, timeout=TIMEOUT) - - @mock.patch.object(ResourceClient, 'get_by_name') - def test_get_default_connection_info(self, mock_get_by_name): - provider_name = "Brocade Network Advisor" - self._resource.get_default_connection_info(provider_name) - mock_get_by_name.assert_called_once_with(provider_name) - - @mock.patch.object(ResourceClient, 'get_by_name') - def test_get_default_connection_info_with_empty_provider(self, mock_get_by_name): - provider_name = "Brocade Network Advisor" - mock_get_by_name.return_value = None - provider = self._resource.get_default_connection_info(provider_name) - self.assertFalse(provider) - mock_get_by_name.assert_called_once_with(provider_name) - - @mock.patch.object(ResourceClient, 'get_all') - def test_get_provider_uri(self, mock_get_all): - provider_name = "Brocade Network Advisor" - mock_get_all.return_value = PROVIDERS - - result = self._resource.get_provider_uri(provider_name) - self.assertEqual(result, PROVIDERS[0]['uri']) + self._san_manager.update(info, uri_rest_call) - @mock.patch.object(ResourceClient, 'get_all') - def test_get_provider_uri_should_return_none_when_not_found(self, mock_get_all): - provider_name = "Brocade Network Advisor" - mock_get_all.return_value = [] + mock_update.assert_called_once_with(resource=info, uri=uri_rest_call) - result = self._resource.get_provider_uri(provider_name) - self.assertEqual(result, None) - - @mock.patch.object(ResourceClient, 'update') - def test_update(self, mock_update): - uri = "/rest/fc-sans/device-managers/4ff2327f-7638-4b66-ad9d-283d4940a4ae" - manager = dict(name="Device Manager Test", description="Direct Attach SAN Manager") - - self._resource.update(resource=manager, id_or_uri=uri) - mock_update.assert_called_once_with(resource=manager, uri=uri) - - @mock.patch.object(ResourceClient, 'delete') + @mock.patch.object(ResourceHelper, 'delete') def test_remove_called_once(self, mock_delete): - id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' - self._resource.remove(id, timeout=-1) + self._san_manager.remove(force=False) - mock_delete.assert_called_once_with(id, timeout=-1) + mock_delete.assert_called_once_with(self.uri, force=False, + custom_headers={'If-Match': '*'}, timeout=TIMEOUT) - @mock.patch.object(ResourceClient, 'get_all') - def test_get_by_name_should_return_san_manager_when_found(self, mock_get_all): + @mock.patch.object(ResourceHelper, 'get_all') + def test_get_by_name_san_manager(self, mock_get_all): mock_get_all.return_value = [ {"name": "172.18.15.1", "uri": "/rest/fc-sans/device-managers/1"}, {"name": "172.18.15.2", "uri": "/rest/fc-sans/device-managers/2"} ] - san_manager = self._resource.get_by_name("172.18.15.2") - expected_result = {"name": "172.18.15.2", "uri": "/rest/fc-sans/device-managers/2"} + san_manager = self._san_manager.get_by_name("172.18.15.2") - self.assertEqual(san_manager, expected_result) + self.assertEqual(san_manager.data, + {"name": "172.18.15.2", "uri": "/rest/fc-sans/device-managers/2"}) - @mock.patch.object(ResourceClient, 'get_all') - def test_get_by_name_should_return_null_when_not_found(self, mock_get_all): + @mock.patch.object(ResourceHelper, 'get_all') + def test_get_by_provider_display_name_san_manager(self, mock_get_all): mock_get_all.return_value = [ - {"name": "172.18.15.1", "uri": "/rest/fc-sans/device-managers/1"}, - {"name": "172.18.15.2", "uri": "/rest/fc-sans/device-managers/2"} - ] - san_manager = self._resource.get_by_name("172.18.15.3") - - self.assertIsNone(san_manager) - - @mock.patch.object(ResourceClient, 'get_all') - def test_get_by_provider_display_name_should_return_san_manager_when_found(self, mock_get_all): - existent_san_managers = [ {"providerDisplayName": "Brocade Network Advisor 1", "uri": "/rest/fc-sans/device-managers/1"}, {"providerDisplayName": "Brocade Network Advisor 2", "uri": "/rest/fc-sans/device-managers/2"} ] - mock_get_all.return_value = existent_san_managers - san_manager = self._resource.get_by_provider_display_name("Brocade Network Advisor 2") + san_manager = self._san_manager.get_by_provider_display_name("Brocade Network Advisor 1") - self.assertEqual(san_manager, existent_san_managers[1]) + self.assertEqual(san_manager.data, + {"providerDisplayName": "Brocade Network Advisor 1", "uri": "/rest/fc-sans/device-managers/1"}) - @mock.patch.object(ResourceClient, 'get_all') + @mock.patch.object(ResourceHelper, 'get_all') def test_get_by_provider_display_name_should_return_null_when_not_found(self, mock_get_all): existent_san_managers = [ {"providerDisplayName": "Brocade Network Advisor 1", "uri": "/rest/fc-sans/device-managers/1"}, {"providerDisplayName": "Brocade Network Advisor 2", "uri": "/rest/fc-sans/device-managers/2"} ] mock_get_all.return_value = existent_san_managers - san_manager = self._resource.get_by_provider_display_name("Brocade Network Advisor 3") + san_manager = self._san_manager.get_by_provider_display_name("Brocade Network Advisor 3") + + self.assertIsNone(san_manager) + + @mock.patch.object(ResourceHelper, 'get_all') + def test_get_by_name_should_return_null_when_not_found(self, mock_get_all): + mock_get_all.return_value = [ + {"name": "172.18.15.1", "uri": "/rest/fc-sans/device-managers/1"}, + {"name": "172.18.15.2", "uri": "/rest/fc-sans/device-managers/2"} + ] + san_manager = self._san_manager.get_by_name("172.18.15.3") self.assertIsNone(san_manager) diff --git a/tests/unit/resources/fc_sans/test_san_providers.py b/tests/unit/resources/fc_sans/test_san_providers.py new file mode 100644 index 000000000..e56fe158d --- /dev/null +++ b/tests/unit/resources/fc_sans/test_san_providers.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- +### +# (C) Copyright [2022] Hewlett Packard Enterprise Development LP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +### + +from unittest import TestCase + +import mock + +from hpeOneView.connection import connection +from hpeOneView.resources.fc_sans.san_providers import SanProviders +from hpeOneView.resources.resource import Resource, ResourceHelper + +TIMEOUT = -1 + + +class SanProvidersTest(TestCase): + def setUp(self): + self.host = '127.0.0.1' + self.connection = connection(self.host, 800) + self._san_provider = SanProviders(self.connection) + self.uri = "/rest/fc-sans/providers/1234-5678" + self._san_provider.data = {"uri": self.uri} + + @mock.patch.object(ResourceHelper, 'create') + def test_add_device_manager_under_a_provider(self, mock_create): + resource = { + "connectionInfo": [ + { + "name": "Host", + "value": "brocade-device-manager.domain.com" + }, + { + "name": "Port", + "value": 5989 + }, + { + "name": "Username", + "value": "Administrator" + }, + { + "name": "Password", + "value": "password" + }, + { + "name": "UseSsl", + "value": True + } + ] + } + uri_or_id = '/rest/fc-sans/providers/534-345-345-55' + rest_uri = "/rest/fc-sans/providers/534-345-345-55/device-managers" + + self._san_provider.add(resource=resource, provider_uri_or_id=uri_or_id, timeout=TIMEOUT) + mock_create.assert_called_once_with(data=resource, uri=rest_uri, timeout=TIMEOUT) + + @mock.patch.object(Resource, 'get_by_field') + def test_get_provider_uri(self, mock_get_by_field): + provider_name = "Brocade Network Advisor" + + self._san_provider.get_provider_uri(provider_name) + mock_get_by_field.assert_called_once_with('displayName', provider_name) + + @mock.patch.object(Resource, 'get_by_field') + def test_get_provider_uri_with_empty_provider(self, mock_get_by_field): + provider_name = "Brocade Network Advisor" + mock_get_by_field.return_value = None + + result = self._san_provider.get_provider_uri(provider_name) + self.assertFalse(result) + mock_get_by_field.assert_called_once_with('displayName', provider_name) + + @mock.patch.object(Resource, 'get_by_field') + def test_get_default_connection_info(self, mock_get_by_field): + provider_name = "Brocade Network Advisor" + self._san_provider.get_default_connection_info(provider_name) + mock_get_by_field.assert_called_once_with('displayName', provider_name) + + @mock.patch.object(Resource, 'get_by_field') + def test_get_default_connection_info_with_empty_provider(self, mock_get_by_field): + provider_name = "Brocade Network Advisor" + mock_get_by_field.return_value = None + provider = self._san_provider.get_default_connection_info(provider_name) + self.assertFalse(provider) + mock_get_by_field.assert_called_once_with('displayName', provider_name) diff --git a/tests/unit/test_oneview_client.py b/tests/unit/test_oneview_client.py index 51fa87ec2..6dd973eff 100755 --- a/tests/unit/test_oneview_client.py +++ b/tests/unit/test_oneview_client.py @@ -27,6 +27,7 @@ from hpeOneView.resources.facilities.racks import Racks from hpeOneView.resources.fc_sans.managed_sans import ManagedSANs from hpeOneView.resources.fc_sans.san_managers import SanManagers +from hpeOneView.resources.fc_sans.san_providers import SanProviders from hpeOneView.resources.fc_sans.endpoints import Endpoints from hpeOneView.resources.settings.firmware_drivers import FirmwareDrivers from hpeOneView.resources.settings.firmware_bundles import FirmwareBundles @@ -660,9 +661,19 @@ def test_san_managers_has_right_type(self): def test_san_managers_has_value(self): self.assertIsNotNone(self._oneview.san_managers) - def test_lazy_loading_san_managers(self): + def test_san_managers(self): san_managers = self._oneview.san_managers - self.assertEqual(san_managers, self._oneview.san_managers) + self.assertNotEqual(san_managers, self._oneview.san_managers) + + def test_san_providers_has_right_type(self): + self.assertIsInstance(self._oneview.san_providers, SanProviders) + + def test_san_providers_has_value(self): + self.assertIsNotNone(self._oneview.san_providers) + + def test_san_providers(self): + san_providers = self._oneview.san_providers + self.assertNotEqual(san_providers, self._oneview.san_providers) def test_endpoints_has_right_type(self): self.assertIsInstance(self._oneview.endpoints, Endpoints)