Repository: ansible/ansible
Pull request: fix failure `got multiple values for keyword argument id`
##### SUMMARY
<!--- Describe the change, including rationale and design decisions -->
This is a bug due to API change from new Azure SDK
<!---
If you are fixing an existing issue, please include "Fixes #nnn" in your
commit message and your description; but you should still explain what
the change does.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bugfix Pull Request

##### COMPONENT NAME
<!--- Name of the module/plugin/module/task -->

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.0
  config file = None
  configured module search path = [u'/Users/zhijzhao/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Sep 25 2017, 09:53:22) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
```


##### ADDITIONAL INFORMATION
<!---
Include additional information to help people understand the change here.
For bugs that don't have a linked bug report, a step-by-step reproduction
of the problem is helpful.
  -->

<!--- Paste verbatim command output below, e.g. before and after your change -->
```

```
Fix #33657

@yuwzho @zikalino @yaweiw 

Problem statement:
azure_rm_securitygroup.py has some problem when creating security group in china region
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report
ansible azrure module cannot create security group in china region.
when I use ansible try to create security group in azure of china region. It will report error to me.
Other function in azure module is successfully. Just azure_rm_securitygroup.py this module does not work.



##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
azure/azure_rm_securitygroup.py

The exception seams raise between  line 439 to 454.

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ubuntu@ip-172-16-1-144:~/mk_az_vm$ ansible --version
ansible 2.4.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4]

```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->

Ubuntu 14.04.5 LTS 64 bits

##### SUMMARY
<!--- Explain the problem briefly -->
When playbook try  to create a security group, it will raise an exception, like the below:

TASK [Create security group that allows SSH] ******************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: __init__() got multiple values for keyword argument 'id'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 716, in <module>\n    main()\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 712, in main\n    AzureRMSecurityGroup()\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 542, in __init__\n    supports_check_mode=True)\n  File \"/tmp/ansible_SKpO0N/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 256, in __init__\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 666, in exec_module\n    self.results['state'] = self.create_or_update(results)\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 685, in create_or_update\n    parameters.security_rules.append(create_rule_instance(rule))\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 452, in create_rule_instance\n    etag=rule.get('etag', None)\nTypeError: __init__() got multiple values for keyword argument 'id'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```
---
- hosts: localhost
  connection: local
  tasks:
  - name: Create security group that allows SSH
    azure_rm_securitygroup:
      resource_group: Testing
      name: secgroup001
      rules:
        - name: SSH
          protocol: Tcp
          destination_port_range: 22
          access: Allow
          priority: 101
          direction: Inbound

```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
It should be return ok=1 or changed=1

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->


<!--- Paste verbatim command output between quotes below -->
```
TASK [Create security group that allows SSH] ******************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: __init__() got multiple values for keyword argument 'id'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 716, in <module>\n    main()\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 712, in main\n    AzureRMSecurityGroup()\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 542, in __init__\n    supports_check_mode=True)\n  File \"/tmp/ansible_SKpO0N/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 256, in __init__\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 666, in exec_module\n    self.results['state'] = self.create_or_update(results)\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 685, in create_or_update\n    parameters.security_rules.append(create_rule_instance(rule))\n  File \"/tmp/ansible_SKpO0N/ansible_module_azure_rm_securitygroup.py\", line 452, in create_rule_instance\n    etag=rule.get('etag', None)\nTypeError: __init__() got multiple values for keyword argument 'id'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
	to retry, use: --limit @/home/ubuntu/mk_az_vm/csg.retry

PLAY RECAP ****************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1  
```

Hints from issue discussion:

Commit message: fix test case failure

Patch to review:
diff --git a/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py b/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
index b6008ef5e51bf6..32c14da1a8c313 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
@@ -447,10 +447,10 @@ def create_rule_instance(rule):
     '''
     return SecurityRule(
         rule['protocol'],
-        rule['source_address_prefix'],
-        rule['destination_address_prefix'],
         rule['access'],
         rule['direction'],
+        source_address_prefix=rule['source_address_prefix'],
+        destination_address_prefix=rule['destination_address_prefix'],
         id=rule.get('id', None),
         description=rule.get('description', None),
         source_port_range=rule.get('source_port_range', None),
diff --git a/packaging/requirements/requirements-azure.txt b/packaging/requirements/requirements-azure.txt
index adb575510a3dc3..c1634ae0c65c5a 100644
--- a/packaging/requirements/requirements-azure.txt
+++ b/packaging/requirements/requirements-azure.txt
@@ -1,7 +1,7 @@
 packaging
 requests[security]
 azure-mgmt-compute>=2.0.0,<3
-azure-mgmt-network>=1.3.0,<2
+azure-mgmt-network>=1.6.0,<2
 azure-mgmt-storage>=1.2.0,<2
 azure-mgmt-resource>=1.1.0,<2
 azure-storage>=0.35.1,<0.36
diff --git a/test/runner/requirements/integration.cloud.azure.txt b/test/runner/requirements/integration.cloud.azure.txt
index adb575510a3dc3..c1634ae0c65c5a 100644
--- a/test/runner/requirements/integration.cloud.azure.txt
+++ b/test/runner/requirements/integration.cloud.azure.txt
@@ -1,7 +1,7 @@
 packaging
 requests[security]
 azure-mgmt-compute>=2.0.0,<3
-azure-mgmt-network>=1.3.0,<2
+azure-mgmt-network>=1.6.0,<2
 azure-mgmt-storage>=1.2.0,<2
 azure-mgmt-resource>=1.1.0,<2
 azure-storage>=0.35.1,<0.36


Code review comments:
diff_hunk: @@ -447,10 +447,10 @@ def create_rule_instance(rule):
     '''
     return SecurityRule(
         rule['protocol'],
-        rule['source_address_prefix'],
-        rule['destination_address_prefix'],
         rule['access'],
         rule['direction'],
+        source_address_prefix=rule['source_address_prefix'],
path: lib/ansible/modules/cloud/azure/azure_rm_securitygroup.py
text: @user1:
empty check?

@user1:
Suggest add a rule spec for the `rules`' element