New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial commits for integration of HPE OneView resources with Ansible #26026
Conversation
@fgbulsoni Have you considered mocking Here's another PR which is doing that: #25450 |
The test
The test
|
Hey @mattclay , thanks for the feedback! I'll look into the PR mentioned and see if I can do the same. |
c464e0b
to
c0236ca
Compare
The test
|
abd45fc
to
fb9701b
Compare
I don't see how this relates to me. |
Hey @robinro , yeah, not sure what made the bot cc you. Thank you for replying though! @mattclay , I've added mocks to the Our module does make use of the Would you have any suggestion on how to deal with this? Perhaps a way to skip the 2.6 tests since the module will not be compatible with that version? |
bc7a3ef
to
969f94d
Compare
I've fixed the unit tests issues regarding OrderedDict and the unit tests for 2.6 should be passing now. It seems that for some reason I can't pinpoint, the From the logs and running it locally, it appears to fail when trying to install yamllint with this output:
I've not added yamllint nor am I sure why is it failing, this looks to me like code that was already in the repo. Any help/ideas here? |
@fgbulsoni I'm working on a fix now. |
@fgbulsoni The issue has been resolved. I've restarted CI for this PR. |
The test
|
These failures are also unrelated. They've been fixed and I'll restart CI again. |
Many thanks for that @mattclay ! Is there anything else that needs to be addressed in this PR or may I wait for it to be merged? Best regards, |
41cd56f
to
a6cdde8
Compare
@abadger I believe I've made all of the requested changes. |
lib/ansible/module_utils/oneview.py
Outdated
MSG_ALREADY_PRESENT = 'Resource is already present.' | ||
MSG_ALREADY_ABSENT = 'Resource is already absent.' | ||
HPE_ONEVIEW_SDK_REQUIRED = 'HPE OneView Python SDK is required for this module.' | ||
FUTURE_PACKAGE_REQUIRED = 'The Future Python package is required for this module.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this message anymore as the future package is no longer used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops. True, removing.
lib/ansible/module_utils/oneview.py
Outdated
|
||
from ansible.module_utils import six | ||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils._text import to_native |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style wise, the ansible imports go below the hpOneView imports.
lib/ansible/module_utils/oneview.py
Outdated
import abc | ||
import collections | ||
import json | ||
import logging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the logging import anymore
lib/ansible/module_utils/oneview.py
Outdated
|
||
|
||
class OneViewModuleBase(object): | ||
__metaclass__ = abc.ABCMeta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, I should have mentioned, how to specify metaclasses changed between python2 and python3. So there's a helper in six so that you can do this acroos both versions.
from ansible.module_utils.six import with_metaclass
[...]
class OneViewModuleBase(with_metaclass(ABCMeta, object)):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it fine to do it as:
@six.add_metaclass(abc.ABCMeta)
class OneViewModuleBase(object):
MSG_CREATED = 'Resource created successfully.'
MSG_UPDATED = 'Resource updated successfully.'
?
Or would that not work? I've seen it used similarly at the crypto
module.
else: | ||
return self.resource_absent(resource) | ||
|
||
def __present(self, resource): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's still a few of these that are using double-underscore to mark private. We generally do that with single underscore instead.
- def __present(self, resource):
+ def _present(self, resource):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops. Missed that, was a new method that I added and ended up not verifying the underscores. Fixing.
lib/ansible/module_utils/oneview.py
Outdated
# If both values are null, empty or False it will be considered equal. | ||
elif not resource1[key] and not resource2[key]: | ||
continue | ||
elif isinstance(resource1[key], dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use collections.Mapping for dict
…meta class, removed extra underscores on methods and swapped isinstance validations of dict for collections.Mapping
lib/ansible/module_utils/oneview.py
Outdated
import json | ||
import os | ||
import traceback | ||
from copy import deepcopy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer need deepcopy
lib/ansible/module_utils/oneview.py
Outdated
|
||
:return: dict: It must return a dictionary with the attributes for the module result, | ||
such as ansible_facts, msg and changed. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation of the end of the string should match with the beginning (I see this in a few other places as well)
lib/ansible/module_utils/oneview.py
Outdated
ansible_facts={fact_name: resource} | ||
) | ||
|
||
MSG_DIFF_AT_KEY = 'Difference found at key \'{0}\'. ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be at the top with the other class attributes?
lib/ansible/module_utils/oneview.py
Outdated
List with all the scope URIs to be added to the resource. | ||
Returns: | ||
A dictionary with the expected arguments for the AnsibleModule.exit_json | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sphinx docstring formatting was missed for this one
lib/ansible/module_utils/oneview.py
Outdated
merged_items[item_key] = items_map[item_key].copy() | ||
merged_items[item_key].update(item) | ||
else: | ||
merged_items[item_key] = item.copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we're still doing copies of the item here twice, once when we enter it into items map at the beginning of hte function and once when we enter it into merged_items here. Is that needed?
…methods from merge_lists and moved MSG that was in the middle of the code to top of the class
lib/ansible/module_utils/oneview.py
Outdated
|
||
return str(value) | ||
|
||
def merge_list_by_key(self, original_list, updated_list, key, ignore_when_null=[]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like merge_list_by_key(), _standardize_value(), and _str_sorted() should be moved to be toplevel functions? (They don't make use of self).
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to, you can change this license header to the short, one line version as shown here: https://github.com/ansible/ansible/blob/devel/docs/docsite/rst/dev_guide/developing_modules_documenting.rst#copyright
I've been trying to move modules to that since modules are copied over the network to the remote machine and so making them smaller can speed that up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so, in that link I see this short licence:
#!/usr/bin/python
# Copyright (c) 2017 [New Contributor(s)]
# Copyright (c) 2015 [Original Contributor(s)]
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
I'm assuming the oneview_fc_network.py will then have:
#!/usr/bin/python
# Copyright (c) 2016-2017 Hewlett Packard Enterprise Development LP
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
Correct? Also, since that licence is GNU and module_utils must be BSD, is there a similar model for BSD?
…cense header in oneview_fc_network.py to short version
Your gplv3 question looks correct. There is none for bsd at this time so
you can leave that one alone.
|
Awesome, thanks. Changes made then, waiting on CI to complete to see if I messed up anywhere. |
Merged to devel for 2.4.0. Thanks for the persistence and hard work! |
For history purposes, related issue: #28354 |
SUMMARY
HPE OneView is an infrastructure automation engine built with software intelligence. It streamlines provisioning and lifecycle management across compute, storage and fabric and enables IT staff to control resources programmatically through a unified API.
It is heavily focused on the DevOps workflow and has many integrations already, including an ansible module not integrated into core.
This PR aims to add the OneView base class to be used for all OneView resources, together with the module for managing the HPE OneView FC Network resource:
FcNetworkModule
and its unit tests.This resource has the
present
andabsent
states which will manage all of its aspects, including creating and updating the resources (usingpresent
) and removal of resources (usingabsent
).ISSUE TYPE
COMPONENT NAME
FcNetworkModule
ANSIBLE VERSION
ADDITIONAL INFORMATION
Example of usage: