Skip to content

Commit

Permalink
Removes unused method OpenedApplicationPortRangesByEndpoint from uniter
Browse files Browse the repository at this point in the history
API client.
  • Loading branch information
manadart committed Oct 2, 2023
1 parent c51b666 commit 254d8b2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 79 deletions.
29 changes: 0 additions & 29 deletions api/agent/uniter/uniter.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,35 +434,6 @@ func (st *State) OpenedPortRangesByEndpoint() (map[names.UnitTag]network.Grouped
return processOpenPortRangesByEndpointResults(results, st.unitTag)
}

// OpenedApplicationPortRangesByEndpoint returns all port ranges currently open for the given
// application, grouped by application endpoint.
func (st *State) OpenedApplicationPortRangesByEndpoint(appTag names.ApplicationTag) (network.GroupedPortRanges, error) {
if st.BestAPIVersion() < 18 {
// OpenedApplicationPortRangesByEndpoint() was introduced in UniterAPIV18.
return nil, errors.NotImplementedf("OpenedApplicationPortRangesByEndpoint() (need V18+)")
}
arg := params.Entity{Tag: appTag.String()}
var result params.ApplicationOpenedPortsResults
if err := st.facade.FacadeCall("OpenedApplicationPortRangesByEndpoint", arg, &result); err != nil {
return nil, errors.Trace(err)
}
if len(result.Results) != 1 {
return nil, errors.Errorf("expected 1 result, got %d", len(result.Results))
}
res := result.Results[0]
if res.Error != nil {
err := apiservererrors.RestoreError(res.Error)
return nil, errors.Annotatef(err, "unable to fetch opened ports for %s", appTag)
}
out := make(network.GroupedPortRanges)
for _, pgs := range res.ApplicationPortRanges {
for _, pg := range pgs.PortRanges {
out[pgs.Endpoint] = append(out[pgs.Endpoint], pg.NetworkPortRange())
}
}
return out, nil
}

// WatchRelationUnits returns a watcher that notifies of changes to the
// counterpart units in the relation for the given unit.
func (st *State) WatchRelationUnits(
Expand Down
49 changes: 0 additions & 49 deletions api/agent/uniter/uniter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,55 +135,6 @@ func (s *uniterSuite) TestOpenedPortRangesByEndpoint(c *gc.C) {
})
}

func (s *uniterSuite) TestOpenedApplicationPortRangesByEndpoint(c *gc.C) {
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Assert(objType, gc.Equals, "Uniter")
c.Assert(request, gc.Equals, "OpenedApplicationPortRangesByEndpoint")
c.Assert(arg, gc.DeepEquals, params.Entity{Tag: "application-gitlab"})
c.Assert(result, gc.FitsTypeOf, &params.ApplicationOpenedPortsResults{})
*(result.(*params.ApplicationOpenedPortsResults)) = params.ApplicationOpenedPortsResults{
Results: []params.ApplicationOpenedPortsResult{
{
ApplicationPortRanges: []params.ApplicationOpenedPorts{
{
Endpoint: "",
PortRanges: []params.PortRange{{100, 200, "tcp"}},
},
{
Endpoint: "server",
PortRanges: []params.PortRange{{3306, 3306, "tcp"}},
},
},
},
},
}
return nil
})
caller := testing.BestVersionCaller{apiCaller, 18}
client := uniter.NewState(caller, names.NewUnitTag("gitlab/0"))

result, err := client.OpenedApplicationPortRangesByEndpoint(names.NewApplicationTag("gitlab"))
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, jc.DeepEquals, network.GroupedPortRanges{
"": []network.PortRange{network.MustParsePortRange("100-200/tcp")},
"server": []network.PortRange{network.MustParsePortRange("3306/tcp")},
})
}

func (s *uniterSuite) TestOpenedApplicationPortRangesByEndpointOldAPINotSupported(c *gc.C) {
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Assert(objType, gc.Equals, "Uniter")
c.Assert(request, gc.Equals, "OpenedApplicationPortRangesByEndpoint")
c.Assert(arg, gc.DeepEquals, params.Entities{Entities: []params.Entity{{Tag: "unit-gitlab-0"}}})
return nil
})
caller := testing.BestVersionCaller{apiCaller, 17}
client := uniter.NewState(caller, names.NewUnitTag("gitlab/0"))

_, err := client.OpenedApplicationPortRangesByEndpoint(names.NewApplicationTag("gitlab"))
c.Assert(err, gc.ErrorMatches, `OpenedApplicationPortRangesByEndpoint\(\) \(need V18\+\) not implemented`)
}

func (s *uniterSuite) TestOpenedPortRangesByEndpointOldAPINotSupported(c *gc.C) {
apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
c.Assert(objType, gc.Equals, "Uniter")
Expand Down
2 changes: 1 addition & 1 deletion api/facadeversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var facadeVersions = map[string][]int{
"Subnets": {5},
"Undertaker": {1},
"UnitAssigner": {1},
"Uniter": {18, 19},
"Uniter": {19},
"Upgrader": {1},
"UpgradeSeries": {3},
"UpgradeSteps": {2},
Expand Down

0 comments on commit 254d8b2

Please sign in to comment.