Example #1
0
func (s *ClientSuite) TestActionFinishSuccess(c *gc.C) {
	tag := names.NewActionTag(utils.MustNewUUID().String())
	status := "stubstatus"
	actionResults := map[string]interface{}{"stub": "stub"}
	message := "stubmsg"
	expectedCalls := []jujutesting.StubCall{{
		"MachineActions.FinishActions",
		[]interface{}{"", params.ActionExecutionResults{
			Results: []params.ActionExecutionResult{{
				ActionTag: tag.String(),
				Status:    status,
				Results:   actionResults,
				Message:   message,
			}},
		}},
	}}
	var stub jujutesting.Stub

	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, id, arg)
		c.Check(result, gc.FitsTypeOf, &params.ErrorResults{})
		*(result.(*params.ErrorResults)) = params.ErrorResults{
			Results: []params.ErrorResult{{}},
		}
		return nil
	})

	client := machineactions.NewClient(apiCaller)
	err := client.ActionFinish(tag, status, actionResults, message)
	c.Assert(err, jc.ErrorIsNil)
	stub.CheckCalls(c, expectedCalls)
}
Example #2
0
func mockAPICaller(c *gc.C, callNumber *int32, apiCalls ...apiCall) apitesting.APICallerFunc {
	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		switch objType {
		case "NotifyWatcher":
			return nil
		case "Uniter":
			index := int(atomic.AddInt32(callNumber, 1)) - 1
			c.Check(index < len(apiCalls), jc.IsTrue)
			call := apiCalls[index]
			c.Logf("request %d, %s", index, request)
			c.Check(version, gc.Equals, 4)
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, call.request)
			c.Check(arg, jc.DeepEquals, call.args)
			if call.err != nil {
				return common.ServerError(call.err)
			}
			testing.PatchValue(result, call.result)
		default:
			c.Fail()
		}
		return nil
	})
	return apiCaller
}
Example #3
0
func (s *storageMockSuite) TestListVolumesEmptyFilter(c *gc.C) {
	var called bool
	tag := "ok"
	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "Storage")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "ListVolumes")

			c.Assert(a, gc.FitsTypeOf, params.VolumeFilter{})
			args := a.(params.VolumeFilter)
			c.Assert(args.IsEmpty(), jc.IsTrue)

			c.Assert(result, gc.FitsTypeOf, &params.VolumeDetailsResults{})
			results := result.(*params.VolumeDetailsResults)
			results.Results = []params.VolumeDetailsResult{
				{LegacyVolume: &params.LegacyVolumeDetails{VolumeTag: tag}},
			}
			return nil
		})
	storageClient := storage.NewClient(apiCaller)
	found, err := storageClient.ListVolumes(nil)
	c.Assert(called, jc.IsTrue)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(found, gc.HasLen, 1)
	c.Assert(found[0].LegacyVolume.VolumeTag, gc.Equals, tag)
}
Example #4
0
func (s *metricsdebugSuiteMock) TestGetMetrics(c *gc.C) {
	var called bool
	now := time.Now()
	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, response interface{},
		) error {
			c.Assert(request, gc.Equals, "GetMetrics")
			result := response.(*params.MetricResults)
			result.Results = []params.EntityMetrics{{
				Metrics: []params.MetricResult{{
					Key:   "pings",
					Value: "5",
					Time:  now,
				}},
				Error: nil,
			}}
			called = true
			return nil
		})
	client := metricsdebug.NewClient(apiCaller)
	metrics, err := client.GetMetrics("unit-wordpress/0")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, jc.IsTrue)
	c.Assert(metrics, gc.HasLen, 1)
	c.Assert(metrics[0].Key, gc.Equals, "pings")
	c.Assert(metrics[0].Value, gc.Equals, "5")
	c.Assert(metrics[0].Time, gc.Equals, now)
}
Example #5
0
func (s *unitStorageSuite) TestAddUnitStorageError(c *gc.C) {
	count := uint64(1)
	args := map[string][]params.StorageConstraints{
		"data": []params.StorageConstraints{params.StorageConstraints{Count: &count}},
	}

	expected := params.StoragesAddParams{
		Storages: []params.StorageAddParams{
			{"unit-mysql-0", "data", params.StorageConstraints{Count: &count}},
		},
	}

	var called bool
	msg := "yoink"
	apiCaller := basetesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		c.Assert(objType, gc.Equals, "Uniter")
		c.Assert(version, gc.Equals, 3)
		c.Assert(id, gc.Equals, "")
		c.Assert(request, gc.Equals, "AddUnitStorage")
		c.Assert(arg, gc.DeepEquals, expected)
		called = true

		c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})
		return errors.New(msg)
	})

	u := s.createTestUnit(c, "mysql/0", apiCaller)
	err := u.AddStorage(args)
	c.Assert(err, gc.ErrorMatches, msg)
	c.Assert(called, jc.IsTrue)
}
func (s *ServingInfoSetterSuite) checkNotStateServer(c *gc.C, job multiwatcher.MachineJob) {
	a := &mockAgent{}
	apiCaller := basetesting.APICallerFunc(
		func(objType string, version int, id, request string, args, response interface{}) error {
			c.Assert(objType, gc.Equals, "Agent")
			switch request {
			case "GetEntities":
				c.Assert(args.(params.Entities).Entities, gc.HasLen, 1)
				result := response.(*params.AgentGetEntitiesResults)
				result.Entities = []params.AgentGetEntitiesResult{{
					Jobs: []multiwatcher.MachineJob{job},
				}}
			default:
				c.Fatalf("not sure how to handle: %q", request)
			}
			return nil
		},
	)
	w, err := s.manifold.Start(dt.StubGetResource(dt.StubResources{
		"agent":      dt.StubResource{Output: a},
		"api-caller": dt.StubResource{Output: apiCaller},
	}))
	c.Assert(w, gc.IsNil)
	c.Assert(err, gc.Equals, dependency.ErrUninstall)

	// State serving info shouldn't have been set for this job type.
	c.Assert(a.conf.ssiSet, jc.IsFalse)
}
Example #7
0
func (s *meterStatusSuite) TestGetMeterStatusResultError(c *gc.C) {
	tag := names.NewUnitTag("wp/1")
	var called bool
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, response interface{}) error {
		c.Check(objType, gc.Equals, "MeterStatus")
		c.Check(version, gc.Equals, 0)
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "GetMeterStatus")
		c.Check(arg, gc.DeepEquals, params.Entities{
			Entities: []params.Entity{{Tag: tag.String()}},
		})
		c.Assert(response, gc.FitsTypeOf, &params.MeterStatusResults{})
		result := response.(*params.MeterStatusResults)
		result.Results = []params.MeterStatusResult{{
			Error: &params.Error{
				Message: "An error in the meter status.",
				Code:    params.CodeNotAssigned,
			},
		}}
		called = true
		return nil
	})
	status := meterstatus.NewClient(apiCaller, tag)
	c.Assert(status, gc.NotNil)

	statusCode, statusInfo, err := status.MeterStatus()
	c.Assert(called, jc.IsTrue)
	c.Assert(err, gc.ErrorMatches, "An error in the meter status.")
	c.Assert(statusCode, gc.Equals, "")
	c.Assert(statusInfo, gc.Equals, "")
}
Example #8
0
func (s *ClientSuite) TestWatchResultError(c *gc.C) {
	tag := names.NewMachineTag("2")
	expectErr := &params.Error{
		Message: "rigged",
		Code:    params.CodeNotAssigned,
	}
	expectedCalls := []jujutesting.StubCall{{
		"MachineActions.WatchActionNotifications",
		[]interface{}{"", params.Entities{
			Entities: []params.Entity{{Tag: tag.String()}},
		}},
	}}
	var stub jujutesting.Stub

	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, id, arg)
		c.Check(result, gc.FitsTypeOf, &params.StringsWatchResults{})
		res := result.(*params.StringsWatchResults)
		res.Results = make([]params.StringsWatchResult, 1)
		res.Results[0].Error = expectErr
		return nil
	})

	client := machineactions.NewClient(apiCaller)
	w, err := client.WatchActionNotifications(tag)
	c.Assert(errors.Cause(err), gc.Equals, expectErr)
	c.Assert(w, gc.IsNil)
	stub.CheckCalls(c, expectedCalls)
}
Example #9
0
func (s *storageSuite) TestWatchStorageAttachments(c *gc.C) {
	var called bool
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		c.Check(objType, gc.Equals, "Uniter")
		c.Check(version, gc.Equals, 2)
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "WatchStorageAttachments")
		c.Check(arg, gc.DeepEquals, params.StorageAttachmentIds{
			Ids: []params.StorageAttachmentId{{
				StorageTag: "storage-data-0",
				UnitTag:    "unit-mysql-0",
			}},
		})
		c.Assert(result, gc.FitsTypeOf, &params.NotifyWatchResults{})
		*(result.(*params.NotifyWatchResults)) = params.NotifyWatchResults{
			Results: []params.NotifyWatchResult{{
				Error: &params.Error{Message: "FAIL"},
			}},
		}
		called = true
		return nil
	})

	st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
	_, err := st.WatchStorageAttachment(names.NewStorageTag("data/0"), names.NewUnitTag("mysql/0"))
	c.Check(err, gc.ErrorMatches, "FAIL")
	c.Check(called, jc.IsTrue)
}
Example #10
0
func (s *ClientSuite) TestRunningActionSuccess(c *gc.C) {
	tag := names.NewMachineTag(utils.MustNewUUID().String())
	expectedCalls := []jujutesting.StubCall{{
		"MachineActions.RunningActions",
		[]interface{}{"", params.Entities{
			Entities: []params.Entity{{Tag: tag.String()}},
		}},
	}}
	actionsList := []params.ActionResult{
		{Action: &params.Action{Name: "foo"}},
		{Action: &params.Action{Name: "baz"}},
	}
	var stub jujutesting.Stub

	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, id, arg)
		c.Check(result, gc.FitsTypeOf, &params.ActionsByReceivers{})
		*(result.(*params.ActionsByReceivers)) = params.ActionsByReceivers{
			Actions: []params.ActionsByReceiver{{
				Actions: actionsList,
			}},
		}
		return nil
	})

	client := machineactions.NewClient(apiCaller)
	actions, err := client.RunningActions(tag)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(actions, jc.DeepEquals, actionsList)
	stub.CheckCalls(c, expectedCalls)
}
Example #11
0
func (s *ClientSuite) TestRunningActionsResultError(c *gc.C) {
	tag := names.NewMachineTag(utils.MustNewUUID().String())
	expectedCalls := []jujutesting.StubCall{{
		"MachineActions.RunningActions",
		[]interface{}{"", params.Entities{
			Entities: []params.Entity{{Tag: tag.String()}},
		}},
	}}
	expectedErr := &params.Error{
		Message: "rigged",
		Code:    params.CodeNotAssigned,
	}
	var stub jujutesting.Stub

	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, id, arg)
		c.Check(result, gc.FitsTypeOf, &params.ActionsByReceivers{})
		*(result.(*params.ActionsByReceivers)) = params.ActionsByReceivers{
			Actions: []params.ActionsByReceiver{{
				Error: expectedErr,
			}},
		}
		return nil
	})

	client := machineactions.NewClient(apiCaller)
	action, err := client.RunningActions(tag)
	c.Assert(errors.Cause(err), gc.Equals, expectedErr)
	c.Assert(action, gc.IsNil)
	stub.CheckCalls(c, expectedCalls)
}
Example #12
0
func (s *ClientSuite) TestGetActionSuccess(c *gc.C) {
	tag := names.NewActionTag(utils.MustNewUUID().String())
	expectedCalls := []jujutesting.StubCall{{
		"MachineActions.Actions",
		[]interface{}{"", params.Entities{
			Entities: []params.Entity{{Tag: tag.String()}},
		}},
	}}
	expectedName := "ack"
	expectedParams := map[string]interface{}{"floob": "zgloob"}
	var stub jujutesting.Stub

	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, id, arg)
		c.Check(result, gc.FitsTypeOf, &params.ActionResults{})
		*(result.(*params.ActionResults)) = params.ActionResults{
			Results: []params.ActionResult{{
				Action: &params.Action{
					Name:       expectedName,
					Parameters: expectedParams,
				},
			}},
		}
		return nil
	})

	client := machineactions.NewClient(apiCaller)
	action, err := client.Action(tag)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(action.Name(), gc.Equals, expectedName)
	c.Assert(action.Params(), gc.DeepEquals, expectedParams)
	stub.CheckCalls(c, expectedCalls)
}
Example #13
0
func (s *ClientSuite) TestActionFinishTooManyResults(c *gc.C) {
	tag := names.NewActionTag(utils.MustNewUUID().String())
	expectedCalls := []jujutesting.StubCall{{
		"MachineActions.FinishActions",
		[]interface{}{"", params.ActionExecutionResults{
			Results: []params.ActionExecutionResult{{
				ActionTag: tag.String(),
				Status:    "",
				Results:   nil,
				Message:   "",
			}},
		}},
	}}
	var stub jujutesting.Stub

	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, id, arg)
		c.Check(result, gc.FitsTypeOf, &params.ErrorResults{})
		res := result.(*params.ErrorResults)
		res.Results = make([]params.ErrorResult, 2)
		return nil
	})

	client := machineactions.NewClient(apiCaller)
	err := client.ActionFinish(tag, "", nil, "")
	c.Assert(err, gc.ErrorMatches, "expected 1 result, got 2")
	stub.CheckCalls(c, expectedCalls)
}
Example #14
0
func (s *ClientSuite) TestActionFinishResultError(c *gc.C) {
	tag := names.NewActionTag(utils.MustNewUUID().String())
	expectedCalls := []jujutesting.StubCall{{
		"MachineActions.FinishActions",
		[]interface{}{"", params.ActionExecutionResults{
			Results: []params.ActionExecutionResult{{
				ActionTag: tag.String(),
				Status:    "",
				Results:   nil,
				Message:   "",
			}},
		}},
	}}
	expectedErr := &params.Error{
		Message: "rigged",
		Code:    params.CodeNotAssigned,
	}
	var stub jujutesting.Stub

	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, id, arg)
		c.Check(result, gc.FitsTypeOf, &params.ErrorResults{})
		*(result.(*params.ErrorResults)) = params.ErrorResults{
			Results: []params.ErrorResult{{expectedErr}},
		}

		return nil
	})

	client := machineactions.NewClient(apiCaller)
	err := client.ActionFinish(tag, "", nil, "")
	c.Assert(errors.Cause(err), gc.Equals, expectedErr)
	stub.CheckCalls(c, expectedCalls)
}
Example #15
0
func (s *retryStrategySuite) TestWatchRetryStrategyResultError(c *gc.C) {
	tag := names.NewUnitTag("wp/1")
	var called bool
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, response interface{}) error {
		called = true

		c.Check(objType, gc.Equals, "RetryStrategy")
		c.Check(version, gc.Equals, 0)
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "WatchRetryStrategy")
		c.Check(arg, gc.DeepEquals, params.Entities{
			Entities: []params.Entity{{Tag: tag.String()}},
		})
		c.Assert(response, gc.FitsTypeOf, &params.NotifyWatchResults{})
		result := response.(*params.NotifyWatchResults)
		result.Results = []params.NotifyWatchResult{{
			Error: &params.Error{
				Message: "rigged",
				Code:    params.CodeNotAssigned,
			},
		}}
		return nil
	})

	client := retrystrategy.NewClient(apiCaller)
	c.Assert(client, gc.NotNil)

	w, err := client.WatchRetryStrategy(tag)
	c.Assert(called, jc.IsTrue)
	c.Assert(err, gc.ErrorMatches, "rigged")
	c.Assert(w, gc.IsNil)
}
Example #16
0
func (s *storageSuite) TestStorageAttachmentLife(c *gc.C) {
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		c.Check(objType, gc.Equals, "Uniter")
		c.Check(version, gc.Equals, 2)
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "StorageAttachmentLife")
		c.Check(arg, gc.DeepEquals, params.StorageAttachmentIds{
			Ids: []params.StorageAttachmentId{{
				StorageTag: "storage-data-0",
				UnitTag:    "unit-mysql-0",
			}},
		})
		c.Assert(result, gc.FitsTypeOf, &params.LifeResults{})
		*(result.(*params.LifeResults)) = params.LifeResults{
			Results: []params.LifeResult{{
				Life: params.Dying,
			}},
		}
		return nil
	})

	st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
	results, err := st.StorageAttachmentLife([]params.StorageAttachmentId{{
		StorageTag: "storage-data-0",
		UnitTag:    "unit-mysql-0",
	}})
	c.Check(err, jc.ErrorIsNil)
	c.Assert(results, jc.DeepEquals, []params.LifeResult{{Life: params.Dying}})
}
Example #17
0
func (s *retryStrategySuite) TestRetryStrategyMoreResults(c *gc.C) {
	tag := names.NewUnitTag("wp/1")
	var called bool
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, response interface{}) error {
		called = true

		c.Check(objType, gc.Equals, "RetryStrategy")
		c.Check(version, gc.Equals, 0)
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "RetryStrategy")
		c.Check(arg, gc.DeepEquals, params.Entities{
			Entities: []params.Entity{{Tag: tag.String()}},
		})
		c.Assert(response, gc.FitsTypeOf, &params.RetryStrategyResults{})
		result := response.(*params.RetryStrategyResults)
		result.Results = make([]params.RetryStrategyResult, 2)
		return nil
	})

	client := retrystrategy.NewClient(apiCaller)
	c.Assert(client, gc.NotNil)

	retryStrategy, err := client.RetryStrategy(tag)
	c.Assert(called, jc.IsTrue)
	c.Assert(err, gc.ErrorMatches, "expected 1 result, got 2")
	c.Assert(retryStrategy, jc.DeepEquals, params.RetryStrategy{})
}
Example #18
0
func (s *storageSuite) TestRemoveStorageAttachment(c *gc.C) {
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		c.Check(objType, gc.Equals, "Uniter")
		c.Check(version, gc.Equals, 2)
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "RemoveStorageAttachments")
		c.Check(arg, gc.DeepEquals, params.StorageAttachmentIds{
			Ids: []params.StorageAttachmentId{{
				StorageTag: "storage-data-0",
				UnitTag:    "unit-mysql-0",
			}},
		})
		c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})
		*(result.(*params.ErrorResults)) = params.ErrorResults{
			Results: []params.ErrorResult{{
				Error: &params.Error{Message: "yoink"},
			}},
		}
		return nil
	})

	st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
	err := st.RemoveStorageAttachment(names.NewStorageTag("data/0"), names.NewUnitTag("mysql/0"))
	c.Check(err, gc.ErrorMatches, "yoink")
}
func (s *ServingInfoSetterSuite) TestEntityLookupFailure(c *gc.C) {
	// Set up a fake Agent and APICaller
	a := &mockAgent{}
	apiCaller := basetesting.APICallerFunc(
		func(objType string, version int, id, request string, args, response interface{}) error {
			c.Assert(objType, gc.Equals, "Agent")
			switch request {
			case "GetEntities":
				c.Assert(args.(params.Entities).Entities, gc.HasLen, 1)
				result := response.(*params.AgentGetEntitiesResults)
				result.Entities = []params.AgentGetEntitiesResult{{
					Error: &params.Error{Message: "boom"},
				}}
			default:
				c.Fatalf("not sure how to handle: %q", request)
			}
			return nil
		},
	)
	// Call the manifold's start func with a fake resource getter that
	// returns the fake Agent and APICaller
	w, err := s.manifold.Start(dt.StubGetResource(dt.StubResources{
		"agent":      dt.StubResource{Output: a},
		"api-caller": dt.StubResource{Output: apiCaller},
	}))
	c.Assert(w, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "boom")
}
Example #20
0
func (s *storageSuite) TestUnitStorageAttachments(c *gc.C) {
	storageAttachmentIds := []params.StorageAttachmentId{{
		StorageTag: "storage-whatever-0",
		UnitTag:    "unit-mysql-0",
	}}

	var called bool
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		c.Check(objType, gc.Equals, "Uniter")
		c.Check(version, gc.Equals, 2)
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "UnitStorageAttachments")
		c.Check(arg, gc.DeepEquals, params.Entities{
			Entities: []params.Entity{{Tag: "unit-mysql-0"}},
		})
		c.Assert(result, gc.FitsTypeOf, &params.StorageAttachmentIdsResults{})
		*(result.(*params.StorageAttachmentIdsResults)) = params.StorageAttachmentIdsResults{
			Results: []params.StorageAttachmentIdsResult{{
				Result: params.StorageAttachmentIds{storageAttachmentIds},
			}},
		}
		called = true
		return nil
	})

	st := uniter.NewState(apiCaller, names.NewUnitTag("mysql/0"))
	attachmentIds, err := st.UnitStorageAttachments(names.NewUnitTag("mysql/0"))
	c.Check(err, jc.ErrorIsNil)
	c.Check(called, jc.IsTrue)
	c.Assert(attachmentIds, gc.DeepEquals, storageAttachmentIds)
}
Example #21
0
func (s *metricsdebugSuiteMock) TestSetMeterStatusAPIServerError(c *gc.C) {
	var called bool
	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, response interface{},
		) error {
			c.Assert(request, gc.Equals, "SetMeterStatus")
			c.Assert(a, gc.DeepEquals, params.MeterStatusParams{
				Statuses: []params.MeterStatusParam{{
					Tag:  "unit-metered/0",
					Code: "RED",
					Info: "test"},
				},
			})
			result := response.(*params.ErrorResults)
			result.Results = []params.ErrorResult{{
				Error: common.ServerError(errors.New("an error")),
			}}
			called = true
			return nil
		})
	client := metricsdebug.NewClient(apiCaller)
	err := client.SetMeterStatus("unit-metered/0", "RED", "test")
	c.Assert(err, gc.ErrorMatches, "an error")
	c.Assert(called, jc.IsTrue)
}
Example #22
0
func (s *storageMockSuite) TestListFilesystemsEmptyFilter(c *gc.C) {
	var called bool
	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "Storage")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "ListFilesystems")

			c.Assert(a, gc.FitsTypeOf, params.FilesystemFilters{})
			args := a.(params.FilesystemFilters)
			c.Assert(args.Filters, gc.HasLen, 1)
			c.Assert(args.Filters[0].IsEmpty(), jc.IsTrue)

			c.Assert(result, gc.FitsTypeOf, &params.FilesystemDetailsListResults{})
			results := result.(*params.FilesystemDetailsListResults)
			results.Results = []params.FilesystemDetailsListResult{{}}

			return nil
		},
	)
	storageClient := storage.NewClient(apiCaller)
	_, err := storageClient.ListFilesystems(nil)
	c.Assert(called, jc.IsTrue)
	c.Assert(err, jc.ErrorIsNil)
}
Example #23
0
func (s *unitStorageSuite) TestAddUnitStorage(c *gc.C) {
	count := uint64(1)
	args := map[string][]params.StorageConstraints{
		"data": []params.StorageConstraints{
			params.StorageConstraints{Count: &count}},
	}

	expected := params.StoragesAddParams{
		Storages: []params.StorageAddParams{
			{"unit-mysql-0", "data", params.StorageConstraints{Count: &count}},
		},
	}

	apiCaller := basetesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		c.Assert(objType, gc.Equals, "Uniter")
		c.Assert(version, gc.Equals, 3)
		c.Assert(id, gc.Equals, "")
		c.Assert(request, gc.Equals, "AddUnitStorage")
		c.Assert(arg, gc.DeepEquals, expected)
		c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})
		*(result.(*params.ErrorResults)) = params.ErrorResults{
			Results: []params.ErrorResult{{
				Error: &params.Error{Message: "yoink"},
			}},
		}
		return nil
	})
	u := s.createTestUnit(c, "mysql/0", apiCaller)
	err := u.AddStorage(args)
	c.Assert(err, gc.ErrorMatches, "yoink")
}
Example #24
0
func (s *modelconfigSuite) TestModelGetWithMetadata(c *gc.C) {
	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			c.Check(objType, gc.Equals, "ModelConfig")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "ModelGet")
			c.Check(a, gc.IsNil)
			c.Assert(result, gc.FitsTypeOf, &params.ModelConfigResults{})
			results := result.(*params.ModelConfigResults)
			results.Config = map[string]params.ConfigValue{
				"foo": {"bar", "model"},
			}
			return nil
		},
	)
	client := modelconfig.NewClient(apiCaller)
	result, err := client.ModelGetWithMetadata()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, config.ConfigValues{
		"foo": {"bar", "model"},
	})
}
Example #25
0
func (s *facadeSuite) TestReportKeys(c *gc.C) {
	stub := new(testing.Stub)
	apiCaller := basetesting.APICallerFunc(func(
		objType string, version int,
		id, request string,
		args, response interface{},
	) error {
		c.Check(objType, gc.Equals, "HostKeyReporter")
		c.Check(version, gc.Equals, 0)
		c.Check(id, gc.Equals, "")
		stub.AddCall(request, args)
		*response.(*params.ErrorResults) = params.ErrorResults{
			Results: []params.ErrorResult{{
				(*params.Error)(nil),
			}},
		}
		return nil
	})
	facade := hostkeyreporter.NewFacade(apiCaller)

	err := facade.ReportKeys("42", []string{"rsa", "dsa"})
	c.Assert(err, jc.ErrorIsNil)

	stub.CheckCalls(c, []testing.StubCall{{
		"ReportKeys", []interface{}{params.SSHHostKeySet{
			EntityKeys: []params.SSHHostKeys{{
				Tag:        names.NewMachineTag("42").String(),
				PublicKeys: []string{"rsa", "dsa"},
			}},
		}},
	}})
}
Example #26
0
func (s *modelconfigSuite) TestModelSet(c *gc.C) {
	called := false
	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			c.Check(objType, gc.Equals, "ModelConfig")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "ModelSet")
			c.Check(a, jc.DeepEquals, params.ModelSet{
				Config: map[string]interface{}{
					"some-name":  "value",
					"other-name": true,
				},
			})
			called = true
			return nil
		},
	)
	client := modelconfig.NewClient(apiCaller)
	err := client.ModelSet(map[string]interface{}{
		"some-name":  "value",
		"other-name": true,
	})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, jc.IsTrue)
}
Example #27
0
func (s *storageMockSuite) TestCreatePool(c *gc.C) {
	var called bool
	poolName := "poolName"
	poolType := "poolType"
	poolConfig := map[string]interface{}{
		"test": "one",
		"pass": true,
	}

	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "Storage")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "CreatePool")

			args, ok := a.(params.StoragePool)
			c.Assert(ok, jc.IsTrue)
			c.Assert(args.Name, gc.Equals, poolName)
			c.Assert(args.Provider, gc.Equals, poolType)
			c.Assert(args.Attrs, gc.DeepEquals, poolConfig)

			return nil
		})
	storageClient := storage.NewClient(apiCaller)
	err := storageClient.CreatePool(poolName, poolType, poolConfig)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, jc.IsTrue)
}
Example #28
0
func (s *imagemanagerSuite) TestDeleteImage(c *gc.C) {
	var callCount int
	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		c.Check(objType, gc.Equals, "ImageManager")
		c.Check(version, gc.Equals, 0)
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "DeleteImages")
		c.Check(arg, gc.DeepEquals, params.ImageFilterParams{
			Images: []params.ImageSpec{{
				Kind:   "lxc",
				Series: "trusty",
				Arch:   "amd64",
			}},
		})
		c.Assert(result, gc.FitsTypeOf, &params.ErrorResults{})
		*(result.(*params.ErrorResults)) = params.ErrorResults{
			Results: []params.ErrorResult{{
				Error: nil,
			}},
		}
		callCount++
		return nil
	})

	im := imagemanager.NewClient(apiCaller)
	err := im.DeleteImage("lxc", "trusty", "amd64")
	c.Check(err, jc.ErrorIsNil)
	c.Check(callCount, gc.Equals, 1)
}
Example #29
0
func (s *storageMockSuite) TestAddToUnit(c *gc.C) {
	size := uint64(42)
	cons := params.StorageConstraints{
		Pool: "value",
		Size: &size,
	}

	errOut := "error"
	unitStorages := []params.StorageAddParams{
		params.StorageAddParams{UnitTag: "u-a", StorageName: "one", Constraints: cons},
		params.StorageAddParams{UnitTag: "u-b", StorageName: errOut, Constraints: cons},
		params.StorageAddParams{UnitTag: "u-b", StorageName: "nil-constraints"},
	}

	storageN := 3
	expectedError := common.ServerError(errors.NotValidf("storage directive"))
	one := func(u, s string, attrs params.StorageConstraints) params.ErrorResult {
		result := params.ErrorResult{}
		if s == errOut {
			result.Error = expectedError
		}
		return result
	}

	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, result interface{},
		) error {
			c.Check(objType, gc.Equals, "Storage")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "AddToUnit")

			args, ok := a.(params.StoragesAddParams)
			c.Assert(ok, jc.IsTrue)
			c.Assert(args.Storages, gc.HasLen, storageN)
			c.Assert(args.Storages, gc.DeepEquals, unitStorages)

			if results, k := result.(*params.ErrorResults); k {
				out := []params.ErrorResult{}
				for _, s := range args.Storages {
					out = append(out, one(s.UnitTag, s.StorageName, s.Constraints))
				}
				results.Results = out
			}

			return nil
		})
	storageClient := storage.NewClient(apiCaller)
	r, err := storageClient.AddToUnit(unitStorages)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(r, gc.HasLen, storageN)
	expected := []params.ErrorResult{
		{nil},
		{expectedError},
		{nil},
	}
	c.Assert(r, jc.SameContents, expected)
}
Example #30
0
func (s *ClientSuite) TestActionBeginSuccess(c *gc.C) {
	tag := names.NewActionTag(utils.MustNewUUID().String())
	expectedCalls := []jujutesting.StubCall{{
		"MachineActions.BeginActions",
		[]interface{}{"", params.Entities{
			Entities: []params.Entity{{Tag: tag.String()}},
		}},
	}}
	var stub jujutesting.Stub

	apiCaller := apitesting.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
		stub.AddCall(objType+"."+request, id, arg)
		c.Check(result, gc.FitsTypeOf, &params.ErrorResults{})
		*(result.(*params.ErrorResults)) = params.ErrorResults{
			Results: []params.ErrorResult{{}},
		}

		return nil
	})

	client := machineactions.NewClient(apiCaller)
	err := client.ActionBegin(tag)
	c.Assert(err, jc.ErrorIsNil)
	stub.CheckCalls(c, expectedCalls)
}