host-local: return error if duplicate allocation is requested for a given ID

Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
This commit is contained in:
Bruce Ma
2019-07-06 10:05:18 +08:00
parent eb1ff18c4c
commit e2984e7840
2 changed files with 30 additions and 46 deletions

View File

@ -299,40 +299,28 @@ var _ = Describe("host-local Operations", func() {
Expect(result0.IPs[0].Address.String()).Should(Equal("10.1.2.2/24"))
// Allocate the IP with the same container ID
r1, raw, err := testutils.CmdAddWithArgs(args, func() error {
_, _, err = testutils.CmdAddWithArgs(args, func() error {
return cmdAdd(args)
})
Expect(err).To(HaveOccurred())
// Allocate the IP with the another container ID
r1, raw, err := testutils.CmdAddWithArgs(args1, func() error {
return cmdAdd(args1)
})
Expect(err).NotTo(HaveOccurred())
Expect(strings.Index(string(raw), "\"version\":")).Should(BeNumerically(">", 0))
result1, err := current.GetResult(r1)
Expect(err).NotTo(HaveOccurred())
Expect(len(result1.IPs)).Should(Equal(1))
Expect(result1.IPs[0].Address.String()).Should(Equal("10.1.2.2/24"))
// Allocate the IP with the another container ID
r2, raw, err := testutils.CmdAddWithArgs(args1, func() error {
return cmdAdd(args1)
})
Expect(err).NotTo(HaveOccurred())
Expect(strings.Index(string(raw), "\"version\":")).Should(BeNumerically(">", 0))
result2, err := current.GetResult(r2)
Expect(err).NotTo(HaveOccurred())
Expect(len(result2.IPs)).Should(Equal(1))
Expect(result2.IPs[0].Address.String()).Should(Equal("10.1.2.3/24"))
Expect(result1.IPs[0].Address.String()).Should(Equal("10.1.2.3/24"))
// Allocate the IP with the same container ID again
r3, raw, err := testutils.CmdAddWithArgs(args, func() error {
_, _, err = testutils.CmdAddWithArgs(args, func() error {
return cmdAdd(args)
})
Expect(err).NotTo(HaveOccurred())
Expect(strings.Index(string(raw), "\"version\":")).Should(BeNumerically(">", 0))
result3, err := current.GetResult(r3)
Expect(err).NotTo(HaveOccurred())
Expect(len(result3.IPs)).Should(Equal(1))
Expect(result3.IPs[0].Address.String()).Should(Equal("10.1.2.2/24"))
Expect(err).To(HaveOccurred())
ipFilePath := filepath.Join(tmpDir, "mynet0", "10.1.2.2")