Add go API for /services/dhcp/leases

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
Christophe Fergeau
2025-09-24 16:06:24 +02:00
parent dc117b2e31
commit 976f29d2d4
4 changed files with 48 additions and 0 deletions

View File

@@ -117,3 +117,20 @@ func (c *Client) AddDNS(req *types.Zone) error {
}
return nil
}
func (c *Client) ListDHCPLeases() (map[string]string, error) {
res, err := c.client.Get(fmt.Sprintf("%s%s", c.base, "/services/dhcp/leases"))
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status: %d", res.StatusCode)
}
dec := json.NewDecoder(res.Body)
var leases map[string]string
if err := dec.Decode(&leases); err != nil {
return nil, err
}
return leases, nil
}

View File

@@ -20,6 +20,13 @@ var _ = ginkgo.Describe("dns with qemu", func() {
})
})
var _ = ginkgo.Describe("dhcp with qemu", func() {
e2e.BasicDHCPTests(e2e.BasicTestProps{
SSHExec: sshExec,
Sock: sock,
})
})
var _ = ginkgo.Describe("command-line format", func() {
ginkgo.It("should convert Command to command line format", func() {
command := types.NewGvproxyCommand()

View File

@@ -31,6 +31,13 @@ var _ = ginkgo.Describe("dns with vfkit", func() {
})
})
var _ = ginkgo.Describe("dhcp with vfkit", func() {
e2e.BasicDHCPTests(e2e.BasicTestProps{
SSHExec: sshExec,
Sock: sock,
})
})
var _ = ginkgo.Describe("upload and download with vfkit", func() {
tmpDir, err := os.MkdirTemp("", "vfkit")
gomega.Expect(err).NotTo(gomega.HaveOccurred())

View File

@@ -52,6 +52,23 @@ func BasicConnectivityTests(props BasicTestProps) {
})
}
func BasicDHCPTests(props BasicTestProps) {
ginkgo.It("should return DHCP leases", func() {
client := gvproxyclient.New(&http.Client{
Transport: &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", props.Sock)
},
},
}, "http://base")
leases, err := client.ListDHCPLeases()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(leases).Should(gomega.HaveKeyWithValue("192.168.127.1", "5a:94:ef:e4:0c:dd"))
gomega.Expect(leases).Should(gomega.HaveKeyWithValue("192.168.127.2", "5a:94:ef:e4:0c:ee"))
})
}
func BasicDNSTests(props BasicTestProps) {
ginkgo.It("should resolve redhat.com", func() {
out, err := props.SSHExec("nslookup redhat.com")