def docker_image_pull(self, image, tag = None, expected_error_message = None): if tag is not None: _tag = tag else: _tag = "latest" try: base._get_string_from_unicode(self.DCLIENT.pull(r'{}:{}'.format(image, _tag))) except Exception, err: if expected_error_message is not None: print "docker image pull error:", str(err) if str(err).lower().find(expected_error_message.lower()) < 0: raise Exception(r"Pull image: Return message {} is not as expected {}".format(return_message, expected_error_message)) else: raise Exception(r" Docker pull image {} failed, error is [{}]".format (image, e.message))
def docker_image_push(self, harbor_registry, tag): try: push_ret = base._get_string_from_unicode( self.DCLIENT.push(harbor_registry, tag, stream=True)) print "push_ret:", push_ret except docker.errors.APIError, e: raise Exception( r" Docker tag image {} failed, error is [{}]".format( image, e.message))
def docker_image_pull(self, image, tag=None): _tag = "latest" if tag is not None: _tag = tag try: tag = base._random_name("tag") pull_ret = base._get_string_from_unicode( self.DCLIENT.pull('{}:{}'.format(image, _tag))) print "pull_ret:", pull_ret except docker.errors.APIError, e: raise Exception( r" Docker pull image {} failed, error is [{}]".format( image, e.message))
def docker_image_push(self, harbor_registry, tag, expected_error_message = None): caught_err = False ret = "" if expected_error_message is "": expected_error_message = None try: ret = base._get_string_from_unicode(self.DCLIENT.push(harbor_registry, tag, stream=True)) except Exception, err: caught_err = True if expected_error_message is not None: print "docker image push error:", str(err) if str(err).lower().find(expected_error_message.lower()) < 0: raise Exception(r"Push image: Return message {} is not as expected {}".format(str(err), expected_error_message)) else: raise Exception(r" Docker push image {} failed, error is [{}]".format (harbor_registry, err.message))
def docker_image_push(self, harbor_registry, tag, expected_error_message=None): caught_err = False ret = "" if expected_error_message is "": expected_error_message = None try: ret = base._get_string_from_unicode( self.DCLIENT.push(harbor_registry, tag, stream=True)) return ret except Exception as err: caught_err = True if expected_error_message is not None: print("docker image push error:", str(err)) if str(err).lower().find(expected_error_message.lower()) < 0: raise Exception( r"Push image: Return message {} is not as expected {}". format(str(err), expected_error_message)) else: raise Exception( r" Docker push image {} failed, error is [{}]".format( harbor_registry, err.message)) if caught_err == False: if expected_error_message is not None: if str(ret).lower().find(expected_error_message.lower()) < 0: raise Exception( r" Failed to catch error [{}] when push image {}, return message: {}" .format(expected_error_message, harbor_registry, str(ret))) else: if str(ret).lower().find("errorDetail".lower()) >= 0: raise Exception( r" It's was not suppose to catch error when push image {}, return message is [{}]" .format(harbor_registry, ret))
def docker_image_pull(self, image, tag=None, expected_error_message=None): if tag is not None: _tag = tag else: _tag = "latest" if expected_error_message is "": expected_error_message = None caught_err = False ret = "" try: ret = base._get_string_from_unicode( self.DCLIENT.pull(r'{}:{}'.format(image, _tag))) return ret except Exception as err: caught_err = True if expected_error_message is not None: print("docker image pull error:", str(err)) if str(err).lower().find(expected_error_message.lower()) < 0: raise Exception( r"Pull image: Return message {} is not as expected {}". format(str(err), expected_error_message)) else: raise Exception( r" Docker pull image {} failed, error is [{}]".format( image, err.message)) if caught_err == False: if expected_error_message is not None: if str(ret).lower().find(expected_error_message.lower()) < 0: raise Exception( r" Failed to catch error [{}] when pull image {}, return message: {}" .format(expected_error_message, image, str(ret))) else: if str(ret).lower().find("error".lower()) >= 0: raise Exception( r" It's was not suppose to catch error when pull image {}, return message is [{}]" .format(image, ret))