Ensure cloud.Name is set and used everywhere #6884

Merged
merged 1 commit into from Jan 30, 2017

Conversation

Projects
None yet
4 participants
Member

axw commented Jan 30, 2017

A recent change introduced the Name field to
cloud.Cloud. In several parts of the code
base we were not setting it properly. This
branch ensures that it is always filled in,
introduces additional validation in state,
and updates various bits of code to stop
passing around the cloud name separately.

QA steps

  1. juju bootstrap localhost
  2. juju bootstrap aws
  3. juju add-model foo
  4. juju add-credential aws
  5. juju add-cloud
@@ -81,14 +84,16 @@ func (s *CloudSuite) TestAddCloudDuplicate(c *gc.C) {
}
func (s *CloudSuite) TestAddCloudNoType(c *gc.C) {
- err := s.State.AddCloud("stratus", cloud.Cloud{
+ err := s.State.AddCloud(cloud.Cloud{
+ Name: "stratus",
AuthTypes: cloud.AuthTypes{cloud.AccessKeyAuthType, cloud.UserPassAuthType},
})
c.Assert(err, gc.ErrorMatches, `invalid cloud: empty Type not valid`)
@wallyworld

wallyworld Jan 30, 2017

Owner

can we have a test for empty name not valid?

@axw

axw Jan 30, 2017

Member

Done.

Sorry for not doing this when I added Cloud.Name.

If we're relying on the key in clouds.yaml taking precedence over cloud name in the case that they're different, could you add a test to ensure that?

cloud/clouds.go
@@ -156,6 +156,7 @@ type cloudSet struct {
// cloud is equivalent to Cloud, for marshalling and unmarshalling.
type cloud struct {
+ Name string `yaml:"name"`
@babbageclunk

babbageclunk Jan 30, 2017

Member

We're serialising out the cloud name here now - does that mean that we'll do the wrong thing for users that have exisiting yaml files without the name attribute in clouds? I guess it'll be ok as long as the reading still code overrides the name from the key. Although that does make it possible for the key and the name to be inconsistent in the file (which is why I didn't change this when I added name). Is that a problem? It might be confusing.

@axw

axw Jan 30, 2017

Member

Ah, actually that's a mistake - we should only be serialising the name outside of the clouds.yaml file format. i.e. clouds.yaml should continue to be formatted as:

name:
    type: foo
...

and for other cases of YAML serialisation, we'll get:

name: foo
type: bar
...

I have updated the code and added tests.

@axw

axw Jan 30, 2017

Member

Also, I'll add a test to show that we ignore the name field in the YAML file if it's there.

Ensure cloud.Name is set and used everywhere
A recent change introduced the Name field to
cloud.Cloud. In several parts of the code
base we were not setting it properly. This
branch ensures that it is always filled in,
introduces additional validation in state,
and updates various bits of code to stop
passing around the cloud name separately.
Member

axw commented Jan 30, 2017

$$merge$$

Contributor

jujubot commented Jan 30, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

Contributor

jujubot commented Jan 30, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10139

Member

axw commented Jan 30, 2017

$$merge$$

Contributor

jujubot commented Jan 30, 2017

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit 10f40c3 into juju:2.1 Jan 30, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment