Fix nested provider validation with hyphens
The method we use to flatten a complete provider config and validate it used the toDict method to re-render the nested label/image/flavor config objects as dictionaries underneath the resulting provider config. However, we want to validate the resulting provider config, which means we need to use hyphens instead of underscores. Add a new method that renders the config object back to its original form for use in flattening. Change-Id: I7f212b0a824b9c473b17ac85df6dea8bdd61e53c
This commit is contained in:
@ -1612,6 +1612,15 @@ class Image(ConfigObject):
|
||||
'description': self.description,
|
||||
}
|
||||
|
||||
def toConfig(self):
|
||||
return {
|
||||
'project_canonical_name': self.project_canonical_name,
|
||||
'name': self.name,
|
||||
'branch': self.branch,
|
||||
'type': self.type,
|
||||
'description': self.description,
|
||||
}
|
||||
|
||||
|
||||
class Flavor(ConfigObject):
|
||||
"""A node flavor.
|
||||
@ -1652,6 +1661,14 @@ class Flavor(ConfigObject):
|
||||
'description': self.description,
|
||||
}
|
||||
|
||||
def toConfig(self):
|
||||
sc = self.source_context
|
||||
return {
|
||||
'project_canonical_name': sc.project_canonical_name,
|
||||
'name': self.name,
|
||||
'description': self.description,
|
||||
}
|
||||
|
||||
|
||||
class Label(ConfigObject):
|
||||
"""A node label.
|
||||
@ -1705,6 +1722,18 @@ class Label(ConfigObject):
|
||||
'max_ready_age': self.max_ready_age,
|
||||
}
|
||||
|
||||
def toConfig(self):
|
||||
sc = self.source_context
|
||||
return {
|
||||
'project_canonical_name': sc.project_canonical_name,
|
||||
'name': self.name,
|
||||
'image': self.image,
|
||||
'flavor': self.flavor,
|
||||
'description': self.description,
|
||||
'min-ready': self.min_ready,
|
||||
'max-ready-age': self.max_ready_age,
|
||||
}
|
||||
|
||||
def validateReferences(self, layout):
|
||||
if not layout.images.get(self.image):
|
||||
raise Exception(
|
||||
@ -1860,7 +1889,7 @@ class ProviderConfig(ConfigObject):
|
||||
image_hashes = {}
|
||||
for image in config.get('images', []):
|
||||
layout_image = self._dropNone(
|
||||
layout.images[image['name']].toDict())
|
||||
layout.images[image['name']].toConfig())
|
||||
image.update(ProviderConfig._mergeDict(layout_image, image))
|
||||
# This is used for identifying unique image configurations
|
||||
# across multiple providers.
|
||||
@ -1870,14 +1899,14 @@ class ProviderConfig(ConfigObject):
|
||||
flavor_hashes = {}
|
||||
for flavor in config.get('flavors', []):
|
||||
layout_flavor = self._dropNone(
|
||||
layout.flavors[flavor['name']].toDict())
|
||||
layout.flavors[flavor['name']].toConfig())
|
||||
flavor.update(ProviderConfig._mergeDict(layout_flavor, flavor))
|
||||
flavor['config_hash'] = hashlib.sha256(
|
||||
json.dumps(flavor, sort_keys=True).encode("utf8")).hexdigest()
|
||||
flavor_hashes[flavor['name']] = flavor['config_hash']
|
||||
for label in config.get('labels', []):
|
||||
layout_label = self._dropNone(
|
||||
layout.labels[label['name']].toDict())
|
||||
layout.labels[label['name']].toConfig())
|
||||
label.update(ProviderConfig._mergeDict(layout_label, label))
|
||||
try:
|
||||
label['config_hash'] = self._getLabelConfigHash(
|
||||
|
@ -32,8 +32,8 @@ base_label = vs.Schema({
|
||||
Optional('image'): Nullable(str),
|
||||
Optional('flavor'): Nullable(str),
|
||||
Optional('tags', default=dict): {str: str},
|
||||
Optional('min_ready', default=0): int,
|
||||
Optional('max_ready_age', default=0): int,
|
||||
Optional('min-ready', default=0): int,
|
||||
Optional('max-ready-age', default=0): int,
|
||||
Optional('boot-timeout', default=300): int,
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user