// Upgrader returns an object that provides access to the Upgrader API facade. // The id argument is reserved for future use and must be empty. func (r *srvRoot) Upgrader(id string) (*upgrader.UpgraderAPI, error) { if id != "" { // TODO: There is no direct test for this return nil, common.ErrBadId } return upgrader.NewUpgraderAPI(r.srv.state, r.resources, r) }
func (s *upgraderSuite) TestUpgraderAPIRefusesNonAgent(c *C) { // We aren't even a machine agent anAuthorizer := s.authorizer anAuthorizer.MachineAgent = false anUpgrader, err := upgrader.NewUpgraderAPI(s.State, s.resources, anAuthorizer) c.Check(err, NotNil) c.Check(anUpgrader, IsNil) c.Assert(err, ErrorMatches, "permission denied") }
func (s *upgraderSuite) TestToolsRefusesWrongAgent(c *C) { anAuthorizer := s.authorizer anAuthorizer.Tag = "machine-12354" anUpgrader, err := upgrader.NewUpgraderAPI(s.State, s.resources, anAuthorizer) c.Check(err, IsNil) args := params.Entities{ Entities: []params.Entity{{Tag: s.rawMachine.Tag()}}, } results, err := anUpgrader.Tools(args) // It is not an error to make the request, but the specific item is rejected c.Assert(err, IsNil) c.Check(results.Results, HasLen, 1) toolResult := results.Results[0] c.Assert(toolResult.Error, DeepEquals, apiservertesting.ErrUnauthorized) }
func (s *upgraderSuite) TestWatchAPIVersionRefusesWrongAgent(c *C) { // We are a machine agent, but not the one we are trying to track anAuthorizer := s.authorizer anAuthorizer.Tag = "machine-12354" anUpgrader, err := upgrader.NewUpgraderAPI(s.State, s.resources, anAuthorizer) c.Check(err, IsNil) args := params.Entities{ Entities: []params.Entity{{Tag: s.rawMachine.Tag()}}, } results, err := anUpgrader.WatchAPIVersion(args) // It is not an error to make the request, but the specific item is rejected c.Assert(err, IsNil) c.Check(results.Results, HasLen, 1) c.Check(results.Results[0].NotifyWatcherId, Equals, "") c.Assert(results.Results[0].Error, DeepEquals, apiservertesting.ErrUnauthorized) }
func (s *upgraderSuite) TestSetToolsRefusesWrongAgent(c *C) { anAuthorizer := s.authorizer anAuthorizer.Tag = "machine-12354" anUpgrader, err := upgrader.NewUpgraderAPI(s.State, s.resources, anAuthorizer) c.Check(err, IsNil) args := params.SetAgentsTools{ AgentTools: []params.SetAgentTools{{ Tag: s.rawMachine.Tag(), Tools: &tools.Tools{ Version: version.Current, }, }}, } results, err := anUpgrader.SetTools(args) c.Assert(results.Results, HasLen, 1) c.Assert(results.Results[0].Error, DeepEquals, apiservertesting.ErrUnauthorized) }
func (s *upgraderSuite) SetUpTest(c *C) { s.JujuConnSuite.SetUpTest(c) s.resources = common.NewResources() // Create a machine to work with var err error s.rawMachine, err = s.State.AddMachine("series", state.JobHostUnits) c.Assert(err, IsNil) err = s.rawMachine.SetPassword("test-password") c.Assert(err, IsNil) // The default auth is as the machine agent s.authorizer = apiservertesting.FakeAuthorizer{ Tag: s.rawMachine.Tag(), LoggedIn: true, Manager: false, MachineAgent: true, Client: false, } s.upgrader, err = upgrader.NewUpgraderAPI(s.State, s.resources, s.authorizer) c.Assert(err, IsNil) }
func (s *upgraderSuite) TestSetToolsRefusesWrongAgent(c *C) { anAuthorizer := s.authorizer anAuthorizer.Tag = "machine-12354" anUpgrader, err := upgrader.NewUpgraderAPI(s.State, s.resources, anAuthorizer) c.Check(err, IsNil) cur := version.Current tools := params.AgentTools{ Tag: s.rawMachine.Tag(), Arch: cur.Arch, Series: cur.Series, Major: cur.Major, Minor: cur.Minor, Patch: cur.Patch, Build: cur.Build, URL: "", } args := params.SetAgentTools{AgentTools: []params.AgentTools{tools}} results, err := anUpgrader.SetTools(args) c.Assert(results.Results, HasLen, 1) c.Assert(results.Results[0].Tag, Equals, s.rawMachine.Tag()) c.Assert(results.Results[0].Error, DeepEquals, apiservertesting.ErrUnauthorized) }