Esempio n. 1
0
// NewState creates a new client-side Firewaller API facade.
func NewState(caller base.APICaller) *State {
	facadeCaller := base.NewFacadeCaller(caller, firewallerFacade)
	return &State{
		facade:       facadeCaller,
		ModelWatcher: common.NewModelWatcher(facadeCaller),
		CloudSpecAPI: cloudspec.NewCloudSpecAPI(facadeCaller),
	}
}
Esempio n. 2
0
File: state.go Progetto: bac/juju
// NewState returns a version of the state that provides functionality
// required by agent code.
func NewState(caller base.APICaller) *State {
	facadeCaller := base.NewFacadeCaller(caller, "Agent")
	return &State{
		facade:              facadeCaller,
		ModelWatcher:        common.NewModelWatcher(facadeCaller),
		CloudSpecAPI:        cloudspec.NewCloudSpecAPI(facadeCaller),
		ControllerConfigAPI: common.NewControllerConfig(facadeCaller),
	}
}
Esempio n. 3
0
func (s *CloudSpecSuite) TestCloudSpecResultCountMismatch(c *gc.C) {
	facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}}
	facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error {
		return nil
	}
	api := cloudspec.NewCloudSpecAPI(&facadeCaller)
	_, err := api.CloudSpec(coretesting.ModelTag)
	c.Assert(err, gc.ErrorMatches, "expected 1 result, got 0")
}
Esempio n. 4
0
// NewClient creates a new `Client` based on an existing authenticated API
// connection.
func NewClient(st base.APICallCloser) *Client {
	frontend, backend := base.NewClientFacade(st, "Controller")
	return &Client{
		ClientFacade:        frontend,
		facade:              backend,
		ControllerConfigAPI: common.NewControllerConfig(backend),
		CloudSpecAPI:        cloudspec.NewCloudSpecAPI(backend),
	}
}
Esempio n. 5
0
func (s *CloudSpecSuite) TestCloudSpecOverallError(c *gc.C) {
	expect := errors.New("bewm")
	facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}}
	facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error {
		return expect
	}
	api := cloudspec.NewCloudSpecAPI(&facadeCaller)
	_, err := api.CloudSpec(coretesting.ModelTag)
	c.Assert(err, gc.Equals, expect)
}
Esempio n. 6
0
func (s *CloudSpecSuite) TestCloudSpecInvalidCloudSpec(c *gc.C) {
	facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}}
	facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error {
		*(response.(*params.CloudSpecResults)) = params.CloudSpecResults{[]params.CloudSpecResult{{
			Result: &params.CloudSpec{
				Type: "",
			},
		}}}
		return nil
	}
	api := cloudspec.NewCloudSpecAPI(&facadeCaller)
	_, err := api.CloudSpec(coretesting.ModelTag)
	c.Assert(err, gc.ErrorMatches, "validating CloudSpec: empty Type not valid")
}
Esempio n. 7
0
func (s *CloudSpecSuite) TestCloudSpecResultError(c *gc.C) {
	facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}}
	facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error {
		*(response.(*params.CloudSpecResults)) = params.CloudSpecResults{
			[]params.CloudSpecResult{{
				Error: &params.Error{
					Code:    params.CodeUnauthorized,
					Message: "dang",
				},
			}},
		}
		return nil
	}
	api := cloudspec.NewCloudSpecAPI(&facadeCaller)
	_, err := api.CloudSpec(coretesting.ModelTag)
	c.Assert(err, jc.Satisfies, params.IsCodeUnauthorized)
	c.Assert(err, gc.ErrorMatches, "API request failed: dang")
}
Esempio n. 8
0
func (s *CloudSpecSuite) TestCloudSpec(c *gc.C) {
	facadeCaller := apitesting.StubFacadeCaller{Stub: &testing.Stub{}}
	facadeCaller.FacadeCallFn = func(name string, args, response interface{}) error {
		c.Assert(name, gc.Equals, "CloudSpec")
		c.Assert(args, jc.DeepEquals, params.Entities{[]params.Entity{
			{coretesting.ModelTag.String()},
		}})
		*(response.(*params.CloudSpecResults)) = params.CloudSpecResults{
			[]params.CloudSpecResult{{
				Result: &params.CloudSpec{
					Type:             "type",
					Name:             "name",
					Region:           "region",
					Endpoint:         "endpoint",
					IdentityEndpoint: "identity-endpoint",
					StorageEndpoint:  "storage-endpoint",
					Credential: &params.CloudCredential{
						AuthType:   "auth-type",
						Attributes: map[string]string{"k": "v"},
					},
				},
			}},
		}
		return nil
	}
	api := cloudspec.NewCloudSpecAPI(&facadeCaller)
	cloudSpec, err := api.CloudSpec(coretesting.ModelTag)
	c.Assert(err, jc.ErrorIsNil)

	credential := cloud.NewCredential(
		"auth-type",
		map[string]string{"k": "v"},
	)
	c.Assert(cloudSpec, jc.DeepEquals, environs.CloudSpec{
		Type:             "type",
		Name:             "name",
		Region:           "region",
		Endpoint:         "endpoint",
		IdentityEndpoint: "identity-endpoint",
		StorageEndpoint:  "storage-endpoint",
		Credential:       &credential,
	})
}
Esempio n. 9
0
func (s *CloudSpecSuite) TestNewCloudSpecAPI(c *gc.C) {
	api := cloudspec.NewCloudSpecAPI(nil)
	c.Check(api, gc.NotNil)
}