From 3d44d104dae867299bd59235ab3878bb3e9f00f8 Mon Sep 17 00:00:00 2001 From: Andrew Jeddeloh Date: Thu, 10 May 2018 10:27:10 -0700 Subject: [PATCH] tests: add more tests for partitioning --- tests/negative/partitions/simple.go | 151 +++++++++++++ tests/negative/partitions/zeroes.go | 95 +++++++++ tests/positive/partitions/complex.go | 170 +++++++++++++++ tests/positive/partitions/creation.go | 155 +++++++++----- tests/positive/partitions/deletion.go | 127 +++++++++++ tests/positive/partitions/mixed.go | 215 +++++++++++++++++++ tests/positive/partitions/no-op.go | 105 +++++++++ tests/positive/partitions/verification.go | 186 ++++++++++++++++ tests/positive/partitions/zeros.go | 246 ++++++++++++++++++++++ tests/registry/registry.go | 1 + 10 files changed, 1397 insertions(+), 54 deletions(-) create mode 100644 tests/negative/partitions/simple.go create mode 100644 tests/negative/partitions/zeroes.go create mode 100644 tests/positive/partitions/complex.go create mode 100644 tests/positive/partitions/deletion.go create mode 100644 tests/positive/partitions/mixed.go create mode 100644 tests/positive/partitions/no-op.go create mode 100644 tests/positive/partitions/verification.go create mode 100644 tests/positive/partitions/zeros.go diff --git a/tests/negative/partitions/simple.go b/tests/negative/partitions/simple.go new file mode 100644 index 0000000000..a4f34d4b39 --- /dev/null +++ b/tests/negative/partitions/simple.go @@ -0,0 +1,151 @@ +// Copyright 2018 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package partitions + +import ( + "github.com/coreos/ignition/tests/register" + "github.com/coreos/ignition/tests/types" +) + +func init() { + // Tests that have do not involve zeros + register.Register(register.NegativeTest, ShouldNotExistNoWipeEntry()) + register.Register(register.NegativeTest, DoesNotMatchNoWipeEntry()) + register.Register(register.NegativeTest, ValidAndDoesNotMatchNoWipeEntry()) + register.Register(register.NegativeTest, NotThereAndDoesNotMatchNoWipeEntry()) +} + +func ShouldNotExistNoWipeEntry() types.Test { + name := "Partition should not exist but wipePartitionEntry is false" + in := types.GetBaseDisk() + out := in + config := `{ + "ignition": {"version": "2.3.0-experimental"}, + "storage": { + "disks": [ + { + "device": "$disk0", + "partitions": [ + { + "number": 9, + "shouldExist": false + } + ] + } + ] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func DoesNotMatchNoWipeEntry() types.Test { + name := "Partition does not match and wipePartitionEntry is false" + in := types.GetBaseDisk() + out := in + config := `{ + "ignition": {"version": "2.3.0-experimental"}, + "storage": { + "disks": [ + { + "device": "$disk0", + "partitions": [ + { + "number": 9, + "size": 4096 + } + ] + } + ] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func ValidAndDoesNotMatchNoWipeEntry() types.Test { + name := "Partition does not match and wipePartitionEntry is false but the first partition matches" + in := types.GetBaseDisk() + out := in + config := `{ + "ignition": {"version": "2.3.0-experimental"}, + "storage": { + "disks": [ + { + "device": "$disk0", + "partitions": [ + { + "number": 1 + }, + { + "number": 9, + "size": 4096 + } + ] + } + ] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func NotThereAndDoesNotMatchNoWipeEntry() types.Test { + name := "Partition does not match and wipePartitionEntry is false but a partition matches not existing" + in := types.GetBaseDisk() + out := in + config := `{ + "ignition": {"version": "2.3.0-experimental"}, + "storage": { + "disks": [ + { + "device": "$disk0", + "partitions": [ + { + "number": 10, + "shouldExist": false + }, + { + "number": 9, + "size": 4096 + } + ] + } + ] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} diff --git a/tests/negative/partitions/zeroes.go b/tests/negative/partitions/zeroes.go new file mode 100644 index 0000000000..c5b3ad67b1 --- /dev/null +++ b/tests/negative/partitions/zeroes.go @@ -0,0 +1,95 @@ +// Copyright 2018 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package partitions + +import ( + "github.com/coreos/ignition/tests/register" + "github.com/coreos/ignition/tests/types" +) + +func init() { + // Tests that involve zeros + register.Register(register.NegativeTest, Partition9DoesNotFillDisk()) + register.Register(register.NegativeTest, Partition9DoesNotStartCorrectly()) +} + +func Partition9DoesNotFillDisk() types.Test { + name := "Partition 9 is size 0 but does not fill the disk" + in := types.GetBaseDisk() + in[0].Partitions = append(in[0].Partitions, &types.Partition{ + Number: 10, + Length: 65536, + }) + out := in + config := `{ + "ignition": {"version": "2.3.0-experimental"}, + "storage": { + "disks": [ + { + "device": "$disk0", + "partitions": [ + { + "number": 9, + "size": 0 + } + ] + } + ] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func Partition9DoesNotStartCorrectly() types.Test { + name := "Partition 9 does not start at the largest chunk" + in := types.GetBaseDisk() + //insert a gap before 9 + tmp := in[0].Partitions[9-2-1] + in[0].Partitions[9-2-1] = &types.Partition{ + Number: 10, + Length: 65536, + } + in[0].Partitions = append(in[0].Partitions, tmp) + out := in + config := `{ + "ignition": {"version": "2.3.0-experimental"}, + "storage": { + "disks": [ + { + "device": "$disk0", + "partitions": [ + { + "number": 9, + "start": 0 + } + ] + } + ] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} diff --git a/tests/positive/partitions/complex.go b/tests/positive/partitions/complex.go new file mode 100644 index 0000000000..c28415b246 --- /dev/null +++ b/tests/positive/partitions/complex.go @@ -0,0 +1,170 @@ +// Copyright 2018 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package partitions + +import ( + "github.com/coreos/ignition/tests/register" + "github.com/coreos/ignition/tests/types" +) + +func init() { + // Everything and the kitchen sink + register.Register(register.PositiveTest, KitchenSink()) +} + +func KitchenSink() types.Test { + name := "Complex partitioning case" + in := types.GetBaseDisk() + out := types.GetBaseDisk() + // Ignition should not clobber by default, so omit the partition 5 entry + config := `{ + "ignition": { + "version": "2.3.0-experimental" + }, + "storage": { + "disks": [{ + "device": "$disk1", + "wipeTable": false, + "partitions": [ + { + "label": "p1", + "number": 1, + "start": 2048, + "size": 65536, + "typeGuid": "316f19f9-9e0f-431e-859e-ae6908dbe8ca", + "guid": "53f2e871-f468-437c-b90d-f3c6409df81a", + "wipePartitionEntry": true + }, + { + "label": "dont-delete", + "number": 2, + "size": 65536 + }, + { + "label": "new-biggest", + "number": 3, + "size": 0, + "start": 0, + "typeGuid": "6050e8fc-1e31-473b-bcc0-714e32fcb09d", + "guid": "f14984bc-6f08-4885-b668-526263469a00", + "wipePartitionEntry": true + }, + { + "number": 4, + "shouldExist": false, + "wipePartitionEntry": true + }, + { + "number": 9, + "shouldExist": false + } + ] + }] + } + }` + + in = append(in, types.Disk{ + Alignment: types.IgnitionAlignment, + Partitions: types.Partitions{ + { + Label: "p1", + Number: 1, + Length: 131072, + TypeGUID: "316f19f9-9e0f-431e-859e-ae6908dbe8ca", + GUID: "3ED3993F-0016-422B-B134-09FCBA6F66EF", + }, + { + Label: "dont-delete", + Number: 2, + Length: 65536, + TypeGUID: "F39C522B-9966-4429-A8F8-417CD5D83E5E", + GUID: "26cc1e6a-39a2-4502-a957-28f8e0ac00e7", + }, + { + Label: "garbo-town", + Number: 3, + Length: 65536, + TypeGUID: "9dfde6db-a308-497b-9f8c-55db12d4d9a1", + GUID: "115ee54b-00bd-4afe-be9b-bf1912dec92d", + }, + { + TypeCode: "blank", + Length: 131072, + }, + { + Label: "more-junk", + Number: 4, + Length: 65536, + TypeGUID: "ee378f79-6b7a-4f7a-8029-7a5736d12bbf", + GUID: "5e89fa40-183c-4346-b2e1-2f10fa2190e1", + }, + { + Label: "dont-delete2", + Number: 5, + Length: 65536, + TypeGUID: "9dd1a91a-a39a-4594-b431-60a7fb630bcb", + GUID: "39baf7ef-cb3e-4343-8bfc-c2391b8b5607", + }, + { + TypeCode: "blank", + Length: 131072, + }, + }, + }) + out = append(out, types.Disk{ + Alignment: types.IgnitionAlignment, + Partitions: types.Partitions{ + { + Label: "p1", + Number: 1, + Length: 65536, + TypeGUID: "316f19f9-9e0f-431e-859e-ae6908dbe8ca", + GUID: "53f2e871-f468-437c-b90d-f3c6409df81a", + }, + { + Label: "dont-delete", + Number: 2, + Length: 65536, + TypeGUID: "F39C522B-9966-4429-A8F8-417CD5D83E5E", + GUID: "26cc1e6a-39a2-4502-a957-28f8e0ac00e7", + }, + { + Label: "new-biggest", + Number: 3, + Length: 262144, + TypeGUID: "6050e8fc-1e31-473b-bcc0-714e32fcb09d", + GUID: "f14984bc-6f08-4885-b668-526263469a00", + }, + { + Label: "dont-delete2", + Number: 5, + Length: 65536, + TypeGUID: "9dd1a91a-a39a-4594-b431-60a7fb630bcb", + GUID: "39baf7ef-cb3e-4343-8bfc-c2391b8b5607", + }, + { + TypeCode: "blank", + Length: 131072, + }, + }, + }) + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} diff --git a/tests/positive/partitions/creation.go b/tests/positive/partitions/creation.go index 714ee246c7..06f1572dee 100644 --- a/tests/positive/partitions/creation.go +++ b/tests/positive/partitions/creation.go @@ -20,39 +20,87 @@ import ( ) func init() { - register.Register(register.PositiveTest, CreateNewPartitions()) - register.Register(register.PositiveTest, AppendPartition()) - register.Register(register.PositiveTest, PartitionSizeStart0()) + // Tests that just create partitions with no 0s + register.Register(register.PositiveTest, CreatePartition()) + register.Register(register.PositiveTest, WipeAndCreateNewPartitions()) + register.Register(register.PositiveTest, AppendPartitions()) + register.Register(register.PositiveTest, ResizeRoot()) } -func CreateNewPartitions() types.Test { +func CreatePartition() types.Test { + name := "Create a single partition on a blank disk" + in := append(types.GetBaseDisk(), types.Disk{Alignment: types.IgnitionAlignment}) + out := append(types.GetBaseDisk(), types.Disk{ + Alignment: types.IgnitionAlignment, + Partitions: types.Partitions{ + { + Label: "create-partition", + Number: 1, + Length: 65536, + TypeGUID: "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", + GUID: "05AE8178-224E-4744-862A-4F4B042662D0", + }, + }, + }) + config := `{ + "ignition": { + "version": "2.1.0" + }, + "storage": { + "disks": [ + { + "device": "$disk1", + "partitions": [ + { + "number": 1, + "size": 65536, + "label": "create-partition", + "typeGuid": "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", + "guid": "05AE8178-224E-4744-862A-4F4B042662D0" + } + ] + } + ] + } + }` + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func WipeAndCreateNewPartitions() types.Test { name := "Create new partitions" in := types.GetBaseDisk() out := types.GetBaseDisk() config := `{ - "ignition": {"version": "2.1.0"}, + "ignition": { + "version": "2.1.0" + }, "storage": { - "disks": [ - { - "device": "$disk1", - "wipeTable": true, - "partitions": [ - { - "label": "important-data", - "number": 1, - "size": 65536, - "typeGuid": "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", - "guid": "8A7A6E26-5E8F-4CCA-A654-46215D4696AC" - }, - { - "label": "ephemeral-data", - "number": 2, - "size": 131072, - "typeGuid": "CA7D7CCB-63ED-4C53-861C-1742536059CC", - "guid": "A51034E6-26B3-48DF-BEED-220562AC7AD1" - } - ] + "disks": [ + { + "device": "$disk1", + "wipeTable": true, + "partitions": [ + { + "label": "important-data", + "number": 1, + "size": 65536, + "typeGuid": "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", + "guid": "8A7A6E26-5E8F-4CCA-A654-46215D4696AC" + }, + { + "label": "ephemeral-data", + "number": 2, + "size": 131072, + "typeGuid": "CA7D7CCB-63ED-4C53-861C-1742536059CC", + "guid": "A51034E6-26B3-48DF-BEED-220562AC7AD1" } + ] + } ] } }` @@ -106,7 +154,7 @@ func CreateNewPartitions() types.Test { } } -func AppendPartition() types.Test { +func AppendPartitions() types.Test { name := "Append partition to an existing partition table" in := types.GetBaseDisk() out := types.GetBaseDisk() @@ -124,6 +172,13 @@ func AppendPartition() types.Test { "size": 65536, "typeGuid": "F39C522B-9966-4429-A8F8-417CD5D83E5E", "guid": "3ED3993F-0016-422B-B134-09FCBA6F66EF" + }, + { + "label": "additional-partition2", + "number": 4, + "size": 65536, + "typeGuid": "F39C522B-9966-4429-A8F8-417CD5D83E5E", + "guid": "accedd09-76c2-4363-9893-f5689a78c47f" }] }] } @@ -172,6 +227,13 @@ func AppendPartition() types.Test { TypeGUID: "F39C522B-9966-4429-A8F8-417CD5D83E5E", GUID: "3ED3993F-0016-422B-B134-09FCBA6F66EF", }, + { + Label: "additional-partition2", + Number: 4, + Length: 65536, + TypeGUID: "F39C522B-9966-4429-A8F8-417CD5D83E5E", + GUID: "accedd09-76c2-4363-9893-f5689a78c47f", + }, }, }) @@ -183,46 +245,31 @@ func AppendPartition() types.Test { } } -func PartitionSizeStart0() types.Test { - name := "Create a partition with size and start 0" +func ResizeRoot() types.Test { + name := "Resize the ROOT partition to be bigger" in := types.GetBaseDisk() out := types.GetBaseDisk() + out[0].Partitions[9-2-1].Length = 12943360 + 65536 config := `{ "ignition": { - "version": "2.1.0" + "version": "2.3.0-experimental" }, "storage": { "disks": [{ - "device": "$disk1", - "wipeTable": false, + "device": "$disk0", "partitions": [{ - "label": "fills-disk", - "number": 1, - "start": 0, - "size": 0, - "typeGuid": "F39C522B-9966-4429-A8F8-417CD5D83E5E", - "guid": "3ED3993F-0016-422B-B134-09FCBA6F66EF" - }] + "label": "ROOT", + "number": 9, + "size": 13008896, + "typeGuid": "3884DD41-8582-4404-B9A8-E9B84F2DF50E", + "guid": "3ED3993F-0016-422B-B134-09FCBA6F66EF", + "wipePartitionEntry": true + } + ] }] } }` - in = append(in, types.Disk{ - Alignment: types.IgnitionAlignment, - }) - out = append(out, types.Disk{ - Alignment: types.IgnitionAlignment, - Partitions: types.Partitions{ - { - Label: "fills-disk", - Number: 1, - Length: 65536, - TypeGUID: "F39C522B-9966-4429-A8F8-417CD5D83E5E", - GUID: "3ED3993F-0016-422B-B134-09FCBA6F66EF", - }, - }, - }) - return types.Test{ Name: name, In: in, diff --git a/tests/positive/partitions/deletion.go b/tests/positive/partitions/deletion.go new file mode 100644 index 0000000000..814577f8fb --- /dev/null +++ b/tests/positive/partitions/deletion.go @@ -0,0 +1,127 @@ +// Copyright 2018 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package partitions + +import ( + "github.com/coreos/ignition/tests/register" + "github.com/coreos/ignition/tests/types" +) + +func init() { + // Tests that deletes partition(s) + register.Register(register.PositiveTest, DeleteOne()) + register.Register(register.PositiveTest, DeleteAll()) +} + +func DeleteOne() types.Test { + name := "Delete single partition" + in := append(types.GetBaseDisk(), types.Disk{ + Alignment: types.IgnitionAlignment, + Partitions: types.Partitions{ + { + Label: "deleteme", + Number: 1, + Length: 65536, + }, + }, + }) + out := append(types.GetBaseDisk(), types.Disk{Alignment: types.IgnitionAlignment}) + config := `{ + "ignition": { + "version": "2.3.0-experimental" + }, + "storage": { + "disks": [ + { + "device": "$disk1", + "partitions": [ + { + "number": 1, + "shouldExist": false, + "wipePartitionEntry": true + } + ] + } + ] + } + }` + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func DeleteAll() types.Test { + name := "Delete all partitions on a disk" + in := append(types.GetBaseDisk(), types.GetBaseDisk()...) + out := append(types.GetBaseDisk(), types.Disk{Alignment: types.IgnitionAlignment}) + config := `{ + "ignition": { + "version": "2.3.0-experimental" + }, + "storage": { + "disks": [ + { + "device": "$disk1", + "partitions": [ + { + "number": 1, + "shouldExist": false, + "wipePartitionEntry": true + }, + { + "number": 2, + "shouldExist": false, + "wipePartitionEntry": true + }, + { + "number": 3, + "shouldExist": false, + "wipePartitionEntry": true + }, + { + "number": 4, + "shouldExist": false, + "wipePartitionEntry": true + }, + { + "number": 6, + "shouldExist": false, + "wipePartitionEntry": true + }, + { + "number": 7, + "shouldExist": false, + "wipePartitionEntry": true + }, + { + "number": 9, + "shouldExist": false, + "wipePartitionEntry": true + } + ] + } + ] + } + }` + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} diff --git a/tests/positive/partitions/mixed.go b/tests/positive/partitions/mixed.go new file mode 100644 index 0000000000..466e95e8f2 --- /dev/null +++ b/tests/positive/partitions/mixed.go @@ -0,0 +1,215 @@ +// Copyright 2018 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package partitions + +import ( + "github.com/coreos/ignition/tests/register" + "github.com/coreos/ignition/tests/types" +) + +func init() { + // Tests that mix verification, wipePartitionEntry, deletion, and creation, but + // do not use any zero semantics. See complex.go if you want to enter that madness + register.Register(register.PositiveTest, Match1Recreate1Delete1Create1()) + register.Register(register.PositiveTest, NothingMatches()) +} + +func Match1Recreate1Delete1Create1() types.Test { + name := "Match 1, recreate 2, delete 3, add 4" + in := append(types.GetBaseDisk(), types.Disk{ + Alignment: types.IgnitionAlignment, + Partitions: types.Partitions{ + { + Label: "important-data", + Number: 1, + Length: 65536, + TypeGUID: "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", + GUID: "8A7A6E26-5E8F-4CCA-A654-46215D4696AC", + }, + { + Label: "ephemeral-data", + Number: 2, + Length: 65536, + TypeGUID: "CA7D7CCB-63ED-4C53-861C-1742536059CC", + GUID: "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", + }, + { + Label: "bunch-of-junk", + Number: 3, + Length: 131072, + TypeGUID: "CA7D7CCB-63ED-4C53-861C-1742536059CC", + GUID: "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", + }, + }, + }) + out := append(types.GetBaseDisk(), types.Disk{ + Alignment: types.IgnitionAlignment, + Partitions: types.Partitions{ + { + Label: "important-data", + Number: 1, + Length: 65536, + }, + { + Label: "ephemeral-data", + Number: 2, + Length: 131072, + }, + { + Label: "even-more-data", + Number: 4, + Length: 65536, + }, + }, + }) + config := `{ + "ignition": { + "version": "2.3.0-experimental" + }, + "storage": { + "disks": [ + { + "device": "$disk1", + "partitions": [ + { + "label": "important-data", + "number": 1, + "start": 2048, + "size": 65536 + }, + { + "label": "ephemeral-data", + "number": 2, + "start": 67584, + "size": 131072, + "wipePartitionEntry": true + }, + { + "number": 3, + "shouldExist": false, + "wipePartitionEntry": true + }, + { + "label": "even-more-data", + "number": 4, + "start": 198656, + "size": 65536 + } + ] + } + ] + } + }` + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func NothingMatches() types.Test { + name := "Recreate all three partitions because nothing matches" + // partition 1 has the wrong type guid, 2 has the wrong guid and 3 has the wrong size and label + // there's a test in complex.go that is similar, but 1 has the wrong size and thus everything + // gets moved around (with start/size 0) + in := append(types.GetBaseDisk(), types.Disk{ + Alignment: types.IgnitionAlignment, + Partitions: types.Partitions{ + { + Label: "important-data", + Number: 1, + Length: 65536, + TypeGUID: "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", + }, + { + Label: "ephemeral-data", + Number: 2, + Length: 65536, + GUID: "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", + }, + { + Label: "bunch-of-junk", + Number: 3, + Length: 131072, + }, + }, + }) + out := append(types.GetBaseDisk(), types.Disk{ + Alignment: types.IgnitionAlignment, + Partitions: types.Partitions{ + { + Label: "important-data", + Number: 1, + Length: 65536, + TypeGUID: "0921B045-1DF0-41C3-AF44-4C6F280D3FAE", + }, + { + Label: "ephemeral-data", + Number: 2, + Length: 65536, + GUID: "0921B045-1DF0-41C3-AF44-4C6F280D3FAE", + }, + { + Label: "even-more-data", + Number: 3, + Length: 65536, + }, + }, + }) + config := `{ + "ignition": { + "version": "2.3.0-experimental" + }, + "storage": { + "disks": [ + { + "device": "$disk1", + "partitions": [ + { + "label": "important-data", + "number": 1, + "start": 2048, + "size": 65536, + "wipePartitionEntry": true, + "typeGuid": "0921B045-1DF0-41C3-AF44-4C6F280D3FAE" + }, + { + "label": "ephemeral-data", + "number": 2, + "start": 67584, + "size": 65536, + "wipePartitionEntry": true, + "guid": "0921B045-1DF0-41C3-AF44-4C6F280D3FAE" + }, + { + "label": "even-more-data", + "number": 3, + "start": 133120, + "size": 65536, + "wipePartitionEntry": true + } + ] + } + ] + } + }` + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} diff --git a/tests/positive/partitions/no-op.go b/tests/positive/partitions/no-op.go new file mode 100644 index 0000000000..8ff65b9c7d --- /dev/null +++ b/tests/positive/partitions/no-op.go @@ -0,0 +1,105 @@ +// Copyright 2018 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package partitions + +import ( + "github.com/coreos/ignition/tests/register" + "github.com/coreos/ignition/tests/types" +) + +func init() { + // Tests that do nothing + register.Register(register.PositiveTest, DoNothing()) + register.Register(register.PositiveTest, SpecifiedNonexistent()) +} + +func DoNothing() types.Test { + name := "Do nothing when told to add no partitions" + in := types.GetBaseDisk() + out := types.GetBaseDisk() + config := `{ + "ignition": { + "version": "2.0.0" + }, + "storage": { + "disks": [ + { + "device": "$disk0" + } + ] + } + }` + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func SpecifiedNonexistent() types.Test { + name := "Verify partitions with shouldexist=false do not get created" + in := append(types.GetBaseDisk(), types.Disk{Alignment: types.IgnitionAlignment}) + out := append(types.GetBaseDisk(), types.Disk{Alignment: types.IgnitionAlignment}) + config := `{ + "ignition": { + "version": "2.3.0-experimental" + }, + "storage": { + "disks": [ + { + "device": "$disk0", + "partitions": [ + { + "number": 10, + "shouldExist": false + }, + { + "number": 11, + "shouldExist": false + }, + { + "number": 999, + "shouldExist": false + } + ] + }, + { + "device": "$disk1", + "partitions": [ + { + "number": 1, + "shouldExist": false + }, + { + "number": 11, + "shouldExist": false + }, + { + "number": 999, + "shouldExist": false + } + ] + } + ] + } + }` + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} diff --git a/tests/positive/partitions/verification.go b/tests/positive/partitions/verification.go new file mode 100644 index 0000000000..7298edbf5d --- /dev/null +++ b/tests/positive/partitions/verification.go @@ -0,0 +1,186 @@ +// Copyright 2018 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package partitions + +import ( + "github.com/coreos/ignition/tests/register" + "github.com/coreos/ignition/tests/types" +) + +func init() { + // Tests the verify existing partitions but do not create new ones + register.Register(register.PositiveTest, VerifyBaseDisk()) + register.Register(register.PositiveTest, VerifyBaseDiskWithWipe()) +} + +func VerifyBaseDisk() types.Test { + name := "Verify the base disk does not change with a matching ignition spec" + in := types.GetBaseDisk() + out := types.GetBaseDisk() + config := `{ + "ignition": { + "version": "2.1.0" + }, + "storage": { + "disks": [{ + "device": "$disk0", + "partitions": [ + { + "label": "EFI-SYSTEM", + "number": 1, + "start": 4096, + "size": 262144, + "typeGuid": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" + }, + { + "label": "BIOS-BOOT", + "number": 2, + "start": 266240, + "size": 4096, + "typeGuid": "21686148-6449-6E6F-744E-656564454649" + }, + { + "label": "USR-A", + "number": 3, + "start": 270336, + "size": 2097152, + "typeGuid": "5dfbf5f4-2848-4bac-aa5e-0d9a20b745a6", + "guid": "7130c94a-213a-4e5a-8e26-6cce9662f132" + }, + { + "label": "USR-B", + "number": 4, + "start": 2367488, + "size": 2097152, + "typeGuid": "5dfbf5f4-2848-4bac-aa5e-0d9a20b745a6", + "guid": "e03dd35c-7c2d-4a47-b3fe-27f15780a57c" + }, + { + "label": "OEM", + "number": 6, + "start": 4464640, + "size": 262144, + "typeGuid": "0FC63DAF-8483-4772-8E79-3D69D8477DE4" + }, + { + "label": "OEM-CONFIG", + "number": 7, + "start": 4726784, + "size": 131072, + "typeGuid": "c95dc21a-df0e-4340-8d7b-26cbfa9a03e0" + }, + { + "label": "ROOT", + "number": 9, + "start": 4857856, + "size": 12943360, + "typeGuid": "3884dd41-8582-4404-b9a8-e9b84f2df50e" + } + ] + }] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func VerifyBaseDiskWithWipe() types.Test { + name := "Verify the base disk does not change with a matching ignition spec with wipePartitionEntry as true" + in := types.GetBaseDisk() + out := types.GetBaseDisk() + // guid from USR-A is removed so if it does try to recreate partitions, it will assign a random + // one and fail the test. + config := `{ + "ignition": { + "version": "2.3.0-experimental" + }, + "storage": { + "disks": [{ + "device": "$disk0", + "partitions": [ + { + "label": "EFI-SYSTEM", + "number": 1, + "start": 4096, + "size": 262144, + "wipePartitionEntry": true, + "typeGuid": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" + }, + { + "label": "BIOS-BOOT", + "number": 2, + "start": 266240, + "size": 4096, + "wipePartitionEntry": true, + "typeGuid": "21686148-6449-6E6F-744E-656564454649" + }, + { + "label": "USR-A", + "number": 3, + "start": 270336, + "size": 2097152, + "wipePartitionEntry": true, + "typeGuid": "5dfbf5f4-2848-4bac-aa5e-0d9a20b745a6" + }, + { + "label": "USR-B", + "number": 4, + "start": 2367488, + "size": 2097152, + "wipePartitionEntry": true, + "typeGuid": "5dfbf5f4-2848-4bac-aa5e-0d9a20b745a6", + "guid": "e03dd35c-7c2d-4a47-b3fe-27f15780a57c" + }, + { + "label": "OEM", + "number": 6, + "start": 4464640, + "size": 262144, + "wipePartitionEntry": true, + "typeGuid": "0FC63DAF-8483-4772-8E79-3D69D8477DE4" + }, + { + "label": "OEM-CONFIG", + "number": 7, + "start": 4726784, + "size": 131072, + "wipePartitionEntry": true, + "typeGuid": "c95dc21a-df0e-4340-8d7b-26cbfa9a03e0" + }, + { + "label": "ROOT", + "number": 9, + "start": 4857856, + "size": 12943360, + "wipePartitionEntry": true, + "typeGuid": "3884dd41-8582-4404-b9a8-e9b84f2df50e" + } + ] + }] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} diff --git a/tests/positive/partitions/zeros.go b/tests/positive/partitions/zeros.go new file mode 100644 index 0000000000..e093013643 --- /dev/null +++ b/tests/positive/partitions/zeros.go @@ -0,0 +1,246 @@ +// Copyright 2018 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package partitions + +import ( + "github.com/coreos/ignition/tests/register" + "github.com/coreos/ignition/tests/types" +) + +func init() { + // Tests that just create partitions and involve 0s + register.Register(register.PositiveTest, PartitionSizeStart0()) + register.Register(register.PositiveTest, PartitionStartNumber0()) + register.Register(register.PositiveTest, ResizeRootFillDisk()) + register.Register(register.PositiveTest, VerifyRootFillsDisk()) + register.Register(register.PositiveTest, VerifyUnspecifiedIsDoNotCare()) +} + +func PartitionSizeStart0() types.Test { + name := "Create a partition with size and start 0" + in := types.GetBaseDisk() + out := types.GetBaseDisk() + config := `{ + "ignition": { + "version": "2.1.0" + }, + "storage": { + "disks": [{ + "device": "$disk1", + "wipeTable": false, + "partitions": [{ + "label": "fills-disk", + "number": 1, + "start": 0, + "size": 0, + "typeGuid": "F39C522B-9966-4429-A8F8-417CD5D83E5E", + "guid": "3ED3993F-0016-422B-B134-09FCBA6F66EF" + }] + }] + } + }` + + in = append(in, types.Disk{ + Alignment: types.IgnitionAlignment, + }) + out = append(out, types.Disk{ + Alignment: types.IgnitionAlignment, + Partitions: types.Partitions{ + { + Label: "fills-disk", + Number: 1, + Length: 65536, + TypeGUID: "F39C522B-9966-4429-A8F8-417CD5D83E5E", + GUID: "3ED3993F-0016-422B-B134-09FCBA6F66EF", + }, + }, + }) + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func PartitionStartNumber0() types.Test { + name := "Create a partition with number and start 0" + in := types.GetBaseDisk() + out := types.GetBaseDisk() + config := `{ + "ignition": { + "version": "2.1.0" + }, + "storage": { + "disks": [{ + "device": "$disk1", + "wipeTable": false, + "partitions": [{ + "label": "uno", + "size": 65536, + "typeGuid": "F39C522B-9966-4429-A8F8-417CD5D83E5E", + "guid": "3ED3993F-0016-422B-B134-09FCBA6F66EF" + }, + { + "label": "dos", + "size": 65536, + "typeGuid": "F39C522B-9966-4429-A8F8-417CD5D83E5E", + "guid": "6A6BD6B9-4345-4AFB-974E-08D5A343E8F8" + }, + { + "label": "tres", + "size": 65536, + "typeGuid": "F39C522B-9966-4429-A8F8-417CD5D83E5E", + "guid": "FE6108DC-096A-4E62-83CB-A11CE9D8E633" + }] + }] + } + }` + + in = append(in, types.Disk{ + Alignment: types.IgnitionAlignment, + }) + out = append(out, types.Disk{ + Alignment: types.IgnitionAlignment, + Partitions: types.Partitions{ + { + Label: "uno", + Number: 1, + Length: 65536, + TypeGUID: "F39C522B-9966-4429-A8F8-417CD5D83E5E", + GUID: "3ED3993F-0016-422B-B134-09FCBA6F66EF", + }, + { + Label: "dos", + Number: 2, + Length: 65536, + TypeGUID: "F39C522B-9966-4429-A8F8-417CD5D83E5E", + GUID: "6A6BD6B9-4345-4AFB-974E-08D5A343E8F8", + }, + { + Label: "tres", + Number: 3, + Length: 65536, + TypeGUID: "F39C522B-9966-4429-A8F8-417CD5D83E5E", + GUID: "FE6108DC-096A-4E62-83CB-A11CE9D8E633", + }, + }, + }) + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func ResizeRootFillDisk() types.Test { + name := "Resize the ROOT partition to fill the disk" + in := types.GetBaseDisk() + out := types.GetBaseDisk() + out[0].Partitions[9-2-1].Length = 12943360 + 65536 + config := `{ + "ignition": { + "version": "2.3.0-experimental" + }, + "storage": { + "disks": [{ + "device": "$disk0", + "partitions": [{ + "label": "ROOT", + "number": 9, + "start": 0, + "size": 0, + "typeGuid": "3884DD41-8582-4404-B9A8-E9B84F2DF50E", + "wipePartitionEntry": true + } + ] + }] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func VerifyRootFillsDisk() types.Test { + name := "Verify the ROOT partition to fills the default disk" + in := types.GetBaseDisk() + out := in + config := `{ + "ignition": { + "version": "2.3.0-experimental" + }, + "storage": { + "disks": [{ + "device": "$disk0", + "partitions": [{ + "label": "ROOT", + "number": 9, + "start": 0, + "size": 0, + "typeGuid": "3884DD41-8582-4404-B9A8-E9B84F2DF50E" + } + ] + }] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} + +func VerifyUnspecifiedIsDoNotCare() types.Test { + name := "Verify the ROOT partition to fills the default disk" + in := types.GetBaseDisk() + in[0].Partitions = append(in[0].Partitions, &types.Partition{ + TypeCode: "blank", + Length: 65536, + }) + out := types.GetBaseDisk() + config := `{ + "ignition": { + "version": "2.3.0-experimental" + }, + "storage": { + "disks": [{ + "device": "$disk0", + "partitions": [{ + "label": "ROOT", + "number": 9, + "typeGuid": "3884DD41-8582-4404-B9A8-E9B84F2DF50E" + } + ] + }] + } + }` + + return types.Test{ + Name: name, + In: in, + Out: out, + Config: config, + } +} diff --git a/tests/registry/registry.go b/tests/registry/registry.go index d995f53a4c..4a65ca49bf 100644 --- a/tests/registry/registry.go +++ b/tests/registry/registry.go @@ -20,6 +20,7 @@ import ( _ "github.com/coreos/ignition/tests/negative/filesystems" _ "github.com/coreos/ignition/tests/negative/general" _ "github.com/coreos/ignition/tests/negative/networkd" + _ "github.com/coreos/ignition/tests/negative/partitions" _ "github.com/coreos/ignition/tests/negative/regression" _ "github.com/coreos/ignition/tests/negative/security" _ "github.com/coreos/ignition/tests/negative/timeouts"