@@ -132,7 +132,7 @@ func TestAttachDetach(t *testing.T) {
132132 name : "Attach_Positive" ,
133133 instanceID : instanceID ,
134134 operationPending : operationPendingCall {volumeID , false , done , nil },
135- diskIsAttached : diskIsAttachedCall {instanceID , volumeID , false , nil },
135+ diskIsAttached : diskIsAttachedCall {instanceID , nodeName , volumeID , false , nil },
136136 attach : attachCall {instanceID , volumeID , "" , nil },
137137 diskPath : diskPathCall {instanceID , volumeID , "/dev/sda" , nil },
138138 test : func (testcase * testcase ) (string , error ) {
@@ -147,7 +147,7 @@ func TestAttachDetach(t *testing.T) {
147147 name : "Attach_Positive_AlreadyAttached" ,
148148 instanceID : instanceID ,
149149 operationPending : operationPendingCall {volumeID , false , done , nil },
150- diskIsAttached : diskIsAttachedCall {instanceID , volumeID , true , nil },
150+ diskIsAttached : diskIsAttachedCall {instanceID , nodeName , volumeID , true , nil },
151151 diskPath : diskPathCall {instanceID , volumeID , "/dev/sda" , nil },
152152 test : func (testcase * testcase ) (string , error ) {
153153 attacher := newAttacher (testcase )
@@ -173,7 +173,7 @@ func TestAttachDetach(t *testing.T) {
173173 name : "Attach_Negative" ,
174174 instanceID : instanceID ,
175175 operationPending : operationPendingCall {volumeID , false , done , nil },
176- diskIsAttached : diskIsAttachedCall {instanceID , volumeID , false , diskCheckError },
176+ diskIsAttached : diskIsAttachedCall {instanceID , nodeName , volumeID , false , diskCheckError },
177177 attach : attachCall {instanceID , volumeID , "/dev/sda" , attachError },
178178 test : func (testcase * testcase ) (string , error ) {
179179 attacher := newAttacher (testcase )
@@ -187,7 +187,7 @@ func TestAttachDetach(t *testing.T) {
187187 name : "Attach_Negative_DiskPatchFails" ,
188188 instanceID : instanceID ,
189189 operationPending : operationPendingCall {volumeID , false , done , nil },
190- diskIsAttached : diskIsAttachedCall {instanceID , volumeID , false , nil },
190+ diskIsAttached : diskIsAttachedCall {instanceID , nodeName , volumeID , false , nil },
191191 attach : attachCall {instanceID , volumeID , "" , nil },
192192 diskPath : diskPathCall {instanceID , volumeID , "" , diskPathError },
193193 test : func (testcase * testcase ) (string , error ) {
@@ -201,7 +201,7 @@ func TestAttachDetach(t *testing.T) {
201201 {
202202 name : "VolumesAreAttached_Positive" ,
203203 instanceID : instanceID ,
204- disksAreAttached : disksAreAttachedCall {instanceID , []string {volumeID }, map [string ]bool {volumeID : true }, nil },
204+ disksAreAttached : disksAreAttachedCall {instanceID , nodeName , []string {volumeID }, map [string ]bool {volumeID : true }, nil },
205205 test : func (testcase * testcase ) (string , error ) {
206206 attacher := newAttacher (testcase )
207207 attachments , err := attacher .VolumesAreAttached ([]* volume.Spec {spec }, nodeName )
@@ -214,7 +214,7 @@ func TestAttachDetach(t *testing.T) {
214214 {
215215 name : "VolumesAreAttached_Negative" ,
216216 instanceID : instanceID ,
217- disksAreAttached : disksAreAttachedCall {instanceID , []string {volumeID }, map [string ]bool {volumeID : false }, nil },
217+ disksAreAttached : disksAreAttachedCall {instanceID , nodeName , []string {volumeID }, map [string ]bool {volumeID : false }, nil },
218218 test : func (testcase * testcase ) (string , error ) {
219219 attacher := newAttacher (testcase )
220220 attachments , err := attacher .VolumesAreAttached ([]* volume.Spec {spec }, nodeName )
@@ -227,7 +227,7 @@ func TestAttachDetach(t *testing.T) {
227227 {
228228 name : "VolumesAreAttached_CinderFailed" ,
229229 instanceID : instanceID ,
230- disksAreAttached : disksAreAttachedCall {instanceID , []string {volumeID }, nil , disksCheckError },
230+ disksAreAttached : disksAreAttachedCall {instanceID , nodeName , []string {volumeID }, nil , disksCheckError },
231231 test : func (testcase * testcase ) (string , error ) {
232232 attacher := newAttacher (testcase )
233233 attachments , err := attacher .VolumesAreAttached ([]* volume.Spec {spec }, nodeName )
@@ -242,7 +242,7 @@ func TestAttachDetach(t *testing.T) {
242242 name : "Detach_Positive" ,
243243 instanceID : instanceID ,
244244 operationPending : operationPendingCall {volumeID , false , done , nil },
245- diskIsAttached : diskIsAttachedCall {instanceID , volumeID , true , nil },
245+ diskIsAttached : diskIsAttachedCall {instanceID , nodeName , volumeID , true , nil },
246246 detach : detachCall {instanceID , volumeID , nil },
247247 test : func (testcase * testcase ) (string , error ) {
248248 detacher := newDetacher (testcase )
@@ -255,7 +255,7 @@ func TestAttachDetach(t *testing.T) {
255255 name : "Detach_Positive_AlreadyDetached" ,
256256 instanceID : instanceID ,
257257 operationPending : operationPendingCall {volumeID , false , done , nil },
258- diskIsAttached : diskIsAttachedCall {instanceID , volumeID , false , nil },
258+ diskIsAttached : diskIsAttachedCall {instanceID , nodeName , volumeID , false , nil },
259259 test : func (testcase * testcase ) (string , error ) {
260260 detacher := newDetacher (testcase )
261261 return "" , detacher .Detach (volumeID , nodeName )
@@ -267,7 +267,7 @@ func TestAttachDetach(t *testing.T) {
267267 name : "Detach_Positive_CheckFails" ,
268268 instanceID : instanceID ,
269269 operationPending : operationPendingCall {volumeID , false , done , nil },
270- diskIsAttached : diskIsAttachedCall {instanceID , volumeID , false , diskCheckError },
270+ diskIsAttached : diskIsAttachedCall {instanceID , nodeName , volumeID , false , diskCheckError },
271271 detach : detachCall {instanceID , volumeID , nil },
272272 test : func (testcase * testcase ) (string , error ) {
273273 detacher := newDetacher (testcase )
@@ -280,7 +280,7 @@ func TestAttachDetach(t *testing.T) {
280280 name : "Detach_Negative" ,
281281 instanceID : instanceID ,
282282 operationPending : operationPendingCall {volumeID , false , done , nil },
283- diskIsAttached : diskIsAttachedCall {instanceID , volumeID , false , diskCheckError },
283+ diskIsAttached : diskIsAttachedCall {instanceID , nodeName , volumeID , false , diskCheckError },
284284 detach : detachCall {instanceID , volumeID , detachError },
285285 test : func (testcase * testcase ) (string , error ) {
286286 detacher := newDetacher (testcase )
@@ -426,6 +426,7 @@ type operationPendingCall struct {
426426
427427type diskIsAttachedCall struct {
428428 instanceID string
429+ nodeName types.NodeName
429430 volumeID string
430431 isAttached bool
431432 ret error
@@ -440,6 +441,7 @@ type diskPathCall struct {
440441
441442type disksAreAttachedCall struct {
442443 instanceID string
444+ nodeName types.NodeName
443445 volumeIDs []string
444446 areAttached map [string ]bool
445447 ret error
@@ -572,6 +574,46 @@ func (testcase *testcase) ShouldTrustDevicePath() bool {
572574 return true
573575}
574576
577+ func (testcase * testcase ) DiskIsAttachedByName (nodeName types.NodeName , volumeID string ) (bool , string , error ) {
578+ expected := & testcase .diskIsAttached
579+ instanceID := expected .instanceID
580+ // If testcase call DetachDisk*, return false
581+ if * testcase .attachOrDetach == detachStatus {
582+ return false , instanceID , nil
583+ }
584+
585+ // If testcase call AttachDisk*, return true
586+ if * testcase .attachOrDetach == attachStatus {
587+ return true , instanceID , nil
588+ }
589+
590+ if expected .nodeName != nodeName {
591+ testcase .t .Errorf ("Unexpected DiskIsAttachedByName call: expected nodename %s, got %s" , expected .nodeName , nodeName )
592+ return false , instanceID , errors .New ("Unexpected DiskIsAttachedByName call: wrong nodename" )
593+ }
594+
595+ if expected .volumeID == "" && expected .instanceID == "" {
596+ // testcase.diskIsAttached looks uninitialized, test did not expect to
597+ // call DiskIsAttached
598+ testcase .t .Errorf ("Unexpected DiskIsAttachedByName call!" )
599+ return false , instanceID , errors .New ("Unexpected DiskIsAttachedByName call!" )
600+ }
601+
602+ if expected .volumeID != volumeID {
603+ testcase .t .Errorf ("Unexpected DiskIsAttachedByName call: expected volumeID %s, got %s" , expected .volumeID , volumeID )
604+ return false , instanceID , errors .New ("Unexpected DiskIsAttachedByName call: wrong volumeID" )
605+ }
606+
607+ if expected .instanceID != instanceID {
608+ testcase .t .Errorf ("Unexpected DiskIsAttachedByName call: expected instanceID %s, got %s" , expected .instanceID , instanceID )
609+ return false , instanceID , errors .New ("Unexpected DiskIsAttachedByName call: wrong instanceID" )
610+ }
611+
612+ glog .V (4 ).Infof ("DiskIsAttachedByName call: %s, %s, returning %v, %v" , volumeID , nodeName , expected .isAttached , expected .instanceID , expected .ret )
613+
614+ return expected .isAttached , expected .instanceID , expected .ret
615+ }
616+
575617func (testcase * testcase ) CreateVolume (name string , size int , vtype , availability string , tags * map [string ]string ) (string , string , bool , error ) {
576618 return "" , "" , false , errors .New ("Not implemented" )
577619}
@@ -626,6 +668,36 @@ func (testcase *testcase) DisksAreAttached(instanceID string, volumeIDs []string
626668 return expected .areAttached , expected .ret
627669}
628670
671+ func (testcase * testcase ) DisksAreAttachedByName (nodeName types.NodeName , volumeIDs []string ) (map [string ]bool , error ) {
672+ expected := & testcase .disksAreAttached
673+ areAttached := make (map [string ]bool )
674+
675+ instanceID := expected .instanceID
676+ if expected .nodeName != nodeName {
677+ testcase .t .Errorf ("Unexpected DisksAreAttachedByName call: expected nodeName %s, got %s" , expected .nodeName , nodeName )
678+ return areAttached , errors .New ("Unexpected DisksAreAttachedByName call: wrong nodename" )
679+ }
680+ if len (expected .volumeIDs ) == 0 && expected .instanceID == "" {
681+ // testcase.volumeIDs looks uninitialized, test did not expect to call DisksAreAttached
682+ testcase .t .Errorf ("Unexpected DisksAreAttachedByName call!" )
683+ return areAttached , errors .New ("Unexpected DisksAreAttachedByName call" )
684+ }
685+
686+ if ! reflect .DeepEqual (expected .volumeIDs , volumeIDs ) {
687+ testcase .t .Errorf ("Unexpected DisksAreAttachedByName call: expected volumeIDs %v, got %v" , expected .volumeIDs , volumeIDs )
688+ return areAttached , errors .New ("Unexpected DisksAreAttachedByName call: wrong volumeID" )
689+ }
690+
691+ if expected .instanceID != instanceID {
692+ testcase .t .Errorf ("Unexpected DisksAreAttachedByName call: expected instanceID %s, got %s" , expected .instanceID , instanceID )
693+ return areAttached , errors .New ("Unexpected DisksAreAttachedByName call: wrong instanceID" )
694+ }
695+
696+ glog .V (4 ).Infof ("DisksAreAttachedByName call: %v, %s, returning %v, %v" , volumeIDs , nodeName , expected .areAttached , expected .ret )
697+
698+ return expected .areAttached , expected .ret
699+ }
700+
629701// Implementation of fake cloudprovider.Instances
630702type instances struct {
631703 instanceID string
0 commit comments