mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-09 12:59:17 +00:00
Use lsblk to detect partitions
like we did here: https://github.com/kairos-io/kairos-sdk/pull/28/files because ghw doesn't play well with lvm Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
@@ -40,14 +40,14 @@ var _ = Describe("Layout", Label("layout"), func() {
|
||||
Partitions: []*block.Partition{
|
||||
{
|
||||
Name: "device1",
|
||||
FilesystemLabel: "FAKE",
|
||||
FilesystemLabel: "FAKE1",
|
||||
Type: "ext4",
|
||||
MountPoint: "/mnt/fake",
|
||||
SizeBytes: 0,
|
||||
},
|
||||
{
|
||||
Name: "device2",
|
||||
FilesystemLabel: "FAKE",
|
||||
FilesystemLabel: "FAKE2",
|
||||
Type: "ext4",
|
||||
MountPoint: "/mnt/fake",
|
||||
SizeBytes: 0,
|
||||
@@ -65,7 +65,7 @@ var _ = Describe("Layout", Label("layout"), func() {
|
||||
|
||||
layout := schema.Layout{
|
||||
Device: &schema.Device{
|
||||
Label: "FAKE",
|
||||
Label: "FAKE1",
|
||||
Path: device,
|
||||
},
|
||||
Expand: &schema.Expand{Size: defaultSizeForTest},
|
||||
@@ -76,6 +76,9 @@ var _ = Describe("Layout", Label("layout"), func() {
|
||||
}
|
||||
|
||||
runner.SideEffect = func(command string, args ...string) ([]byte, error) {
|
||||
if command == "lsblk" && args[0] == "--list" {
|
||||
return lsblkMockOutput(), nil
|
||||
}
|
||||
if command == "parted" && args[4] == "unit" && args[5] == "s" && args[6] == "print" {
|
||||
/*
|
||||
|
||||
@@ -143,6 +146,9 @@ BYT;
|
||||
It("Fails if there is not enough space", func() {
|
||||
// Override runner side effect to return 0 sectors when asked
|
||||
runner.SideEffect = func(command string, args ...string) ([]byte, error) {
|
||||
if command == "lsblk" && args[0] == "--list" {
|
||||
return lsblkMockOutput(), nil
|
||||
}
|
||||
if command == "parted" && args[4] == "unit" && args[5] == "s" && args[6] == "print" {
|
||||
rtn := `
|
||||
BYT;
|
||||
@@ -166,6 +172,9 @@ BYT;
|
||||
It("Fails if new device didnt get created", func() {
|
||||
// Override runner side effect to return error when partition is recreated
|
||||
runner.SideEffect = func(command string, args ...string) ([]byte, error) {
|
||||
if command == "lsblk" && args[0] == "--list" {
|
||||
return lsblkMockOutput(), nil
|
||||
}
|
||||
if command == "parted" && args[4] == "unit" && args[5] == "s" && args[6] == "print" {
|
||||
rtn := `
|
||||
BYT;
|
||||
@@ -189,6 +198,9 @@ BYT;
|
||||
It("Fails if new device didnt get created, even when command didnt return an error", func() {
|
||||
// Override runner side effect to return error when partition is recreated
|
||||
runner.SideEffect = func(command string, args ...string) ([]byte, error) {
|
||||
if command == "lsblk" && args[0] == "--list" {
|
||||
return lsblkMockOutput(), nil
|
||||
}
|
||||
if command == "parted" && args[4] == "unit" && args[5] == "s" && args[6] == "print" {
|
||||
rtn := `
|
||||
BYT;
|
||||
@@ -215,6 +227,9 @@ BYT;
|
||||
Describe("Add partitions", Label("add", "partitions"), func() {
|
||||
BeforeEach(func() {
|
||||
runner.SideEffect = func(command string, args ...string) ([]byte, error) {
|
||||
if command == "lsblk" && args[0] == "--list" {
|
||||
return lsblkMockOutput(), nil
|
||||
}
|
||||
if command == "parted" && args[4] == "unit" && args[5] == "s" && args[6] == "print" {
|
||||
rtn := `
|
||||
BYT;
|
||||
@@ -235,7 +250,7 @@ BYT;
|
||||
|
||||
layout := schema.Layout{
|
||||
Device: &schema.Device{
|
||||
Label: "FAKE",
|
||||
Label: "FAKE1",
|
||||
Path: device,
|
||||
},
|
||||
Parts: []schema.Partition{
|
||||
@@ -251,6 +266,9 @@ BYT;
|
||||
Layout: layout,
|
||||
}
|
||||
runner.SideEffect = func(command string, args ...string) ([]byte, error) {
|
||||
if command == "lsblk" && args[0] == "--list" {
|
||||
return lsblkMockOutput(), nil
|
||||
}
|
||||
if command == "parted" && args[4] == "unit" && args[5] == "s" && args[6] == "print" {
|
||||
rtn := `
|
||||
BYT;
|
||||
@@ -303,7 +321,7 @@ BYT;
|
||||
|
||||
layout := schema.Layout{
|
||||
Device: &schema.Device{
|
||||
Label: "FAKE",
|
||||
Label: "FAKE1",
|
||||
Path: device,
|
||||
},
|
||||
Parts: partitions,
|
||||
@@ -324,6 +342,10 @@ BYT;
|
||||
createdPartitions := []partitionData{}
|
||||
|
||||
runner.SideEffect = func(command string, args ...string) ([]byte, error) {
|
||||
if command == "lsblk" && args[0] == "--list" {
|
||||
return lsblkMockOutput(), nil
|
||||
}
|
||||
|
||||
if command == "parted" && args[4] == "unit" && args[5] == "s" && args[6] == "print" {
|
||||
rtn := `
|
||||
BYT;
|
||||
@@ -401,3 +423,37 @@ BYT;
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
func lsblkMockOutput() []byte {
|
||||
return []byte(`{ "blockdevices":
|
||||
[
|
||||
{
|
||||
"name": "device",
|
||||
"pkname": "",
|
||||
"path": "/dev/device",
|
||||
"fstype": "",
|
||||
"mountpoint": "",
|
||||
"size": 0,
|
||||
"ro": false,
|
||||
"label": ""
|
||||
},{
|
||||
"name": "device1",
|
||||
"pkname": "device",
|
||||
"path": "/dev/device1",
|
||||
"fstype": "ext4",
|
||||
"mountpoint": "/mnt/fake1",
|
||||
"size": 0,
|
||||
"ro": false,
|
||||
"label": "FAKE1"
|
||||
},{
|
||||
"name": "device2",
|
||||
"pkname": "device",
|
||||
"path": "/dev/device2",
|
||||
"fstype": "ext4",
|
||||
"mountpoint": "/mnt/fake2",
|
||||
"size": 0,
|
||||
"ro": false,
|
||||
"label": "FAKE2"
|
||||
}
|
||||
]}`)
|
||||
}
|
||||
|
Reference in New Issue
Block a user