@@ -80,14 +80,13 @@ func TestValidate(t *testing.T) {
80
80
require .Error (t , err )
81
81
require .Equal (t , "Attachment a specified more than once" , err .Error ())
82
82
83
- // Unsupported Attachment Type.
83
+ // Attachment for all
84
84
err = managerFlavor .Validate (
85
85
types .AnyString (`{
86
86
"Docker" : {"Host":"unix:///var/run/docker.sock"},
87
- "Attachments": {"127.0.0.1 ": [{"ID": "a", "Type": "keyboard "}]}}` ),
87
+ "Attachments": {"* ": [{"ID": "a", "Type": "NFSVolume "}]}}` ),
88
88
group_types.AllocationMethod {LogicalIDs : []instance.LogicalID {"127.0.0.1" }})
89
- require .Error (t , err )
90
- require .Equal (t , "Invalid attachment Type 'keyboard', only ebs is supported" , err .Error ())
89
+ require .NoError (t , err )
91
90
92
91
close (managerStop )
93
92
close (workerStop )
@@ -192,16 +191,28 @@ func TestManager(t *testing.T) {
192
191
client .EXPECT ().NodeInspectWithRaw (gomock .Any (), nodeID ).Return (nodeInfo , nil , nil ).AnyTimes ()
193
192
client .EXPECT ().Close ().AnyTimes ()
194
193
194
+ flavorSpec := types .AnyString (`
195
+ {
196
+ "Attachments" : {
197
+ "10.20.100.1" : [ { "ID" : "disk01", "Type" : "disk" }, { "ID" : "nic01", "Type" : "nic" } ],
198
+ "10.20.100.2" : [ { "ID" : "disk02", "Type" : "disk" }, { "ID" : "nic02", "Type" : "nic" } ],
199
+ "10.20.100.3" : [ { "ID" : "disk03", "Type" : "disk" }, { "ID" : "nic03", "Type" : "nic" } ]
200
+ }
201
+ }
202
+ ` )
203
+
195
204
index := group_types.Index {Group : group .ID ("group" ), Sequence : 0 }
196
- id := instance .LogicalID ("127.0.0.1" )
197
- details , err := flavorImpl .Prepare (
198
- types .AnyString (`{"Attachments": {"127.0.0.1": [{"ID": "a", "Type": "gpu"}]}}` ),
205
+ id := instance .LogicalID ("10.20.100.1" )
206
+ details , err := flavorImpl .Prepare (flavorSpec ,
199
207
instance.Spec {Tags : map [string ]string {"a" : "b" }, LogicalID : & id },
200
- group_types.AllocationMethod {LogicalIDs : []instance.LogicalID {"127.0.0 .1" }},
208
+ group_types.AllocationMethod {LogicalIDs : []instance.LogicalID {"10.20.100 .1" }},
201
209
index )
202
210
require .NoError (t , err )
203
211
require .Equal (t , "b" , details .Tags ["a" ])
204
212
213
+ // ensures that the attachments are matched to the logical ID of the instance and in the attachments map
214
+ require .Equal (t , []instance.Attachment {{ID : "disk01" , Type : "disk" }, {ID : "nic01" , Type : "nic" }}, details .Attachments )
215
+
205
216
link := types .NewLinkFromMap (details .Tags )
206
217
require .True (t , link .Valid ())
207
218
require .True (t , len (link .KVPairs ()) > 0 )
@@ -228,6 +239,31 @@ func TestManager(t *testing.T) {
228
239
229
240
require .Equal (t , []instance.Attachment {{ID : "a" , Type : "gpu" }}, details .Attachments )
230
241
242
+ // Shared AllInstances for attachment
243
+ for _ , id := range []instance.LogicalID {
244
+ instance .LogicalID ("10.20.100.1" ),
245
+ instance .LogicalID ("10.20.100.2" ),
246
+ instance .LogicalID ("10.20.100.3" ),
247
+ } {
248
+
249
+ details , err = flavorImpl .Prepare (
250
+ types .AnyString (`{"Attachments": {"*": [{"ID": "nfs", "Type": "NFSVolume"}]}}` ),
251
+ instance.Spec {Tags : map [string ]string {"a" : "b" }, LogicalID : & id },
252
+ group_types.AllocationMethod {LogicalIDs : []instance.LogicalID {"10.20.100.1" , "10.20.100.2" , "10.20.100.3" }},
253
+ index )
254
+ require .NoError (t , err )
255
+ require .Equal (t , []instance.Attachment {{ID : "nfs" , Type : "NFSVolume" }}, details .Attachments )
256
+ }
257
+
258
+ // Shared AllInstances for attachment -- for workers / no special logical IDs
259
+ details , err = flavorImpl .Prepare (
260
+ types .AnyString (`{"Attachments": {"*": [{"ID": "nfs", "Type": "NFSVolume"}]}}` ),
261
+ instance.Spec {Tags : map [string ]string {"a" : "b" }},
262
+ group_types.AllocationMethod {Size : 10 },
263
+ index )
264
+ require .NoError (t , err )
265
+ require .Equal (t , []instance.Attachment {{ID : "nfs" , Type : "NFSVolume" }}, details .Attachments )
266
+
231
267
// An instance with no association information is considered unhealthy.
232
268
health , err := flavorImpl .Healthy (types .AnyString ("{}" ), instance.Description {})
233
269
require .NoError (t , err )
@@ -278,16 +314,16 @@ func TestTemplateFunctions(t *testing.T) {
278
314
279
315
properties := types .AnyString (`
280
316
{
281
- "Attachments": {"127.0.0 .1": [{"ID": "a", "Type": "gpu"}]},
317
+ "Attachments": {"10.20.100 .1": [{"ID": "a", "Type": "gpu"}]},
282
318
"InitScriptTemplateURL" : "str://` + initTemplate + `"
283
319
}
284
320
` )
285
321
286
322
index := group_types.Index {Group : group .ID ("group" ), Sequence : 100 }
287
- id := instance .LogicalID ("127.0.0 .1" )
323
+ id := instance .LogicalID ("10.20.100 .1" )
288
324
details , err := flavorImpl .Prepare (properties ,
289
325
instance.Spec {Tags : map [string ]string {"a" : "b" }, LogicalID : & id },
290
- group_types.AllocationMethod {LogicalIDs : []instance.LogicalID {"127.0.0 .1" }},
326
+ group_types.AllocationMethod {LogicalIDs : []instance.LogicalID {"10.20.100 .1" }},
291
327
index )
292
328
require .NoError (t , err )
293
329
require .Equal (t , fmt .Sprintf ("%v,%v" , index .Group , index .Sequence ), details .Init )
0 commit comments