SatelliteQE / satellite-populate

This new module adds tools and commands to populate and validate entities in the system based in YAML file.
Other
8 stars 10 forks source link

[nailgun] Error creating Architecture entities #66

Closed chbrown13 closed 7 years ago

chbrown13 commented 7 years ago

Description

While trying to create an Architecture entity, I received the following error message: "RuntimeError: More than 1 item returned search is not unique". The new architecture was actually unique but all the existing architectures were returned from the search. I expected the new Architecture to be created and no values returned in the results.

What I Did

test_architecture.yaml

# satellite-populate test_architecture.yaml -h hp-sl4545g7-01.khw.lab.eng.bos.redhat.com -v

2017-07-18 10:24:21 - satellite_populate.base - INFO - Starting in populate mode
2017-07-18 10:24:21 - satellite_populate.base - INFO - CREATE: default_arch
2017-07-18 10:24:21 - nailgun.client - DEBUG - Making HTTP GET request to https://hp-sl4545g7-01.khw.lab.eng.bos.redhat.com/api/v2/architectures with options {'verify': False, 'data': '{"name": "[\'x64-128\']"}', 'auth': ('admin', 'changeme'), 'headers': {'content-type': 'application/json'}} and no data.
2017-07-18 10:24:21 - requests.packages.urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): hp-sl4545g7-01.khw.lab.eng.bos.redhat.com
2017-07-18 10:24:22 - requests.packages.urllib3.connectionpool - DEBUG - https://hp-sl4545g7-01.khw.lab.eng.bos.redhat.com:443 "GET /api/v2/architectures HTTP/1.1" 200 181
2017-07-18 10:24:22 - nailgun.client - DEBUG - Received HTTP 200 response: {
  "total": 2,
  "subtotal": 2,
  "page": 1,
  "per_page": 20,
  "search": null,
  "sort": {
    "by": null,
    "order": null
  },
  "results": [{"created_at":"2017-07-17 16:35:36 UTC","updated_at":"2017-07-17 16:35:36 UTC","name":"x86_64","id":1},{"created_at":"2017-07-17 16:35:36 UTC","updated_at":"2017-07-17 16:35:36 UTC","name":"i386","id":2}]
}

2017-07-18 10:24:22 - satellite_populate.base - ERROR - search: Architecture {'name': u"['x64-128']"} is not unique
2017-07-18 10:24:22 - satellite_populate.base - DEBUG - [nailgun.entities.Architecture(id=1, name=u'x86_64'), nailgun.entities.Architecture(id=2, name=u'i386')]
2017-07-18 10:24:22 - satellite_populate.base - ERROR - populate: More than 1 item returned search is not unique {'log_message': u'default_arch', 'model': 'Architecture', 'register': 'default_arch', 'data': {'name': '{{ arch_name }}'}}
Traceback (most recent call last):
  File "/usr/bin/satellite-populate", line 9, in <module>
    load_entry_point('satellite-populate', 'console_scripts', 'satellite-populate')()
  File "/usr/lib64/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib64/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/lib64/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib64/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/chris/Documents/satellite-populate/satellite_populate/commands.py", line 161, in main
    hostname, username, password, report, enable_output)
  File "/home/chris/Documents/satellite-populate/satellite_populate/commands.py", line 47, in execute_populate
    enable_output=enable_output
  File "/home/chris/Documents/satellite-populate/satellite_populate/main.py", line 62, in populate
    populator.execute()
  File "/home/chris/Documents/satellite-populate/satellite_populate/base.py", line 180, in execute
    entity_data, action_data, search, action
  File "/home/chris/Documents/satellite-populate/satellite_populate/api.py", line 39, in populate
    rendered_action_data, action_data, search, model, silent_errors
  File "/home/chris/Documents/satellite-populate/satellite_populate/api.py", line 58, in action_create
    model, search, unique=True, silent_errors=silent_errors
  File "/home/chris/Documents/satellite-populate/satellite_populate/base.py", line 619, in get_search_result
    "More than 1 item returned "
RuntimeError: More than 1 item returned search is not unique
rochacbruno commented 7 years ago

We may need to add search rules to https://github.com/SatelliteQE/satellite-populate/blob/master/satellite_populate/constants.py#L12

in the same way we did for organization

'architecture': {'_force_raw': True}

It will force a raw search using name and may work, but if not m then we need to tweak other fields as we did there for user