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

Actions fail without required entity parameters #84

Open chbrown13 opened 7 years ago

chbrown13 commented 7 years ago

Description

I created an Interface entity but cannot delete it because when an interface it created, it requires a Host entity parameter. However sometimes satellite-populate actions only uses the entity_id or other specified attributes which causes an error.

EDIT: Also applies to other actions other than delete [delete] ( (https://github.com/SatelliteQE/satellite-populate/blob/master/satellite_populate/api.py#L120) [search] (https://github.com/SatelliteQE/satellite-populate/blob/master/satellite_populate/base.py#L595)

TypeError: A value must be provided for the ___ field.

What I Did

test_interface.yaml

[root@localhost satellite]# satellite-populate test_interface.yaml -h hp-dl380gen9-01.khw.lab.eng.bos.redhat.com --no-output -v

...
2017-08-04 15:32:26 - satellite_populate.base - INFO - DELETE: executing...
2017-08-04 15:32:26 - nailgun.client - DEBUG - Making HTTP GET request to https://hp-dl380gen9-01.khw.lab.eng.bos.redhat.com/api/v2/hosts/51/interfaces with options {'verify': False, 'data': '{"host_id": 51, "name": "Interface"}', 'auth': ('admin', 'changeme'), 'headers': {'content-type': 'application/json'}}, no params and no data.
2017-08-04 15:32:26 - urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): hp-dl380gen9-01.khw.lab.eng.bos.redhat.com
2017-08-04 15:32:26 - urllib3.connectionpool - DEBUG - https://hp-dl380gen9-01.khw.lab.eng.bos.redhat.com:443 "GET /api/v2/hosts/51/interfaces HTTP/1.1" 200 288
2017-08-04 15:32:26 - nailgun.client - DEBUG - Received HTTP 200 response: {
  "total": 1,
  "subtotal": 1,
  "page": 1,
  "per_page": 20,
  "search": null,
  "sort": {
    "by": null,
    "order": null
  },
  "results": [{"subnet_id":null,"subnet_name":null,"subnet6_id":null,"subnet6_name":null,"domain_id":61,"domain_name":"mcjrdftg1w","created_at":"2017-08-04 19:32:25 UTC","updated_at":"2017-08-04 19:32:25 UTC","managed":true,"identifier":null,"id":66,"name":"host.mcjrdftg1w","ip":null,"ip6":null,"mac":"ca:fe:4b:d0:96:85","primary":true,"provision":true,"type":"interface","virtual":false}]
}
2017-08-04 15:32:26 - satellite_populate.base - INFO - search: Interface {'host': 51, 'name': u'Interface'} found unique item
2017-08-04 15:32:26 - satellite_populate.base - ERROR - populate: A value must be provided for the "host" field. {'action': 'delete', 'search_query': {'host': {'from_registry': 'reg_host'}, 'name': '{{ name }}'}, 'model': 'Interface', 'log_message': u'executing...'}
Traceback (most recent call last):
  File "/opt/virtual_env/satellite-populate/bin/satellite-populate", line 11, in <module>
    load_entry_point('satellite-populate', 'console_scripts', 'satellite-populate')()
  File "/opt/virtual_env/satellite-populate/lib/python2.7/site-packages/click-6.7-py2.7.egg/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/opt/virtual_env/satellite-populate/lib/python2.7/site-packages/click-6.7-py2.7.egg/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/opt/virtual_env/satellite-populate/lib/python2.7/site-packages/click-6.7-py2.7.egg/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/virtual_env/satellite-populate/lib/python2.7/site-packages/click-6.7-py2.7.egg/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/chris/Documents/satellite-populate/satellite_populate/commands.py", line 160, 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 124, in action_delete
    model(id=entity_id).delete()
  File "/opt/virtual_env/satellite-populate/lib/python2.7/site-packages/nailgun/entities.py", line 3369, in __init__
    _check_for_value('host', kwargs)
  File "/opt/virtual_env/satellite-populate/lib/python2.7/site-packages/nailgun/entities.py", line 152, in _check_for_value
    'A value must be provided for the "{0}" field.'.format(field_name)
TypeError: A value must be provided for the "host" field.
rochacbruno commented 7 years ago

@chbrown13 so maybe nailgun must have a way to validate all the required fields before making the api call?

chbrown13 commented 7 years ago

Yep, not sure if there's any way around this other than adding required values for every action.

chbrown13 commented 7 years ago

Also in some cases I think required attributes are automatically generated because I've gotten around this before with other entities, but not in this example.

chbrown13 commented 7 years ago

Solution- When entities are updated, searched, or deleted we only pass the entity_id but all required arguments also need to be passed in either in the yaml commands or the object constructor.

delete- https://github.com/SatelliteQE/satellite-populate/blob/master/satellite_populate/api.py#L120 update- https://github.com/SatelliteQE/satellite-populate/blob/master/satellite_populate/api.py#L94 search- https://github.com/SatelliteQE/satellite-populate/blob/master/satellite_populate/base.py#L595