-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the allocator interface to prevent allocation of still in used pc…
…i addresses Fixes: #219 Signed-off-by: Sebastian Sch <sebassch@gmail.com>
- Loading branch information
Showing
6 changed files
with
153 additions
and
17 deletions.
There are no files selected for viewing
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
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,60 @@ | ||
package utils | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/containernetworking/plugins/pkg/ns" | ||
"github.com/containernetworking/plugins/pkg/testutils" | ||
) | ||
|
||
var _ = Describe("PCIAllocator", func() { | ||
var targetNetNS ns.NetNS | ||
var err error | ||
|
||
AfterEach(func() { | ||
if targetNetNS != nil { | ||
targetNetNS.Close() | ||
testutils.UnmountNS(targetNetNS) | ||
} | ||
}) | ||
|
||
Context("IsAllocated", func() { | ||
It("Assuming is not allocated", func() { | ||
allocator := NewPCIAllocator(ts.dirRoot) | ||
isAllocated, err := allocator.IsAllocated("0000:af:00.1") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(isAllocated).To(BeFalse()) | ||
}) | ||
|
||
It("Assuming is allocated and namespace exist", func() { | ||
targetNetNS, err = testutils.NewNS() | ||
Expect(err).NotTo(HaveOccurred()) | ||
allocator := NewPCIAllocator(ts.dirRoot) | ||
|
||
err = allocator.SaveAllocatedPCI("0000:af:00.1", targetNetNS.Path()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
isAllocated, err := allocator.IsAllocated("0000:af:00.1") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(isAllocated).To(BeTrue()) | ||
}) | ||
|
||
It("Assuming is allocated and namespace doesn't exist", func() { | ||
targetNetNS, err = testutils.NewNS() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
allocator := NewPCIAllocator(ts.dirRoot) | ||
err = allocator.SaveAllocatedPCI("0000:af:00.1", targetNetNS.Path()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
err = targetNetNS.Close() | ||
Expect(err).ToNot(HaveOccurred()) | ||
err = testutils.UnmountNS(targetNetNS) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
isAllocated, err := allocator.IsAllocated("0000:af:00.1") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(isAllocated).To(BeFalse()) | ||
}) | ||
}) | ||
}) |
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