From 315cd12bd442cd0f1ae9c160f0c69c235a6523ce Mon Sep 17 00:00:00 2001 From: smalpani Date: Thu, 29 Apr 2021 16:15:19 +0530 Subject: [PATCH 01/39] Eventhub CRUD operations --- plugins/module_utils/azure_rm_common.py | 19 +- plugins/modules/azure_rm_eventhub.py | 405 ++++++++++++++++++ plugins/modules/azure_rm_eventhub_info.py | 240 +++++++++++ pr-pipelines.yml | 1 + requirements-azure.txt | 1 + .../targets/azure_rm_eventhub/aliases | 3 + .../targets/azure_rm_eventhub/meta/main.yml | 2 + .../targets/azure_rm_eventhub/tasks/main.yml | 152 +++++++ 8 files changed, 822 insertions(+), 1 deletion(-) create mode 100644 plugins/modules/azure_rm_eventhub.py create mode 100644 plugins/modules/azure_rm_eventhub_info.py create mode 100644 tests/integration/targets/azure_rm_eventhub/aliases create mode 100644 tests/integration/targets/azure_rm_eventhub/meta/main.yml create mode 100644 tests/integration/targets/azure_rm_eventhub/tasks/main.yml diff --git a/plugins/module_utils/azure_rm_common.py b/plugins/module_utils/azure_rm_common.py index 95a823a4a..ad8e53c95 100644 --- a/plugins/module_utils/azure_rm_common.py +++ b/plugins/module_utils/azure_rm_common.py @@ -106,7 +106,8 @@ def default_api_version(self): 'MySQLManagementClient': '2017-12-01', 'MariaDBManagementClient': '2019-03-01', 'ManagementLockClient': '2016-09-01', - 'DataLakeStoreAccountManagementClient': '2016-11-01' + 'DataLakeStoreAccountManagementClient': '2016-11-01', + 'EventHubManagementClient': '2018-05-04' }, '2019-03-01-hybrid': { 'StorageManagementClient': '2017-10-01', @@ -120,6 +121,7 @@ def default_api_version(self): 'ManagementLockClient': '2016-09-01', 'PolicyClient': '2016-12-01', 'ResourceManagementClient': '2018-05-01', + 'EventHubManagementClient': '2018-05-04', 'SubscriptionClient': '2016-06-01', 'DnsManagementClient': '2016-04-01', 'KeyVaultManagementClient': '2016-10-01', @@ -275,6 +277,7 @@ def default_api_version(self): from azure.mgmt.search import SearchManagementClient from azure.mgmt.datalake.store import DataLakeStoreAccountManagementClient import azure.mgmt.datalake.store.models as DataLakeStoreAccountModel + from azure.mgmt.eventhub import EventHubManagementClient except ImportError as exc: Authentication = object @@ -362,6 +365,10 @@ def normalize_location_name(name): 'package_name': 'trafficmanager', 'expected_version': '0.50.0' }, + 'EventHubManagementClient': { + 'package_name': 'azure-mgmt-eventhub', + 'expected_version': '2.0.0' + }, } if HAS_AZURE else {} @@ -439,6 +446,7 @@ def __init__(self, derived_arg_spec, bypass_checks=False, no_log=False, self._recovery_services_backup_client = None self._search_client = None self._datalake_store_client = None + self._event_hub_client = None self.check_mode = self.module.check_mode self.api_profile = self.module.params.get('api_profile') @@ -1325,6 +1333,15 @@ def datalake_store_client(self): def datalake_store_models(self): return DataLakeStoreAccountModel + @property + def event_hub_client(self): + self.log('Getting event hub client') + if not self._event_hub_client: + self._event_hub_client = self.get_mgmt_svc_client( + EventHubManagementClient, + base_url=self._cloud_environment.endpoints.resource_manager, + api_version='2018-05-04') + return self._event_hub_client class AzureSASAuthentication(Authentication): """Simple SAS Authentication. diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py new file mode 100644 index 000000000..b4bb3b9e2 --- /dev/null +++ b/plugins/modules/azure_rm_eventhub.py @@ -0,0 +1,405 @@ +#!/usr/bin/python +# +# Copyright (c) 2021 Praveen Ghuge(@praveenghuge) Karl Dasan(@karldas30) Saurabh Malpani (@saurabh3796) +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase + +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: azure_rm_eventhub +short_description: Manage Event Hub +description: + - Create, update and delete instance of Event Hub. +options: + resource_group: + description: + - Name of the resource group to which the resource belongs. + required: True + type: str + namespace_name: + description: + - Name of the namespace in which to create event hub. + required: True + type: str + name: + description: + - Unique name of the Event Hub. + required: True + type: str + location: + description: + - Resource location. If not set, location from the resource group will be used as default. + required: if state is present + type: str + sku: + description: + - The name of the SKU. + - Please see L(https://azure.microsoft.com/en-in/pricing/details/event-hubs/). + default: Basic + choices: + - Basic + - Standard + type: str + state: + description: + - Assert the state of the Event Hub. + - Use C(present) to create or update an event hub and C(absent) to delete it. + default: present + choices: + - absent + - present + type: str + +extends_documentation_fragment: + - azure.azcollection.azure + - azure.azcollection.azure_tags + +author: + - Praveen Ghuge (@praveenghuge) + - Karl Dasan (@karldas30) + - Saurabh Malpani(@saurabh3796) +''' +EXAMPLES = ''' + +- name: "Create Event Hub" + azure_rm_eventhub: + resource_group: testgroupans + location: eastus + namespace_name: myNamespace + name: myhub + tags: + - a: b + sku: free + +- name: Delete Event Hub + azure_rm_eventhub: + resource_group: testgroupans + name: myNamespace + state: absent + +- name: "Create Event Hub Namespace" + azure_rm_eventhub: + resource_group: testgroupans + location: eastus + namespace_name: myNamespace + tags: + a: b + sku: free + +- name: Delete Event Hub Namespace + azure_rm_eventhub: + resource_group: testgroupans + namespace_name: myNamespace + state: absent + +''' + +RETURN = ''' +state: + description: + - Current state of the Event Hub namesapce or Event Hub. + returned: always + type: dict + sample: { + "additional_properties": {"location": "East US"}, + "critical": false, + "enabled": true, + "metric_id": null, + "name": "testnaedd3d22d3w", + "namespace_type": "eventHub", + "status": "Active", + "region": null, + "scale_unit": null, + "service_bus_endpoint": "https://testnaedd3d22d3w.servicebus.windows.net:443/", + "sku": "Basic", + "tags": { + "a": "b" + }, + "message_retention_in_days": 7, + "partition_count": 4, + "partition_ids": ["0", "1", "2", "3"], + "updated_at": "2021-04-29T10:05:24.000Z", + "created_at": "2021-04-29T10:05:20.377Z", + "type": "Microsoft.eventHubs/namespaces" + } + +''' + + +try: + from msrestazure.azure_exceptions import CloudError + from azure.mgmt.eventhub.models import Eventhub, EHNamespace + from azure.mgmt.eventhub.models.sku import Sku + import time +except ImportError: + # This is handled in azure_rm_common + pass + +partition_count_list = [i for i in range(1, 33)] + + +class AzureEventHub(AzureRMModuleBase): + + def __init__(self): + # define user inputs from playbook + + self.authorizations_spec = dict( + name=dict(type='str', required=True) + ) + + self.module_arg_spec = dict( + message_retention_in_days=dict(type='int'), + name=dict(type='str'), + namespace_name=dict(type='str', required=True), + partition_count=dict(type='int', choices=partition_count_list), + resource_group=dict(type='str', required=True), + sku=dict(type='str', choices=[ + 'Basic', 'Standard'], default='Basic'), + status=dict(choices=["Active", "Disabled", "Restoring", "SendDisabled", "ReceiveDisabled", "Creating", "Deleting", "Renaming", "Unknown"], + default='Active', type='str'), + state=dict(choices=['present', 'absent'], + default='present', type='str'), + location=dict(type='str') + ) + required_if = [ + ('state', 'present', [ + 'partition_count', 'message_retention_in_days']) + ] + self.sku = None + self.resource_group = None + self.namespace_name = None + self.message_retention_in_days = None + self.name = None + self.location = None + self.authorizations = None + self.tags = None + self.status = None + self.partition_count = None + self.results = dict( + changed=False, + state=dict() + ) + self.state = None + + super(AzureEventHub, self).__init__(derived_arg_spec=self.module_arg_spec, + supports_check_mode=True, + supports_tags=True) + + def exec_module(self, **kwargs): + for key in list(self.module_arg_spec.keys()) + ['tags']: + setattr(self, key, kwargs[key]) + + # retrieve resource group to make sure it exists + self.get_resource_group(self.resource_group) + + results = dict() + changed = False + + try: + self.log( + 'Fetching Event Hub Namespace {0}'.format(self.name)) + namespace = self.event_hub_client.namespaces.get( + self.resource_group, self.namespace_name) + + results = namespace_to_dict(namespace) + if self.name: + self.log('Fetching event Hub {0}'.format(self.name)) + event_hub = self.event_hub_client.event_hubs.get( + self.resource_group, self.namespace_name, self.name) + event_hub_results = event_hub_to_dict( + event_hub) + # don't change anything if creating an existing namespace, but change if deleting it + if self.state == 'present': + changed = False + + update_tags, results['tags'] = self.update_tags( + results['tags']) + + if update_tags: + changed = True + elif self.namespace_name and not self.name: + if self.sku != results['sku'].lower(): + changed = True + + elif self.state == 'absent': + changed = True + + except Exception: + # the event hub does not exist so create it + if self.state == 'present': + changed = True + else: + # you can't delete what is not there + changed = False + + self.results['changed'] = changed + if self.name and not changed: + self.results['state'] = event_hub_results + else: + self.results['state'] = results + + # return the results if your only gathering information + if self.check_mode: + return self.results + if changed: + if self.state == "present": + if self.name is None: + self.results['state'] = self.create_or_update_namespaces() + elif self.namespace_name and self.name: + self.results['state'] = self.create_or_update_event_hub() + elif self.state == "absent": + # delete Event Hub + if self.name is None: + self.delete_namespace() + elif self.namespace_name and self.name: + self.delete_event_hub() + self.results['state']['status'] = 'Deleted' + + return self.results + + def create_or_update_namespaces(self): + ''' + create or update namespaces + ''' + try: + namespace_params = EHNamespace( + location=self.location, + sku=Sku(name=self.sku), + tags=self.tags + ) + result = self.event_hub_client.namespaces.create_or_update( + self.resource_group, + self.namespace_name, + namespace_params) + + namespace = self.event_hub_client.namespaces.get( + self.resource_group, + self.namespace_name) + while namespace.provisioning_state == "Created": + time.sleep(30) + namespace = self.event_hub_client.namespaces.get( + self.resource_group, + self.namespace_name, + ) + except CloudError as ex: + self.fail("Failed to create namespace {0} in resource group {1}: {2}".format( + self.namespace_name, self.resource_group, str(ex))) + return namespace_to_dict(namespace) + + def create_or_update_event_hub(self): + ''' + Create or update Event Hub. + :return: create or update Event Hub instance state dictionary + ''' + try: + params = Eventhub( + name=self.name, + message_retention_in_days=self.message_retention_in_days, + partition_count=self.partition_count, + status=self.status + ) + result = self.event_hub_client.event_hubs.create_or_update( + self.resource_group, + self.namespace_name, + self.name, + params) + + self.log("Response : {0}".format(result)) + except CloudError as ex: + self.fail("Failed to create event hub {0} in resource group {1}: {2}".format( + self.name, self.resource_group, str(ex))) + return event_hub_to_dict(result) + + def delete_event_hub(self): + ''' + Deletes specified event hub + :return True + ''' + self.log("Deleting the event hub {0}".format(self.name)) + try: + result = self.event_hub_client.event_hubs.delete( + self.resource_group, self.namespace_name, self.name) + except CloudError as e: + self.log('Error attempting to delete event hub.') + self.fail( + "Error deleting the event hub : {0}".format(str(e))) + return True + + def delete_namespace(self): + ''' + Deletes specified namespace + :return True + ''' + self.log("Deleting the namespace {0}".format(self.namespace_name)) + try: + result = self.event_hub_client.namespaces.delete( + self.resource_group, self.namespace_name) + except CloudError as e: + self.log('Error attempting to delete namespace.') + self.fail( + "Error deleting the namespace : {0}".format(str(e))) + return True + + +def event_hub_to_dict(item): + # turn event hub object into a dictionary (serialization) + event_hub = item.as_dict() + result = dict() + if item.additional_properties: + result['additional_properties'] = item.additional_properties + result['name'] = event_hub.get('name', None) + result['partition_ids'] = event_hub.get('partition_ids', None) + result['created_at'] = event_hub.get('created_at', None) + result['updated_at'] = event_hub.get('updated_at', None) + result['message_retention_in_days'] = event_hub.get( + 'message_retention_in_days', None) + result['partition_count'] = event_hub.get('partition_count', None) + result['status'] = event_hub.get('status', None) + result['tags'] = event_hub.get('tags', None) + return result + + +def namespace_to_dict(item): + # turn event hub namespace object into a dictionary (serialization) + namespace = item.as_dict() + result = dict( + additional_properties=namespace.get( + 'additional_properties', {}), + name=namespace.get('name', None), + type=namespace.get('type', None), + location=namespace.get( + 'location', '').replace(' ', '').lower(), + sku=namespace.get("sku").get("name"), + tags=namespace.get('tags', None), + provisioning_state=namespace.get( + 'provisioning_state', None), + region=namespace.get('region', None), + metric_id=namespace.get('metric_id', None), + service_bus_endpoint=namespace.get( + 'service_bus_endpoint', None), + scale_unit=namespace.get('scale_unit', None), + enabled=namespace.get('enabled', None), + critical=namespace.get('critical', None), + data_center=namespace.get('data_center', None), + namespace_type=namespace.get('namespace_type', None), + updated_at=namespace.get('updated_at', None), + created_at=namespace.get('created_at', None), + is_auto_inflate_enabled=namespace.get( + 'is_auto_inflate_enabled', None), + maximum_throughput_units=namespace.get( + 'maximum_throughput_units', None) + ) + return result + + +def main(): + AzureEventHub() + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/azure_rm_eventhub_info.py b/plugins/modules/azure_rm_eventhub_info.py new file mode 100644 index 000000000..b3ec014a5 --- /dev/null +++ b/plugins/modules/azure_rm_eventhub_info.py @@ -0,0 +1,240 @@ +#!/usr/bin/python +# +# Copyright (c) 2021 Praveen Ghuge(@praveenghuge) Karl Dasan(@karldas30) Saurabh Malpani (@saurabh3796) +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase + +__metaclass__ = type + + +DOCUMENTATION = ''' +--- +module: azure_eventhub_info +short_description: Get Azure Event Hub +description: + - Get facts of Azure Event Hub +options: + resource_group: + description: + - The name of the resource group. + required: True + type: str + namespace_name: + - The name of the namspace + required: True + type: str + name: + description: + - The name of the Event hub. + type: str +extends_documentation_fragment: +- azure.azcollection.azure +author: + - Saurabh Malpani (@saurabh3796) +''' + + +EXAMPLES = ''' + - name: Get facts of specific Event hub + community.azure.azure_rm_eventhub_info: + resource_group: myResourceGroup + name: myEventHub +''' + +RETURN = ''' +state: + description: + - Current state of the Event Hub namesapce or Event Hub. + returned: always + type: dict + sample:{ + "additional_properties": {}, + "created_at": "2021-04-19T12:49:46.597Z", + "critical": null, + "data_center": null, + "status": "Active", + "location": "eastus", + "metric_id": "149f0952-6f3d-48ba-9e98-57011575cbbd:eventhubtestns1753", + "name": "eventhubtestns1753", + "namespace_type": null, + "provisioning_state": "Succeeded", + "region": null, + "scale_unit": null, + "service_bus_endpoint": "https://eventhubtestns1753.servicebus.windows.net:443/", + "sku": "Basic", + "tags": {}, + "type": "Microsoft.EventHub/Namespaces", + "updated_at": "2021-04-19T12:54:33.397Z" + } +''' + +try: + from msrestazure.azure_exceptions import CloudError +except ImportError: + # This is handled in azure_rm_common + pass + + +class AzureEventHubInfo(AzureRMModuleBase): + def __init__(self): + + self.module_arg_spec = dict( + resource_group=dict( + type='str', + required=True + ), + namespace_name=dict( + type='str', + required=False + ), + name=dict( + type='str', + required=False + ) + ) + + # store the results of the module operation + self.results = dict( + changed=False) + self.resource_group = None + self.namespace_name = None + self.name = None + self.tags = None + + super(AzureEventHubInfo, self).__init__( + self.module_arg_spec, supports_tags=False) + + def exec_module(self, **kwargs): + + for key in self.module_arg_spec: + setattr(self, key, kwargs[key]) + + if self.name and self.namespace_name and self.resource_group: + results = self.get_event_hub() + self.results['eventhub'] = [ + self.event_hub_to_dict(x) for x in results] + elif self.namespace_name: + results = self.get_namespace() + self.results['namespace'] = [ + self.namespace_to_dict(x) for x in results] + elif self.name is None and self.namespace_name is None: + results = self.list_all_namespace() + self.results['namespaces'] = [ + self.namespace_to_dict(x) for x in results] + return self.results + + def get_namespace(self): + ''' + Get the namespace using resource group and namespace name + ''' + response = None + results = [] + try: + response = self.event_hub_client.namespaces.get( + self.resource_group, self.namespace_name) + self.log("Response : {0}".format(response)) + + except CloudError as e: + self.fail('Could not get info for namespace. {0}').format( + str(e)) + + if response: + results = [response] + return results + + def get_event_hub(self): + ''' + get event hub using resource_group, namespace_name and name. + ''' + response = None + results = [] + + try: + response = self.event_hub_client.event_hubs.get( + self.resource_group, self.namespace_name, self.name) + + except CloudError as e: + self.fail('Could not get info for event hub. {0}').format( + str(e)) + + if response: + results = [response] + return results + + def list_all_namespace(self): + ''' + List all namespaces in particular resource_group + ''' + self.log('List items for resource group') + try: + response = self.event_hub_client.namespaces.list_by_resource_group( + self.resource_group) + + except CloudError as exc: + self.fail( + "Failed to list for resource group {0} - {1}".format(self.resource_group, str(exc))) + + results = [] + for item in response: + results.append(item) + return results + + def namespace_to_dict(self, item): + # turn event hub object into a dictionary (serialization) + namespace = item.as_dict() + result = dict( + additional_properties=namespace.get( + 'additional_properties', {}), + name=namespace.get('name', None), + type=namespace.get('type', None), + location=namespace.get( + 'location', '').replace(' ', '').lower(), + sku=namespace.get("sku").get("name"), + tags=namespace.get('tags', None), + provisioning_state=namespace.get( + 'provisioning_state', None), + region=namespace.get('region', None), + metric_id=namespace.get('metric_id', None), + service_bus_endpoint=namespace.get( + 'service_bus_endpoint', None), + scale_unit=namespace.get('scale_unit', None), + enabled=namespace.get('enabled', None), + critical=namespace.get('critical', None), + data_center=namespace.get('data_center', None), + namespace_type=namespace.get('namespace_type', None), + updated_at=namespace.get('updated_at', None), + created_at=namespace.get('created_at', None), + is_auto_inflate_enabled=namespace.get( + 'is_auto_inflate_enabled', None), + maximum_throughput_units=namespace.get( + 'maximum_throughput_units', None) + ) + return result + + def event_hub_to_dict(self, item): + # turn event hub object into a dictionary (serialization) + event_hub = item.as_dict() + result = dict() + if item.additional_properties: + result['additional_properties'] = item.additional_properties + result['name'] = event_hub.get('name', None) + result['partition_ids'] = event_hub.get('partition_ids', None) + result['created_at'] = event_hub.get('created_at', None) + result['updated_at'] = event_hub.get('updated_at', None) + result['message_retention_in_days'] = event_hub.get( + 'message_retention_in_days', None) + result['partition_count'] = event_hub.get('partition_count', None) + result['status'] = event_hub.get('status', None) + result['tags'] = event_hub.get('tags', None) + return result + + +def main(): + AzureEventHubInfo() + + +if __name__ == '__main__': + main() diff --git a/pr-pipelines.yml b/pr-pipelines.yml index 66dc0d30f..fc7279892 100644 --- a/pr-pipelines.yml +++ b/pr-pipelines.yml @@ -42,6 +42,7 @@ parameters: - "azure_rm_deployment" - "azure_rm_dnsrecordset" - "azure_rm_dnszone" + - "azure_rm_eventhub" - "azure_rm_functionapp" - "azure_rm_gallery" - "azure_rm_hdinsightcluster" diff --git a/requirements-azure.txt b/requirements-azure.txt index 23dd8d6dd..4818c8d76 100644 --- a/requirements-azure.txt +++ b/requirements-azure.txt @@ -44,3 +44,4 @@ azure-mgmt-automation==0.1.1 azure-mgmt-iothub==0.7.0 azure-mgmt-recoveryservices==0.4.0 azure-mgmt-recoveryservicesbackup==0.6.0 +azure-mgmt-eventhub==2.0.0 diff --git a/tests/integration/targets/azure_rm_eventhub/aliases b/tests/integration/targets/azure_rm_eventhub/aliases new file mode 100644 index 000000000..5cf25760d --- /dev/null +++ b/tests/integration/targets/azure_rm_eventhub/aliases @@ -0,0 +1,3 @@ +cloud/azure +shippable/azure/group10 +destructive \ No newline at end of file diff --git a/tests/integration/targets/azure_rm_eventhub/meta/main.yml b/tests/integration/targets/azure_rm_eventhub/meta/main.yml new file mode 100644 index 000000000..95e1952f9 --- /dev/null +++ b/tests/integration/targets/azure_rm_eventhub/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - setup_azure diff --git a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml new file mode 100644 index 000000000..40239fce3 --- /dev/null +++ b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml @@ -0,0 +1,152 @@ +`- name: Create random event hub and namespace + set_fact: + namespace_name: "test{{ resource_group | hash('md5') | truncate(16, True, '') + (65535 | random | string) }}" + name: "test{{ resource_group | hash('md5') | truncate(16, True, '') + (65535 | random | string) }}" + + +- name: Create Event Hub Namespace (check mode) + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + resource_group: "{{ resource_group }}" + sku: "Basic" + check_mode: yes + register: results + +- assert: + that: results.changed + + + +- name: Create Event Hub (check mode) + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + name: "{{ name }}" + resource_group: "{{ resource_group }}" + sku: "Basic" + check_mode: yes + register: results + +- assert: + that: results.changed + + +- name: Create Event Hub Namespace (check mode) + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + resource_group: "{{ resource_group }}" + sku: "Basic" + register: results + +- assert: + that: results.changed + + + +- name: Create Event Hub + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + name: "{{ name }}" + resource_group: "{{ resource_group }}" + sku: "Basic" + register: results + +- assert: + that: results.changed + +- name: Update Namespace + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + resource_group: "{{ resource_group }}" + tags: + test: modified + register: results + +- assert: + that: + - results.changed + - results.state.tags.test == 'modified' + + +- name: Update Event Hub + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + name: "{{ name }}" + resource_group: "{{ resource_group }}" + tags: + test: modified + register: results + +- assert: + that: + - results.changed + - results.state.tags.test == 'modified' + +- name: Retrieve Namespace + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + resource_group: "{{ resource_group }}" + register: results + +- name: Assert that facts module returned result + assert: + that: + - results.ddos_protection_plan[0].tags.test == 'modified' + +- name: Test idempotent + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + resource_group: "{{ resource_group }}" + register: results + +- assert: + that: + - not results.changed + +#cleanup + +- name: Delete Namespace + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + resource_group: "{{ resource_group }}" + state: absent + +- name: Delete Namespace (idempotent) + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + resource_group: "{{ resource_group }}" + state: absent + register: results + +- assert: + that: not results.changed + + +- name: Delete Event Hub + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + name: "{{ name }}" + resource_group: "{{ resource_group }}" + state: absent + +- name: Delete Event Hub (idempotent) + azure_rm_eventhub: + location: eastus2 + namespace_name: "{{ namespace_name }}" + name: "{{ name }}" + resource_group: "{{ resource_group }}" + state: absent + register: results + +- assert: + that: not results.changed` \ No newline at end of file From 3901601d90cdca4d6d594deb3cea999cedde5179 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Fri, 14 May 2021 10:53:25 +0530 Subject: [PATCH 02/39] Update azure_rm_common.py --- plugins/module_utils/azure_rm_common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/module_utils/azure_rm_common.py b/plugins/module_utils/azure_rm_common.py index ad8e53c95..9c07637b6 100644 --- a/plugins/module_utils/azure_rm_common.py +++ b/plugins/module_utils/azure_rm_common.py @@ -1343,6 +1343,7 @@ def event_hub_client(self): api_version='2018-05-04') return self._event_hub_client + class AzureSASAuthentication(Authentication): """Simple SAS Authentication. An implementation of Authentication in From 6b7c1a5e06d4937de22fc437fc6e88fcb6ff1751 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Fri, 14 May 2021 10:54:30 +0530 Subject: [PATCH 03/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 42 +++++++++++++++++++--------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index b4bb3b9e2..6a7f754e7 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -5,8 +5,6 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function -from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase - __metaclass__ = type DOCUMENTATION = ''' @@ -29,12 +27,27 @@ name: description: - Unique name of the Event Hub. - required: True + required: False + type: str + message_retention_in_days: + description: + - Number of days to retain the events for this Event Hub. + required: False + type: int + partition_count: + description: + - Number of partitions created for the Event Hub. + required: False + type: int + status: + description: + - Enumerates the possible values for the status of the Event hub. + required: False type: str location: description: - Resource location. If not set, location from the resource group will be used as default. - required: if state is present + required: False type: str sku: description: @@ -54,7 +67,7 @@ - absent - present type: str - + extends_documentation_fragment: - azure.azcollection.azure - azure.azcollection.azure_tags @@ -127,12 +140,12 @@ "created_at": "2021-04-29T10:05:20.377Z", "type": "Microsoft.eventHubs/namespaces" } - -''' +''' try: from msrestazure.azure_exceptions import CloudError + from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase from azure.mgmt.eventhub.models import Eventhub, EHNamespace from azure.mgmt.eventhub.models.sku import Sku import time @@ -143,7 +156,7 @@ partition_count_list = [i for i in range(1, 33)] -class AzureEventHub(AzureRMModuleBase): +class AzureRMEventHub(AzureRMModuleBase): def __init__(self): # define user inputs from playbook @@ -186,16 +199,19 @@ def __init__(self): ) self.state = None - super(AzureEventHub, self).__init__(derived_arg_spec=self.module_arg_spec, - supports_check_mode=True, - supports_tags=True) + super(AzureRMEventHub, self).__init__(derived_arg_spec=self.module_arg_spec, + supports_check_mode=True, + supports_tags=True) def exec_module(self, **kwargs): for key in list(self.module_arg_spec.keys()) + ['tags']: setattr(self, key, kwargs[key]) # retrieve resource group to make sure it exists - self.get_resource_group(self.resource_group) + resource_group = self.get_resource_group(self.resource_group) + if not self.location: + # Set default location + self.location = resource_group.location results = dict() changed = False @@ -398,7 +414,7 @@ def namespace_to_dict(item): def main(): - AzureEventHub() + AzureRMEventHub() if __name__ == '__main__': From 9761d1b7e3ffd15aeebaee2eb347da24c73455f4 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Fri, 14 May 2021 10:55:02 +0530 Subject: [PATCH 04/39] Update azure_rm_eventhub_info.py --- plugins/modules/azure_rm_eventhub_info.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub_info.py b/plugins/modules/azure_rm_eventhub_info.py index b3ec014a5..660297fd9 100644 --- a/plugins/modules/azure_rm_eventhub_info.py +++ b/plugins/modules/azure_rm_eventhub_info.py @@ -5,8 +5,6 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function -from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase - __metaclass__ = type @@ -31,7 +29,7 @@ - The name of the Event hub. type: str extends_documentation_fragment: -- azure.azcollection.azure + - azure.azcollection.azure author: - Saurabh Malpani (@saurabh3796) ''' @@ -73,12 +71,13 @@ try: from msrestazure.azure_exceptions import CloudError + from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase except ImportError: # This is handled in azure_rm_common pass -class AzureEventHubInfo(AzureRMModuleBase): +class AzureRMEventHubInfo(AzureRMModuleBase): def __init__(self): self.module_arg_spec = dict( @@ -104,7 +103,7 @@ def __init__(self): self.name = None self.tags = None - super(AzureEventHubInfo, self).__init__( + super(AzureRMEventHubInfo, self).__init__( self.module_arg_spec, supports_tags=False) def exec_module(self, **kwargs): @@ -233,7 +232,7 @@ def event_hub_to_dict(self, item): def main(): - AzureEventHubInfo() + AzureRMEventHubInfo() if __name__ == '__main__': From cb8be48a8e6d18d0eae38e9fcd8edb44682f3df7 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Fri, 14 May 2021 10:56:13 +0530 Subject: [PATCH 05/39] Update ignore-2.10.txt --- tests/sanity/ignore-2.10.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 5d1cda335..83e37abac 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -767,5 +767,9 @@ plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-req plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-unknown-key plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-requirements-unknown plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-unknown-key +plugins/modules/azure_rm_enventhub.py validate-modules:required_if-requirements-unknown +plugins/modules/azure_rm_enventhub.py validate-modules:required_if-unknown-key +plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-requirements-unknown +plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-unknown-key tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang From 2c6677d0ed99bc8f48f87cfa28aca44449cb809e Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Fri, 14 May 2021 10:56:33 +0530 Subject: [PATCH 06/39] Update ignore-2.11.txt --- tests/sanity/ignore-2.11.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 22f1d37c2..2f6371531 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -767,5 +767,9 @@ plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-req plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-unknown-key plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-requirements-unknown plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-unknown-key +plugins/modules/azure_rm_enventhub.py validate-modules:required_if-requirements-unknown +plugins/modules/azure_rm_enventhub.py validate-modules:required_if-unknown-key +plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-requirements-unknown +plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-unknown-key tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang From c9ee4fa2cb14fdf0c042177c1a37622d0e4d2689 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Fri, 14 May 2021 10:56:51 +0530 Subject: [PATCH 07/39] Update ignore-2.12.txt --- tests/sanity/ignore-2.12.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index 147959000..b343f0289 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -767,5 +767,9 @@ plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-req plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-unknown-key plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-requirements-unknown plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-unknown-key +plugins/modules/azure_rm_enventhub.py validate-modules:required_if-requirements-unknown +plugins/modules/azure_rm_enventhub.py validate-modules:required_if-unknown-key +plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-requirements-unknown +plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-unknown-key tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang From 0f5173c1bc64e56c2c5ed0f106f0d2ae045fc177 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Fri, 14 May 2021 10:57:12 +0530 Subject: [PATCH 08/39] Update ignore-2.9.txt --- tests/sanity/ignore-2.9.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 6e9796e7c..a1d2b3eb9 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -181,5 +181,9 @@ plugins/modules/azure_rm_adpassword_info.py validate-modules:nonexistent-paramet plugins/modules/azure_rm_adpassword_info.py validate-modules:import-before-documentation plugins/modules/azure_rm_adserviceprincipal.py validate-modules:nonexistent-parameter-documented plugins/modules/azure_rm_adserviceprincipal_info.py validate-modules:nonexistent-parameter-documented +plugins/modules/azure_rm_enventhub.py validate-modules:required_if-requirements-unknown +plugins/modules/azure_rm_enventhub.py validate-modules:required_if-unknown-key +plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-requirements-unknown +plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-unknown-key tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang From 48bb0fdcd9cad9bd8bca7f1e6d3f9e91434505ae Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Fri, 14 May 2021 11:04:01 +0530 Subject: [PATCH 09/39] Update main.yml --- tests/integration/targets/azure_rm_eventhub/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml index 40239fce3..41df664c4 100644 --- a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml +++ b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml @@ -1,4 +1,4 @@ -`- name: Create random event hub and namespace +- name: Create random event hub and namespace set_fact: namespace_name: "test{{ resource_group | hash('md5') | truncate(16, True, '') + (65535 | random | string) }}" name: "test{{ resource_group | hash('md5') | truncate(16, True, '') + (65535 | random | string) }}" @@ -149,4 +149,4 @@ register: results - assert: - that: not results.changed` \ No newline at end of file + that: not results.changed From 120b6c672a385fb2fe977e4e3f373c65b64df442 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Tue, 25 May 2021 15:00:18 +0530 Subject: [PATCH 10/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index 6a7f754e7..1d6862606 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -10,6 +10,7 @@ DOCUMENTATION = ''' --- module: azure_rm_eventhub +version_added: "1.6.0" short_description: Manage Event Hub description: - Create, update and delete instance of Event Hub. From 421de69505a8136d9410a0e722ff4a3a004b96a5 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Tue, 25 May 2021 15:00:24 +0530 Subject: [PATCH 11/39] Update azure_rm_eventhub_info.py --- plugins/modules/azure_rm_eventhub_info.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/azure_rm_eventhub_info.py b/plugins/modules/azure_rm_eventhub_info.py index 660297fd9..b7882fdc1 100644 --- a/plugins/modules/azure_rm_eventhub_info.py +++ b/plugins/modules/azure_rm_eventhub_info.py @@ -11,6 +11,7 @@ DOCUMENTATION = ''' --- module: azure_eventhub_info +version_added: "1.6.0" short_description: Get Azure Event Hub description: - Get facts of Azure Event Hub From 1e532da9162ce37d5d21244b6ef16a5033b7543e Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Tue, 25 May 2021 15:22:39 +0530 Subject: [PATCH 12/39] Update azure_rm_eventhub_info.py --- plugins/modules/azure_rm_eventhub_info.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub_info.py b/plugins/modules/azure_rm_eventhub_info.py index b7882fdc1..b1448d097 100644 --- a/plugins/modules/azure_rm_eventhub_info.py +++ b/plugins/modules/azure_rm_eventhub_info.py @@ -14,7 +14,7 @@ version_added: "1.6.0" short_description: Get Azure Event Hub description: - - Get facts of Azure Event Hub + - Get facts of Azure Event Hub. options: resource_group: description: @@ -22,7 +22,8 @@ required: True type: str namespace_name: - - The name of the namspace + description: + - The name of the namspace. required: True type: str name: From 442b11946248701662c9345d4abe9b8cf034393d Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Tue, 25 May 2021 15:31:34 +0530 Subject: [PATCH 13/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index 1d6862606..dceb39cef 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -31,7 +31,7 @@ required: False type: str message_retention_in_days: - description: + description: - Number of days to retain the events for this Event Hub. required: False type: int @@ -40,11 +40,23 @@ - Number of partitions created for the Event Hub. required: False type: int + choices: Choose value between 1 to 32(both included). status: description: - Enumerates the possible values for the status of the Event hub. + default: Active required: False type: str + choices: + - Active + - Disabled + - Restoring + - SendDisabled + - ReceiveDisabled + - Creating + - Deleting + - Renaming + - Unknown location: description: - Resource location. If not set, location from the resource group will be used as default. From 791995f81c20377f847660dd61344c72fe7d4ad7 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Tue, 25 May 2021 15:35:07 +0530 Subject: [PATCH 14/39] Update main.yml --- tests/integration/targets/azure_rm_eventhub/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml index 41df664c4..a9e0e91b6 100644 --- a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml +++ b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml @@ -10,7 +10,7 @@ namespace_name: "{{ namespace_name }}" resource_group: "{{ resource_group }}" sku: "Basic" - check_mode: yes + check_mode: yes register: results - assert: @@ -25,7 +25,7 @@ name: "{{ name }}" resource_group: "{{ resource_group }}" sku: "Basic" - check_mode: yes + check_mode: yes register: results - assert: From 18b34132507bc0ec55247eea2fe146e53e6c5c1d Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Tue, 25 May 2021 15:35:38 +0530 Subject: [PATCH 15/39] Update main.yml --- tests/integration/targets/azure_rm_eventhub/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml index a9e0e91b6..7ed84a7e2 100644 --- a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml +++ b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml @@ -32,7 +32,7 @@ that: results.changed -- name: Create Event Hub Namespace (check mode) +- name: Create Event Hub Namespace azure_rm_eventhub: location: eastus2 namespace_name: "{{ namespace_name }}" From 09a97ecc0cb193dfd4fc8ed1f3474581aec6cdd5 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 09:16:49 +0530 Subject: [PATCH 16/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index dceb39cef..77e1a2d01 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -40,7 +40,7 @@ - Number of partitions created for the Event Hub. required: False type: int - choices: Choose value between 1 to 32(both included). + choices: [1,2,3,4,5,6,7,8,......,31,32] status: description: - Enumerates the possible values for the status of the Event hub. @@ -166,7 +166,7 @@ # This is handled in azure_rm_common pass -partition_count_list = [i for i in range(1, 33)] +partition_count_list = [1,2,3,4,5,6,7,8,......,31,32] class AzureRMEventHub(AzureRMModuleBase): From 1efe890bfb5dc1494ebcc1bf70181b0ef23b9312 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 09:19:50 +0530 Subject: [PATCH 17/39] Update azure_rm_eventhub_info.py --- plugins/modules/azure_rm_eventhub_info.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub_info.py b/plugins/modules/azure_rm_eventhub_info.py index b1448d097..3e51101d0 100644 --- a/plugins/modules/azure_rm_eventhub_info.py +++ b/plugins/modules/azure_rm_eventhub_info.py @@ -10,7 +10,7 @@ DOCUMENTATION = ''' --- -module: azure_eventhub_info +module: azure_rm_eventhub_info version_added: "1.6.0" short_description: Get Azure Event Hub description: @@ -24,7 +24,7 @@ namespace_name: description: - The name of the namspace. - required: True + required: False type: str name: description: @@ -50,7 +50,7 @@ - Current state of the Event Hub namesapce or Event Hub. returned: always type: dict - sample:{ + sample: { "additional_properties": {}, "created_at": "2021-04-19T12:49:46.597Z", "critical": null, From 884c6a101eb421e01e275670745773563c35d257 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 09:21:55 +0530 Subject: [PATCH 18/39] Update ignore-2.9.txt --- tests/sanity/ignore-2.9.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index a1d2b3eb9..6e9796e7c 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -181,9 +181,5 @@ plugins/modules/azure_rm_adpassword_info.py validate-modules:nonexistent-paramet plugins/modules/azure_rm_adpassword_info.py validate-modules:import-before-documentation plugins/modules/azure_rm_adserviceprincipal.py validate-modules:nonexistent-parameter-documented plugins/modules/azure_rm_adserviceprincipal_info.py validate-modules:nonexistent-parameter-documented -plugins/modules/azure_rm_enventhub.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_enventhub.py validate-modules:required_if-unknown-key -plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-unknown-key tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang From d90fab66d77b17705efc72375241a1487d36db4a Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 09:24:38 +0530 Subject: [PATCH 19/39] Update ignore-2.12.txt --- tests/sanity/ignore-2.12.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index 5679d1fa8..9c280ce48 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -354,13 +354,5 @@ plugins/modules/azure_rm_openshiftmanagedcluster.py validate-modules:parameter-l plugins/modules/azure_rm_subnet.py validate-modules:doc-elements-mismatch plugins/modules/azure_rm_vmbackuppolicy.py validate-modules:parameter-list-no-elements plugins/modules/azure_rm_privatednsrecordset.py validate-modules:invalid-ansiblemodule-schema -plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-unknown-key -plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-unknown-key -plugins/modules/azure_rm_enventhub.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_enventhub.py validate-modules:required_if-unknown-key -plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-unknown-key tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang From 33038bf2af3378fdd5b18c10d31195ad50b61096 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 09:25:50 +0530 Subject: [PATCH 20/39] Update ignore-2.11.txt --- tests/sanity/ignore-2.11.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 8cd7a01cd..a8700c66f 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -354,13 +354,5 @@ plugins/modules/azure_rm_openshiftmanagedcluster.py validate-modules:parameter-l plugins/modules/azure_rm_subnet.py validate-modules:doc-elements-mismatch plugins/modules/azure_rm_vmbackuppolicy.py validate-modules:parameter-list-no-elements plugins/modules/azure_rm_privatednsrecordset.py validate-modules:invalid-ansiblemodule-schema -plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-unknown-key -plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-unknown-key -plugins/modules/azure_rm_enventhub.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_enventhub.py validate-modules:required_if-unknown-key -plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-unknown-key tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang From e41f68fe145aabfe1fce8352c689ff27af7f4112 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 09:28:16 +0530 Subject: [PATCH 21/39] Update ignore-2.10.txt --- tests/sanity/ignore-2.10.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 1ed38b047..468c3e35c 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -354,13 +354,5 @@ plugins/modules/azure_rm_openshiftmanagedcluster.py validate-modules:parameter-l plugins/modules/azure_rm_subnet.py validate-modules:doc-elements-mismatch plugins/modules/azure_rm_vmbackuppolicy.py validate-modules:parameter-list-no-elements plugins/modules/azure_rm_privatednsrecordset.py validate-modules:invalid-ansiblemodule-schema -plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_privatednsrecordset.py validate-modules:required_if-unknown-key -plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_privatednsrecordset_info.py validate-modules:required_if-unknown-key -plugins/modules/azure_rm_enventhub.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_enventhub.py validate-modules:required_if-unknown-key -plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-requirements-unknown -plugins/modules/azure_rm_enventhub_info.py validate-modules:required_if-unknown-key tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang From ed0167da530f1c04f059d7ea98ea8ffed0df3eff Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 15:19:49 +0530 Subject: [PATCH 22/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index 77e1a2d01..aa22fbedb 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -38,9 +38,9 @@ partition_count: description: - Number of partitions created for the Event Hub. + - Range from 1 to 32. required: False type: int - choices: [1,2,3,4,5,6,7,8,......,31,32] status: description: - Enumerates the possible values for the status of the Event hub. @@ -166,8 +166,6 @@ # This is handled in azure_rm_common pass -partition_count_list = [1,2,3,4,5,6,7,8,......,31,32] - class AzureRMEventHub(AzureRMModuleBase): @@ -182,7 +180,7 @@ def __init__(self): message_retention_in_days=dict(type='int'), name=dict(type='str'), namespace_name=dict(type='str', required=True), - partition_count=dict(type='int', choices=partition_count_list), + partition_count=dict(type='int'), resource_group=dict(type='str', required=True), sku=dict(type='str', choices=[ 'Basic', 'Standard'], default='Basic'), From 6a22fb23964a076f6c51137ba80941b3ff4abe45 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 16:57:58 +0530 Subject: [PATCH 23/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index aa22fbedb..81dc669e3 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -156,15 +156,12 @@ ''' -try: - from msrestazure.azure_exceptions import CloudError - from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase - from azure.mgmt.eventhub.models import Eventhub, EHNamespace - from azure.mgmt.eventhub.models.sku import Sku - import time -except ImportError: - # This is handled in azure_rm_common - pass + +from msrestazure.azure_exceptions import CloudError +from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase +from azure.mgmt.eventhub.models import Eventhub, EHNamespace +from azure.mgmt.eventhub.models.sku import Sku +import time class AzureRMEventHub(AzureRMModuleBase): From 76efd3eeab149433800202c32364655601ff5066 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 16:59:27 +0530 Subject: [PATCH 24/39] Update azure_rm_eventhub_info.py --- plugins/modules/azure_rm_eventhub_info.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub_info.py b/plugins/modules/azure_rm_eventhub_info.py index 3e51101d0..fe22ff4bd 100644 --- a/plugins/modules/azure_rm_eventhub_info.py +++ b/plugins/modules/azure_rm_eventhub_info.py @@ -71,12 +71,8 @@ } ''' -try: - from msrestazure.azure_exceptions import CloudError - from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase -except ImportError: - # This is handled in azure_rm_common - pass +from msrestazure.azure_exceptions import CloudError +from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase class AzureRMEventHubInfo(AzureRMModuleBase): From 4fdd0aada9a27634f5dfefacf4b066daac2228e8 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 17:20:30 +0530 Subject: [PATCH 25/39] Update azure_rm_eventhub_info.py --- plugins/modules/azure_rm_eventhub_info.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub_info.py b/plugins/modules/azure_rm_eventhub_info.py index fe22ff4bd..3e51101d0 100644 --- a/plugins/modules/azure_rm_eventhub_info.py +++ b/plugins/modules/azure_rm_eventhub_info.py @@ -71,8 +71,12 @@ } ''' -from msrestazure.azure_exceptions import CloudError -from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase +try: + from msrestazure.azure_exceptions import CloudError + from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase +except ImportError: + # This is handled in azure_rm_common + pass class AzureRMEventHubInfo(AzureRMModuleBase): From 917543990fde68a36620781fc0489b627ba5f63d Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 17:41:25 +0530 Subject: [PATCH 26/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index 81dc669e3..8405d3fcd 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -156,8 +156,11 @@ ''' - -from msrestazure.azure_exceptions import CloudError +try: + from msrestazure.azure_exceptions import CloudError +except ImportError: + # This is handled in azure_rm_common + pass from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase from azure.mgmt.eventhub.models import Eventhub, EHNamespace from azure.mgmt.eventhub.models.sku import Sku From 8644c7ebe72f06bfea5fd95d4a2c87f873c97fea Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 17:41:51 +0530 Subject: [PATCH 27/39] Update azure_rm_eventhub_info.py --- plugins/modules/azure_rm_eventhub_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/azure_rm_eventhub_info.py b/plugins/modules/azure_rm_eventhub_info.py index 3e51101d0..1e8cd4765 100644 --- a/plugins/modules/azure_rm_eventhub_info.py +++ b/plugins/modules/azure_rm_eventhub_info.py @@ -73,10 +73,10 @@ try: from msrestazure.azure_exceptions import CloudError - from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase except ImportError: # This is handled in azure_rm_common pass +from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase class AzureRMEventHubInfo(AzureRMModuleBase): From 49cb2ddbc95a97124a44b84b2fda4c4d0c816117 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 18:19:23 +0530 Subject: [PATCH 28/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index 8405d3fcd..ff173194d 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -324,8 +324,9 @@ def create_or_update_event_hub(self): :return: create or update Event Hub instance state dictionary ''' try: + if self.sku == 'Basic': + self.message_retention_in_days = 1 params = Eventhub( - name=self.name, message_retention_in_days=self.message_retention_in_days, partition_count=self.partition_count, status=self.status @@ -337,7 +338,7 @@ def create_or_update_event_hub(self): params) self.log("Response : {0}".format(result)) - except CloudError as ex: + except Exception as ex: self.fail("Failed to create event hub {0} in resource group {1}: {2}".format( self.name, self.resource_group, str(ex))) return event_hub_to_dict(result) From 12ea22597d55298852e305496ffa194fdc9fa0a4 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Wed, 26 May 2021 18:20:59 +0530 Subject: [PATCH 29/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index ff173194d..7b55dc6a7 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -158,12 +158,12 @@ try: from msrestazure.azure_exceptions import CloudError + from azure.mgmt.eventhub.models import Eventhub, EHNamespace + from azure.mgmt.eventhub.models.sku import Sku except ImportError: # This is handled in azure_rm_common pass from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase -from azure.mgmt.eventhub.models import Eventhub, EHNamespace -from azure.mgmt.eventhub.models.sku import Sku import time From d9106bc8bf12dcd8c6d468749c6c7139a50a7f22 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Thu, 27 May 2021 10:46:17 +0530 Subject: [PATCH 30/39] Update main.yml --- .../targets/azure_rm_eventhub/tasks/main.yml | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml index 7ed84a7e2..3d9859248 100644 --- a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml +++ b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml @@ -3,7 +3,6 @@ namespace_name: "test{{ resource_group | hash('md5') | truncate(16, True, '') + (65535 | random | string) }}" name: "test{{ resource_group | hash('md5') | truncate(16, True, '') + (65535 | random | string) }}" - - name: Create Event Hub Namespace (check mode) azure_rm_eventhub: location: eastus2 @@ -16,8 +15,6 @@ - assert: that: results.changed - - - name: Create Event Hub (check mode) azure_rm_eventhub: location: eastus2 @@ -31,7 +28,6 @@ - assert: that: results.changed - - name: Create Event Hub Namespace azure_rm_eventhub: location: eastus2 @@ -43,8 +39,6 @@ - assert: that: results.changed - - - name: Create Event Hub azure_rm_eventhub: location: eastus2 @@ -71,7 +65,6 @@ - results.changed - results.state.tags.test == 'modified' - - name: Update Event Hub azure_rm_eventhub: location: eastus2 @@ -88,8 +81,7 @@ - results.state.tags.test == 'modified' - name: Retrieve Namespace - azure_rm_eventhub: - location: eastus2 + azure_rm_eventhub_info: namespace_name: "{{ namespace_name }}" resource_group: "{{ resource_group }}" register: results @@ -97,7 +89,7 @@ - name: Assert that facts module returned result assert: that: - - results.ddos_protection_plan[0].tags.test == 'modified' + - results.namespace[0].tags.test == 'modified' - name: Test idempotent azure_rm_eventhub: @@ -111,18 +103,19 @@ - not results.changed #cleanup - -- name: Delete Namespace +- name: Delete Event Hub azure_rm_eventhub: location: eastus2 namespace_name: "{{ namespace_name }}" + name: "{{ name }}" resource_group: "{{ resource_group }}" state: absent -- name: Delete Namespace (idempotent) +- name: Delete Event Hub (idempotent) azure_rm_eventhub: location: eastus2 namespace_name: "{{ namespace_name }}" + name: "{{ name }}" resource_group: "{{ resource_group }}" state: absent register: results @@ -130,20 +123,17 @@ - assert: that: not results.changed - -- name: Delete Event Hub +- name: Delete Namespace azure_rm_eventhub: location: eastus2 namespace_name: "{{ namespace_name }}" - name: "{{ name }}" resource_group: "{{ resource_group }}" state: absent -- name: Delete Event Hub (idempotent) +- name: Delete Namespace (idempotent) azure_rm_eventhub: location: eastus2 namespace_name: "{{ namespace_name }}" - name: "{{ name }}" resource_group: "{{ resource_group }}" state: absent register: results From 2bc5306801abb8c1d7001a91cd9a634939d3cf30 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Thu, 27 May 2021 15:40:51 +0530 Subject: [PATCH 31/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index 7b55dc6a7..6a09c4608 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -158,6 +158,7 @@ try: from msrestazure.azure_exceptions import CloudError + from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase from azure.mgmt.eventhub.models import Eventhub, EHNamespace from azure.mgmt.eventhub.models.sku import Sku except ImportError: @@ -252,6 +253,9 @@ def exec_module(self, **kwargs): elif self.namespace_name and not self.name: if self.sku != results['sku'].lower(): changed = True + elif self.namespace_name and self.name and event_hub_results: + if self.sku != 'Basic' and self.message_retention_in_days != event_hub_results['message_retention_in_days']: + changed = True elif self.state == 'absent': changed = True From 5599ae5abc7c595d1c4c7dca5e7fe53a143e9fc5 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Thu, 27 May 2021 15:44:04 +0530 Subject: [PATCH 32/39] Update main.yml --- .../targets/azure_rm_eventhub/tasks/main.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml index 3d9859248..2cdee6b18 100644 --- a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml +++ b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml @@ -56,6 +56,7 @@ location: eastus2 namespace_name: "{{ namespace_name }}" resource_group: "{{ resource_group }}" + sku: "Standard" tags: test: modified register: results @@ -71,14 +72,14 @@ namespace_name: "{{ namespace_name }}" name: "{{ name }}" resource_group: "{{ resource_group }}" + message_retention_in_days: 2 tags: test: modified register: results - assert: that: - - results.changed - - results.state.tags.test == 'modified' + - not results.changed - name: Retrieve Namespace azure_rm_eventhub_info: @@ -86,11 +87,6 @@ resource_group: "{{ resource_group }}" register: results -- name: Assert that facts module returned result - assert: - that: - - results.namespace[0].tags.test == 'modified' - - name: Test idempotent azure_rm_eventhub: location: eastus2 From e46cb6a56422c7ff00216f42efe1934a4898d53f Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Thu, 27 May 2021 15:47:42 +0530 Subject: [PATCH 33/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index 6a09c4608..7b55dc6a7 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -158,7 +158,6 @@ try: from msrestazure.azure_exceptions import CloudError - from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase from azure.mgmt.eventhub.models import Eventhub, EHNamespace from azure.mgmt.eventhub.models.sku import Sku except ImportError: @@ -253,9 +252,6 @@ def exec_module(self, **kwargs): elif self.namespace_name and not self.name: if self.sku != results['sku'].lower(): changed = True - elif self.namespace_name and self.name and event_hub_results: - if self.sku != 'Basic' and self.message_retention_in_days != event_hub_results['message_retention_in_days']: - changed = True elif self.state == 'absent': changed = True From 29875fb56df24d24f74bf78886bddb9c0de49d77 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Thu, 27 May 2021 15:48:21 +0530 Subject: [PATCH 34/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index 7b55dc6a7..c1d37ad2e 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -252,6 +252,9 @@ def exec_module(self, **kwargs): elif self.namespace_name and not self.name: if self.sku != results['sku'].lower(): changed = True + elif self.namespace_name and self.name and event_hub_results: + if self.sku != 'Basic' and self.message_retention_in_days != event_hub_results['message_retention_in_days']: + changed = True elif self.state == 'absent': changed = True From 043c88c4b45138fb8824029e3a7737c2dda5e35c Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Thu, 27 May 2021 18:47:03 +0530 Subject: [PATCH 35/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index c1d37ad2e..445a6dbc7 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -234,6 +234,7 @@ def exec_module(self, **kwargs): self.resource_group, self.namespace_name) results = namespace_to_dict(namespace) + event_hub_results = None if self.name: self.log('Fetching event Hub {0}'.format(self.name)) event_hub = self.event_hub_client.event_hubs.get( From 08dba228f907ca605be5de7192d0970c7cff6cc3 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Thu, 27 May 2021 18:50:03 +0530 Subject: [PATCH 36/39] Update main.yml --- tests/integration/targets/azure_rm_eventhub/tasks/main.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml index 2cdee6b18..8c0595ac7 100644 --- a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml +++ b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml @@ -96,7 +96,7 @@ - assert: that: - - not results.changed + - results.changed #cleanup - name: Delete Event Hub @@ -126,6 +126,10 @@ resource_group: "{{ resource_group }}" state: absent +- name: Pause for 1 minutes to check namespace deleted + pause: + minutes: 1 + - name: Delete Namespace (idempotent) azure_rm_eventhub: location: eastus2 From e622f1bd55c1fdb3f38178e0b901b8e78ba249f9 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Thu, 27 May 2021 20:07:21 +0530 Subject: [PATCH 37/39] Update main.yml --- .../targets/azure_rm_eventhub/tasks/main.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml index 8c0595ac7..484f0146d 100644 --- a/tests/integration/targets/azure_rm_eventhub/tasks/main.yml +++ b/tests/integration/targets/azure_rm_eventhub/tasks/main.yml @@ -45,7 +45,6 @@ namespace_name: "{{ namespace_name }}" name: "{{ name }}" resource_group: "{{ resource_group }}" - sku: "Basic" register: results - assert: @@ -72,14 +71,15 @@ namespace_name: "{{ namespace_name }}" name: "{{ name }}" resource_group: "{{ resource_group }}" - message_retention_in_days: 2 + message_retention_in_days: 4 + state: present tags: test: modified register: results - assert: that: - - not results.changed + - results.changed - name: Retrieve Namespace azure_rm_eventhub_info: @@ -92,11 +92,14 @@ location: eastus2 namespace_name: "{{ namespace_name }}" resource_group: "{{ resource_group }}" + sku: "Standard" + tags: + test: modified register: results - assert: that: - - results.changed + - not results.changed #cleanup - name: Delete Event Hub From a46b7e1a199ec5e82eb1b98ee6958edac48965e5 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Thu, 27 May 2021 20:08:13 +0530 Subject: [PATCH 38/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index 445a6dbc7..3b3d86ecf 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -244,19 +244,20 @@ def exec_module(self, **kwargs): # don't change anything if creating an existing namespace, but change if deleting it if self.state == 'present': changed = False - + update_tags, results['tags'] = self.update_tags( results['tags']) if update_tags: changed = True elif self.namespace_name and not self.name: - if self.sku != results['sku'].lower(): + + if self.sku != results['sku']: changed = True elif self.namespace_name and self.name and event_hub_results: - if self.sku != 'Basic' and self.message_retention_in_days != event_hub_results['message_retention_in_days']: + if results['sku'] != 'Basic' and self.message_retention_in_days != event_hub_results['message_retention_in_days']: + self.sku = results['sku'] changed = True - elif self.state == 'absent': changed = True @@ -269,6 +270,7 @@ def exec_module(self, **kwargs): changed = False self.results['changed'] = changed + if self.name and not changed: self.results['state'] = event_hub_results else: @@ -277,6 +279,7 @@ def exec_module(self, **kwargs): # return the results if your only gathering information if self.check_mode: return self.results + if changed: if self.state == "present": if self.name is None: @@ -290,7 +293,6 @@ def exec_module(self, **kwargs): elif self.namespace_name and self.name: self.delete_event_hub() self.results['state']['status'] = 'Deleted' - return self.results def create_or_update_namespaces(self): From a9893d9b75b4c74719b37cae49b091e19a2c5419 Mon Sep 17 00:00:00 2001 From: saurabh3796 <44325563+saurabh3796@users.noreply.github.com> Date: Thu, 27 May 2021 20:38:49 +0530 Subject: [PATCH 39/39] Update azure_rm_eventhub.py --- plugins/modules/azure_rm_eventhub.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_eventhub.py b/plugins/modules/azure_rm_eventhub.py index 3b3d86ecf..dd94c554a 100644 --- a/plugins/modules/azure_rm_eventhub.py +++ b/plugins/modules/azure_rm_eventhub.py @@ -244,14 +244,13 @@ def exec_module(self, **kwargs): # don't change anything if creating an existing namespace, but change if deleting it if self.state == 'present': changed = False - + update_tags, results['tags'] = self.update_tags( results['tags']) if update_tags: changed = True elif self.namespace_name and not self.name: - if self.sku != results['sku']: changed = True elif self.namespace_name and self.name and event_hub_results: