Skip to content

Commit

Permalink
Merge pull request juju#1639 from TheMue/network-adopt-name-changes
Browse files Browse the repository at this point in the history
Adopt name change of NetworkConfig

The type `NetworkInfo` has been changed to `NetworkConfig` in a previous PR. Now this change leads to a change of the according functions/methods too. Due to compatibility reasons both names are provided for a transitional period.

(Review request: http://reviews.vapour.ws/r/968/)
  • Loading branch information
jujubot committed Feb 22, 2015
2 parents 8e486f4 + bbdc742 commit b98776a
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 25 deletions.
15 changes: 15 additions & 0 deletions api/networker/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package networker

import (
"github.com/juju/juju/api/base/testing"
)

// PatchFacadeCall patches the State's facade such that
// FacadeCall method calls are diverted to the provided
// function.
func PatchFacadeCall(p testing.Patcher, st *State, f func(request string, params, response interface{}) error) {
testing.PatchFacadeCall(p, &st.facade, f)
}
16 changes: 11 additions & 5 deletions api/networker/networker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,23 @@ func NewState(caller base.APICaller) *State {
return &State{base.NewFacadeCaller(caller, networkerFacade)}
}

// MachineNetworkInfo returns information about network interfaces to
// MachineNetworkConfig returns information about network interfaces to
// setup only for a single machine.
func (st *State) MachineNetworkInfo(tag names.MachineTag) ([]network.InterfaceInfo, error) {
func (st *State) MachineNetworkConfig(tag names.MachineTag) ([]network.InterfaceInfo, error) {
args := params.Entities{
Entities: []params.Entity{{Tag: tag.String()}},
}
var results params.MachineNetworkConfigResults
err := st.facade.FacadeCall("MachineNetworkInfo", args, &results)
err := st.facade.FacadeCall("MachineNetworkConfig", args, &results)
if err != nil {
// TODO: Not directly tested
return nil, err
if params.IsCodeNotImplemented(err) {
// Fallback to former name.
err = st.facade.FacadeCall("MachineNetworkInfo", args, &results)
}
if err != nil {
// TODO: Not directly tested.
return nil, err
}
}
if len(results.Results) != 1 {
// TODO: Not directly tested
Expand Down
38 changes: 32 additions & 6 deletions api/networker/networker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/juju/juju/api"
"github.com/juju/juju/api/networker"
"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/instance"
"github.com/juju/juju/juju/testing"
Expand Down Expand Up @@ -168,14 +169,39 @@ func (s *networkerSuite) SetUpTest(c *gc.C) {
c.Assert(s.networker, gc.NotNil)
}

func (s *networkerSuite) TestMachineNetworkInfoPermissionDenied(c *gc.C) {
info, err := s.networker.MachineNetworkInfo(names.NewMachineTag("1"))
func (s *networkerSuite) TestMachineNetworkConfigPermissionDenied(c *gc.C) {
info, err := s.networker.MachineNetworkConfig(names.NewMachineTag("1"))
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
c.Assert(info, gc.IsNil)
}

func (s *networkerSuite) TestMachineNetworkInfo(c *gc.C) {
func (s *networkerSuite) TestMachineNetworkConfigNameChange(c *gc.C) {
var called bool
networker.PatchFacadeCall(s, s.networker, func(request string, args, response interface{}) error {
if !called {
called = true
c.Assert(request, gc.Equals, "MachineNetworkConfig")
return &params.Error{"MachineNetworkConfig", params.CodeNotImplemented}
}
c.Assert(request, gc.Equals, "MachineNetworkInfo")
expected := params.Entities{
Entities: []params.Entity{{Tag: names.NewMachineTag("42").String()}},
}
c.Assert(args, gc.DeepEquals, expected)
result := response.(*params.MachineNetworkConfigResults)
result.Results = make([]params.MachineNetworkConfigResult, 1)
result.Results[0].Error = common.ServerError(common.ErrPerm)
return nil
})
// Make a call, in this case result is "permission denied".
info, err := s.networker.MachineNetworkConfig(names.NewMachineTag("42"))
c.Assert(err, gc.ErrorMatches, "permission denied")
c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
c.Assert(info, gc.IsNil)
}

func (s *networkerSuite) TestMachineNetworkConfig(c *gc.C) {
// TODO(bogdanteleaga): Find out what's the problem with this test
// It seems to work on some machines
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -250,15 +276,15 @@ func (s *networkerSuite) TestMachineNetworkInfo(c *gc.C) {
InterfaceName: "eth0",
}}

results, err := s.networker.MachineNetworkInfo(names.NewMachineTag("0"))
results, err := s.networker.MachineNetworkConfig(names.NewMachineTag("0"))
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, gc.DeepEquals, expectedMachineInfo)

results, err = s.networker.MachineNetworkInfo(names.NewMachineTag("0/lxc/0"))
results, err = s.networker.MachineNetworkConfig(names.NewMachineTag("0/lxc/0"))
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, gc.DeepEquals, expectedContainerInfo)

results, err = s.networker.MachineNetworkInfo(names.NewMachineTag("0/lxc/0/lxc/0"))
results, err = s.networker.MachineNetworkConfig(names.NewMachineTag("0/lxc/0/lxc/0"))
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, gc.DeepEquals, expectedNestedContainerInfo)
}
Expand Down
10 changes: 9 additions & 1 deletion apiserver/networker/networker.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,16 @@ func (n *NetworkerAPI) oneMachineConfig(id string) ([]params.NetworkConfig, erro
return configs, nil
}

// Networks returns the list of networks with related interfaces for a given set of machines.
// MachineNetworkInfo returns the list of networks with related interfaces for a
// given set of machines.
// DEPRECATED: Use MachineNetworkConfig() instead.
func (n *NetworkerAPI) MachineNetworkInfo(args params.Entities) (params.MachineNetworkConfigResults, error) {
return n.MachineNetworkConfig(args)
}

// MachineNetworkConfig returns the list of networks with related interfaces
// for a given set of machines.
func (n *NetworkerAPI) MachineNetworkConfig(args params.Entities) (params.MachineNetworkConfigResults, error) {
result := params.MachineNetworkConfigResults{
Results: make([]params.MachineNetworkConfigResult, len(args.Entities)),
}
Expand Down
28 changes: 16 additions & 12 deletions apiserver/networker/networker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (s *networkerSuite) TestNetworkerNonMachineAgent(c *gc.C) {
c.Assert(aNetworker, gc.IsNil)
}

func (s *networkerSuite) TestMachineNetworkInfoPermissions(c *gc.C) {
func (s *networkerSuite) TestMachineNetworkConfigPermissions(c *gc.C) {
args := params.Entities{Entities: []params.Entity{
{Tag: "service-bar"},
{Tag: "foo-42"},
Expand All @@ -195,7 +195,7 @@ func (s *networkerSuite) TestMachineNetworkInfoPermissions(c *gc.C) {
{Tag: "machine-1"},
{Tag: "machine-0-lxc-42"},
}}
results, err := s.networker.MachineNetworkInfo(args)
results, err := s.networker.MachineNetworkConfig(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, gc.DeepEquals, params.MachineNetworkConfigResults{
Results: []params.MachineNetworkConfigResult{
Expand Down Expand Up @@ -284,21 +284,25 @@ func (s *networkerSuite) TestMachineNetworkConfig(c *gc.C) {
VLANTag: 0,
InterfaceName: "eth0",
}}

args := params.Entities{Entities: []params.Entity{
{Tag: "machine-0"},
{Tag: "machine-0-lxc-0"},
{Tag: "machine-0-lxc-0-lxc-0"},
}}
results, err := s.networker.MachineNetworkInfo(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, gc.DeepEquals, params.MachineNetworkConfigResults{
Results: []params.MachineNetworkConfigResult{
{Error: nil, Config: expectedMachineConfig},
{Error: nil, Config: expectedContainerConfig},
{Error: nil, Config: expectedNestedContainerConfig},
},
})

assert := func(f func(params.Entities) (params.MachineNetworkConfigResults, error)) {
results, err := f(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(results, gc.DeepEquals, params.MachineNetworkConfigResults{
Results: []params.MachineNetworkConfigResult{
{Error: nil, Config: expectedMachineConfig},
{Error: nil, Config: expectedContainerConfig},
{Error: nil, Config: expectedNestedContainerConfig},
},
})
}
assert(s.networker.MachineNetworkInfo)
assert(s.networker.MachineNetworkConfig)
}

func (s *networkerSuite) TestWatchInterfacesPermissions(c *gc.C) {
Expand Down
1 change: 1 addition & 0 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const (
// InterfaceInfo describes a single network interface available on an
// instance. For providers that support networks, this will be
// available at StartInstance() time.
// TODO(mue): Rename to InterfaceConfig due to consistency later.
type InterfaceInfo struct {
// DeviceIndex specifies the order in which the network interface
// appears on the host. The primary interface has an index of 0.
Expand Down
2 changes: 1 addition & 1 deletion worker/networker/networker.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (nw *Networker) updateInterfaces() error {
// commands to load the kernal 8021q VLAN module, if not already
// loaded and when not running inside an LXC container.
func (nw *Networker) fetchInterfaceInfo() error {
interfaceInfo, err := nw.st.MachineNetworkInfo(nw.tag)
interfaceInfo, err := nw.st.MachineNetworkConfig(nw.tag)
if err != nil {
logger.Errorf("failed to retrieve network info: %v", err)
return err
Expand Down

0 comments on commit b98776a

Please sign in to comment.