forked from ciao-project/ciao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.go
853 lines (706 loc) · 22.3 KB
/
agent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
//
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package testutil
import (
"errors"
"fmt"
"os"
"sync"
"time"
"github.com/01org/ciao/payloads"
"github.com/01org/ciao/ssntp"
"gopkg.in/yaml.v2"
)
// SsntpTestClient is global state for the testutil SSNTP client worker
type SsntpTestClient struct {
Ssntp ssntp.Client
Name string
instances []payloads.InstanceStat
instancesLock *sync.Mutex
ticker *time.Ticker
UUID string
Role ssntp.Role
StartFail bool
StartFailReason payloads.StartFailureReason
StopFail bool
StopFailReason payloads.StopFailureReason
RestartFail bool
RestartFailReason payloads.RestartFailureReason
DeleteFail bool
DeleteFailReason payloads.DeleteFailureReason
AttachFail bool
AttachVolumeFailReason payloads.AttachVolumeFailureReason
DetachFail bool
DetachVolumeFailReason payloads.DetachVolumeFailureReason
traces []*ssntp.Frame
tracesLock *sync.Mutex
CmdChans map[ssntp.Command]chan Result
CmdChansLock *sync.Mutex
EventChans map[ssntp.Event]chan Result
EventChansLock *sync.Mutex
ErrorChans map[ssntp.Error]chan Result
ErrorChansLock *sync.Mutex
StatusChans map[ssntp.Status]chan Result
StatusChansLock *sync.Mutex
}
// Shutdown shuts down the testutil.SsntpTestClient and cleans up state
func (client *SsntpTestClient) Shutdown() {
closeClientChans(client)
client.Ssntp.Close()
}
// NewSsntpTestClientConnection creates an SsntpTestClient and dials the server.
// Calling with a unique name parameter string for inclusion in the SsntpTestClient.Name
// field aides in debugging. The role parameter is mandatory. The uuid string
// parameter allows tests to specify a known uuid for simpler tests.
func NewSsntpTestClientConnection(name string, role ssntp.Role, uuid string) (*SsntpTestClient, error) {
if role == ssntp.UNKNOWN {
return nil, errors.New("no role specified")
}
if uuid == "" {
return nil, errors.New("no uuid specified")
}
client := new(SsntpTestClient)
client.Name = "Test " + role.String() + " " + name
client.UUID = uuid
client.Role = role
client.StartFail = false
client.CmdChansLock = &sync.Mutex{}
client.EventChansLock = &sync.Mutex{}
client.ErrorChansLock = &sync.Mutex{}
client.StatusChansLock = &sync.Mutex{}
openClientChans(client)
client.instancesLock = &sync.Mutex{}
client.tracesLock = &sync.Mutex{}
config := &ssntp.Config{
CAcert: ssntp.DefaultCACert,
Cert: ssntp.RoleToDefaultCertName(role),
Log: ssntp.Log,
UUID: client.UUID,
}
if err := client.Ssntp.Dial(config, client); err != nil {
return nil, err
}
return client, nil
}
// AddCmdChan adds an ssntp.Command to the SsntpTestClient command channel
func (client *SsntpTestClient) AddCmdChan(cmd ssntp.Command) *chan Result {
c := make(chan Result)
client.CmdChansLock.Lock()
client.CmdChans[cmd] = c
client.CmdChansLock.Unlock()
return &c
}
// GetCmdChanResult gets a Result from the SsntpTestClient command channel
func (client *SsntpTestClient) GetCmdChanResult(c *chan Result, cmd ssntp.Command) (result Result, err error) {
select {
case result = <-*c:
if result.Err != nil {
err = fmt.Errorf("Client error sending %s command: %s\n", cmd, result.Err)
}
case <-time.After(25 * time.Second):
err = fmt.Errorf("Timeout waiting for client %s command result\n", cmd)
}
return result, err
}
// SendResultAndDelCmdChan deletes an ssntp.Command from the SsntpTestClient command channel
func (client *SsntpTestClient) SendResultAndDelCmdChan(cmd ssntp.Command, result Result) {
client.CmdChansLock.Lock()
c, ok := client.CmdChans[cmd]
if ok {
delete(client.CmdChans, cmd)
client.CmdChansLock.Unlock()
c <- result
close(c)
return
}
client.CmdChansLock.Unlock()
}
// AddEventChan adds a ssntp.Event to the SsntpTestClient event channel
func (client *SsntpTestClient) AddEventChan(evt ssntp.Event) *chan Result {
c := make(chan Result)
client.EventChansLock.Lock()
client.EventChans[evt] = c
client.EventChansLock.Unlock()
return &c
}
// GetEventChanResult gets a Result from the SsntpTestClient event channel
func (client *SsntpTestClient) GetEventChanResult(c *chan Result, evt ssntp.Event) (result Result, err error) {
select {
case result = <-*c:
if result.Err != nil {
err = fmt.Errorf("Client error sending %s event: %s\n", evt, result.Err)
}
case <-time.After(25 * time.Second):
err = fmt.Errorf("Timeout waiting for client %s event result\n", evt)
}
return result, err
}
// SendResultAndDelEventChan deletes an ssntp.Event from the SsntpTestClient event channel
func (client *SsntpTestClient) SendResultAndDelEventChan(evt ssntp.Event, result Result) {
client.EventChansLock.Lock()
c, ok := client.EventChans[evt]
if ok {
delete(client.EventChans, evt)
client.EventChansLock.Unlock()
c <- result
close(c)
return
}
client.EventChansLock.Unlock()
}
// AddErrorChan adds a ssntp.Error to the SsntpTestClient error channel
func (client *SsntpTestClient) AddErrorChan(error ssntp.Error) *chan Result {
c := make(chan Result)
client.ErrorChansLock.Lock()
client.ErrorChans[error] = c
client.ErrorChansLock.Unlock()
return &c
}
// GetErrorChanResult gets a Result from the SsntpTestClient error channel
func (client *SsntpTestClient) GetErrorChanResult(c *chan Result, error ssntp.Error) (result Result, err error) {
select {
case result = <-*c:
if result.Err != nil {
err = fmt.Errorf("Client error sending %s error: %s\n", error, result.Err)
}
case <-time.After(25 * time.Second):
err = fmt.Errorf("Timeout waiting for client %s error result\n", error)
}
return result, err
}
// SendResultAndDelErrorChan deletes an ssntp.Error from the SsntpTestClient error channel
func (client *SsntpTestClient) SendResultAndDelErrorChan(error ssntp.Error, result Result) {
client.ErrorChansLock.Lock()
c, ok := client.ErrorChans[error]
if ok {
delete(client.ErrorChans, error)
client.ErrorChansLock.Unlock()
c <- result
close(c)
return
}
client.ErrorChansLock.Unlock()
}
// AddStatusChan adds an ssntp.Status to the SsntpTestClient status channel
func (client *SsntpTestClient) AddStatusChan(status ssntp.Status) *chan Result {
c := make(chan Result)
client.StatusChansLock.Lock()
client.StatusChans[status] = c
client.StatusChansLock.Unlock()
return &c
}
// GetStatusChanResult gets a Result from the SsntpTestClient status channel
func (client *SsntpTestClient) GetStatusChanResult(c *chan Result, status ssntp.Status) (result Result, err error) {
select {
case result = <-*c:
if result.Err != nil {
err = fmt.Errorf("Client error sending %s status: %s\n", status, result.Err)
}
case <-time.After(25 * time.Second):
err = fmt.Errorf("Timeout waiting for client %s status result\n", status)
}
return result, err
}
// SendResultAndDelStatusChan deletes an ssntp.Status from the SsntpTestClient status channel
func (client *SsntpTestClient) SendResultAndDelStatusChan(status ssntp.Status, result Result) {
client.StatusChansLock.Lock()
c, ok := client.StatusChans[status]
if ok {
delete(client.StatusChans, status)
client.StatusChansLock.Unlock()
c <- result
close(c)
return
}
client.StatusChansLock.Unlock()
}
func openClientChans(client *SsntpTestClient) {
client.CmdChansLock.Lock()
client.CmdChans = make(map[ssntp.Command]chan Result)
client.CmdChansLock.Unlock()
client.EventChansLock.Lock()
client.EventChans = make(map[ssntp.Event]chan Result)
client.EventChansLock.Unlock()
client.ErrorChansLock.Lock()
client.ErrorChans = make(map[ssntp.Error]chan Result)
client.ErrorChansLock.Unlock()
client.StatusChansLock.Lock()
client.StatusChans = make(map[ssntp.Status]chan Result)
client.StatusChansLock.Unlock()
}
func closeClientChans(client *SsntpTestClient) {
client.CmdChansLock.Lock()
for k := range client.CmdChans {
close(client.CmdChans[k])
delete(client.CmdChans, k)
}
client.CmdChansLock.Unlock()
client.EventChansLock.Lock()
for k := range client.EventChans {
close(client.EventChans[k])
delete(client.EventChans, k)
}
client.EventChansLock.Unlock()
client.ErrorChansLock.Lock()
for k := range client.ErrorChans {
close(client.ErrorChans[k])
delete(client.ErrorChans, k)
}
client.ErrorChansLock.Unlock()
client.StatusChansLock.Lock()
for k := range client.StatusChans {
close(client.StatusChans[k])
delete(client.StatusChans, k)
}
client.StatusChansLock.Unlock()
}
// ConnectNotify implements the SSNTP client ConnectNotify callback for SsntpTestClient
func (client *SsntpTestClient) ConnectNotify() {
var result Result
go client.SendResultAndDelEventChan(ssntp.NodeConnected, result)
}
// DisconnectNotify implements the SSNTP client ConnectNotify callback for SsntpTestClient
func (client *SsntpTestClient) DisconnectNotify() {
var result Result
go client.SendResultAndDelEventChan(ssntp.NodeDisconnected, result)
}
// StatusNotify implements the SSNTP client StatusNotify callback for SsntpTestClient
func (client *SsntpTestClient) StatusNotify(status ssntp.Status, frame *ssntp.Frame) {
}
func (client *SsntpTestClient) handleStart(payload []byte) Result {
var result Result
var cmd payloads.Start
err := yaml.Unmarshal(payload, &cmd)
if err != nil {
result.Err = err
return result
}
result.InstanceUUID = cmd.Start.InstanceUUID
result.TenantUUID = cmd.Start.TenantUUID
result.NodeUUID = client.UUID
if client.Role.IsNetAgent() {
result.CNCI = true
}
if client.StartFail == true {
result.Err = errors.New(client.StartFailReason.String())
client.sendStartFailure(cmd.Start.InstanceUUID, client.StartFailReason)
go client.SendResultAndDelErrorChan(ssntp.StartFailure, result)
return result
}
istat := payloads.InstanceStat{
InstanceUUID: cmd.Start.InstanceUUID,
State: payloads.Running,
MemoryUsageMB: 0,
DiskUsageMB: 0,
CPUUsage: 0,
}
client.instancesLock.Lock()
client.instances = append(client.instances, istat)
client.instancesLock.Unlock()
return result
}
func (client *SsntpTestClient) handleStop(payload []byte) Result {
var result Result
var cmd payloads.Stop
err := yaml.Unmarshal(payload, &cmd)
if err != nil {
result.Err = err
return result
}
if client.StopFail == true {
result.Err = errors.New(client.StopFailReason.String())
client.sendStopFailure(cmd.Stop.InstanceUUID, client.StopFailReason)
go client.SendResultAndDelErrorChan(ssntp.StopFailure, result)
return result
}
client.instancesLock.Lock()
defer client.instancesLock.Unlock()
for i := range client.instances {
istat := client.instances[i]
if istat.InstanceUUID == cmd.Stop.InstanceUUID {
client.instances[i].State = payloads.Exited
}
}
return result
}
func (client *SsntpTestClient) handleRestart(payload []byte) Result {
var result Result
var cmd payloads.Restart
err := yaml.Unmarshal(payload, &cmd)
if err != nil {
result.Err = err
return result
}
if client.RestartFail == true {
result.Err = errors.New(client.RestartFailReason.String())
client.sendRestartFailure(cmd.Restart.InstanceUUID, client.RestartFailReason)
go client.SendResultAndDelErrorChan(ssntp.RestartFailure, result)
return result
}
client.instancesLock.Lock()
defer client.instancesLock.Unlock()
for i := range client.instances {
istat := client.instances[i]
if istat.InstanceUUID == cmd.Restart.InstanceUUID {
client.instances[i].State = payloads.Running
}
}
return result
}
func (client *SsntpTestClient) handleDelete(payload []byte) Result {
var result Result
var cmd payloads.Delete
err := yaml.Unmarshal(payload, &cmd)
if err != nil {
result.Err = err
return result
}
if client.DeleteFail == true {
result.Err = errors.New(client.DeleteFailReason.String())
client.sendDeleteFailure(cmd.Delete.InstanceUUID, client.DeleteFailReason)
go client.SendResultAndDelErrorChan(ssntp.DeleteFailure, result)
return result
}
client.instancesLock.Lock()
defer client.instancesLock.Unlock()
for i := range client.instances {
istat := client.instances[i]
if istat.InstanceUUID == cmd.Delete.InstanceUUID {
client.instances = append(client.instances[:i], client.instances[i+1:]...)
break
}
}
return result
}
func (client *SsntpTestClient) handleAttachVolume(payload []byte) Result {
var result Result
var cmd payloads.AttachVolume
err := yaml.Unmarshal(payload, &cmd)
if err != nil {
result.Err = err
return result
}
if client.AttachFail == true {
result.Err = errors.New(client.AttachVolumeFailReason.String())
client.sendAttachVolumeFailure(cmd.Attach.InstanceUUID, cmd.Attach.VolumeUUID, client.AttachVolumeFailReason)
client.SendResultAndDelErrorChan(ssntp.AttachVolumeFailure, result)
return result
}
// update statistics for volume
client.instancesLock.Lock()
for i, istat := range client.instances {
if istat.InstanceUUID == cmd.Attach.InstanceUUID {
client.instances[i].Volumes = append(istat.Volumes, cmd.Attach.VolumeUUID)
}
}
client.instancesLock.Unlock()
return result
}
func (client *SsntpTestClient) handleDetachVolume(payload []byte) Result {
var result Result
var cmd payloads.DetachVolume
err := yaml.Unmarshal(payload, &cmd)
if err != nil {
result.Err = err
return result
}
if client.DetachFail == true {
result.Err = errors.New(client.DetachVolumeFailReason.String())
client.sendDetachVolumeFailure(cmd.Detach.InstanceUUID, cmd.Detach.VolumeUUID, client.DetachVolumeFailReason)
client.SendResultAndDelErrorChan(ssntp.DetachVolumeFailure, result)
return result
}
return result
}
// CommandNotify implements the SSNTP client CommandNotify callback for SsntpTestClient
func (client *SsntpTestClient) CommandNotify(command ssntp.Command, frame *ssntp.Frame) {
payload := frame.Payload
var result Result
if frame.Trace != nil {
frame.SetEndStamp()
client.tracesLock.Lock()
client.traces = append(client.traces, frame)
client.tracesLock.Unlock()
}
switch command {
/* FIXME: implement
case ssntp.CONNECT:
case ssntp.STATS:
case ssntp.EVACUATE:
case ssntp.AssignPublicIP:
case ssntp.ReleasePublicIP:
case ssntp.CONFIGURE:
*/
case ssntp.START:
result = client.handleStart(payload)
case ssntp.STOP:
result = client.handleStop(payload)
case ssntp.RESTART:
result = client.handleRestart(payload)
case ssntp.DELETE:
result = client.handleDelete(payload)
case ssntp.AttachVolume:
result = client.handleAttachVolume(payload)
case ssntp.DetachVolume:
result = client.handleDetachVolume(payload)
default:
fmt.Fprintf(os.Stderr, "client %s unhandled command %s\n", client.Role.String(), command.String())
}
go client.SendResultAndDelCmdChan(command, result)
}
// EventNotify is an SSNTP callback stub for SsntpTestClient
func (client *SsntpTestClient) EventNotify(event ssntp.Event, frame *ssntp.Frame) {
var result Result
switch event {
case ssntp.NodeConnected:
//handled by ConnectNotify()
return
case ssntp.NodeDisconnected:
//handled by DisconnectNotify()
return
case ssntp.TenantAdded:
var tenantAddedEvent payloads.EventTenantAdded
err := yaml.Unmarshal(frame.Payload, &tenantAddedEvent)
if err != nil {
result.Err = err
}
case ssntp.TenantRemoved:
var tenantRemovedEvent payloads.EventTenantRemoved
err := yaml.Unmarshal(frame.Payload, &tenantRemovedEvent)
if err != nil {
result.Err = err
}
default:
fmt.Fprintf(os.Stderr, "client %s unhandled event: %s\n", client.Role.String(), event.String())
}
go client.SendResultAndDelEventChan(event, result)
}
// ErrorNotify is an SSNTP callback stub for SsntpTestClient
func (client *SsntpTestClient) ErrorNotify(error ssntp.Error, frame *ssntp.Frame) {
}
// SendStatsCmd pushes an ssntp.STATS command frame from the SsntpTestClient
func (client *SsntpTestClient) SendStatsCmd() {
var result Result
payload := StatsPayload(client.UUID, client.Name, client.instances, nil)
y, err := yaml.Marshal(payload)
if err != nil {
result.Err = err
} else {
_, err = client.Ssntp.SendCommand(ssntp.STATS, y)
if err != nil {
result.Err = err
}
}
go client.SendResultAndDelCmdChan(ssntp.STATS, result)
}
// SendStatus pushes an ssntp status frame from the SsntpTestClient with
// the indicated total and available memory statistics
func (client *SsntpTestClient) SendStatus(memTotal int, memAvail int) {
var result Result
payload := ReadyPayload(client.UUID, memTotal, memAvail)
y, err := yaml.Marshal(payload)
if err != nil {
result.Err = err
} else {
_, err = client.Ssntp.SendStatus(ssntp.READY, y)
if err != nil {
result.Err = err
}
}
go client.SendResultAndDelCmdChan(ssntp.STATS, result)
}
// SendTrace allows an SsntpTestClient to push an ssntp.TraceReport event frame
func (client *SsntpTestClient) SendTrace() {
var result Result
var s payloads.Trace
client.tracesLock.Lock()
defer client.tracesLock.Unlock()
for _, f := range client.traces {
t, err := f.DumpTrace()
if err != nil {
continue
}
s.Frames = append(s.Frames, *t)
}
y, err := yaml.Marshal(&s)
if err != nil {
result.Err = err
} else {
client.traces = nil
_, err = client.Ssntp.SendEvent(ssntp.TraceReport, y)
if err != nil {
result.Err = err
}
}
go client.SendResultAndDelEventChan(ssntp.TraceReport, result)
}
// SendDeleteEvent allows an SsntpTestClient to push an ssntp.InstanceDeleted event frame
func (client *SsntpTestClient) SendDeleteEvent(uuid string) {
var result Result
evt := payloads.InstanceDeletedEvent{
InstanceUUID: uuid,
}
event := payloads.EventInstanceDeleted{
InstanceDeleted: evt,
}
y, err := yaml.Marshal(event)
if err != nil {
result.Err = err
} else {
_, err = client.Ssntp.SendEvent(ssntp.InstanceDeleted, y)
if err != nil {
result.Err = err
}
}
go client.SendResultAndDelEventChan(ssntp.InstanceDeleted, result)
}
// SendTenantAddedEvent allows an SsntpTestClient to push an ssntp.TenantAdded event frame
func (client *SsntpTestClient) SendTenantAddedEvent() {
var result Result
_, err := client.Ssntp.SendEvent(ssntp.TenantAdded, []byte(TenantAddedYaml))
if err != nil {
result.Err = err
}
go client.SendResultAndDelEventChan(ssntp.TenantAdded, result)
}
// SendTenantRemovedEvent allows an SsntpTestClient to push an ssntp.TenantRemoved event frame
func (client *SsntpTestClient) SendTenantRemovedEvent() {
var result Result
_, err := client.Ssntp.SendEvent(ssntp.TenantRemoved, []byte(TenantRemovedYaml))
if err != nil {
result.Err = err
}
go client.SendResultAndDelEventChan(ssntp.TenantRemoved, result)
}
// SendPublicIPAssignedEvent allows an SsntpTestClient to push an ssntp.PublicIPAssigned event frame
func (client *SsntpTestClient) SendPublicIPAssignedEvent() {
var result Result
_, err := client.Ssntp.SendEvent(ssntp.PublicIPAssigned, []byte(AssignedIPYaml))
if err != nil {
result.Err = err
}
go client.SendResultAndDelEventChan(ssntp.PublicIPAssigned, result)
}
// SendConcentratorAddedEvent allows an SsntpTestClient to push an ssntp.ConcentratorInstanceAdded event frame
func (client *SsntpTestClient) SendConcentratorAddedEvent(instanceUUID string, tenantUUID string, ip string, vnicMAC string) {
var result Result
evt := payloads.ConcentratorInstanceAddedEvent{
InstanceUUID: instanceUUID,
TenantUUID: tenantUUID,
ConcentratorIP: ip,
ConcentratorMAC: vnicMAC,
}
result.InstanceUUID = instanceUUID
event := payloads.EventConcentratorInstanceAdded{
CNCIAdded: evt,
}
y, err := yaml.Marshal(event)
if err != nil {
result.Err = err
} else {
_, err = client.Ssntp.SendEvent(ssntp.ConcentratorInstanceAdded, y)
if err != nil {
result.Err = err
}
}
go client.SendResultAndDelEventChan(ssntp.ConcentratorInstanceAdded, result)
}
func (client *SsntpTestClient) sendStartFailure(instanceUUID string, reason payloads.StartFailureReason) {
e := payloads.ErrorStartFailure{
InstanceUUID: instanceUUID,
Reason: reason,
}
y, err := yaml.Marshal(e)
if err != nil {
return
}
_, err = client.Ssntp.SendError(ssntp.StartFailure, y)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
func (client *SsntpTestClient) sendStopFailure(instanceUUID string, reason payloads.StopFailureReason) {
e := payloads.ErrorStopFailure{
InstanceUUID: instanceUUID,
Reason: reason,
}
y, err := yaml.Marshal(e)
if err != nil {
return
}
_, err = client.Ssntp.SendError(ssntp.StopFailure, y)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
func (client *SsntpTestClient) sendRestartFailure(instanceUUID string, reason payloads.RestartFailureReason) {
e := payloads.ErrorRestartFailure{
InstanceUUID: instanceUUID,
Reason: reason,
}
y, err := yaml.Marshal(e)
if err != nil {
return
}
_, err = client.Ssntp.SendError(ssntp.RestartFailure, y)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
func (client *SsntpTestClient) sendDeleteFailure(instanceUUID string, reason payloads.DeleteFailureReason) {
e := payloads.ErrorDeleteFailure{
InstanceUUID: instanceUUID,
Reason: reason,
}
y, err := yaml.Marshal(e)
if err != nil {
return
}
_, err = client.Ssntp.SendError(ssntp.DeleteFailure, y)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
func (client *SsntpTestClient) sendAttachVolumeFailure(instanceUUID string, volumeUUID string, reason payloads.AttachVolumeFailureReason) {
e := payloads.ErrorAttachVolumeFailure{
InstanceUUID: instanceUUID,
VolumeUUID: volumeUUID,
Reason: reason,
}
y, err := yaml.Marshal(e)
if err != nil {
return
}
_, err = client.Ssntp.SendError(ssntp.AttachVolumeFailure, y)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
func (client *SsntpTestClient) sendDetachVolumeFailure(instanceUUID string, volumeUUID string, reason payloads.DetachVolumeFailureReason) {
e := payloads.ErrorDetachVolumeFailure{
InstanceUUID: instanceUUID,
VolumeUUID: volumeUUID,
Reason: reason,
}
y, err := yaml.Marshal(e)
if err != nil {
return
}
_, err = client.Ssntp.SendError(ssntp.DetachVolumeFailure, y)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}