isula-build: sync for fix save multi-tags and tests update

Sync from upstream for:
- bugfix: fix save multiple tags single image failed
- tests:
  - pidofbuilder do not set when running a new bash script in new child process
  - shellcheck fix of common.sh
  - add integration tests for saving one image with multiple tags

Signed-off-by: jingxiaolu <lujingxiao@huawei.com>
This commit is contained in:
jingxiaolu 2021-08-31 10:54:46 +08:00
parent 2b4943fa48
commit 16d4ded5e2
8 changed files with 720 additions and 3 deletions

View File

@ -1 +1 @@
0.9.5-10
0.9.5-11

View File

@ -1 +1 @@
25d21686be52b8801d9988c7a4d13aec1a4965f4
18f3f6d05d45f4b295bdc951b91bb700d3d83275

View File

@ -2,7 +2,7 @@
Name: isula-build
Version: 0.9.5
Release: 10
Release: 11
Summary: A tool to build container images
License: Mulan PSL V2
URL: https://gitee.com/openeuler/isula-build
@ -85,6 +85,12 @@ fi
/usr/share/bash-completion/completions/isula-build
%changelog
* Tue Aug 31 2021 jingxiaolu <lujingxiao@huawei.com> - 0.9.5-11
- Type:bugfix
- CVE:NA
- SUG:restart
- DESC:sync patches from upstream, including fix for save multiple tags, test cases improvement
* Mon Jul 26 2021 DCCooper <1866858@gmail.com> - 0.9.5-10
- Type:bugfix
- CVE:NA

View File

@ -0,0 +1,27 @@
From c1061acaafa4120075fe83ca8075e593403cb6f8 Mon Sep 17 00:00:00 2001
From: xingweizheng <xingweizheng@huawei.com>
Date: Sun, 22 Aug 2021 12:21:21 +0800
Subject: [PATCH 1/4] bugfix: pidofbuilder do not set when running a new bash
script in new child process
---
tests/lib/common.sh | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tests/lib/common.sh b/tests/lib/common.sh
index f393ee1..5cd66ff 100755
--- a/tests/lib/common.sh
+++ b/tests/lib/common.sh
@@ -13,6 +13,9 @@
# Create: 2020-03-01
# Description: common functions for tests
+# cross process environment for killing isula-builder
+declare -x pidofbuilder
+
# check if legacy builder exists
function pre_check() {
if pgrep isula-builder > /dev/null 2>&1; then
--
1.8.3.1

View File

@ -0,0 +1,90 @@
From 29ad6f4d4de67e143ba0ab7bba1ca3668cda9797 Mon Sep 17 00:00:00 2001
From: xingweizheng <xingweizheng@huawei.com>
Date: Tue, 24 Aug 2021 19:23:55 +0800
Subject: [PATCH 2/4] shellcheck fix of common.sh
---
tests/lib/common.sh | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/tests/lib/common.sh b/tests/lib/common.sh
index f393ee1..2099eac 100755
--- a/tests/lib/common.sh
+++ b/tests/lib/common.sh
@@ -123,8 +123,7 @@ function test_build_with_oci_archive_output() {
# test build image with docker-daemon output
function test_build_with_docker_daemon_output() {
- systemctl status docker > /dev/null 2>&1
- if [ $? -ne 0 ]; then
+ if ! systemctl status docker > /dev/null 2>&1; then
return 0
fi
@@ -146,9 +145,8 @@ function test_build_with_docker_daemon_output() {
}
# test build image with isulad output
-function test_build_with_isulad_output() {
- systemctl status isulad > /dev/null 2>&1
- if [ $? -ne 0 ]; then
+function test_build_with_isulad_output() {
+ if ! systemctl status isulad > /dev/null 2>&1; then
return 0
fi
@@ -172,41 +170,41 @@ function test_build_with_isulad_output() {
# test isula build base command
function test_isula_build_base_command() {
show_and_run_command "Build docker format image:" \
- " isula-build ctr-img build --tag "$1"-docker:latest --output=docker-archive:/tmp/"$1"-docker.tar:"$1"-docker:latest "$2""
+ " isula-build ctr-img build --tag $1-docker:latest --output=docker-archive:/tmp/$1-docker.tar:$1-docker:latest $2"
show_and_run_command "Build oci format image:" \
- "isula-build ctr-img build --tag "$1"-oci:latest --output=oci-archive:/tmp/"$1"-oci.tar:"$1"-oci:latest "$2""
+ "isula-build ctr-img build --tag $1-oci:latest --output=oci-archive:/tmp/$1-oci.tar:$1-oci:latest $2"
show_and_run_command "List all images:" \
"isula-build ctr-img images"
show_and_run_command "List docker format image:" \
- "isula-build ctr-img images "$1"-docker:latest"
+ "isula-build ctr-img images $1-docker:latest"
show_and_run_command "List oci format image:" \
- "isula-build ctr-img images "$1"-oci:latest"
+ "isula-build ctr-img images $1-oci:latest"
rm -f /tmp/"$1"-docker.tar /tmp/"$1"-oci.tar
show_and_run_command "Save image with docker format:" \
- "isula-build ctr-img save -f docker "$1"-docker:latest -o /tmp/"$1"-docker.tar"
+ "isula-build ctr-img save -f docker $1-docker:latest -o /tmp/$1-docker.tar"
show_and_run_command "Save image with oci format:" \
- "isula-build ctr-img save -f oci "$1"-oci:latest -o /tmp/"$1"-oci.tar"
+ "isula-build ctr-img save -f oci $1-oci:latest -o /tmp/$1-oci.tar"
show_and_run_command "Load docker format images:" \
- "isula-build ctr-img load -i /tmp/"$1"-docker.tar"
+ "isula-build ctr-img load -i /tmp/$1-docker.tar"
show_and_run_command "Load oci format images:" \
- "isula-build ctr-img load -i /tmp/"$1"-oci.tar"
+ "isula-build ctr-img load -i /tmp/$1-oci.tar"
show_and_run_command "Save multipile images with docker format:" \
- "isula-build ctr-img save -f docker "$1"-docker:latest "$1"-oci:latest -o /tmp/"$1"-all.tar"
+ "isula-build ctr-img save -f docker $1-docker:latest $1-oci:latest -o /tmp/$1-all.tar"
rm -f /tmp/"$1"-docker.tar /tmp/"$1"-oci.tar /tmp/"$1"-all.tar
show_and_run_command "Remove images:" \
- "isula-build ctr-img rm "$1"-docker:latest "$1"-oci:latest"
+ "isula-build ctr-img rm $1-docker:latest $1-oci:latest"
}
function show_and_run_command() {
--
1.8.3.1

View File

@ -0,0 +1,309 @@
From caf11183fa91a301402a00a302e81894861f9957 Mon Sep 17 00:00:00 2001
From: xingweizheng <xingweizheng@huawei.com>
Date: Sun, 22 Aug 2021 12:31:04 +0800
Subject: [PATCH 3/4] bugfix: fix save multiple tags single image failed
---
daemon/save.go | 145 ++++++++++++++++++++++++-------------
exporter/docker/archive/archive.go | 23 +-----
image/image.go | 18 -----
3 files changed, 95 insertions(+), 91 deletions(-)
diff --git a/daemon/save.go b/daemon/save.go
index de644c3..7ad1285 100644
--- a/daemon/save.go
+++ b/daemon/save.go
@@ -17,6 +17,7 @@ import (
"context"
"os"
+ "github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -33,26 +34,30 @@ import (
)
type saveOptions struct {
- sysCtx *types.SystemContext
- logger *logger.Logger
- localStore *store.Store
- logEntry *logrus.Entry
- saveID string
- outputPath string
- oriImgList []string
- format string
+ sysCtx *types.SystemContext
+ localStore *store.Store
+ saveID string
+ format string
+ oriImgList []string
+ finalImageOrdered []string
+ finalImageSet map[string][]reference.NamedTagged
+ outputPath string
+ logger *logger.Logger
+ logEntry *logrus.Entry
}
func (b *Backend) getSaveOptions(req *pb.SaveRequest) saveOptions {
return saveOptions{
- sysCtx: image.GetSystemContext(),
- logger: logger.NewCliLogger(constant.CliLogBufferLen),
- localStore: b.daemon.localStore,
- saveID: req.GetSaveID(),
- outputPath: req.GetPath(),
- oriImgList: req.GetImages(),
- format: req.GetFormat(),
- logEntry: logrus.WithFields(logrus.Fields{"SaveID": req.GetSaveID(), "Format": req.GetFormat()}),
+ sysCtx: image.GetSystemContext(),
+ localStore: b.daemon.localStore,
+ saveID: req.GetSaveID(),
+ format: req.GetFormat(),
+ oriImgList: req.GetImages(),
+ finalImageOrdered: make([]string, 0),
+ finalImageSet: make(map[string][]reference.NamedTagged),
+ outputPath: req.GetPath(),
+ logger: logger.NewCliLogger(constant.CliLogBufferLen),
+ logEntry: logrus.WithFields(logrus.Fields{"SaveID": req.GetSaveID(), "Format": req.GetFormat()}),
}
}
@@ -63,28 +68,14 @@ func (b *Backend) Save(req *pb.SaveRequest, stream pb.Control_SaveServer) error
"Format": req.GetFormat(),
}).Info("SaveRequest received")
- var (
- ok bool
- err error
- )
-
+ var err error
opts := b.getSaveOptions(req)
- switch opts.format {
- case constant.DockerTransport:
- opts.format = constant.DockerArchiveTransport
- case constant.OCITransport:
- opts.format = constant.OCIArchiveTransport
- default:
- return errors.New("wrong image format provided")
+ if err = checkFormatAndExpandTag(&opts); err != nil {
+ return err
}
-
- for i, imageName := range opts.oriImgList {
- nameWithTag, cErr := image.CheckAndAddDefaultTag(imageName, opts.localStore)
- if cErr != nil {
- return cErr
- }
- opts.oriImgList[i] = nameWithTag
+ if err = filterImageName(&opts); err != nil {
+ return err
}
defer func() {
@@ -98,26 +89,18 @@ func (b *Backend) Save(req *pb.SaveRequest, stream pb.Control_SaveServer) error
ctx := context.WithValue(stream.Context(), util.LogFieldKey(util.LogKeySessionID), opts.saveID)
eg, _ := errgroup.WithContext(ctx)
- eg.Go(exportHandler(ctx, opts))
+ eg.Go(exportHandler(ctx, &opts))
eg.Go(messageHandler(stream, opts.logger))
- errC := make(chan error, 1)
- errC <- eg.Wait()
- defer close(errC)
-
- err, ok = <-errC
- if !ok {
- opts.logEntry.Info("Channel errC closed")
- return nil
- }
- if err != nil {
+ if err = eg.Wait(); err != nil {
+ opts.logEntry.Warnf("Save stream closed with: %v", err)
return err
}
return nil
}
-func exportHandler(ctx context.Context, opts saveOptions) func() error {
+func exportHandler(ctx context.Context, opts *saveOptions) func() error {
return func() error {
defer func() {
opts.logger.CloseContent()
@@ -129,18 +112,22 @@ func exportHandler(ctx context.Context, opts saveOptions) func() error {
}
}()
- for _, imageID := range opts.oriImgList {
+ for _, imageID := range opts.finalImageOrdered {
+ copyCtx := *opts.sysCtx
+ // It's ok for DockerArchiveAdditionalTags == nil, as a result, no additional tags will be appended to the final archive file.
+ copyCtx.DockerArchiveAdditionalTags = opts.finalImageSet[imageID]
+
exOpts := exporter.ExportOptions{
Ctx: ctx,
- SystemContext: opts.sysCtx,
+ SystemContext: &copyCtx,
ExportID: opts.saveID,
ReportWriter: opts.logger,
}
if err := exporter.Export(imageID, exporter.FormatTransport(opts.format, opts.outputPath),
exOpts, opts.localStore); err != nil {
- opts.logEntry.Errorf("Save Image %s output to %s failed with: %v", imageID, opts.format, err)
- return errors.Wrapf(err, "save Image %s output to %s failed", imageID, opts.format)
+ opts.logEntry.Errorf("Save image %q in format %q failed: %v", imageID, opts.format, err)
+ return errors.Wrapf(err, "save image %q in format %q failed", imageID, opts.format)
}
}
@@ -164,3 +151,59 @@ func messageHandler(stream pb.Control_SaveServer, cliLogger *logger.Logger) func
return nil
}
}
+
+func checkFormatAndExpandTag(opts *saveOptions) error {
+ switch opts.format {
+ case constant.DockerTransport:
+ opts.format = constant.DockerArchiveTransport
+ case constant.OCITransport:
+ opts.format = constant.OCIArchiveTransport
+ default:
+ return errors.New("wrong image format provided")
+ }
+
+ for i, imageName := range opts.oriImgList {
+ nameWithTag, err := image.CheckAndAddDefaultTag(imageName, opts.localStore)
+ if err != nil {
+ return errors.Wrapf(err, "check format and expand tag failed with image name %q", imageName)
+ }
+ opts.oriImgList[i] = nameWithTag
+ }
+
+ return nil
+}
+
+func filterImageName(opts *saveOptions) error {
+ if opts.format == constant.OCIArchiveTransport {
+ opts.finalImageOrdered = opts.oriImgList
+ return nil
+ }
+
+ visitedImage := make(map[string]bool)
+ for _, imageName := range opts.oriImgList {
+ if _, exists := visitedImage[imageName]; exists {
+ continue
+ }
+ visitedImage[imageName] = true
+
+ _, img, err := image.FindImageLocally(opts.localStore, imageName)
+ if err != nil {
+ return errors.Wrapf(err, "filter image name failed when finding image name %q", imageName)
+ }
+ if _, ok := opts.finalImageSet[img.ID]; !ok {
+ opts.finalImageOrdered = append(opts.finalImageOrdered, img.ID)
+ }
+
+ ref, err := reference.Parse(imageName)
+ if err != nil {
+ return errors.Wrapf(err, "filter image name failed when parsing name %q", imageName)
+ }
+ tagged, withTag := ref.(reference.NamedTagged)
+ if !withTag {
+ continue
+ }
+ opts.finalImageSet[img.ID] = append(opts.finalImageSet[img.ID], tagged)
+ }
+
+ return nil
+}
diff --git a/exporter/docker/archive/archive.go b/exporter/docker/archive/archive.go
index 04654cf..cc6b872 100644
--- a/exporter/docker/archive/archive.go
+++ b/exporter/docker/archive/archive.go
@@ -21,9 +21,7 @@ import (
"github.com/containers/image/v5/docker/archive"
"github.com/containers/image/v5/transports/alltransports"
"github.com/containers/image/v5/types"
- "github.com/docker/distribution/reference"
"github.com/pkg/errors"
- "github.com/sirupsen/logrus"
constant "isula.org/isula-build"
"isula.org/isula-build/exporter"
@@ -91,32 +89,13 @@ func (d *dockerArchiveExporter) Init(opts exporter.ExportOptions, src, destSpec
DockerArchiveExporter.InitArchiveWriter(opts.ExportID, archWriter)
}
- // There is a slightly difference between FindImageLocally and ParseImagesToReference to get a reference.
- // FindImageLocally or FindImage, both result a reference with a nil named field of *storageReference.
- // ParseImagesToReference returns a reference with non-nil named field of *storageReference that used to set destReference, if names is the format of name[:tag] with and without repository domain.
-
- // If using srcReferenceForDest to replace srcReference, When src is the format of name[:tag] without a registry domain name,
- // in which time, cp.Image() will be called and new image source will call imageMatchesRepo() to check If image matches repository or not.
- // ParseNormalizedNamed will finally called to add default docker.io/library/ prefix to name[:tag], return false result of the checking.
- // As a result, we will get error of no image matching reference found.
srcReference, _, err = image.FindImageLocally(localStore, src)
if err != nil {
return errors.Wrapf(err, "find src image: %q failed with transport %q", src, d.Name())
}
- imageReferenceForDest, _, err := image.ParseImagesToReference(localStore, []string{src})
- if err != nil {
- return errors.Wrapf(err, "parse image: %q to reference failed with transport %q", src, d.Name())
- }
archiveWriter := DockerArchiveExporter.GetArchiveWriter(opts.ExportID)
- nameAndTag, ok := imageReferenceForDest.DockerReference().(reference.NamedTagged)
- // src is the format of ImageID, ok is false
- if ok {
- destReference, err = archiveWriter.NewReference(nameAndTag)
- } else {
- logrus.Infof("Transform image reference failed, use nil instead")
- destReference, err = archiveWriter.NewReference(nil)
- }
+ destReference, err = archiveWriter.NewReference(nil)
if err != nil {
return errors.Wrapf(err, "parse dest spec: %q failed", destSpec)
}
diff --git a/image/image.go b/image/image.go
index e06d253..5ae7245 100644
--- a/image/image.go
+++ b/image/image.go
@@ -504,8 +504,6 @@ func FindImageLocally(store *store.Store, image string) (types.ImageReference, *
}
// ParseImagesToReference get the image reference in store
-// When names is the format of ImageID (sha256), return ref with nil named field of *storageReference
-// When names is the format of name[:tag] with and without repository domain, such as registry.example.com/name:tag, name:tag, return corresponding ref with non-nil named field of *storageReference with and without domain
func ParseImagesToReference(store *store.Store, names []string) (types.ImageReference, *storage.Image, error) {
var (
ref types.ImageReference
@@ -529,22 +527,6 @@ func ParseImagesToReference(store *store.Store, names []string) (types.ImageRefe
continue
}
img = img2
-
- // For support export archive file, we need provide reference.Named field when names is the format of name[:tag] not the image ID
- pRef, pErr := reference.Parse(name)
- if pErr != nil {
- return nil, nil, errors.Wrapf(pErr, "error parse name %q", name)
- }
- namedRef, isNamed := pRef.(reference.Named)
- if !isNamed {
- return nil, nil, errors.Errorf("reference %s has no name", pRef.String())
- }
-
- var nErr error
- ref, nErr = is.Transport.NewStoreReference(store, namedRef, img2.ID)
- if nErr != nil {
- return nil, nil, errors.Wrap(nErr, "error get reference from store")
- }
}
break
}
--
1.8.3.1

View File

@ -0,0 +1,281 @@
From 87c8603713cdcbd0f2abad29c73d3909b3f4c417 Mon Sep 17 00:00:00 2001
From: xingweizheng <xingweizheng@huawei.com>
Date: Tue, 24 Aug 2021 17:14:47 +0800
Subject: [PATCH 4/4] add integration test for saving one image with multiple
tags
---
Makefile | 1 +
tests/lib/common.sh | 8 +++
...gration_test_save_single_image_multiple_tags.sh | 58 ++++++++++++++++++++
tests/src/integration_test_set_new_root.sh | 62 ++++++++++++++++++++++
tests/src/test_integration_set_new_root.sh | 60 ---------------------
tests/test.sh | 9 ++--
6 files changed, 134 insertions(+), 64 deletions(-)
create mode 100644 tests/src/integration_test_save_single_image_multiple_tags.sh
create mode 100644 tests/src/integration_test_set_new_root.sh
delete mode 100644 tests/src/test_integration_set_new_root.sh
diff --git a/Makefile b/Makefile
index a9d4c93..1d87625 100644
--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,7 @@ test-unit:
.PHONY: test-integration
test-integration:
@echo "Integration test starting..."
+ @./tests/test.sh base
@./tests/test.sh integration
@echo "Integration test done!"
diff --git a/tests/lib/common.sh b/tests/lib/common.sh
index f393ee1..5e4c208 100755
--- a/tests/lib/common.sh
+++ b/tests/lib/common.sh
@@ -219,3 +219,11 @@ function show_and_run_command() {
fi
echo "PASS"
}
+
+function run_with_debug() {
+ if [ "${DEBUG:-0}" -eq 1 ]; then
+ $1
+ else
+ $1 > /dev/null 2>&1
+ fi
+}
\ No newline at end of file
diff --git a/tests/src/integration_test_save_single_image_multiple_tags.sh b/tests/src/integration_test_save_single_image_multiple_tags.sh
new file mode 100644
index 0000000..a25786a
--- /dev/null
+++ b/tests/src/integration_test_save_single_image_multiple_tags.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
+# isula-build licensed under the Mulan PSL v2.
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
+# You may obtain a copy of Mulan PSL v2 at:
+# http://license.coscl.org.cn/MulanPSL2
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# PURPOSE.
+# See the Mulan PSL v2 for more details.
+# Author: Weizheng Xing
+# Create: 2021-08-24
+# Description: check if saving single image with multiple tags has been corrected
+
+top_dir=$(git rev-parse --show-toplevel)
+# shellcheck disable=SC1091
+source "$top_dir"/tests/lib/common.sh
+
+image_name=add-chown-basic
+context_dir="$top_dir"/tests/data/add-chown-basic
+
+function clean()
+{
+ systemctl stop isula-build
+ rm -rf "$temp_tar"
+}
+
+function pre_test()
+{
+ temp_tar=$(mktemp -u --suffix=.tar)
+ systemctl restart isula-build
+}
+
+function do_test()
+{
+ if ! run_with_debug "isula-build ctr-img build -t $image_name:latest $context_dir"; then
+ echo "FAIL"
+ fi
+
+ if ! run_with_debug "isula-build ctr-img tag $image_name:latest $image_name:latest-child"; then
+ echo "FAIL"
+ fi
+
+ if ! run_with_debug "isula-build ctr-img save -f docker $image_name:latest $image_name:latest-child -o $temp_tar"; then
+ echo "FAIL"
+ fi
+
+ if ! run_with_debug "isula-build ctr-img rm $image_name:latest $image_name:latest-child"; then
+ echo "FAIL"
+ fi
+
+ echo "PASS"
+}
+
+pre_test
+do_test
+clean
diff --git a/tests/src/integration_test_set_new_root.sh b/tests/src/integration_test_set_new_root.sh
new file mode 100644
index 0000000..7238240
--- /dev/null
+++ b/tests/src/integration_test_set_new_root.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
+# isula-build licensed under the Mulan PSL v2.
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
+# You may obtain a copy of Mulan PSL v2 at:
+# http://license.coscl.org.cn/MulanPSL2
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# PURPOSE.
+# See the Mulan PSL v2 for more details.
+# Author: Weizheng Xing
+# Create: 2021-05-29
+# Description: test set new run and data root in configuration.toml
+
+top_dir=$(git rev-parse --show-toplevel)
+# shellcheck disable=SC1091
+source "$top_dir"/tests/lib/common.sh
+
+run_root="/var/run/new-isula-build"
+data_root="/var/lib/new-isula-build"
+config_file="/etc/isula-build/configuration.toml"
+base_image="hub.oepkgs.net/openeuler/openeuler:21.03"
+
+function clean()
+{
+ rm -f $config_file
+ mv "$config_file".bak $config_file
+ systemctl stop isula-build
+ rm -rf $run_root $data_root
+}
+
+# change to new data and run root
+function pre_test()
+{
+ cp $config_file "$config_file".bak
+ sed -i "/run_root/d;/data_root/d" $config_file
+ echo "run_root = \"${run_root}\"" >> $config_file
+ echo "data_root = \"${data_root}\"" >> $config_file
+
+ systemctl restart isula-build
+}
+
+# check if new resources are downloaded in new root
+function do_test()
+{
+ tree_node_befor=$(tree -L 3 $data_root | wc -l)
+ run_with_debug "isula-build ctr-img pull $base_image"
+ tree_node_after=$(tree -L 3 $data_root | wc -l)
+
+ if [ $((tree_node_after - tree_node_befor)) -eq 8 ] && run_with_debug "isula-build ctr-img rm $base_image"; then
+ echo "PASS"
+ else
+ echo "Sets of run and data root are not effective"
+ clean
+ exit 1
+ fi
+}
+
+pre_test
+do_test
+clean
diff --git a/tests/src/test_integration_set_new_root.sh b/tests/src/test_integration_set_new_root.sh
deleted file mode 100644
index 85b724a..0000000
--- a/tests/src/test_integration_set_new_root.sh
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
-# isula-build licensed under the Mulan PSL v2.
-# You can use this software according to the terms and conditions of the Mulan PSL v2.
-# You may obtain a copy of Mulan PSL v2 at:
-# http://license.coscl.org.cn/MulanPSL2
-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
-# PURPOSE.
-# See the Mulan PSL v2 for more details.
-# Author: Weizheng Xing
-# Create: 2021-05-29
-# Description: test set new run and data root in configuration.toml
-
-run_root="/var/run/new-isula-build"
-data_root="/var/lib/new-isula-build"
-config_file="/etc/isula-build/configuration.toml"
-base_image="hub.oepkgs.net/openeuler/openeuler:21.03"
-
-function clean()
-{
- isula-build ctr-img rm $base_image >/dev/null 2>&1
- rm -f $config_file
- mv "$config_file".bak $config_file
- systemctl stop isula-build
- rm -rf $run_root $data_root
-}
-
-# change to new data and run root
-function pre_test()
-{
- cp $config_file "$config_file".bak
- sed -i "/run_root/d;/data_root/d" $config_file
- echo "run_root = \"${run_root}\"" >> $config_file
- echo "data_root = \"${data_root}\"" >> $config_file
-
- systemctl restart isula-build
-}
-
-# check if new resources are downloaded in new root
-function do_test()
-{
- tree_node_befor=$(tree -L 3 $data_root | wc -l)
- isula-build ctr-img pull $base_image >/dev/null 2>&1
- tree_node_after=$(tree -L 3 $data_root | wc -l)
-
- if [ $(($tree_node_after - $tree_node_befor)) -eq 8 ]; then
- echo "PASS"
- else
- echo "Sets of run and data root are not effective"
- clean
- exit 1
- fi
-}
-
-# clean
-pre_test
-do_test
-clean
diff --git a/tests/test.sh b/tests/test.sh
index e04cc96..01f0f31 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -33,18 +33,17 @@ function fuzz() {
exit $failed
}
-# base test
+# integration test
function integration() {
source "$top_dir"/tests/lib/common.sh
- pre_check
systemctl restart isula-build
while IFS= read -r testfile; do
- printf "%-45s" "test $(basename "$testfile"): "
+ printf "%-65s" "test $(basename "$testfile"): "
if ! bash "$testfile"; then
exit 1
fi
- done < <(find "$top_dir"/tests/src -maxdepth 1 -name "test_integration*" -type f -print)
+ done < <(find "$top_dir"/tests/src -maxdepth 1 -name "integration_test*" -type f -print)
}
# main function to chose which kind of test
@@ -67,4 +66,6 @@ function main() {
}
export "ISULABUILD_CLI_EXPERIMENTAL"="enabled"
+export DEBUG=0
+
main "$@"
--
1.8.3.1

View File

@ -20,3 +20,7 @@ patch/0053-integration-test-from-new-flaw-of-run-and-data-root-.patch
patch/0054-isula-build-cleancode-for-errors.Wrap-function.patch
patch/0055-isula-build-change-isula-build-file-mode.patch
patch/0056-isula-build-update-documents-about-file-mode.patch
patch/0057-bugfix-pidofbuilder-do-not-set-when-running-a-new-ba.patch
patch/0058-shellcheck-fix-of-common.sh.patch
patch/0059-bugfix-fix-save-multiple-tags-single-image-failed.patch
patch/0060-add-integration-test-for-saving-one-image-with-multi.patch