def push_kernel(kdir, api, token, install_path=None): """Push the kernel binaries to the storage server Push the kernel image, the modules tarball, the dtbs and the build.json meta-data to the storage server via the KernelCI backend API. *kdir* is the path to the kernel source directory *api* is the URL of the KernelCI backend API *token* is the token to use with the KernelCI backend API *install_path* is the path to the installation directory The returned value is True if it was done successfully or False if an error occurred. """ if not install_path: install_path = os.path.join(kdir, '_install_') with open(os.path.join(install_path, 'bmeta.json')) as f: bmeta = json.load(f) artifacts = {} for root, _, files in os.walk(install_path): for f in files: px = os.path.relpath(root, install_path) artifacts[os.path.join(px, f)] = open(os.path.join(root, f), "rb") upload_path = bmeta['file_server_resource'] print_flush("Upload path: {}".format(upload_path)) upload_files(api, token, upload_path, artifacts) return True
def push_tarball(config, kdir, storage, api, token): """Create and push a linux kernel source tarball to the storage server If a tarball with a same name is already on the storage server, no new tarball is uploaded. Otherwise, a tarball is created *config* is a BuildConfig object *kdir* is the path to a kernel source directory *storage* is the base URL of the storage server *api* is the URL of the KernelCI backend API *token* is the token to use with the KernelCI backend API The returned value is the URL of the uploaded tarball. """ tarball_name = "linux-src_{}.tar.gz".format(config.name) describe = git_describe(config.tree.name, kdir) path = '/'.join(list(item.replace('/', '-') for item in [ config.tree.name, config.branch, describe ])) tarball_url = urllib.parse.urljoin(storage, '/'.join([path, tarball_name])) resp = requests.head(tarball_url) if resp.status_code == 200: return tarball_url tarball = "{}.tar.gz".format(config.name) make_tarball(kdir, tarball) upload_files(api, token, path, {tarball_name: open(tarball, 'rb')}) os.unlink(tarball) return tarball_url
def set_last_commit(config, api, token, commit): """Set the last commit SHA that was built for a given build configuration *config* is a BuildConfig object *api* is the URL of the KernelCI backend API *token* is the backend API token to use *commit* is the git SHA to send """ upload_files(api, token, config.tree.name, {_get_last_commit_file_name(config): commit})
def upload(api, token, upload_path, input_dir): """Upload rootfs to KernelCI backend. *api* is the URL of the KernelCI backend API *token* is the backend API token to use *upload_path* is the target on KernelCI backend *input_dir* is the local rootfs directory path to upload """ artifacts = {} for root, _, files in os.walk(input_dir): for f in files: px = os.path.relpath(root, input_dir) artifacts[os.path.join(px, f)] = open(os.path.join(root, f), "rb") upload_files(api, token, upload_path, artifacts)