def _read_stream(self, resource, watcher, stream, name, replicas):
        """ Wait for ready_replicas to equal the requested number of replicas. """
        return_obj = None
        try:
            for event in stream:
                if event.get('object'):
                    obj = ResourceInstance(resource, event['object'])
                    if obj.metadata.name == name and hasattr(obj, 'status'):
                        if replicas == 0:
                            if not hasattr(obj.status, 'readyReplicas') or not obj.status.readyReplicas:
                                return_obj = obj
                                watcher.stop()
                                break
                        if hasattr(obj.status, 'readyReplicas') and obj.status.readyReplicas == replicas:
                            return_obj = obj
                            watcher.stop()
                            break
        except Exception as exc:
            self.fail_json(msg="Exception reading event stream: {0}".format(exc))

        if not return_obj:
            self.fail_json(msg="Error fetching the patched object. Try a higher wait_timeout value.")
        if replicas and return_obj.status.readyReplicas is None:
            self.fail_json(msg="Failed to fetch the number of ready replicas. Try a higher wait_timeout value.")
        if replicas and return_obj.status.readyReplicas != replicas:
            self.fail_json(msg="Number of ready replicas is {0}. Failed to reach {1} ready replicas within "
                               "the wait_timeout period.".format(return_obj.status.ready_replicas, replicas))
        return return_obj
コード例 #2
0
    def _read_stream(self, resource, watcher, stream, name, running):
        """ Wait for ready_replicas to equal the requested number of replicas. """
        for event in stream:
            if event.get('object'):
                obj = ResourceInstance(resource, event['object'])
                if running:
                    if obj.metadata.name == name and hasattr(obj, 'status'):
                        phase = getattr(obj.status, 'phase', None)
                        if phase:
                            if phase == 'Running' and running:
                                watcher.stop()
                                return
                else:
                    # TODO: wait for stopped state:
                    watcher.stop()
                    return

        self.fail_json(msg="Error waiting for virtual machine. Try a higher wait_timeout value. %s" % obj.to_dict())
コード例 #3
0
    def _read_stream(self, resource, watcher, stream):
        return_obj = None

        for event in stream:
            if event.get('object'):
                entity = ResourceInstance(resource, event['object'])
                metadata = entity.metadata
                if entity.status.phase == 'Bound':
                    annotations = metadata.annotations if \
                        metadata.annotations else {}
                    IMPORT_STATUS_KEY = 'cdi.kubevirt.io/storage.pod.phase'
                    import_status = annotations.get(IMPORT_STATUS_KEY)
                    labels = metadata.labels if metadata.labels else {}
                    if (not self._use_cdi(annotations, labels)
                            or import_status == 'Succeeded'):
                        watcher.stop()
                        return_obj = entity
                        break
                elif entity.status.phase == 'Failed':
                    watcher.stop()
                    self.fail_json(
                        msg="Failed to import PersistentVolumeClaim")

        return self.fix_serialization(return_obj)