-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: mv params parse and valid part to pkg package that client a…
…nd daemon can both use Signed-off-by: Michael Wan <zirenwan@gmail.com>
- Loading branch information
Showing
33 changed files
with
1,402 additions
and
864 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package mgr | ||
|
||
import ( | ||
"github.com/alibaba/pouch/apis/types" | ||
) | ||
|
||
// verifyContainerSetting is to verify the correctness of hostconfig and config. | ||
func (mgr *ContainerManager) verifyContainerSetting(hostConfig *types.HostConfig, config *types.ContainerConfig) error { | ||
if config != nil { | ||
// TODO | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package opts | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/alibaba/pouch/apis/types" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseDeviceMapping(t *testing.T) { | ||
type args struct { | ||
device []string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []*types.DeviceMapping | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "deviceMapping1", | ||
args: args{ | ||
device: []string{"/dev/deviceName:/dev/deviceName:mrw"}, | ||
}, | ||
want: []*types.DeviceMapping{{ | ||
PathOnHost: "/dev/deviceName", | ||
PathInContainer: "/dev/deviceName", | ||
CgroupPermissions: "mrw", | ||
}}, | ||
|
||
wantErr: false, | ||
}, | ||
{ | ||
name: "deviceMapping2", | ||
args: args{ | ||
device: []string{"/dev/deviceName:"}, | ||
}, | ||
want: []*types.DeviceMapping{{ | ||
PathOnHost: "/dev/deviceName", | ||
PathInContainer: "/dev/deviceName", | ||
CgroupPermissions: "rwm", | ||
}}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "deviceMappingWrong1", | ||
args: args{ | ||
device: []string{"/dev/deviceName:/dev/deviceName:rrw"}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "deviceMappingWrong2", | ||
args: args{ | ||
device: []string{"/dev/deviceName:/dev/deviceName:arw"}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "deviceMappingWrong3", | ||
args: args{ | ||
device: []string{"/dev/deviceName:/dev/deviceName:mrw:mrw"}, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ParseDeviceMappings(tt.args.device) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("parseDeviceMappings() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("parseDeviceMappings() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
type tDeviceModeCase struct { | ||
input string | ||
expected bool | ||
} | ||
|
||
type tParseDeviceCase struct { | ||
input string | ||
expected *types.DeviceMapping | ||
err error | ||
} | ||
|
||
func Test_parseDevice(t *testing.T) { | ||
for _, tc := range []tParseDeviceCase{ | ||
{ | ||
input: "/dev/zero:/dev/zero:rwm", | ||
expected: &types.DeviceMapping{ | ||
PathOnHost: "/dev/zero", | ||
PathInContainer: "/dev/zero", | ||
CgroupPermissions: "rwm", | ||
}, | ||
err: nil, | ||
}, { | ||
input: "/dev/zero:rwm", | ||
expected: &types.DeviceMapping{ | ||
PathOnHost: "/dev/zero", | ||
PathInContainer: "rwm", | ||
CgroupPermissions: "rwm", | ||
}, | ||
err: nil, | ||
}, { | ||
input: "/dev/zero", | ||
expected: &types.DeviceMapping{ | ||
PathOnHost: "/dev/zero", | ||
PathInContainer: "/dev/zero", | ||
CgroupPermissions: "rwm", | ||
}, | ||
err: nil, | ||
}, { | ||
input: "/dev/zero:/dev/testzero:rwm", | ||
expected: &types.DeviceMapping{ | ||
PathOnHost: "/dev/zero", | ||
PathInContainer: "/dev/testzero", | ||
CgroupPermissions: "rwm", | ||
}, | ||
err: nil, | ||
}, { | ||
input: "/dev/zero:/dev/testzero:rwm:tooLong", | ||
expected: nil, | ||
err: fmt.Errorf("invalid device specification: /dev/zero:/dev/testzero:rwm:tooLong"), | ||
}, | ||
} { | ||
output, err := parseDevice(tc.input) | ||
assert.Equal(t, tc.err, err, tc.input) | ||
assert.Equal(t, tc.expected, output, tc.input) | ||
} | ||
} | ||
|
||
func TestValidateDeviceMode(t *testing.T) { | ||
for _, modeCase := range []tDeviceModeCase{ | ||
{ | ||
input: "rwm", | ||
expected: true, | ||
}, { | ||
input: "r", | ||
expected: true, | ||
}, { | ||
input: "rw", | ||
expected: true, | ||
}, { | ||
input: "rr", | ||
expected: false, | ||
}, { | ||
input: "rxm", | ||
expected: false, | ||
}, | ||
} { | ||
isValid := ValidateDeviceMode(modeCase.input) | ||
assert.Equal(t, modeCase.expected, isValid, modeCase.input) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package opts | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ParseDiskQuota parses diskquota configurations of container. | ||
func ParseDiskQuota(quotas []string) (map[string]string, error) { | ||
var quotaMaps = make(map[string]string) | ||
|
||
for _, quota := range quotas { | ||
if quota == "" { | ||
return nil, fmt.Errorf("invalid format for disk quota: %s", quota) | ||
} | ||
|
||
parts := strings.Split(quota, "=") | ||
switch len(parts) { | ||
case 1: | ||
quotaMaps["/"] = parts[0] | ||
case 2: | ||
quotaMaps[parts[0]] = parts[1] | ||
default: | ||
return nil, fmt.Errorf("invalid format for disk quota: %s", quota) | ||
} | ||
} | ||
|
||
return quotaMaps, nil | ||
} | ||
|
||
// ValidateDiskQuota verifies diskquota configurations of container. | ||
func ValidateDiskQuota(quotaMaps map[string]string) error { | ||
// TODO | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package opts | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestParseDiskQuota(t *testing.T) { | ||
type args struct { | ||
diskquota []string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]string | ||
wantErr bool | ||
}{ | ||
// TODO: Add test cases. | ||
{name: "test1", args: args{diskquota: []string{""}}, want: nil, wantErr: true}, | ||
{name: "test2", args: args{diskquota: []string{"foo=foo=foo"}}, want: nil, wantErr: true}, | ||
{name: "test3", args: args{diskquota: []string{"foo"}}, want: map[string]string{"/": "foo"}, wantErr: false}, | ||
{name: "test3", args: args{diskquota: []string{"foo=foo"}}, want: map[string]string{"foo": "foo"}, wantErr: false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ParseDiskQuota(tt.args.diskquota) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ParseDiskQuota() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ParseDiskQuota() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package opts | ||
|
||
// ParseIntelRdt parses inter-rdt params of container | ||
func ParseIntelRdt(intelRdtL3Cbm string) (string, error) { | ||
// FIXME: add Intel RDT L3 Cbm validation | ||
return intelRdtL3Cbm, nil | ||
} | ||
|
||
// TODO: ValidateInterRdt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package opts | ||
|
||
import "testing" | ||
|
||
func TestParseIntelRdt(t *testing.T) { | ||
type args struct { | ||
intelRdtL3Cbm string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
// TODO: Add test cases. | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ParseIntelRdt(tt.args.intelRdtL3Cbm) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("parseIntelRdt() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("parseIntelRdt() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.