Skip to content

Commit

Permalink
Merge pull request #95 from simplysoft/fix/node-networks
Browse files Browse the repository at this point in the history
fix node network deserialization
  • Loading branch information
luthermonson committed Oct 17, 2023
2 parents 37d0caa + 50cd9d4 commit d86c043
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 4 deletions.
30 changes: 29 additions & 1 deletion nodes_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestNetwork(t *testing.T) {
assert.Equal(t, network.Iface, "vmbr0")
}

func TestNetworks(t *testing.T) {
func TestNode1Networks(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
client := mockClient()
Expand All @@ -34,3 +34,31 @@ func TestNetworks(t *testing.T) {
assert.Nil(t, err)
assert.Len(t, networks, 2)
}

func TestNode2Networks(t *testing.T) {
mocks.On(mockConfig)
defer mocks.Off()
client := mockClient()
node := Node{
client: client,
Name: "node2",
}

networks, err := node.Networks()
assert.Nil(t, err)
assert.Len(t, networks, 2)
}

func TestNetworksPve8(t *testing.T) {
mocks.ProxmoxVE8x(mockConfig)
defer mocks.Off()
client := mockClient()
node := Node{
client: client,
Name: "node1",
}

networks, err := node.Networks()
assert.Nil(t, err)
assert.Len(t, networks, 5)
}
6 changes: 6 additions & 0 deletions tests/mocks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/luthermonson/go-proxmox/tests/mocks/config"
"github.com/luthermonson/go-proxmox/tests/mocks/pve6x"
"github.com/luthermonson/go-proxmox/tests/mocks/pve7x"
"github.com/luthermonson/go-proxmox/tests/mocks/pve8x"
)

func On(c config.Config) {
Expand All @@ -15,6 +16,11 @@ func Off() {
gock.Off()
}

func ProxmoxVE8x(c config.Config) {
config.C = c
pve8x.Load()
}

func ProxmoxVE7x(c config.Config) {
config.C = c
pve7x.Load()
Expand Down
58 changes: 58 additions & 0 deletions tests/mocks/pve7x/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,62 @@ func nodes() {
}
}`)

gock.New(config.C.URI).
Persist().
Get("^/nodes/node2/network$").
Reply(200).
JSON(`{
"data": [
{
"bridge_vlan_aware": 1,
"method6": "static",
"bridge_vids": "2-4094",
"address": "192.168.1.10",
"bridge_stp": "off",
"families": [
"inet",
"inet6"
],
"mtu": "1500",
"bridge_ports": "enp8s0",
"iface": "vmbr2",
"netmask": "24",
"method": "static",
"type": "bridge",
"bridge_fd": "0",
"cidr6": "fd66:5ac3:eeaf:3200::10/64",
"active": 1,
"cidr": "192.168.1.10/24",
"address6": "fd66:5ac3:eeaf:3200::10",
"comments": "comment\n",
"autostart": 1,
"priority": 9,
"netmask6": "64"
},
{
"active": 1,
"cidr6": "fd66:5ac3:eeaf::10/64",
"address6": "fd66:5ac3:eeaf::10",
"comments": "comment\n",
"autostart": 1,
"priority": 11,
"cidr": "192.168.0.10/24",
"netmask6": "64",
"vlan-raw-device": "vmbr0",
"exists": null,
"method6": "static",
"address": "192.168.0.10",
"families": [
"inet",
"inet6"
],
"iface": "vmbr0.2",
"netmask": "24",
"method": "static",
"vlan-id": "2",
"type": "vlan"
}
]
}`)

}
109 changes: 109 additions & 0 deletions tests/mocks/pve8x/nodes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package pve8x

import (
"github.com/h2non/gock"
"github.com/luthermonson/go-proxmox/tests/mocks/config"
)

func nodes() {
gock.New(config.C.URI).
Persist().
Get("^/nodes/node1/network$").
Reply(200).
JSON(`{
"data": [
{
"method": "manual",
"method6": "manual",
"priority": 20,
"families": [
"inet"
],
"type": "eth",
"exists": 1,
"iface": "eno1"
},
{
"netmask": "32",
"priority": 16,
"families": [
"inet"
],
"address": "192.168.2.50",
"cidr": "192.168.2.50/32",
"vlan-raw-device": "eno1",
"vlan-id": "2",
"iface": "eno1.2",
"autostart": 1,
"exists": 1,
"options": [
"metric 200"
],
"method6": "manual",
"method": "static",
"type": "vlan",
"comments": "Some Comment\n",
"active": 1
},
{
"iface": "vmbr1",
"bridge_fd": "0",
"autostart": 1,
"bridge_ports": "eno1.2 vmbr2.10",
"priority": 31,
"families": [
"inet"
],
"bridge_vids": "2-4094",
"active": 1,
"bridge_stp": "off",
"bridge_vlan_aware": 1,
"type": "bridge",
"comments": "some comment\n",
"method6": "manual",
"method": "manual"
},
{
"options": [
"metric 100"
],
"exists": null,
"iface": "vmbr2.2",
"autostart": 1,
"vlan-id": "2",
"vlan-raw-device": "vmbr2",
"cidr": "192.168.22.31/24",
"address": "192.168.22.31",
"priority": 33,
"families": [
"inet"
],
"netmask": "24",
"active": 1,
"type": "vlan",
"method": "static",
"method6": "manual"
},
{
"families": [
"inet"
],
"priority": 35,
"netmask": "24",
"cidr": "172.16.20.1/24",
"vlan-raw-device": "vmbr2",
"address": "172.20.0.1",
"iface": "vmbr2.8",
"exists": null,
"autostart": 1,
"vlan-id": "8",
"method": "static",
"method6": "manual",
"comments": "Some Network\n",
"type": "vlan",
"active": 1
}
]
}`)

}
5 changes: 5 additions & 0 deletions tests/mocks/pve8x/proxmox.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package pve8x

func Load() {
nodes()
}
6 changes: 3 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,12 +823,12 @@ type NodeNetwork struct {
CIDR6 string `json:"cidr6,omitempty"`
Gateway string `json:"gateway,omitempty"`
Gateway6 string `json:"gateway6,omitempty"`
MTU int `json:"mtu,omitempty"`
MTU string `json:"mtu,omitempty"`
Netmask string `json:"netmask,omitempty"`
Netmask6 string `json:"netmask6,omitempty"`
VLANID int `json:"vlan-id,omitempty"`
VLANID string `json:"vlan-id,omitempty"`
VLANRawDevice string `json:"vlan-raw-device,omitempty"`
BridgeVLANAware bool `json:"bridge_vlan_aware,omitempty"`
BridgeVLANAware int `json:"bridge_vlan_aware,omitempty"`
BridgePorts string `json:"bridge_ports,omitempty"`
BridgeStp string `json:"bridge_stp,omitempty"` // not in current docs, deprecated?
BridgeFd string `json:"bridge_fd,omitempty"` // not in current docs, deprecated?
Expand Down

0 comments on commit d86c043

Please sign in to comment.