Skip to content

Commit

Permalink
Merge ffac7e2 into 027cf2d
Browse files Browse the repository at this point in the history
  • Loading branch information
pbortlov committed Oct 26, 2020
2 parents 027cf2d + ffac7e2 commit ca9a08c
Show file tree
Hide file tree
Showing 5 changed files with 603 additions and 295 deletions.
357 changes: 232 additions & 125 deletions iiblib/iib_build_details_model.py
Original file line number Diff line number Diff line change
@@ -1,135 +1,242 @@
class IIBBuildDetailsModel(object):
"""Model class handling data about index build task"""

def __init__(
self,
_id,
state,
reason,
state_history,
from_index,
from_index_resolved,
bundles,
removed_operators,
organization,
binary_image,
binary_image_resolved,
index_image,
request_type,
arches,
bundle_mapping,
omps_operator_version,
):
"""
Args:
_id (int)
Id of build
state (str)
State of build
state (str)
Reason for state change
from_index (str)
Reference of index image used as source for rebuild
from_index_resolved (str)
Reference of new index image
bundles (list)
List of bundles to be added to index image
removed_operators (list)
List of operators to be removed from index image
organization (str)
Name of organization to push to in the legacy app registry
binary_image (str)
Reference of binary image used for rebuilding
binary_image_resolved (str)
Checksum reference of binary image that was used for rebuilding
index_image (str)
Reference of index image to rebuild
request_type (str)
Type of iib build task (add or remove)
arches (list)
List of architectures supported in new index image
bundle_mapping (dict)
Operator names in "bundles" map to: list of "bundles" which
map to the operator key
omps_operator_version (dict)
Operator version returned from OMPS API call used for Add request
"""
self.id = _id
self.state = state
self.reason = reason
self.state_history = state_history
self.from_index = from_index
self.from_index_resolved = from_index_resolved
self.bundles = bundles
self.removed_operators = removed_operators
self.organization = organization
self.binary_image = binary_image
self.binary_image_resolved = binary_image_resolved
self.index_image = index_image
self.request_type = request_type
self.arches = arches
self.bundle_mapping = bundle_mapping
self.omps_operator_version = omps_operator_version
_data_attrs = [
"id",
"arches",
"state",
"state_reason",
"request_type",
"state_history",
"batch",
"batch_annotations",
"logs",
"updated",
"user"
]

_kwattrs = []

def __init__(self, *args, **kwargs):
self.data = {}
for attr_val, attr in zip(args, self._data_attrs):
self.data[attr] = attr_val
for key, value in kwargs.items():
self.data[key] = value

@classmethod
def from_dict(cls, data):
return cls(
data["id"],
data["state"],
data["state_reason"],
data.get("state_history", []),
data["from_index"],
data["from_index_resolved"],
data.get("bundles", []),
data.get("removed_operators", []),
data.get("organization"),
data["binary_image"],
data["binary_image_resolved"],
data["index_image"],
data["request_type"],
data["arches"],
data["bundle_mapping"],
data.get("omps_operator_version", {}),
)
if data["request_type"] == "add":
return AddModel._from_dict(data)
elif data["request_type"] == "rm":
return RmModel._from_dict(data)
elif data["request_type"] == "regenerate-bundle":
return RegenerateBundleModel._from_dict(data)
raise KeyError("Unsupported request type: %s" % data["request_type"])

@classmethod
def _from_dict(cls, data):
args = []
kwargs = {}
for attr in cls._data_attrs:
args.append(data[attr])
for kwattr in cls._kwattrs:
kwargs[kwattr] = data[kwattr]
return cls(*args, **kwargs)

def to_dict(self):
return {
"id": self.id,
"state": self.state,
"state_reason": self.reason,
"state_history": self.state_history,
"from_index": self.from_index,
"from_index_resolved": self.from_index,
"bundles": self.bundles,
"removed_operators": self.removed_operators,
"organization": self.organization,
"binary_image": self.binary_image,
"binary_image_resolved": self.binary_image_resolved,
"index_image": self.index_image,
"request_type": self.request_type,
"arches": self.arches,
"bundle_mapping": self.bundle_mapping,
"omps_operator_version": self.omps_operator_version,
}
result = {}
for key in self._data_attrs:
result[key] = self.data[key]
for key in self._kwattrs:
result[key] = self.data[key]
return result

def __eq__(self, other):
if (
self.id == other.id
and self.state == other.state
and self.reason == other.reason
and self.state_history == other.state_history
and self.from_index == other.from_index
and self.from_index_resolved == other.from_index_resolved
and self.bundles == other.bundles
and self.removed_operators == other.removed_operators
and self.organization == other.organization
and self.binary_image == other.binary_image
and self.binary_image_resolved == other.binary_image_resolved
and self.index_image == other.index_image
and self.request_type == other.request_type
and self.arches == other.arches
and self.bundle_mapping == other.bundle_mapping
and self.omps_operator_version == other.omps_operator_version
):
return True
return False
return isinstance(other, IIBBuildDetailsModel) and self.data == other.data

@property
def id(self):
return self.data["id"]

@property
def arches(self):
return self.data["arches"]

@property
def state(self):
return self.data["state"]

@property
def state_reason(self):
return self.data["state_reason"]

@property
def request_type(self):
return self.data["request_type"]

@property
def state_history(self):
return self.data["state_history"]

@property
def batch(self):
return self.data["batch"]

@property
def batch_annotations(self):
return self.data["batch_annotations"]

@property
def logs(self):
return self.data["logs"]

@property
def updated(self):
return self.data["updated"]

@property
def user(self):
return self.data["user"]


class AddModel(IIBBuildDetailsModel):

_kwattrs = [
"binary_image",
"binary_image_resolved",
"bundles",
"bundle_mapping",
"from_index",
"from_index_resolved",
"index_image",
"removed_operators",
"organization",
"omps_operator_version",
"distribution_scope",
]

@property
def binary_image(self):
return self.data["binary_image"]

@property
def binary_image_resolved(self):
return self.data["binary_image_resolved"]

@property
def bundles(self):
return self.data["bundles"]

@property
def bundle_mapping(self):
return self.data["bundle_mapping"]

@property
def from_index(self):
return self.data["from_index"]

@property
def from_index_resolved(self):
return self.data["from_index_resolved"]

@property
def index_image(self):
return self.data["index_image"]

@property
def removed_operators(self):
return self.data["removed_operators"]

@property
def organization(self):
return self.data["organization"]

@property
def omps_operator_version(self):
return self.data["omps_operator_version"]

@property
def distribution_scope(self):
return self.data["distribution_scope"]


class RmModel(IIBBuildDetailsModel):

_kwattrs = [
"binary_image",
"binary_image_resolved",
"bundles",
"bundle_mapping",
"from_index",
"from_index_resolved",
"index_image",
"removed_operators",
"organization",
"distribution_scope",
]

@property
def binary_image(self):
return self.data["binary_image"]

@property
def binary_image_resolved(self):
return self.data["binary_image_resolved"]

@property
def bundles(self):
return self.data["bundles"]

@property
def bundle_mapping(self):
return self.data["bundle_mapping"]

@property
def from_index(self):
return self.data["from_index"]

@property
def from_index_resolved(self):
return self.data["from_index_resolved"]

@property
def index_image(self):
return self.data["index_image"]

@property
def removed_operators(self):
return self.data["removed_operators"]

@property
def organization(self):
return self.data["organization"]

@property
def distribution_scope(self):
return self.data["distribution_scope"]


class RegenerateBundleModel(IIBBuildDetailsModel):

_kwattrs = [
"bundle_image",
"from_bundle_image",
"from_bundle_image_resolved",
"organization",
]
@property
def bundle_image(self):
return self.data["bundle_image"]

@property
def from_bundle_image(self):
return self.data["from_bundle_image"]

@property
def from_bundle_image_resolved(self):
return self.data["from_bundle_image_resolved"]

@property
def organization(self):
return self.data["organization"]
6 changes: 3 additions & 3 deletions iiblib/iib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ def wait_for_build(self, build):
"""
timeout = time.time() + self.wait_for_build_timeout
while True:
build_details = self.get_build(build.id)
if build_details.state in ("complete", "failed"):
build_details = self.get_build(build.data["id"])
if build_details.data["state"] in ("complete", "failed"):
return build_details
if time.time() >= timeout:
raise IIBException(
"Timeout reached. Build request %s was not processed in %d seconds."
% (build.id, self.wait_for_build_timeout),
% (build.data["id"], self.wait_for_build_timeout),
)
time.sleep(self.poll_interval)

Expand Down
Loading

0 comments on commit ca9a08c

Please sign in to comment.