|
| 1 | +package restserver |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/netip" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/Azure/azure-container-networking/cns" |
| 9 | + "github.com/Azure/azure-container-networking/cns/common" |
| 10 | + "github.com/Azure/azure-container-networking/cns/fakes" |
| 11 | + "github.com/Azure/azure-container-networking/cns/nodesubnet" |
| 12 | + acn "github.com/Azure/azure-container-networking/common" |
| 13 | + "github.com/Azure/azure-container-networking/nmagent" |
| 14 | + "github.com/Azure/azure-container-networking/store" |
| 15 | +) |
| 16 | + |
| 17 | +// GetRestServiceObjectForNodeSubnetTest creates a new HTTPRestService object for use in nodesubnet unit tests. |
| 18 | +func GetRestServiceObjectForNodeSubnetTest(t *testing.T, generator CNIConflistGenerator) *HTTPRestService { |
| 19 | + config := &common.ServiceConfig{ |
| 20 | + Name: "test", |
| 21 | + Version: "1.0", |
| 22 | + ChannelMode: "AzureHost", |
| 23 | + Store: store.NewMockStore("test"), |
| 24 | + } |
| 25 | + interfaces := nmagent.Interfaces{ |
| 26 | + Entries: []nmagent.Interface{ |
| 27 | + { |
| 28 | + MacAddress: nmagent.MACAddress{0x00, 0x0D, 0x3A, 0xF9, 0xDC, 0xA6}, |
| 29 | + IsPrimary: true, |
| 30 | + InterfaceSubnets: []nmagent.InterfaceSubnet{ |
| 31 | + { |
| 32 | + Prefix: "10.0.0.0/24", |
| 33 | + IPAddress: []nmagent.NodeIP{ |
| 34 | + { |
| 35 | + Address: nmagent.IPAddress(netip.AddrFrom4([4]byte{10, 0, 0, 4})), |
| 36 | + IsPrimary: true, |
| 37 | + }, |
| 38 | + { |
| 39 | + Address: nmagent.IPAddress(netip.AddrFrom4([4]byte{10, 0, 0, 52})), |
| 40 | + IsPrimary: false, |
| 41 | + }, |
| 42 | + { |
| 43 | + Address: nmagent.IPAddress(netip.AddrFrom4([4]byte{10, 0, 0, 63})), |
| 44 | + IsPrimary: false, |
| 45 | + }, |
| 46 | + { |
| 47 | + Address: nmagent.IPAddress(netip.AddrFrom4([4]byte{10, 0, 0, 45})), |
| 48 | + IsPrimary: false, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | + } |
| 56 | + |
| 57 | + svc, err := cns.NewService(config.Name, config.Version, config.ChannelMode, config.Store) |
| 58 | + if err != nil { |
| 59 | + return nil |
| 60 | + } |
| 61 | + |
| 62 | + svc.SetOption(acn.OptCnsURL, "") |
| 63 | + svc.SetOption(acn.OptCnsPort, "") |
| 64 | + err = svc.Initialize(config) |
| 65 | + if err != nil { |
| 66 | + return nil |
| 67 | + } |
| 68 | + |
| 69 | + t.Cleanup(func() { svc.Uninitialize() }) |
| 70 | + |
| 71 | + return &HTTPRestService{ |
| 72 | + Service: svc, |
| 73 | + cniConflistGenerator: generator, |
| 74 | + state: &httpRestServiceState{}, |
| 75 | + PodIPConfigState: make(map[string]cns.IPConfigurationStatus), |
| 76 | + PodIPIDByPodInterfaceKey: make(map[string][]string), |
| 77 | + nma: &fakes.NMAgentClientFake{ |
| 78 | + GetInterfaceIPInfoF: func(_ context.Context) (nmagent.Interfaces, error) { |
| 79 | + return interfaces, nil |
| 80 | + }, |
| 81 | + }, |
| 82 | + wscli: &fakes.WireserverClientFake{}, |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +// GetNodesubnetIPFetcher gets the nodesubnetIPFetcher from the HTTPRestService. |
| 87 | +func (service *HTTPRestService) GetNodesubnetIPFetcher() *nodesubnet.IPFetcher { |
| 88 | + return service.nodesubnetIPFetcher |
| 89 | +} |
0 commit comments