예제 #1
0
func (s *MachineSuite) CheckServerError(c *gc.C, wf methodWrapper, expectErr string, serverResults interface{}) {
	var called int
	apiCaller := successAPICaller(c, "", nil, serverResults, &called)
	machine := instancepoller.NewMachine(apiCaller, s.tag, params.Alive)
	c.Check(wf(machine), gc.ErrorMatches, expectErr)
	c.Check(called, gc.Equals, 1)
}
예제 #2
0
func (s *MachineSuite) CheckClientError(c *gc.C, wf methodWrapper) {
	var called int
	apiCaller := clientErrorAPICaller(c, "", nil, &called)
	machine := instancepoller.NewMachine(apiCaller, s.tag, params.Alive)
	c.Check(wf(machine), gc.ErrorMatches, "client error!")
	c.Check(called, gc.Equals, 1)
}
예제 #3
0
func (s *MachineSuite) TestRefreshSuccess(c *gc.C) {
	var called int
	results := params.LifeResults{
		Results: []params.LifeResult{{Life: params.Dying}},
	}
	apiCaller := successAPICaller(c, "Life", entitiesArgs, results, &called)
	machine := instancepoller.NewMachine(apiCaller, s.tag, params.Alive)
	c.Check(machine.Refresh(), jc.ErrorIsNil)
	c.Check(machine.Life(), gc.Equals, params.Dying)
	c.Check(called, gc.Equals, 1)
}
예제 #4
0
func (s *MachineSuite) TestInstanceIdSuccess(c *gc.C) {
	var called int
	results := params.StringResults{
		Results: []params.StringResult{{Result: "i-foo"}},
	}
	apiCaller := successAPICaller(c, "InstanceId", entitiesArgs, results, &called)
	machine := instancepoller.NewMachine(apiCaller, s.tag, params.Alive)
	instId, err := machine.InstanceId()
	c.Check(err, jc.ErrorIsNil)
	c.Check(instId, gc.Equals, instance.Id("i-foo"))
	c.Check(called, gc.Equals, 1)
}
예제 #5
0
func (s *MachineSuite) TestIsManualSuccess(c *gc.C) {
	var called int
	results := params.BoolResults{
		Results: []params.BoolResult{{Result: true}},
	}
	apiCaller := successAPICaller(c, "AreManuallyProvisioned", entitiesArgs, results, &called)
	machine := instancepoller.NewMachine(apiCaller, s.tag, params.Alive)
	isManual, err := machine.IsManual()
	c.Check(err, jc.ErrorIsNil)
	c.Check(isManual, jc.IsTrue)
	c.Check(called, gc.Equals, 1)
}
예제 #6
0
func (s *MachineSuite) TestInstanceStatusSuccess(c *gc.C) {
	var called int
	results := params.StringResults{
		Results: []params.StringResult{{Result: "A-OK"}},
	}
	apiCaller := successAPICaller(c, "InstanceStatus", entitiesArgs, results, &called)
	machine := instancepoller.NewMachine(apiCaller, s.tag, params.Alive)
	status, err := machine.InstanceStatus()
	c.Check(err, jc.ErrorIsNil)
	c.Check(status, gc.Equals, "A-OK")
	c.Check(called, gc.Equals, 1)
}
예제 #7
0
func (s *MachineSuite) TestNonFacadeMethods(c *gc.C) {
	nopCaller := apitesting.APICallerFunc(
		func(_ string, _ int, _, _ string, _, _ interface{}) error {
			c.Fatalf("facade call was not expected")
			return nil
		},
	)
	machine := instancepoller.NewMachine(nopCaller, s.tag, params.Dying)

	c.Assert(machine.Id(), gc.Equals, "42")
	c.Assert(machine.Tag(), jc.DeepEquals, s.tag)
	c.Assert(machine.String(), gc.Equals, "42")
	c.Assert(machine.Life(), gc.Equals, params.Dying)
}
예제 #8
0
func (s *MachineSuite) TestProviderAddressesSuccess(c *gc.C) {
	var called int
	addresses := network.NewAddresses("2001:db8::1", "0.1.2.3")
	results := params.MachineAddressesResults{
		Results: []params.MachineAddressesResult{{
			Addresses: params.FromNetworkAddresses(addresses),
		}}}
	apiCaller := successAPICaller(c, "ProviderAddresses", entitiesArgs, results, &called)
	machine := instancepoller.NewMachine(apiCaller, s.tag, params.Alive)
	addrs, err := machine.ProviderAddresses()
	c.Check(err, jc.ErrorIsNil)
	c.Check(addrs, jc.DeepEquals, addresses)
	c.Check(called, gc.Equals, 1)
}
예제 #9
0
func (s *MachineSuite) TestSetInstanceStatusSuccess(c *gc.C) {
	var called int
	expectArgs := params.SetStatus{
		Entities: []params.EntityStatusArgs{{
			Tag:    "machine-42",
			Status: "RUNNING",
		}}}
	results := params.ErrorResults{
		Results: []params.ErrorResult{{Error: nil}},
	}
	apiCaller := successAPICaller(c, "SetInstanceStatus", expectArgs, results, &called)
	machine := instancepoller.NewMachine(apiCaller, s.tag, params.Alive)
	err := machine.SetInstanceStatus("RUNNING", "", nil)
	c.Check(err, jc.ErrorIsNil)
	c.Check(called, gc.Equals, 1)
}
예제 #10
0
func (s *MachineSuite) TestSetProviderAddressesSuccess(c *gc.C) {
	var called int
	addresses := network.NewAddresses("2001:db8::1", "0.1.2.3")
	expectArgs := params.SetMachinesAddresses{
		MachineAddresses: []params.MachineAddresses{{
			Tag:       "machine-42",
			Addresses: params.FromNetworkAddresses(addresses),
		}}}
	results := params.ErrorResults{
		Results: []params.ErrorResult{{Error: nil}},
	}
	apiCaller := successAPICaller(c, "SetProviderAddresses", expectArgs, results, &called)
	machine := instancepoller.NewMachine(apiCaller, s.tag, params.Alive)
	err := machine.SetProviderAddresses(addresses...)
	c.Check(err, jc.ErrorIsNil)
	c.Check(called, gc.Equals, 1)
}
예제 #11
0
func (s *MachineSuite) TestStatusSuccess(c *gc.C) {
	var called int
	now := time.Now()
	expectStatus := params.StatusResult{
		Status: "foo",
		Info:   "bar",
		Data: map[string]interface{}{
			"int":    42,
			"bool":   true,
			"float":  3.14,
			"slice":  []string{"a", "b"},
			"map":    map[int]string{5: "five"},
			"string": "argh",
		},
		Since: &now,
	}
	results := params.StatusResults{Results: []params.StatusResult{expectStatus}}
	apiCaller := successAPICaller(c, "Status", entitiesArgs, results, &called)
	machine := instancepoller.NewMachine(apiCaller, s.tag, params.Alive)
	status, err := machine.Status()
	c.Check(err, jc.ErrorIsNil)
	c.Check(status, jc.DeepEquals, expectStatus)
	c.Check(called, gc.Equals, 1)
}