diff --git a/.conform.yaml b/.conform.yaml index 1272d85..ba8797d 100644 --- a/.conform.yaml +++ b/.conform.yaml @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2021-11-15T13:22:12Z by kres c4d092b. +# Generated on 2022-03-28T13:15:04Z by kres 8bc4139-dirty. --- policies: @@ -10,7 +10,7 @@ policies: gpg: required: true identity: - gitHubOrganization: talos-systems + gitHubOrganization: siderolabs spellcheck: locale: US maximumOfOneCommit: true diff --git a/Makefile b/Makefile index ed9b3c7..380e722 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2021-11-15T13:22:12Z by kres c4d092b. +# Generated on 2022-03-28T13:15:04Z by kres 8bc4139-dirty. # common variables @@ -9,7 +9,7 @@ TAG := $(shell git describe --tag --always --dirty) BRANCH := $(shell git rev-parse --abbrev-ref HEAD) ARTIFACTS := _out REGISTRY ?= ghcr.io -USERNAME ?= talos-systems +USERNAME ?= siderolabs REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME) GOFUMPT_VERSION ?= abc0db2c416aca0f60ea33c23c76665f6e7ba0b6 GO_VERSION ?= 1.17 @@ -18,7 +18,7 @@ GRPC_GO_VERSION ?= 1.1.0 GRPC_GATEWAY_VERSION ?= 2.4.0 VTPROTOBUF_VERSION ?= 81d623a9a700ede8ef765e5ab08b3aa1f5b4d5a8 TESTPKGS ?= ./... -KRES_IMAGE ?= ghcr.io/talos-systems/kres:latest +KRES_IMAGE ?= ghcr.io/siderolabs/kres:latest # docker build settings diff --git a/blockdevice/probe/probe.go b/blockdevice/probe/probe.go index cfddf79..3208a8e 100644 --- a/blockdevice/probe/probe.go +++ b/blockdevice/probe/probe.go @@ -43,11 +43,10 @@ func WithPartitionLabel(label string) SelectOption { } } -// WithFileSystemLabel search for a block device which has filesystem on root level -// and that filesystem is labeled as provided label. +// WithFileSystemLabel searches for a block device which has filesystem labeled with the provided label. func WithFileSystemLabel(label string) SelectOption { return func(device *ProbedBlockDevice) (bool, error) { - superblock, err := filesystem.Probe(device.Device().Name()) + superblock, err := filesystem.Probe(device.Path) if err != nil { return false, err } diff --git a/blockdevice/probe/probe_test.go b/blockdevice/probe/probe_test.go index 2eabbf4..ad6c700 100644 --- a/blockdevice/probe/probe_test.go +++ b/blockdevice/probe/probe_test.go @@ -5,13 +5,13 @@ package probe_test import ( + "errors" "os" "os/exec" "testing" "github.com/stretchr/testify/suite" - "github.com/talos-systems/go-blockdevice/blockdevice" "github.com/talos-systems/go-blockdevice/blockdevice/partition/gpt" "github.com/talos-systems/go-blockdevice/blockdevice/probe" "github.com/talos-systems/go-blockdevice/blockdevice/test" @@ -26,7 +26,18 @@ func (suite *ProbeSuite) SetupTest() { } func (suite *ProbeSuite) addPartition(name string, size uint64) *gpt.Partition { - g, err := gpt.New(suite.Dev) + var ( + g *gpt.GPT + err error + ) + + g, err = gpt.Open(suite.Dev) + if errors.Is(err, gpt.ErrPartitionTableDoesNotExist) { + g, err = gpt.New(suite.Dev) + } else if err == nil { + err = g.Read() + } + suite.Require().NoError(err) partition, err := g.Add(size, gpt.WithPartitionName(name)) @@ -34,9 +45,6 @@ func (suite *ProbeSuite) addPartition(name string, size uint64) *gpt.Partition { suite.Require().NoError(g.Write()) - _, err = blockdevice.Open(suite.LoopbackDevice.Name()) - suite.Require().NoError(err) - partPath, err := partition.Path() suite.Require().NoError(err) @@ -84,7 +92,7 @@ func (suite *ProbeSuite) TestGetDevWithFileSystemLabel() { func (suite *ProbeSuite) TestProbeByPartitionLabel() { size := uint64(1024 * 1024 * 256) suite.addPartition("test", size) - suite.addPartition("test", size) + suite.addPartition("test2", size) probed, err := probe.All(probe.WithPartitionLabel("test")) suite.Require().NoError(err) @@ -93,6 +101,30 @@ func (suite *ProbeSuite) TestProbeByPartitionLabel() { suite.Require().Equal(suite.LoopbackDevice.Name(), probed[0].Device().Name()) } +func (suite *ProbeSuite) TestProbeByFilesystemLabelBlockdevice() { + suite.setSystemLabel("FSLBABELBD") + + probed, err := probe.All(probe.WithFileSystemLabel("FSLBABELBD")) + suite.Require().NoError(err) + suite.Require().Equal(1, len(probed)) + + suite.Require().Equal(suite.LoopbackDevice.Name(), probed[0].Device().Name()) + suite.Require().Equal(suite.LoopbackDevice.Name(), probed[0].Path) +} + +func (suite *ProbeSuite) TestProbeByFilesystemLabelPartition() { + size := uint64(1024 * 1024 * 256) + suite.addPartition("FOO", size) + suite.addPartition("FSLABELPART", size) + + probed, err := probe.All(probe.WithFileSystemLabel("FSLABELPART")) + suite.Require().NoError(err) + suite.Require().Equal(1, len(probed)) + + suite.Require().Equal(suite.LoopbackDevice.Name(), probed[0].Device().Name()) + suite.Require().Equal(suite.LoopbackDevice.Name()+"p2", probed[0].Path) +} + func TestProbe(t *testing.T) { if os.Getuid() != 0 { t.Skip("can't run the test as non-root") diff --git a/hack/release.sh b/hack/release.sh index 6cfa253..9e5ad9e 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -2,11 +2,11 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2021-11-15T13:22:12Z by kres c4d092b. +# Generated on 2022-03-28T13:13:16Z by kres 8bc4139-dirty. set -e -RELEASE_TOOL_IMAGE="ghcr.io/talos-systems/release-tool:latest" +RELEASE_TOOL_IMAGE="ghcr.io/siderolabs/release-tool:latest" function release-tool { docker pull "${RELEASE_TOOL_IMAGE}" >/dev/null