gocd-contrib / gomatic

A Python API for configuring GoCD
https://pypi.python.org/pypi/gomatic
MIT License
142 stars 60 forks source link

Elastic agents are broken in gocd 18.1.0 #49

Closed akshaykarle closed 6 years ago

akshaykarle commented 6 years ago

With gocd 18.1.0 released, one of the changes made was to move the elastic profiles out of the server config. This breaking the elastic profiles being created with gomatic against gocd 18.1. The error I get trying to update my elastic profile:

File "/usr/lib/python3.6/site-packages/gomatic/go_cd_configurator.py", line 296, in save_updated_config
    self.__host_rest_client.post('/go/admin/restful/configuration/file/POST/xml', data, headers)
  File "/usr/lib/python3.6/site-packages/gomatic/go_cd_configurator.py", line 335, in post
    raise RuntimeError("Could not post config to Go server (%s) [status code=%s]:\n%s" % (url, result.status_code, message))
RuntimeError: Could not post config to Go server (http://localhost:8153/go/admin/restful/configuration/file/POST/xml) [status code=409]:
Invalid content was found starting with element 'elastic'. One of '{mailhost}' is expected.

I could move the elastic config to be out of the <server> tag but it would break for all the older gocd versions.

dudadornelles commented 6 years ago

What about checking against the version to decide what to do? You can get the current gocd version from the configurator object now:

https://github.com/gocd-contrib/gomatic/blob/8de4878c28f2d6103ad74a635f620c134efccac9/gomatic/go_cd_configurator.py#L64-L66

The version gets fetched from the api endpoint

akshaykarle commented 6 years ago

Nice, will do that and create a PR :)