Skip to content

Commit

Permalink
Create branch with fix for Issue #557
Browse files Browse the repository at this point in the history
* cherry-picking code from forked repo
* #559

Co-authored-by: Mark Stokan <[email protected]>
Co-authored-by: claire tinati <[email protected]>
  • Loading branch information
markstokan and claire tinati committed Nov 9, 2022
1 parent dabcc50 commit 8e5d17c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
23 changes: 22 additions & 1 deletion api/director_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ type Networks struct {
}

type Network struct {
GUID string `yaml:"guid,omitempty"`
Name string `yaml:"name"`
Subnets []Subnet `yaml:"subnets,omitempty"`
Fields map[string]interface{} `yaml:",inline"`
}

type Subnet struct {
GUID string `yaml:"guid,omitempty"`
Name string `yaml:"name"`
CIDR string `yaml:"cidr"`
Fields map[string]interface{} `yaml:",inline"`
}

Expand Down Expand Up @@ -254,6 +261,7 @@ func (a Api) addGUIDToExistingNetworks(networks Networks) (Networks, error) {
for _, existingNetwork := range existingNetworks.Networks {
if network.Name == existingNetwork.Name {
network.GUID = existingNetwork.GUID
network.Subnets = a.addGUIDToExistingSubnet(network, existingNetwork)
break
}
}
Expand All @@ -262,6 +270,19 @@ func (a Api) addGUIDToExistingNetworks(networks Networks) (Networks, error) {
return networks, nil
}

func (a Api) addGUIDToExistingSubnet(network *Network, existingNetwork *Network) []Subnet {
for k, subnet := range network.Subnets {
for _, existingSubnet := range existingNetwork.Subnets {
if subnet.CIDR == existingSubnet.CIDR {
network.Subnets[k].GUID = existingSubnet.GUID
break
}
}
}

return network.Subnets
}

type IAASConfigurationsInput json.RawMessage

type IAASConfigurationsAPIPayload struct {
Expand Down
46 changes: 45 additions & 1 deletion api/director_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ var _ = Describe("Director", func() {
ghttp.RespondWith(http.StatusOK, `{
"networks": [{
"guid": "existing-network-guid",
"name": "existing-network"
"name": "existing-network",
"subnets": [{"guid": "existing-subnet-guid", "cidr":"10.0.0.0/24"}]
}]
}`),
),
Expand Down Expand Up @@ -533,6 +534,49 @@ var _ = Describe("Director", func() {
})
Expect(err).ToNot(HaveOccurred())
})

It("configures subnet and associates existing guids", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", "/api/v0/staged/director/networks"),
ghttp.VerifyJSON(`{
"icmp_checks_enabled":false,
"networks": [{
"name": "existing-network",
"guid": "existing-network-guid",
"subnets": [{"guid": "existing-subnet-guid", "cidr":"10.0.0.0/24"}]
}]
}`),
),
)

err := service.UpdateStagedDirectorNetworks(api.NetworkInput{
Networks: json.RawMessage(`{"icmp_checks_enabled":false, "networks": [{"name":"existing-network", "subnets": [{"guid": "existing-subnet-guid", "cidr":"10.0.0.0/24"}]}]}`),
})
Expect(err).ToNot(HaveOccurred())

})

It("configures subnets and associates existing guids and no guid for new subnet", func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("PUT", "/api/v0/staged/director/networks"),
ghttp.VerifyJSON(`{
"icmp_checks_enabled":false,
"networks": [{
"name": "existing-network",
"guid": "existing-network-guid",
"subnets": [{"guid": "existing-subnet-guid", "cidr":"10.0.0.0/24"}, {"cidr": "172.16.0.0/12"}]
}]
}`),
),
)

err := service.UpdateStagedDirectorNetworks(api.NetworkInput{
Networks: json.RawMessage(`{"icmp_checks_enabled":false, "networks": [{"name":"existing-network","subnets":[{"guid":"existing-subnet-guid","cidr":"10.0.0.0/24"},{"cidr":"172.16.0.0/12"}]}]}`),
})
Expect(err).ToNot(HaveOccurred())
})
})

Context("failure cases", func() {
Expand Down

0 comments on commit 8e5d17c

Please sign in to comment.