Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
marikrg committed Apr 17, 2017
1 parent a925c29 commit a49821c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
18 changes: 9 additions & 9 deletions library/oneview_logical_downlinks_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
'''

RETURN = '''
logical_interconnects:
logical_downlinks:
description: The list of logical downlinks.
returned: Always, but can be null.
type: list
Expand All @@ -109,23 +109,23 @@ def execute_module(self):
logical_downlinks = None

if name and excludeEthernet:
logical_downlinks_by_name = self.__get_by_name(name)
logical_downlinks = []
if logical_downlinks_by_name:
logical_downlink = logical_downlinks_by_name[0]
logical_downlinks = self.resource_client.get_without_ethernet(id_or_uri=logical_downlink["uri"])
logical_downlink_by_name = self.get_by_name(name)
if logical_downlink_by_name:
uri = logical_downlink_by_name["uri"]
logical_downlink_without_ethernet = self.resource_client.get_without_ethernet(id_or_uri=uri)
if logical_downlink_without_ethernet:
logical_downlinks = [logical_downlink_without_ethernet]

elif name:
logical_downlinks = self.__get_by_name(name)
logical_downlinks = self.resource_client.get_by('name', name)
elif excludeEthernet:
logical_downlinks = self.resource_client.get_all_without_ethernet()
else:
logical_downlinks = self.resource_client.get_all(**self.facts_params)

return dict(changed=False, ansible_facts=dict(logical_downlinks=logical_downlinks))

def __get_by_name(self, name):
return self.resource_client.get_by('name', name)


def main():
LogicalDownlinksFactsModule().run()
Expand Down
2 changes: 1 addition & 1 deletion oneview-ansible.md
Original file line number Diff line number Diff line change
Expand Up @@ -3518,7 +3518,7 @@ Retrieve facts about one or more of the OneView Logical Downlinks.

| Name | Description | Returned | Type |
| ------------- |-------------| ---------|----------- |
| logical_interconnects | The list of logical downlinks. | Always, but can be null. | list |
| logical_downlinks | The list of logical downlinks. | Always, but can be null. | list |


#### Notes
Expand Down
24 changes: 20 additions & 4 deletions test/test_oneview_logical_downlinks_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
###

import unittest
from oneview_module_loader import LogicalDownlinksFactsModule
from hpe_test_utils import FactsParamsTestCase
Expand Down Expand Up @@ -110,10 +109,9 @@ def test_should_get_all_without_ethernet(self):

def test_should_get_without_ethernet(self):
logical_downlinks = [LOGICAL_DOWNLINK]
logical_downlinks_without_ethernet = []

self.logical_downlinks.get_by.return_value = logical_downlinks
self.logical_downlinks.get_without_ethernet.return_value = logical_downlinks_without_ethernet
self.logical_downlinks.get_without_ethernet.return_value = []

self.mock_ansible_module.params = PARAMS_FOR_GET_WITHOUT_ETHERNET

Expand All @@ -124,7 +122,25 @@ def test_should_get_without_ethernet(self):

self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
ansible_facts=dict(logical_downlinks=logical_downlinks_without_ethernet)
ansible_facts=dict(logical_downlinks=[])
)

def test_should_not_get_without_ethernet_when_not_found(self):
logical_downlinks = []

self.logical_downlinks.get_by.return_value = logical_downlinks
self.logical_downlinks.get_without_ethernet.return_value = []

self.mock_ansible_module.params = PARAMS_FOR_GET_WITHOUT_ETHERNET

LogicalDownlinksFactsModule().run()

self.logical_downlinks.get_by.assert_called_once_with('name', LOGICAL_DOWNLINK_NAME)
self.logical_downlinks.get_without_ethernet.not_been_called()

self.mock_ansible_module.exit_json.assert_called_once_with(
changed=False,
ansible_facts=dict(logical_downlinks=[])
)


Expand Down

0 comments on commit a49821c

Please sign in to comment.