GitHub PullRequestReviewCommentEvent at 2014-06-05 12:17:04
Repository: juju
Actor: dimitern
Payload: {"comment":{"url":"https://api.github.com/repos/juju/juju/pulls/comments/13435993","id":13435993,"diff_hunk":"@@ -0,0 +1,303 @@\n+// Copyright 2014 Canonical Ltd.\n+// Licensed under the AGPLv3, see LICENCE file for details.\n+\n+package networker_test\n+\n+import (\n+\tgc \"launchpad.net/gocheck\"\n+\n+\t\"github.com/juju/juju/environs/network\"\n+\t\"github.com/juju/juju/instance\"\n+\t\"github.com/juju/juju/juju/testing\"\n+\t\"github.com/juju/juju/state\"\n+\t\"github.com/juju/juju/state/api/params\"\n+\t\"github.com/juju/juju/state/apiserver/common\"\n+\t\"github.com/juju/juju/state/apiserver/networker\"\n+\tapiservertesting \"github.com/juju/juju/state/apiserver/testing\"\n+)\n+\n+type networkerSuite struct {\n+\ttesting.JujuConnSuite\n+\n+\tnetworks []state.NetworkInfo\n+\n+\tmachine         *state.Machine\n+\tcontainer       *state.Machine\n+\tnestedContainer *state.Machine\n+\n+\tmachineIfaces         []state.NetworkInterfaceInfo\n+\tcontainerIfaces       []state.NetworkInterfaceInfo\n+\tnestedContainerIfaces []state.NetworkInterfaceInfo\n+\n+\tauthorizer apiservertesting.FakeAuthorizer\n+\tresources  *common.Resources\n+\tnetworker  *networker.NetworkerAPI\n+}\n+\n+var _ = gc.Suite(&networkerSuite{})\n+\n+// Create several networks.\n+func (s *networkerSuite) setUpNetworks(c *gc.C) {\n+\ts.networks = []state.NetworkInfo{{\n+\t\tName:       \"net1\",\n+\t\tProviderId: \"net1\",\n+\t\tCIDR:       \"0.1.2.0/24\",\n+\t\tVLANTag:    0,\n+\t}, {\n+\t\tName:       \"vlan42\",\n+\t\tProviderId: \"vlan42\",\n+\t\tCIDR:       \"0.2.2.0/24\",\n+\t\tVLANTag:    42,\n+\t}, {\n+\t\tName:       \"vlan69\",\n+\t\tProviderId: \"vlan69\",\n+\t\tCIDR:       \"0.3.2.0/24\",\n+\t\tVLANTag:    69,\n+\t}, {\n+\t\tName:       \"vlan123\",\n+\t\tProviderId: \"vlan123\",\n+\t\tCIDR:       \"0.4.2.0/24\",\n+\t\tVLANTag:    123,\n+\t}, {\n+\t\tName:       \"net2\",\n+\t\tProviderId: \"net2\",\n+\t\tCIDR:       \"0.5.2.0/24\",\n+\t\tVLANTag:    0,\n+\t}}\n+}\n+\n+// Create a machine to use.\n+func (s *networkerSuite) setUpMachine(c *gc.C) {\n+\tvar err error\n+\ts.machine, err = s.State.AddMachine(\"quantal\", state.JobHostUnits)\n+\tc.Assert(err, gc.IsNil)\n+\thwChars := instance.MustParseHardware(\"arch=i386\", \"mem=4G\")\n+\ts.machineIfaces = []state.NetworkInterfaceInfo{{\n+\t\tMACAddress:    \"aa:bb:cc:dd:ee:f0\",\n+\t\tInterfaceName: \"eth0\",\n+\t\tNetworkName:   \"net1\",\n+\t\tIsVirtual:     false,\n+\t}, {\n+\t\tMACAddress:    \"aa:bb:cc:dd:ee:f1\",\n+\t\tInterfaceName: \"eth1\",\n+\t\tNetworkName:   \"net1\",\n+\t\tIsVirtual:     false,\n+\t}, {\n+\t\tMACAddress:    \"aa:bb:cc:dd:ee:f1\",\n+\t\tInterfaceName: \"eth1.42\",\n+\t\tNetworkName:   \"vlan42\",\n+\t\tIsVirtual:     true,\n+\t}, {\n+\t\tMACAddress:    \"aa:bb:cc:dd:ee:f0\",\n+\t\tInterfaceName: \"eth0.69\",\n+\t\tNetworkName:   \"vlan69\",\n+\t\tIsVirtual:     true,\n+\t}, {\n+\t\tMACAddress:    \"aa:bb:cc:dd:ee:f2\",\n+\t\tInterfaceName: \"eth2\",\n+\t\tNetworkName:   \"net2\",\n+\t\tIsVirtual:     false,\n+\t}}\n+\terr = s.machine.SetInstanceInfo(\"i-am\", \"fake_nonce\", &hwChars, s.networks, s.machineIfaces)\n+\tc.Assert(err, gc.IsNil)\n+}\n+\n+// Create and provision a container and a nested container.\n+func (s *networkerSuite) setUpContainers(c *gc.C) {\n+\ttemplate := state.MachineTemplate{\n+\t\tSeries: \"quantal\",\n+\t\tJobs:   []state.MachineJob{state.JobHostUnits},\n+\t}\n+\tvar err error\n+\ts.container, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)\n+\tc.Assert(err, gc.IsNil)\n+\ts.containerIfaces = []state.NetworkInterfaceInfo{{\n+\t\tMACAddress:    \"aa:bb:cc:dd:ee:e0\",\n+\t\tInterfaceName: \"eth0\",\n+\t\tNetworkName:   \"net1\",\n+\t\tIsVirtual:     false,\n+\t}, {\n+\t\tMACAddress:    \"aa:bb:cc:dd:ee:e1\",\n+\t\tInterfaceName: \"eth1\",\n+\t\tNetworkName:   \"net1\",\n+\t\tIsVirtual:     false,\n+\t}, {\n+\t\tMACAddress:    \"aa:bb:cc:dd:ee:e1\",\n+\t\tInterfaceName: \"eth1.42\",\n+\t\tNetworkName:   \"vlan42\",\n+\t\tIsVirtual:     true,\n+\t}}\n+\thwChars := instance.MustParseHardware(\"arch=i386\", \"mem=4G\")\n+\terr = s.container.SetInstanceInfo(\"i-container\", \"fake_nonce\", &hwChars, s.networks[:2],\n+\t\ts.containerIfaces)\n+\tc.Assert(err, gc.IsNil)\n+\n+\ts.nestedContainer, err = s.State.AddMachineInsideMachine(template, s.container.Id(), instance.LXC)\n+\tc.Assert(err, gc.IsNil)\n+\ts.nestedContainerIfaces = []state.NetworkInterfaceInfo{{\n+\t\tMACAddress:    \"aa:bb:cc:dd:ee:d0\",\n+\t\tInterfaceName: \"eth0\",\n+\t\tNetworkName:   \"net1\",\n+\t\tIsVirtual:     false,\n+\t}}\n+\terr = s.nestedContainer.SetInstanceInfo(\"i-too\", \"fake_nonce\", &hwChars, s.networks[:1],\n+\t\ts.nestedContainerIfaces)\n+\tc.Assert(err, gc.IsNil)\n+}\n+\n+func (s *networkerSuite) SetUpTest(c *gc.C) {\n+\ts.JujuConnSuite.SetUpTest(c)\n+\n+\ts.setUpNetworks(c)\n+\ts.setUpMachine(c)\n+\ts.setUpContainers(c)\n+\n+\t// Create a FakeAuthorizer so we can check permissions,\n+\t// set up assuming we logged in as a machine agent.\n+\ts.authorizer = apiservertesting.FakeAuthorizer{\n+\t\tLoggedIn:     true,\n+\t\tMachineAgent: true,\n+\t\tTag:          s.machine.Tag(),\n+\t}\n+\n+\t// Create the resource registry separately.\n+\ts.resources = common.NewResources()\n+\n+\t// Create a networker API for the machine.\n+\tvar err error\n+\ts.networker, err = networker.NewNetworkerAPI(\n+\t\ts.State,\n+\t\ts.resources,\n+\t\ts.authorizer,\n+\t)\n+\tc.Assert(err, gc.IsNil)\n+","path":"state/apiserver/networker/networker_test.go","position":174,"original_position":174,"commit_id":"c61625649708f52c6cde31578d20f3a9d9fe3446","original_commit_id":"c61625649708f52c6cde31578d20f3a9d9fe3446","user":{"login":"dimitern","id":619986,"avatar_url":"https://avatars.githubusercontent.com/u/619986?","gravatar_id":"6889e0065cf206ab0e4b3873576b5026","url":"https://api.github.com/users/dimitern","html_url":"https://github.com/dimitern","followers_url":"https://api.github.com/users/dimitern/followers","following_url":"https://api.github.com/users/dimitern/following{/other_user}","gists_url":"https://api.github.com/users/dimitern/gists{/gist_id}","starred_url":"https://api.github.com/users/dimitern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimitern/subscriptions","organizations_url":"https://api.github.com/users/dimitern/orgs","repos_url":"https://api.github.com/users/dimitern/repos","events_url":"https://api.github.com/users/dimitern/events{/privacy}","received_events_url":"https://api.github.com/users/dimitern/received_events","type":"User","site_admin":false},"body":"d","created_at":"2014-06-05T12:17:04Z","updated_at":"2014-06-05T12:17:04Z","html_url":"https://github.com/juju/juju/pull/16#discussion_r13435993","pull_request_url":"https://api.github.com/repos/juju/juju/pulls/16","_links":{"self":{"href":"https://api.github.com/repos/juju/juju/pulls/comments/13435993"},"html":{"href":"https://github.com/juju/juju/pull/16#discussion_r13435993"},"pull_request":{"href":"https://api.github.com/repos/juju/juju/pulls/16"}}}}