Fix bug: report exist trait exception
check the trait first before create trait to placement Change-Id: I37cddd13c12536bc20bd6039127d348e6f9949da
This commit is contained in:
parent
57fa0d442d
commit
155f6ae97d
@ -85,16 +85,19 @@ class PlacementClient(object):
|
||||
def _ensure_traits(self, trait_names):
|
||||
# TODO(Xinran): maintain a reference count of how many RPs use
|
||||
# this trait and do the deletion only when the last RP is deleted.
|
||||
for trait in trait_names:
|
||||
resp = self.put("/traits/%s" % trait, None, version='1.6')
|
||||
for trait_name in trait_names:
|
||||
trait = self.get("/traits/%s" % trait_name, version='1.6')
|
||||
if trait:
|
||||
LOG.info("Trait %(trait)s already existed",
|
||||
{"trait": trait_name})
|
||||
continue
|
||||
resp = self.put("/traits/%s" % trait_name, None, version='1.6')
|
||||
if resp.status_code == 201:
|
||||
LOG.info("Created trait %(trait)s", {"trait": trait})
|
||||
elif resp.status_code == 204:
|
||||
LOG.info("Trait %(trait)s already existed", {"trait": trait})
|
||||
LOG.info("Created trait %(trait)s", {"trait": trait_name})
|
||||
else:
|
||||
raise Exception(
|
||||
"Failed to create trait %s: HTTP %d: %s" %
|
||||
(trait, resp.status_code, resp.text))
|
||||
(trait_name, resp.status_code, resp.text))
|
||||
|
||||
def _put_rp_traits(self, rp_uuid, traits_json):
|
||||
generation = self.get_resource_provider(
|
||||
|
Loading…
Reference in New Issue
Block a user