Unable to add_machine with 'tags' as constraints

Bug #1645225 reported by Denis Buliga
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-jujuclient
In Progress
Undecided
Felipe Reyes

Bug Description

Calling add_machine with 'tags' as constraints fails as follows:

>>> from jujuclient.juju2 import environment
>>> juju = environment.Environment.connect("maas:default")
>>> juju.add_machine(series="xenial", constraints={'tags': 'test'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/jujuclient/environment.py", line 473, in add_machine
    return self.client.add_machine(*args, **kws)
  File "/usr/local/lib/python2.7/dist-packages/jujuclient/juju2/facades.py", line 90, in add_machine
    return self.add_machines([params])['machines'][0]
  File "/usr/local/lib/python2.7/dist-packages/jujuclient/juju2/facades.py", line 100, in add_machines
    "params": machines}})
  File "/usr/local/lib/python2.7/dist-packages/jujuclient/facades.py", line 72, in rpc
    return self.env._rpc(self.check_op(op))
  File "/usr/local/lib/python2.7/dist-packages/jujuclient/rpc.py", line 42, in _rpc
    raise EnvError(result)
jujuclient.exc.EnvError: <Env Error - Details:
 { u'error': u'json: cannot unmarshal string into Go value of type []string',
    u'request-id': 2,
    u'response': { }}

This is because of the fact that the current implementation of the _prepare_constraints looks as follows:

 53 def _prepare_constraints(self, constraints):
 54 for k in ['cpu-cores', 'cpu-power', 'mem']:
 55 if constraints.get(k):
 56 constraints[k] = int(constraints[k])
 57 return constraints

On providers such as MAAS, I think it is normal that constraints such as 'tags' to be supported.

Felipe Reyes (freyes)
Changed in python-jujuclient:
assignee: nobody → Felipe Reyes (freyes)
status: New → In Progress
Revision history for this message
Felipe Reyes (freyes) wrote :

tags (and spaces) constraints are expected to be a list, if you use {'tags': ['test']} the request will be properly formatted.

Although It will be nice if jujuclient could deal with strings like the ones are used in the CLI "--constraints tags=t1,t2"

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.