15467: check that array config items must end in 'List'
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Wed, 24 Jul 2019 14:12:07 +0000 (10:12 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Mon, 29 Jul 2019 18:58:16 +0000 (14:58 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

lib/cloud/ec2/ec2.go
lib/config/config.default.yml
lib/config/generated_config.go
lib/config/load_test.go

index 079c32802ca4d3a038b1a395b5d56188b99a7cce..7ee8138665159874777dd39f98e399effcf1bd73 100644 (file)
@@ -32,7 +32,7 @@ type ec2InstanceSetConfig struct {
        AccessKeyID      string
        SecretAccessKey  string
        Region           string
-       SecurityGroupIDs []string
+       SecurityGroupIDs map[string]interface{}
        SubnetID         string
        AdminUsername    string
        EBSVolumeType    string
@@ -161,6 +161,11 @@ func (instanceSet *ec2InstanceSet) Create(
                })
        }
 
+       var groups []string
+       for sg := range instanceSet.ec2config.SecurityGroupIDs {
+               groups = append(groups, sg)
+       }
+
        rii := ec2.RunInstancesInput{
                ImageId:      aws.String(string(imageID)),
                InstanceType: &instanceType.ProviderType,
@@ -173,7 +178,7 @@ func (instanceSet *ec2InstanceSet) Create(
                                AssociatePublicIpAddress: aws.Bool(false),
                                DeleteOnTermination:      aws.Bool(true),
                                DeviceIndex:              aws.Int64(0),
-                               Groups:                   aws.StringSlice(instanceSet.ec2config.SecurityGroupIDs),
+                               Groups:                   aws.StringSlice(groups),
                                SubnetId:                 &instanceSet.ec2config.SubnetID,
                        }},
                DisableApiTermination:             aws.Bool(false),
index 88177cb1b411bdb97cf1dc06018dc05d60f281e8..2b1da2f2a86b734d43464867c819a4be81dbbd7c 100644 (file)
@@ -691,7 +691,7 @@ Clusters:
 
           # (ec2) Instance configuration.
           SecurityGroupIDs:
-            - ""
+            "SAMPLE": {}
           SubnetID: ""
           Region: ""
           EBSVolumeType: gp2
index 05648ca77f6484ad55d41df044e25fde774833f7..35edb05bcd683a1b07596d39e39ae441c1b7aa86 100644 (file)
@@ -697,7 +697,7 @@ Clusters:
 
           # (ec2) Instance configuration.
           SecurityGroupIDs:
-            - ""
+            "SAMPLE": {}
           SubnetID: ""
           Region: ""
           EBSVolumeType: gp2
index fa04c007515c1cf155bdefff87be4b2daa30eee5..a06ad282ca442cf035d625bf6a674a95973d8add 100644 (file)
@@ -375,3 +375,45 @@ func (s *LoadSuite) checkEquivalent(c *check.C, goty, expectedy string) {
                c.Check(err, check.IsNil)
        }
 }
+
+func (s *LoadSuite) checkListKeys(c *check.C, path string, x interface{}) {
+       v := reflect.Indirect(reflect.ValueOf(x))
+       switch v.Kind() {
+       case reflect.Map:
+               iter := v.MapRange()
+               for iter.Next() {
+                       k := iter.Key()
+                       if k.Kind() == reflect.String {
+                               s.checkListKeys(c, path+"."+k.String(), iter.Value().Interface())
+                       }
+               }
+               return
+
+       case reflect.Struct:
+               for i := 0; i < v.NumField(); i++ {
+                       val := v.Field(i)
+                       fieldname := v.Type().Field(i).Name
+                       endsWithList := strings.HasSuffix(fieldname, "List")
+                       isAnArray := v.Type().Field(i).Type.Kind() == reflect.Slice
+                       if endsWithList != isAnArray {
+                               if endsWithList {
+                                       c.Errorf("%s.%s ends with 'List' but field is not an array (type %v)", path, fieldname, val.Kind())
+                               }
+                               if isAnArray && v.Type().Field(i).Type.Elem().Kind() != reflect.Uint8 {
+                                       c.Errorf("%s.%s is an array but field name does not end in 'List' (slice of %v)", path, fieldname, v.Type().Field(i).Type.Elem().Kind())
+                               }
+                       }
+                       if val.CanInterface() {
+                               s.checkListKeys(c, path+"."+v.Type().Field(i).Name, val.Interface())
+                       }
+               }
+       }
+}
+
+func (s *LoadSuite) TestListKeys(c *check.C) {
+       var logbuf bytes.Buffer
+       loader := testLoader(c, string(DefaultYAML), &logbuf)
+       cfg, err := loader.Load()
+       c.Assert(err, check.IsNil)
+       s.checkListKeys(c, "", cfg)
+}