Fix tag creation race condition
This commit is contained in:
parent
f6d15ab791
commit
44e312b828
@ -1115,9 +1115,18 @@ class MaasTaskRunner(drivers.DriverTaskRunner):
|
||||
tag = tag_list.select(t)
|
||||
|
||||
if tag is None:
|
||||
self.logger.debug("Creating static tag %s" % t)
|
||||
tag = maas_tag.Tag(self.maas_client, name=t)
|
||||
tag = tag_list.add(tag)
|
||||
try:
|
||||
self.logger.debug("Creating static tag %s" % t)
|
||||
tag = maas_tag.Tag(self.maas_client, name=t)
|
||||
tag = tag_list.add(tag)
|
||||
except DriverError as dex:
|
||||
tag_list.refresh()
|
||||
tag = tag_list.select(t)
|
||||
if tag is not None:
|
||||
self.logger.debug("Tag %s arrived out of nowhere." % t
|
||||
else:
|
||||
self.logger.error("Error creating tag %s." % t)
|
||||
continue
|
||||
|
||||
self.logger.debug("Applying tag %s to node %s" % (tag.resource_id, machine.resource_id))
|
||||
tag.apply_to_node(machine.resource_id)
|
||||
|
@ -131,7 +131,9 @@ class Tags(model_base.ResourceCollectionBase):
|
||||
resp_json = resp.json()
|
||||
res.set_resource_id(resp_json.get('name'))
|
||||
return res
|
||||
|
||||
raise errors.DriverError("Failed updating MAAS url %s - return code %s"
|
||||
% (url, resp.status_code))
|
||||
elif resp.status_code == 400 and resp.text.find('Tag with this Name already exists.') != -1:
|
||||
raise errors.DriverError("Tag %s already exists" % res.name)
|
||||
else:
|
||||
raise errors.DriverError("Failed updating MAAS url %s - return code %s"
|
||||
% (url, resp.status_code))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user