예제 #1
0
    def wait_for_pod(self, pod: Pod):

        try:
            if pod.get_phase() == PodPhase.RUNNING and pod.is_ready():
                return
            else:
                raise NhaDockerError("Timed out waiting for pod '{}'".format(
                    pod.name))
        except (ConuException, K8sApiException, NhaDockerError) as e:
            msg = "Waiting up to {} seconds for pod '{}' to start".format(
                self.timeout, pod.name)
            raise PatientError(wait_callback=lambda: self.LOG.info(msg),
                               original_exception=e)
예제 #2
0
    def _find_sth(self, what, name, method, **kwargs):

        try:
            return super()._find_sth(
                what=what,
                name=name,
                method=lambda: method(self.namespace).items,
                key=lambda i: i.metadata.name == name)
        except (ConuException, K8sApiException) as e:
            msg = "Waiting up to {} seconds to find {} '{}'".format(
                self.timeout, what, name)
            raise PatientError(wait_callback=lambda: self.LOG.info(msg),
                               original_exception=e)
예제 #3
0
    def find_pod(self, name):

        try:
            with K8sBackend(logging_level=logging.ERROR) as k8s_backend:
                result = super()._find_sth(what='pods',
                                           method=k8s_backend.list_pods,
                                           name=name,
                                           namespace=self.namespace)

            return result
        except (ConuException, K8sApiException) as e:
            msg = "Waiting up to {} seconds to find {} '{}'".format(
                self.timeout, 'pod', name)
            raise PatientError(wait_callback=lambda: self.LOG.info(msg),
                               original_exception=e)
예제 #4
0
    def assert_namespace(self):

        try:
            with K8sBackend(logging_level=logging.ERROR) as k8s_backend:
                assert super()._find_sth(
                    what='namespaces',
                    name=self.namespace,
                    method=lambda: k8s_backend.core_api.list_namespace().items,
                    key=lambda i: i.metadata.name == self.namespace
                ) is not None, ConfigurationError(
                    "Namespace '{}' does not exist".format(self.namespace))
        except (ConuException, K8sApiException) as e:
            msg = "Waiting up to {} seconds to find {} '{}'".format(
                self.timeout, 'namespace', self.namespace)
            raise PatientError(wait_callback=lambda: self.LOG.info(msg),
                               original_exception=e)
예제 #5
0
    def rm_vol(self, cargo: Cargo, ignore=False):

        if isinstance(cargo, MappedCargo):
            return False

        try:
            self.docker_api.remove_volume(name=cargo.name, force=True)
            return True
        except DockerAPIError as e:
            if ignore:
                self.LOG.error(e)
                return False
            else:
                msg = "Waiting up to {} seconds for removal of volume {}".format(
                    self.timeout, cargo.name)
                raise PatientError(wait_callback=lambda: self.LOG.info(msg),
                                   original_exception=e)
예제 #6
0
    def rm_pod(self, name: str, ignore=True):

        try:
            with K8sBackend(logging_level=logging.ERROR) as k8s_backend:
                k8s_backend.core_api.delete_namespaced_pod(
                    name=name,
                    namespace=self.namespace,
                    grace_period_seconds=0)
        except (ConuException, K8sApiException) as e:
            msg = "Waiting up to {} seconds to kill Pod '{}'".format(
                self.timeout, name)
            raise PatientError(wait_callback=lambda: self.LOG.info(msg),
                               original_exception=e)
        except Exception as e:
            self.LOG.info("Could not patiently delete Pod: {}".format(name))
            if ignore:
                self.LOG.debug(repr(e))
            else:
                raise e