diff --git a/CHANGELOG.md b/CHANGELOG.md index 50d5cf9a8..38c74b287 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,11 @@ This release extends the planned support of the modules to OneView REST API vers #### Major changes 1. Extended support of planned modules to API800/1000/1200. -2. Modules implemented in this release requires hpOneView version 5.1.0. +2. Modules implemented in this release requires hpOneView version 5.1.1. #### Modules supported in this release +- oneview_certificates_server +- oneview_certificates_server_facts - oneview_hypervisor_cluster_profile - oneview_hypervisor_cluster_profile_facts - oneview_hypervisor_manager diff --git a/endpoints-support.md b/endpoints-support.md index e4a0c0bcb..987b7f29a 100755 --- a/endpoints-support.md +++ b/endpoints-support.md @@ -52,6 +52,12 @@ | **Appliance Time and Locale Configuration** | |/rest/appliance/configuration/time-locale |GET | :white_check_mark: | |/rest/appliance/configuration/time-locale |POST | :white_check_mark: | +| **Certificates Server** +|/rest/certificates/servers |POST | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +|/rest/certificates/https/remote/example.com |GET | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +|/rest/certificates/servers/{aliasName} |GET | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +|/rest/certificates/servers/{aliasName} |PUT | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +|/rest/certificates/servers/{aliasName} |DELETE | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | **Connection Templates** | |/rest/connection-templates |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | |/rest/connection-templates/defaultConnectionTemplate |GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | diff --git a/examples/oneview_certificates_server.yml b/examples/oneview_certificates_server.yml new file mode 100644 index 000000000..9f66f1351 --- /dev/null +++ b/examples/oneview_certificates_server.yml @@ -0,0 +1,82 @@ +### +# Copyright (2016-2020) 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. +### +--- +- hosts: all + vars: + config: "{{ playbook_dir }}/oneview_config.json" + remote_server: '172.18.13.11' + tasks: + - name: Gather facts about a Server Certificate by remote address + oneview_certificates_server_facts: + config: "{{ config }}" + remote: "{{ remote_server }}" + delegate_to: localhost + + - set_fact: + certificate: "{{ remote_certificate['certificateDetails'][0]['base64Data'] }}" + + - name: Create a Server Certificate + oneview_certificates_server: + config: "{{ config }}" + state: present + name: "{{ remote_server }}" + data: + certificateDetails: + - aliasName: "{{ remote_server }}" + base64Data: "{{ certificate }}" + delegate_to: localhost + register: svr_cert + + - name: Do nothing with the Server Certificate when no changes are provided + oneview_certificates_server: + config: "{{ config }}" + state: present + name: "{{ remote_server }}" + data: + certificateDetails: + - aliasName: "{{ remote_server }}" + base64Data: "{{ certificate }}" + delegate_to: localhost + + - name: Update the Server Certificate changing the attribute name + oneview_certificates_server: + config: "{{ config }}" + state: present + name: "{{ remote_server }}" + data: + name: "test" + certificateDetails: + - aliasName: "{{ remote_server }}" + base64Data: "{{ certificate }}" + delegate_to: localhost + + - name: Delete the Server Certificate + oneview_certificates_server: + config: "{{ config }}" + state: absent + name: "{{ remote_server }}" + data: "{{ svr_cert.ansible_facts.certificate_server }}" + delegate_to: localhost + register: deleted + + - name: Do nothing when Server Certificate is absent + oneview_certificates_server: + config: "{{ config }}" + state: absent + name: "{{ remote_server }}" + data: "{{ svr_cert.ansible_facts.certificate_server }}" + delegate_to: localhost + register: deleted diff --git a/examples/oneview_certificates_server_facts.yml b/examples/oneview_certificates_server_facts.yml new file mode 100644 index 000000000..cae33d18e --- /dev/null +++ b/examples/oneview_certificates_server_facts.yml @@ -0,0 +1,35 @@ +### +# Copyright (2016-2020) 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. +### +--- +- hosts: all + vars: + - config: "{{ playbook_dir }}/oneview_config.json" + tasks: + - name: Gather facts about a Server Certificate by remote address + oneview_certificates_server_facts: + config: "{{ config }}" + remote: "172.18.13.11" + delegate_to: localhost + + - debug: var=remote_certificate['certificateDetails'][0]['base64Data'] + + - name: Gather facts about a Server Certificate by alias_name + oneview_certificates_server_facts: + config: "{{ config }}" + aliasName: "172.18.13.11" + delegate_to: localhost + + - debug: var=certificates_server diff --git a/library/oneview_certificates_server.py b/library/oneview_certificates_server.py new file mode 100644 index 000000000..7e556cd08 --- /dev/null +++ b/library/oneview_certificates_server.py @@ -0,0 +1,141 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +### +# Copyright (2016-2020) 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. +### + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + +DOCUMENTATION = ''' +--- +module: oneview_certificates_server +short_description: Manage OneView Server Certificate resources. +description: + - Provides an interface to manage Server Certificate resources. Can create, update, and delete. +version_added: "2.4" +requirements: + - "python >= 3.4.2" + - "hpOneView >= 5.1.1" +author: "Venkatesh Ravula (@VenkateshRavula)" +options: + state: + description: + - Indicates the desired state for the Server Certificate resource. + C(present) will ensure data properties are compliant with OneView. + C(absent) will remove the resource from OneView, if it exists. + choices: ['present', 'absent'] + data: + description: + - List with the Server Certificate properties. + required: true + +extends_documentation_fragment: + - oneview + - oneview.validateetag +''' + +EXAMPLES = ''' +- name: Create a Server Certificate + oneview_certificates_server: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + state: present + name: "172.18.13.11" + data: + certificateDetails: + - aliasName: 'vcenter' + base64Data: '--- Certificate ---' + +- name: Update the Server Certificate name to 'vcenter Renamed' + oneview_certificates_server: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + state: present + name: "172.18.13.11" + data: + name: 'vcenter renamed' + certificateDetails: + - aliasName: 'vcenter' + base64Data: '--- Certificate ---' + +- name: Ensure that the Hypervisor Manager is absent + oneview_certificates_server: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + state: absent + name: "172.18.13.11" + data: + alias_name: 'vcenter' +''' + +RETURN = ''' +certificate_server: + description: Has the facts about the managed OneView Hypervisor Manager. + returned: On state 'present'. Can be null. + type: dict +''' + +from ansible.module_utils.oneview import OneViewModule + + +class CertificatesServerModule(OneViewModule): + MSG_CREATED = 'Server Certificate created successfully.' + MSG_UPDATED = 'Server Certificate updated successfully.' + MSG_DELETED = 'Server Certificate deleted successfully.' + MSG_ALREADY_PRESENT = 'Server Certificate is already present.' + MSG_ALREADY_ABSENT = 'Server Certificate is already absent.' + RESOURCE_FACT_NAME = 'certificate_server' + + def __init__(self): + additional_arg_spec = dict(data=dict(required=True, type='dict'), + name=dict(required=False, type='str'), + state=dict( + required=True, + choices=['present', 'absent'])) + + super(CertificatesServerModule, self).__init__(additional_arg_spec=additional_arg_spec, validate_etag_support=True) + self.__set_current_resource(self.oneview_client.certificates_server) + + def execute_module(self): + if self.state == 'present': + return self.resource_present(self.RESOURCE_FACT_NAME) + elif self.state == 'absent': + return self.resource_absent() + + def __set_current_resource(self, resource_client): + self.resource_client = resource_client + aliasname = None + + if self.module.params.get('name'): + aliasname = self.module.params['name'] + + if self.resource_client.get_by_alias_name(aliasname): + self.current_resource = self.resource_client.get_by_alias_name(aliasname) + + +def main(): + CertificatesServerModule().run() + + +if __name__ == '__main__': + main() diff --git a/library/oneview_certificates_server_facts.py b/library/oneview_certificates_server_facts.py new file mode 100644 index 000000000..51ddba86a --- /dev/null +++ b/library/oneview_certificates_server_facts.py @@ -0,0 +1,110 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +### +# Copyright (2016-2020) 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. +### + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + +DOCUMENTATION = ''' +--- +module: oneview_certificates_server_facts +short_description: Retrieve the facts about one or more of the OneView Server Certificates +description: + - Retrieve the facts about one or more of the Server Certificates from OneView. +version_added: "2.4" +requirements: + - "python >= 3.4.2" + - hpOneView >= 5.1.1 +author: "Venkatesh Ravula (@VenkateshRavula)" +options: + alias_name: + description: + - Server Certificate aliasname. + +extends_documentation_fragment: + - oneview + - oneview.factsparams +''' + +EXAMPLES = ''' +- name: Gather facts about a Server Certificate by remote address + oneview_certificates_server_facts: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + remote: "172.18.13.11" + delegate_to: localhost + +- debug: var=remote_certificate['certificateDetails'][0]['base64Data'] + +- name: Gather facts about a Server Certificate by alias_name + oneview_certificates_server_facts: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + aliasName: "172.18.13.11" + delegate_to: localhost + +- debug: var=certificate +''' + +RETURN = ''' +certificate_server: + description: Has all the OneView facts about the Server Certificates. + returned: Always, but can be null. + type: dict +''' + +from ansible.module_utils.oneview import OneViewModule + + +class CertificatesServerFactsModule(OneViewModule): + def __init__(self): + + argument_spec = dict( + remote=dict(required=False, type='str'), + aliasName=dict(required=False, type='str'), + ) + + super(CertificatesServerFactsModule, self).__init__(additional_arg_spec=argument_spec) + self.resource_client = self.oneview_client.certificates_server + + def execute_module(self): + ansible_facts = {} + + if self.module.params.get('aliasName'): + aliasname = self.module.params['aliasName'] + certificates_server = self.resource_client.get_by_alias_name(aliasname) + ansible_facts['certificates_server'] = certificates_server.data if certificates_server else None + + elif self.module.params.get('remote'): + remote_address = self.module.params['remote'] + remote_cert = self.resource_client.get_remote(remote_address) + ansible_facts['remote_certificate'] = remote_cert.data + + return dict(changed=False, ansible_facts=ansible_facts) + + +def main(): + CertificatesServerFactsModule().run() + + +if __name__ == '__main__': + main() diff --git a/oneview-ansible.md b/oneview-ansible.md index c087b4177..880d9d838 100644 --- a/oneview-ansible.md +++ b/oneview-ansible.md @@ -27,6 +27,8 @@ * [oneview_appliance_device_snmp_v3_users_facts - Retrieve the facts about the OneView appliance SNMPv3 users.](#oneview_appliance_device_snmp_v3_users_facts) * [oneview_appliance_time_and_locale_configuration - Manage OneView Appliance Locale and Time Configuration.](#oneview_appliance_time_and_locale_configuration) * [oneview_appliance_time_and_locale_configuration_facts - Retrieve the facts about the OneView appliance time and locale configuration.](#oneview_appliance_time_and_locale_configuration_facts) + * [oneview_certificates_server - Manage OneView Certificates Server resources.](#oneview_certificates_server) + * [oneview_certificates_server_facts - Retrieve the facts about one or more of the OneView Certificates Server.](#oneview_certificates_server_facts) * [oneview_connection_template - Manage the OneView Connection Template resources.](#oneview_connection_template) * [oneview_connection_template_facts - Retrieve facts about the OneView Connection Templates.](#oneview_connection_template_facts) * [oneview_datacenter - Manage OneView Data Center resources.](#oneview_datacenter) @@ -2270,6 +2272,157 @@ Retrieve the facts about the OneView appliance time and locale configuration. --- +## oneview_certificates_server +Manage OneView Certificates Server resources. + +#### Synopsis + Provides an interface to manage Certificates Server resources. Can create, update, or delete. + +#### Requirements (on the host that executes the module) + * hpOneView >= 5.1.1 + * python >= 3.4.2 + +#### Options + +| Parameter | Required | Default | Choices | Comments | +| ------------- |-------------| ---------|----------- |--------- | +| config | | | | Path to a .json configuration file containing the OneView client configuration. The configuration file is optional and when used should be present in the host running the ansible commands. If the file path is not provided, the configuration will be loaded from environment variables. For links to example configuration files or how to use the environment variables verify the notes section. | +| data | Yes | | | List with the Certificates Server properties. | +| state | | | | Indicates the desired state for the Certificates Server resource. `present` ensures data properties are compliant with OneView. `absent` removes the resource from OneView, if it exists. | +| validate_etag | | True | | When the ETag Validation is enabled, the request will be conditionally processed only if the current ETag for the resource matches the ETag provided in the data. | + + + +#### Examples + +```yaml + +- name: Create a Server Certificate + oneview_certificates_server: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + state: present + data: + name: 'vcenter' + certificateDetails: + - aliasName: 'vcenter' + base64Data: '--- Certificate ---' + +- name: Update the Server Certificate name to 'vcenter Renamed' + oneview_certificates_server: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + state: present + data: + name: 'vcenter renamed' + certificateDetails: + - aliasName: 'vcenter' + base64Data: '--- Certificate ---' + +- name: Ensure that the Server Certificate is absent + oneview_certificates_server: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + state: absent + data: + alias_name: 'vcenter' + +--- + + + +#### Notes + +- A sample configuration file for the config parameter can be found at: https://github.com/HewlettPackard/oneview-ansible/blob/master/examples/oneview_config-rename.json + +- Check how to use environment variables for configuration at: https://github.com/HewlettPackard/oneview-ansible#environment-variables + +- Additional Playbooks for the HPE OneView Ansible modules can be found at: https://github.com/HewlettPackard/oneview-ansible/tree/master/examples + +- The OneView API version used will directly affect returned and expected fields in resources. Information on setting the desired API version and can be found at: https://github.com/HewlettPackard/oneview-ansible#setting-your-oneview-version + + +--- + + +## oneview_certificates_server_facts +Retrieve the facts about one or more of the OneView Certificates Server. + +#### Synopsis + Retrieve the facts about one or more of the Certificates Server from OneView. + +#### Requirements (on the host that executes the module) + * hpOneView >= 5.1.1 + * python >= 3.4.2 + +#### Options + +| Parameter | Required | Default | Choices | Comments | +| ------------- |-------------| ---------|----------- |--------- | +| config | | | | Path to a .json configuration file containing the OneView client configuration. The configuration file is optional and when used should be present in the host running the ansible commands. If the file path is not provided, the configuration will be loaded from environment variables. For links to example configuration files or how to use the environment variables verify the notes section. | +| aliasName | No | | | Certificates Server aliasName. | +| remote | No | | | Remote Server Certificate. | + + + +#### Examples + +```yaml + +- name: Gather facts about a Server Certificate by aliasname + oneview_certificates_server_facts: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + aliasname: "vcenter" + delegate_to: localhost + +- debug: var=certificates_server + +- name: Gather facts about a Server Certificate by remote server + oneview_certificates_server_facts: + hostname: 172.16.101.48 + username: administrator + password: my_password + api_version: 1200 + remote: "172.18.13.11" + delegate_to: localhost + +- debug: var=remote_certificate + +``` + + + +#### Return Values + +| Name | Description | Returned | Type | +| ------------- |-------------| ---------|----------- | +| certificates_servers | Has all the OneView facts about the Certificates Server. | Always, but can be null. | dict | +| remote_certificate | Has facts about remote server certificates | When required | dict | + +#### Notes + +- A sample configuration file for the config parameter can be found at: https://github.com/HewlettPackard/oneview-ansible/blob/master/examples/oneview_config-rename.json + +- Check how to use environment variables for configuration at: https://github.com/HewlettPackard/oneview-ansible#environment-variables + +- Additional Playbooks for the HPE OneView Ansible modules can be found at: https://github.com/HewlettPackard/oneview-ansible/tree/master/examples + +- The OneView API version used will directly affect returned and expected fields in resources. Information on setting the desired API version and can be found at: https://github.com/HewlettPackard/oneview-ansible#setting-your-oneview-version + + +--- + + + ## oneview_connection_template Manage the OneView Connection Template resources. diff --git a/test/oneview_module_loader.py b/test/oneview_module_loader.py index 1c98b2800..0004ba59b 100755 --- a/test/oneview_module_loader.py +++ b/test/oneview_module_loader.py @@ -68,6 +68,8 @@ from oneview_appliance_device_snmp_v3_users_facts import ApplianceDeviceSnmpV3UsersFactsModule from oneview_appliance_time_and_locale_configuration_facts import ApplianceTimeAndLocaleConfigurationFactsModule from oneview_appliance_time_and_locale_configuration import ApplianceTimeAndLocaleConfigurationModule +from oneview_certificates_server import CertificatesServerModule +from oneview_certificates_server_facts import CertificatesServerFactsModule from oneview_connection_template import ConnectionTemplateModule from oneview_connection_template_facts import ConnectionTemplateFactsModule from oneview_datacenter import DatacenterModule diff --git a/test/test_oneview_certificates_server.py b/test/test_oneview_certificates_server.py new file mode 100644 index 000000000..c3ed3ec9e --- /dev/null +++ b/test/test_oneview_certificates_server.py @@ -0,0 +1,129 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +### +# Copyright (2016-2020) 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. +### + +import pytest + +from hpe_test_utils import OneViewBaseTest +from oneview_module_loader import CertificatesServerModule + +server_certificate = dict( + aliasName='172.18.13.11', + name='test', +) + +PARAMS_FOR_PRESENT = dict( + config='config.json', + state='present', + name='cert', + data=dict(aliasName=server_certificate['aliasName'], + name="test") +) + +PARAMS_WITH_CHANGES = dict( + config='config.json', + state='present', + name='cert', + data=dict(aliasName=server_certificate['aliasName'], + name="vcenter renamed") +) + +PARAMS_FOR_ABSENT = dict( + config='config.json', + state='absent', + name='cert', + data=dict(aliasName=server_certificate['aliasName']) +) + + +@pytest.mark.resource(TestCertificatesServerModule='certificates_server') +class TestCertificatesServerModule(OneViewBaseTest): + """ + OneViewBaseTestCase provides the mocks used in this test case + """ + + def test_should_create_new_certificate_server(self): + self.resource.get_by_alias_name.return_value = None + self.resource.create.return_value = self.resource + self.resource.data = server_certificate + self.mock_ansible_module.params = PARAMS_FOR_PRESENT + + CertificatesServerModule().run() + + self.mock_ansible_module.exit_json.assert_called_once_with( + changed=True, + msg=CertificatesServerModule.MSG_CREATED, + ansible_facts=dict(certificate_server=server_certificate) + ) + + def test_should_not_update_when_data_is_equals(self): + self.resource.data = server_certificate + self.resource.get_by_alias_name.return_value = self.resource + self.resource.update = self.resource + self.mock_ansible_module.params = PARAMS_FOR_PRESENT + + CertificatesServerModule().run() + + self.mock_ansible_module.exit_json.assert_called_once_with( + changed=False, + msg=CertificatesServerModule.MSG_ALREADY_PRESENT, + ansible_facts=dict(certificate_server=server_certificate) + ) + + def test_update_when_data_has_modified_attributes(self): + self.resource.data = server_certificate + self.resource.get_by_alias_name.return_value = self.resource + data_merged = server_certificate.copy() + data_merged['name'] = 'vcenter renamed' + self.resource.data = server_certificate + self.resource.update = self.resource + + self.mock_ansible_module.params = PARAMS_WITH_CHANGES + + CertificatesServerModule().run() + + self.mock_ansible_module.exit_json.assert_called_once_with( + changed=True, + msg=CertificatesServerModule.MSG_UPDATED, + ansible_facts=dict(certificate_server=server_certificate) + ) + + def test_should_remove_certificate_server(self): + self.resource.data = server_certificate + self.mock_ansible_module.params = PARAMS_FOR_ABSENT + + CertificatesServerModule().run() + + self.mock_ansible_module.exit_json.assert_called_once_with( + changed=True, + msg=CertificatesServerModule.MSG_DELETED + ) + + def test_should_do_nothing_when_certificate_server_not_exist(self): + self.resource.get_by_alias_name.return_value = None + self.mock_ansible_module.params = PARAMS_FOR_ABSENT + + CertificatesServerModule().run() + + self.mock_ansible_module.exit_json.assert_called_once_with( + changed=False, + msg=CertificatesServerModule.MSG_ALREADY_ABSENT + ) + + +if __name__ == '__main__': + pytest.main([__file__]) diff --git a/test/test_oneview_certificates_server_facts.py b/test/test_oneview_certificates_server_facts.py new file mode 100644 index 000000000..1f0790596 --- /dev/null +++ b/test/test_oneview_certificates_server_facts.py @@ -0,0 +1,73 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +### +# Copyright (2016-2020) 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. +### + +import pytest + +from hpe_test_utils import OneViewBaseTest +from oneview_module_loader import CertificatesServerFactsModule + +PRESENT_CERTIFICATES = { + "aliasName": "172.18.13.11", + "uri": "/rest/certificates/servers/172.18.13.11", + "data": { + "aliasName": "172.18.13.11" + } +} + +PARAMS_GET_REMOTE = dict( + config='config.json', + remote="172.18.13.11", +) + +PARAMS_GET_BY_ALIASNAME = dict( + config='config.json', + aliasName="172.18.13.11", +) + +DICT_DEFAULT_CERTIFICATE = PRESENT_CERTIFICATES["data"] + + +@pytest.mark.resource(TestCertificatesServerFactsModule='certificates_server') +class TestCertificatesServerFactsModule(OneViewBaseTest): + def test_should_get_remote_certificate(self): + self.resource.data = DICT_DEFAULT_CERTIFICATE + self.resource.get_remote.return_value = self.resource + self.mock_ansible_module.params = PARAMS_GET_REMOTE + + CertificatesServerFactsModule().run() + + self.mock_ansible_module.exit_json.assert_called_once_with( + changed=False, + ansible_facts=dict(remote_certificate=DICT_DEFAULT_CERTIFICATE) + ) + + def test_should_get_certificate_server_by_aliasname(self): + self.resource.data = DICT_DEFAULT_CERTIFICATE + self.resource.get_by_alias_name.return_value = self.resource + self.mock_ansible_module.params = PARAMS_GET_BY_ALIASNAME + + CertificatesServerFactsModule().run() + + self.mock_ansible_module.exit_json.assert_called_once_with( + changed=False, + ansible_facts=dict(certificates_server=DICT_DEFAULT_CERTIFICATE) + ) + + +if __name__ == '__main__': + pytest.main([__file__])