prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  rhn_channel is using depreciated methods
  Issue Type:
  Bug Report
  
  Ansible Version: 
  1.7.2
  
  Environment: 
  OS X 10.9 / RHEL 6/7
  
  Summary:
  When adding a child channel to rhn sat server rhn_channel fails with 500 error. 
  
  Steps To Reproduce:
  attempt to subscribe to a child channel with rhn_channel to sat server 5.4+
  
  Expected Results:
  Server gets subscribed to child channel.
  
  Actual Results:
  xmlrpclib.ProtocolError: <ProtocolError for redhat.example.com/rpc/api: 500 Internal Server Error>
  
  channel.software.setSystemChannels is depreciated. 
  https://access.redhat.com/documentation/en-US/Red_Hat_Network_Satellite/5.5/html/API_Overview/files/html/handlers/ChannelSoftwareHandler.html#setSystemChannels
  
  PR to follow
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `packaging/os/rhn_channel.py`
  Content:
  ```
  1 #!/usr/bin/python
  2 
  3 # (c) Vincent Van de Kussen
  4 #
  5 # This file is part of Ansible
  6 #
  7 # Ansible is free software: you can redistribute it and/or modify
  8 # it under the terms of the GNU General Public License as published by
  9 # the Free Software Foundation, either version 3 of the License, or
  10 # (at your option) any later version.
  11 #
  12 # Ansible is distributed in the hope that it will be useful,
  13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 # GNU General Public License for more details.
  16 #
  17 # You should have received a copy of the GNU General Public License
  18 # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
  19 
  20 DOCUMENTATION = '''
  21 ---
  22 module: rhn_channel
  23 short_description: Adds or removes Red Hat software channels
  24 description:
  25     - Adds or removes Red Hat software channels
  26 version_added: "1.1"
  27 author: Vincent Van der Kussen
  28 notes:
  29     - this module fetches the system id from RHN. 
  30 requirements:
  31     - none
  32 options:
  33     name:
  34         description:
  35             - name of the software channel
  36         required: true
  37         default: null
  38     sysname:
  39         description:
  40             - name of the system as it is known in RHN/Satellite
  41         required: true
  42         default: null
  43     state:
  44         description:
  45             - whether the channel should be present or not
  46         required: false
  47         default: present
  48     url:
  49         description: 
  50             - The full url to the RHN/Satellite api
  51         required: true
  52     user:
  53         description:
  54             - RHN/Satellite user
  55         required: true
  56     password:
  57         description:
  58             - "the user's password"
  59         required: true
  60 '''
  61 
  62 EXAMPLES = '''
  63 - rhn_channel: name=rhel-x86_64-server-v2vwin-6 sysname=server01 url=https://rhn.redhat.com/rpc/api user=rhnuser password=guessme
  64 '''
  65 
  66 import xmlrpclib
  67 from operator import itemgetter
  68 import re
  69 
  70 
  71 # ------------------------------------------------------- #
  72 
  73 def get_systemid(client, session, sysname):
  74     systems = client.system.listUserSystems(session)
  75     for system in systems:
  76         if system.get('name') == sysname:
  77             idres = system.get('id')
  78             idd = int(idres)
  79             return idd
  80 
  81 # ------------------------------------------------------- #
  82 
  83 # unused:
  84 #
  85 #def get_localsystemid():
  86 #    f = open("/etc/sysconfig/rhn/systemid", "r")
  87 #    content = f.read()
  88 #    loc_id = re.search(r'\b(ID-)(\d{10})' ,content)
  89 #    return loc_id.group(2)
  90 
  91 # ------------------------------------------------------- #
  92 
  93 def subscribe_channels(channels, client, session, sysname, sys_id):
  94     c = base_channels(client, session, sys_id)
  95     c.append(channels)
  96     return client.channel.software.setSystemChannels(session, sys_id, c)
  97 
  98 # ------------------------------------------------------- #
  99 
  100 def unsubscribe_channels(channels, client, session, sysname, sys_id):
  101     c = base_channels(client, session, sys_id)
  102     c.remove(channels)
  103     return client.channel.software.setSystemChannels(session, sys_id, c)
  104 
  105 # ------------------------------------------------------- #
  106 
  107 def base_channels(client, session, sys_id):
  108     basechan = client.channel.software.listSystemChannels(session, sys_id)
  109     try:
  110         chans = [item['label'] for item in basechan]
  111     except KeyError:
  112         chans = [item['channel_label'] for item in basechan]
  113     return chans
  114 
  115 # ------------------------------------------------------- #
  116 
  117 
  118 def main():
  119 
  120     module = AnsibleModule(
  121         argument_spec = dict(
  122             state = dict(default='present', choices=['present', 'absent']),
  123             name = dict(required=True),
  124             sysname = dict(required=True),
  125             url = dict(required=True),
  126             user = dict(required=True),
  127             password = dict(required=True, aliases=['pwd']),
  128         )
  129 #        supports_check_mode=True
  130     )
  131 
  132     state = module.params['state']
  133     channelname = module.params['name']
  134     systname = module.params['sysname']
  135     saturl = module.params['url']
  136     user = module.params['user']
  137     password = module.params['password']
  138     
  139     #initialize connection
  140     client = xmlrpclib.Server(saturl, verbose=0)
  141     session = client.auth.login(user, password)
  142      
  143     # get systemid
  144     sys_id = get_systemid(client, session, systname)
  145 
  146     # get channels for system
  147     chans = base_channels(client, session, sys_id)
  148     
  149     
  150     if state == 'present':
  151         if channelname in chans:
  152             module.exit_json(changed=False, msg="Channel %s already exists" % channelname)
  153         else:
  154             subscribe_channels(channelname, client, session, systname, sys_id)
  155             module.exit_json(changed=True, msg="Channel %s added" % channelname)
  156 
  157     if state == 'absent':
  158         if not channelname in chans:
  159             module.exit_json(changed=False, msg="Not subscribed to channel %s." % channelname)
  160         else:
  161             unsubscribe_channels(channelname, client, session, systname, sys_id)
  162             module.exit_json(changed=True, msg="Channel %s removed" % channelname)
  163 
  164     client.auth.logout(session)
  165 
  166 
  167 # import module snippets
  168 from ansible.module_utils.basic import *
  169 main()
  170
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/packaging/os/rhn_channel.py b/packaging/os/rhn_channel.py
  --- a/packaging/os/rhn_channel.py
  +++ b/packaging/os/rhn_channel.py
  @@ -90,17 +90,17 @@
   
   # ------------------------------------------------------- #
   
  -def subscribe_channels(channels, client, session, sysname, sys_id):
  -    c = base_channels(client, session, sys_id)
  -    c.append(channels)
  -    return client.channel.software.setSystemChannels(session, sys_id, c)
  +def subscribe_channels(channelname, client, session, sysname, sys_id):
  +    channels = base_channels(client, session, sys_id)
  +    channels.append(channelname)
  +    return client.system.setChildChannels(session, sys_id, channels)
   
   # ------------------------------------------------------- #
   
  -def unsubscribe_channels(channels, client, session, sysname, sys_id):
  -    c = base_channels(client, session, sys_id)
  -    c.remove(channels)
  -    return client.channel.software.setSystemChannels(session, sys_id, c)
  +def unsubscribe_channels(channelname, client, session, sysname, sys_id):
  +    channels = base_channels(client, session, sys_id)
  +    channels.remove(channelname)
  +    return client.system.setChildChannels(session, sys_id, channels)
   
   # ------------------------------------------------------- #
   
  @@ -167,3 +167,4 @@
   # import module snippets
   from ansible.module_utils.basic import *
   main()
  +
  
verification_info: {"golden_diff": "diff --git a/packaging/os/rhn_channel.py b/packaging/os/rhn_channel.py\n--- a/packaging/os/rhn_channel.py\n+++ b/packaging/os/rhn_channel.py\n@@ -90,17 +90,17 @@\n \n # ------------------------------------------------------- #\n \n-def subscribe_channels(channels, client, session, sysname, sys_id):\n-    c = base_channels(client, session, sys_id)\n-    c.append(channels)\n-    return client.channel.software.setSystemChannels(session, sys_id, c)\n+def subscribe_channels(channelname, client, session, sysname, sys_id):\n+    channels = base_channels(client, session, sys_id)\n+    channels.append(channelname)\n+    return client.system.setChildChannels(session, sys_id, channels)\n \n # ------------------------------------------------------- #\n \n-def unsubscribe_channels(channels, client, session, sysname, sys_id):\n-    c = base_channels(client, session, sys_id)\n-    c.remove(channels)\n-    return client.channel.software.setSystemChannels(session, sys_id, c)\n+def unsubscribe_channels(channelname, client, session, sysname, sys_id):\n+    channels = base_channels(client, session, sys_id)\n+    channels.remove(channelname)\n+    return client.system.setChildChannels(session, sys_id, channels)\n \n # ------------------------------------------------------- #\n \n@@ -167,3 +167,4 @@\n # import module snippets\n from ansible.module_utils.basic import *\n main()\n+\n", "issue": "rhn_channel is using depreciated methods\nIssue Type:\nBug Report\n\nAnsible Version: \n1.7.2\n\nEnvironment: \nOS X 10.9 / RHEL 6/7\n\nSummary:\nWhen adding a child channel to rhn sat server rhn_channel fails with 500 error. \n\nSteps To Reproduce:\nattempt to subscribe to a child channel with rhn_channel to sat server 5.4+\n\nExpected Results:\nServer gets subscribed to child channel.\n\nActual Results:\nxmlrpclib.ProtocolError: <ProtocolError for redhat.example.com/rpc/api: 500 Internal Server Error>\n\nchannel.software.setSystemChannels is depreciated. \nhttps://access.redhat.com/documentation/en-US/Red_Hat_Network_Satellite/5.5/html/API_Overview/files/html/handlers/ChannelSoftwareHandler.html#setSystemChannels\n\nPR to follow\n\n", "before_files": [{"content": "#!/usr/bin/python\n\n# (c) Vincent Van de Kussen\n#\n# This file is part of Ansible\n#\n# Ansible is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# Ansible is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n\nDOCUMENTATION = '''\n---\nmodule: rhn_channel\nshort_description: Adds or removes Red Hat software channels\ndescription:\n    - Adds or removes Red Hat software channels\nversion_added: \"1.1\"\nauthor: Vincent Van der Kussen\nnotes:\n    - this module fetches the system id from RHN. \nrequirements:\n    - none\noptions:\n    name:\n        description:\n            - name of the software channel\n        required: true\n        default: null\n    sysname:\n        description:\n            - name of the system as it is known in RHN/Satellite\n        required: true\n        default: null\n    state:\n        description:\n            - whether the channel should be present or not\n        required: false\n        default: present\n    url:\n        description: \n            - The full url to the RHN/Satellite api\n        required: true\n    user:\n        description:\n            - RHN/Satellite user\n        required: true\n    password:\n        description:\n            - \"the user's password\"\n        required: true\n'''\n\nEXAMPLES = '''\n- rhn_channel: name=rhel-x86_64-server-v2vwin-6 sysname=server01 url=https://rhn.redhat.com/rpc/api user=rhnuser password=guessme\n'''\n\nimport xmlrpclib\nfrom operator import itemgetter\nimport re\n\n\n# ------------------------------------------------------- #\n\ndef get_systemid(client, session, sysname):\n    systems = client.system.listUserSystems(session)\n    for system in systems:\n        if system.get('name') == sysname:\n            idres = system.get('id')\n            idd = int(idres)\n            return idd\n\n# ------------------------------------------------------- #\n\n# unused:\n#\n#def get_localsystemid():\n#    f = open(\"/etc/sysconfig/rhn/systemid\", \"r\")\n#    content = f.read()\n#    loc_id = re.search(r'\\b(ID-)(\\d{10})' ,content)\n#    return loc_id.group(2)\n\n# ------------------------------------------------------- #\n\ndef subscribe_channels(channels, client, session, sysname, sys_id):\n    c = base_channels(client, session, sys_id)\n    c.append(channels)\n    return client.channel.software.setSystemChannels(session, sys_id, c)\n\n# ------------------------------------------------------- #\n\ndef unsubscribe_channels(channels, client, session, sysname, sys_id):\n    c = base_channels(client, session, sys_id)\n    c.remove(channels)\n    return client.channel.software.setSystemChannels(session, sys_id, c)\n\n# ------------------------------------------------------- #\n\ndef base_channels(client, session, sys_id):\n    basechan = client.channel.software.listSystemChannels(session, sys_id)\n    try:\n        chans = [item['label'] for item in basechan]\n    except KeyError:\n        chans = [item['channel_label'] for item in basechan]\n    return chans\n\n# ------------------------------------------------------- #\n\n\ndef main():\n\n    module = AnsibleModule(\n        argument_spec = dict(\n            state = dict(default='present', choices=['present', 'absent']),\n            name = dict(required=True),\n            sysname = dict(required=True),\n            url = dict(required=True),\n            user = dict(required=True),\n            password = dict(required=True, aliases=['pwd']),\n        )\n#        supports_check_mode=True\n    )\n\n    state = module.params['state']\n    channelname = module.params['name']\n    systname = module.params['sysname']\n    saturl = module.params['url']\n    user = module.params['user']\n    password = module.params['password']\n    \n    #initialize connection\n    client = xmlrpclib.Server(saturl, verbose=0)\n    session = client.auth.login(user, password)\n     \n    # get systemid\n    sys_id = get_systemid(client, session, systname)\n\n    # get channels for system\n    chans = base_channels(client, session, sys_id)\n    \n    \n    if state == 'present':\n        if channelname in chans:\n            module.exit_json(changed=False, msg=\"Channel %s already exists\" % channelname)\n        else:\n            subscribe_channels(channelname, client, session, systname, sys_id)\n            module.exit_json(changed=True, msg=\"Channel %s added\" % channelname)\n\n    if state == 'absent':\n        if not channelname in chans:\n            module.exit_json(changed=False, msg=\"Not subscribed to channel %s.\" % channelname)\n        else:\n            unsubscribe_channels(channelname, client, session, systname, sys_id)\n            module.exit_json(changed=True, msg=\"Channel %s removed\" % channelname)\n\n    client.auth.logout(session)\n\n\n# import module snippets\nfrom ansible.module_utils.basic import *\nmain()\n", "path": "packaging/os/rhn_channel.py"}], "after_files": [{"content": "#!/usr/bin/python\n\n# (c) Vincent Van de Kussen\n#\n# This file is part of Ansible\n#\n# Ansible is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# Ansible is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n\nDOCUMENTATION = '''\n---\nmodule: rhn_channel\nshort_description: Adds or removes Red Hat software channels\ndescription:\n    - Adds or removes Red Hat software channels\nversion_added: \"1.1\"\nauthor: Vincent Van der Kussen\nnotes:\n    - this module fetches the system id from RHN. \nrequirements:\n    - none\noptions:\n    name:\n        description:\n            - name of the software channel\n        required: true\n        default: null\n    sysname:\n        description:\n            - name of the system as it is known in RHN/Satellite\n        required: true\n        default: null\n    state:\n        description:\n            - whether the channel should be present or not\n        required: false\n        default: present\n    url:\n        description: \n            - The full url to the RHN/Satellite api\n        required: true\n    user:\n        description:\n            - RHN/Satellite user\n        required: true\n    password:\n        description:\n            - \"the user's password\"\n        required: true\n'''\n\nEXAMPLES = '''\n- rhn_channel: name=rhel-x86_64-server-v2vwin-6 sysname=server01 url=https://rhn.redhat.com/rpc/api user=rhnuser password=guessme\n'''\n\nimport xmlrpclib\nfrom operator import itemgetter\nimport re\n\n\n# ------------------------------------------------------- #\n\ndef get_systemid(client, session, sysname):\n    systems = client.system.listUserSystems(session)\n    for system in systems:\n        if system.get('name') == sysname:\n            idres = system.get('id')\n            idd = int(idres)\n            return idd\n\n# ------------------------------------------------------- #\n\n# unused:\n#\n#def get_localsystemid():\n#    f = open(\"/etc/sysconfig/rhn/systemid\", \"r\")\n#    content = f.read()\n#    loc_id = re.search(r'\\b(ID-)(\\d{10})' ,content)\n#    return loc_id.group(2)\n\n# ------------------------------------------------------- #\n\ndef subscribe_channels(channelname, client, session, sysname, sys_id):\n    channels = base_channels(client, session, sys_id)\n    channels.append(channelname)\n    return client.system.setChildChannels(session, sys_id, channels)\n\n# ------------------------------------------------------- #\n\ndef unsubscribe_channels(channelname, client, session, sysname, sys_id):\n    channels = base_channels(client, session, sys_id)\n    channels.remove(channelname)\n    return client.system.setChildChannels(session, sys_id, channels)\n\n# ------------------------------------------------------- #\n\ndef base_channels(client, session, sys_id):\n    basechan = client.channel.software.listSystemChannels(session, sys_id)\n    try:\n        chans = [item['label'] for item in basechan]\n    except KeyError:\n        chans = [item['channel_label'] for item in basechan]\n    return chans\n\n# ------------------------------------------------------- #\n\n\ndef main():\n\n    module = AnsibleModule(\n        argument_spec = dict(\n            state = dict(default='present', choices=['present', 'absent']),\n            name = dict(required=True),\n            sysname = dict(required=True),\n            url = dict(required=True),\n            user = dict(required=True),\n            password = dict(required=True, aliases=['pwd']),\n        )\n#        supports_check_mode=True\n    )\n\n    state = module.params['state']\n    channelname = module.params['name']\n    systname = module.params['sysname']\n    saturl = module.params['url']\n    user = module.params['user']\n    password = module.params['password']\n    \n    #initialize connection\n    client = xmlrpclib.Server(saturl, verbose=0)\n    session = client.auth.login(user, password)\n     \n    # get systemid\n    sys_id = get_systemid(client, session, systname)\n\n    # get channels for system\n    chans = base_channels(client, session, sys_id)\n    \n    \n    if state == 'present':\n        if channelname in chans:\n            module.exit_json(changed=False, msg=\"Channel %s already exists\" % channelname)\n        else:\n            subscribe_channels(channelname, client, session, systname, sys_id)\n            module.exit_json(changed=True, msg=\"Channel %s added\" % channelname)\n\n    if state == 'absent':\n        if not channelname in chans:\n            module.exit_json(changed=False, msg=\"Not subscribed to channel %s.\" % channelname)\n        else:\n            unsubscribe_channels(channelname, client, session, systname, sys_id)\n            module.exit_json(changed=True, msg=\"Channel %s removed\" % channelname)\n\n    client.auth.logout(session)\n\n\n# import module snippets\nfrom ansible.module_utils.basic import *\nmain()\n\n", "path": "packaging/os/rhn_channel.py"}]}