HewlettPackard / oneview-ansible-collection

Ansible Collection and Sample Playbooks for HPE OneView
Apache License 2.0
26 stars 22 forks source link

Passing a "Network Set" by name via the NetworkName attribute to oneview_server_profile_template.py doesn't work #232

Closed frippe75 closed 1 year ago

frippe75 commented 1 year ago

OneView API Ver: 4000 (7.0)

Error: 'The field named networkName is not a valid field in this JSON object'

I'm not sure but this function in the OneView client seems to handle it. Even though the code could handle checking for existance of [0] element.

    def _get_network_by_name(self, name):
        fc_networks = self.oneview_client.fc_networks.get_by('name', name)
        if fc_networks:
            return fc_networks[0]

        fcoe_networks = self.oneview_client.fcoe_networks.get_by('name', name)
        if fcoe_networks:
            return fcoe_networks[0]

        network_sets = self.oneview_client.network_sets.get_by('name', name)
        if network_sets:
            return network_sets[0]

        ethernet_networks = self.oneview_client.ethernet_networks.get_by('name', name)
        if not ethernet_networks:
            raise OneViewModuleResourceNotFound(self.SERVER_PROFILE_NETWORK_NOT_FOUND + name)
        return ethernet_networks[0]

Full stacktrace:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: hpeOneView.exceptions.HPEOneViewException: ('Unrecognized JSON field.', {'errorCode': 'UNRECOGNIZED_JSON_FIELD', 'message': 'Unrecognized JSON field.', 'details': 'The field named networkName near line 1, column 3,886 is not a valid field in this JSON object.', 'messageParameters': [], 'recommendedActions': ['Check the valid fields for this JSON object and remove or correct the unrecognized field.'], 'errorSource': None, 'nestedErrors': [], 'data': {}})
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1668762389.31-32434-96820125648416/AnsiballZ_oneview_server_profile_template.py\", line 247, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1668762389.31-32434-96820125648416/AnsiballZ_oneview_server_profile_template.py\", line 237, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1668762389.31-32434-96820125648416/AnsiballZ_oneview_server_profile_template.py\", line 108, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.hpe.oneview.plugins.modules.oneview_server_profile_template', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_oneview_server_profile_template_payload_8k2o5z7y/ansible_oneview_server_profile_template_payload.zip/ansible_collections/hpe/oneview/plugins/modules/oneview_server_profile_template.py\", line 261, in <module>\n  File \"/tmp/ansible_oneview_server_profile_template_payload_8k2o5z7y/ansible_oneview_server_profile_template_payload.zip/ansible_collections/hpe/oneview/plugins/modules/oneview_server_profile_template.py\", line 257, in main\n  File \"/tmp/ansible_oneview_server_profile_template_payload_8k2o5z7y/ansible_oneview_server_profile_template_payload.zip/ansible_collections/hpe/oneview/plugins/module_utils/oneview.py\", line 685, in run\n  File \"/tmp/ansible_oneview_server_profile_template_payload_8k2o5z7y/ansible_oneview_server_profile_template_payload.zip/ansible_collections/hpe/oneview/plugins/modules/oneview_server_profile_template.py\", line 171, in execute_module\n  File \"/tmp/ansible_oneview_server_profile_template_payload_8k2o5z7y/ansible_oneview_server_profile_template_payload.zip/ansible_collections/hpe/oneview/plugins/modules/oneview_server_profile_template.py\", line 185, in __present\n  File \"/tmp/ansible_oneview_server_profile_template_payload_8k2o5z7y/ansible_oneview_server_profile_template_payload.zip/ansible_collections/hpe/oneview/plugins/modules/oneview_server_profile_template.py\", line 211, in __create\n  File \"/usr/local/lib/python3.6/site-packages/hpeOneView/resources/servers/server_profile_templates.py\", line 114, in create\n    resource_data = self._helper.create(data, uri, timeout, force=force)\n  File \"/usr/local/lib/python3.6/site-packages/hpeOneView/resources/resource.py\", line 464, in create\n    return self.do_post(uri, data, timeout, custom_headers)\n  File \"/usr/local/lib/python3.6/site-packages/hpeOneView/resources/resource.py\", line 811, in do_post\n    task, entity = self._connection.post(uri, resource, custom_headers=custom_headers)\n  File \"/usr/local/lib/python3.6/site-packages/hpeOneView/connection.py\", line 386, in post\n    return self.__do_rest_call('POST', uri, body, custom_headers=custom_headers)\n  File \"/usr/local/lib/python3.6/site-packages/hpeOneView/connection.py\", line 413, in __do_rest_call\n    raise HPEOneViewException(body)\nhpeOneView.exceptions.HPEOneViewException: ('Unrecognized JSON field.', {'errorCode': 'UNRECOGNIZED_JSON_FIELD', 'message': 'Unrecognized JSON field.', 'details': 'The field named networkName near line 1, column 3,886 is not a valid field in this JSON object.', 'messageParameters': [], 'recommendedActions': ['Check the valid fields for this JSON object and remove or correct the unrecognized field.'], 'errorSource': None, 'nestedErrors': [], 'data': {}})\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
alisha-k-kalladassery commented 1 year ago

Hi Fredrik,

Below is a working snippet for an spt with network set name passed in networkName field.

- name: Create a server profile template
  oneview_server_profile_template:
    config: "{{ config }}"
    state: present
    sessionID: "{{ session.ansible_facts.session }}"
    data:
      name: "{{ item.name }}"
      serverHardwareTypeName: "{{ contents.server_profile_template.server_hardware_type_name }}"
      enclosureGroupName: "{{ contents.server_profile_template.enclosure_group_name }}"
      connectionSettings:
        manageConnections: true
        complianceControl: "Checked"
        connections:
          - id: 1
            name: "mgmt"
            functionType: "Ethernet"
            portId: "Auto"
            requestedMbps: 2000
            networkName: "nwset_test"
            # networkUri: '/rest/ethernet-networks/f5d68cb6-7766-4662-9774-af461436005d'
    params:
      force: "True" # Supported only for API version >= 600
  delegate_to: localhost
  with_items:
    - { name: '{{ contents.server_profile_template.server_profile_template_name }}' }

Kindly run the above snippet alone and check if it works for you

frippe75 commented 1 year ago

Will try that today. But I somehow feel it's related to versions of Ansible/OneView-module/Oneview-API. In my demo env passing network sets for name->uri works just fine. So must be something else. Or maybe other part of the JSON contains errors and the error message is simply bougus.

alisha-k-kalladassery commented 1 year ago

Hi Fredrik,

Thanks for the update. We will wait for your response.

frippe75 commented 1 year ago

Started modifying the connections to using URI instead of names. Still got the same error and the realizing it's actually for the storagePaths section the Ansible modules fails to do URI -> Name conversion.

Snippet:

            volumeAttachments:
              storagePaths:
              - isEnabled: true
                connectionId: 1
                networkName: FabricA
              - isEnabled: true
                connectionId: 2
                networkName: FabricB

The customer is experience problems with how OneView picks paths using the Port Groups. Not getting an even "spread" of the load.

alisha-k-kalladassery commented 1 year ago

Hi Fredrik,

Thanks for your response. We are currently supporting networkName->networkUri conversion for connectionSettings only. We have added this to our backlog and will fix it on priority.