8
8
#include < string>
9
9
#include < thread>
10
10
#include < vector>
11
- #include < iostream>
12
11
13
12
#include " mock_reboot_interfaces.h"
14
13
#include " reboot_common.h"
@@ -63,6 +62,7 @@ class RebootBETestWithoutStop : public ::testing::Test {
63
62
m_rebootbeReponseChannel(&m_db, REBOOT_RESPONSE_NOTIFICATION_CHANNEL),
64
63
m_rebootbe(m_dbus_interface) {
65
64
sigterm_requested = false ;
65
+ // TestUtils::clear_tables(m_db);
66
66
67
67
68
68
m_s.addSelectable (&m_rebootbeReponseChannel);
@@ -74,6 +74,15 @@ class RebootBETestWithoutStop : public ::testing::Test {
74
74
}
75
75
virtual ~RebootBETestWithoutStop () = default ;
76
76
77
+ void force_warm_start_state (bool enabled) {
78
+ swss::Table enable_table (&m_db, STATE_WARM_RESTART_ENABLE_TABLE_NAME);
79
+ enable_table.hset (" system" , " enable" , enabled ? " true" : " false" );
80
+ enable_table.hset (" sonic-framework" , " enable" , enabled ? " true" : " false" );
81
+
82
+ swss::Table restart_table (&m_db, STATE_WARM_RESTART_TABLE_NAME);
83
+ restart_table.hset (" rebootbackend" , " restore_count" , enabled ? " 0" : " " );
84
+ }
85
+
77
86
void start_rebootbe () {
78
87
m_rebootbe_thread =
79
88
std::make_unique<std::thread>(&RebootBE::Start, &m_rebootbe);
@@ -202,18 +211,62 @@ class RebootBETest : public RebootBETestWithoutStop {
202
211
}
203
212
};
204
213
214
+ TEST_F (RebootBETest, WarmbootInProgressBlocksNewWarmboot) {
215
+ force_warm_start_state (true );
216
+
217
+ start_rebootbe ();
218
+ std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
219
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (),
220
+ RebootBE::RebManagerStatus::WARM_INIT_WAIT);
221
+
222
+ // Send a warmboot request, confirm it fails.
223
+ RebootRequest request;
224
+ request.set_method (RebootMethod::WARM);
225
+ start_reboot_via_rpc (request, swss::StatusCode::SWSS_RC_IN_USE);
226
+
227
+ std::this_thread::sleep_for (std::chrono::milliseconds (TENTH_SECOND_MS));
228
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (),
229
+ RebootBE::RebManagerStatus::WARM_INIT_WAIT);
230
+ force_warm_start_state (false );
231
+ }
232
+
233
+
234
+ TEST_F (RebootBETest, ColdbootWhileWarmbootInProgress) {
235
+ force_warm_start_state (true );
236
+ set_mock_defaults ();
237
+
238
+ start_rebootbe ();
239
+ std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
240
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (),
241
+ RebootBE::RebManagerStatus::WARM_INIT_WAIT);
242
+
243
+ // Send a coldboot request, confirm it starts.
244
+ RebootRequest request;
245
+ request.set_method (RebootMethod::COLD);
246
+ start_reboot_via_rpc (request);
247
+
248
+ std::this_thread::sleep_for (std::chrono::milliseconds (TENTH_SECOND_MS));
249
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (),
250
+ RebootBE::RebManagerStatus::COLD_REBOOT_IN_PROGRESS);
251
+
252
+ // Cleanup without going through the whole reboot.
253
+ send_stop_reboot_thread ();
254
+ force_warm_start_state (false );
255
+ }
256
+
257
+
205
258
// Test fixture to skip through the startup sequence into the main loop.
206
259
// Param indicates if RebootBE should be initialized into a state where the
207
260
// system came up in warmboot.
208
261
class RebootBEAutoStartTest : public RebootBETest ,
209
262
public ::testing::WithParamInterface<bool > {
210
263
protected:
211
264
RebootBEAutoStartTest () {
212
- // force_warm_start_state(GetParam());
213
265
214
266
start_rebootbe ();
215
267
216
- std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
268
+ // std::this_thread::sleep_for(std::chrono::milliseconds(50));
269
+ std::this_thread::sleep_for (std::chrono::milliseconds (ONE_SECOND_MS));
217
270
EXPECT_EQ (m_rebootbe.GetCurrentStatus (), RebootBE::RebManagerStatus::IDLE);
218
271
}
219
272
};
@@ -312,6 +365,31 @@ TEST_P(RebootBEAutoStartTest, TestColdRebootDbusToCompletion) {
312
365
" platform failed to reboot" ));
313
366
}
314
367
368
+
369
+ TEST_P (RebootBEAutoStartTest, TestWarmRebootDbusToCompletion) {
370
+ DbusInterface::DbusResponse dbus_response{
371
+ DbusInterface::DbusStatus::DBUS_SUCCESS, " " };
372
+ EXPECT_CALL (m_dbus_interface, Reboot (_))
373
+ .Times (1 )
374
+ .WillRepeatedly (Return (dbus_response));
375
+
376
+ overwrite_reboot_timeout (1 );
377
+ RebootRequest request;
378
+ request.set_method (RebootMethod::WARM);
379
+ start_reboot_via_rpc (request);
380
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (), RebootBE::RebManagerStatus::WARM_REBOOT_IN_PROGRESS);
381
+
382
+ sleep (TWO_SECONDS);
383
+
384
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (), RebootBE::RebManagerStatus::IDLE);
385
+ gnoi::system ::RebootStatusResponse response = do_reboot_status_rpc ();
386
+ EXPECT_THAT (response, ActiveCountMethod (false , 1 , RebootMethod::WARM));
387
+ EXPECT_THAT (response,
388
+ IsStatus (RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE,
389
+ " failed to warm reboot" ));
390
+
391
+ }
392
+
315
393
TEST_P (RebootBEAutoStartTest, TestColdBootSigterm) {
316
394
sigterm_requested = true ;
317
395
set_mock_defaults ();
@@ -331,6 +409,25 @@ TEST_P(RebootBEAutoStartTest, TestColdBootSigterm) {
331
409
IsStatus (RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, " " ));
332
410
}
333
411
412
+ TEST_P (RebootBEAutoStartTest, TestWarmBootSigterm) {
413
+ sigterm_requested = true ;
414
+ set_mock_defaults ();
415
+ overwrite_reboot_timeout (1 );
416
+
417
+ RebootRequest request;
418
+ request.set_method (RebootMethod::WARM);
419
+ start_reboot_via_rpc (request);
420
+
421
+ sleep (ONE_SECOND);
422
+
423
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (), RebootBE::RebManagerStatus::IDLE);
424
+ gnoi::system ::RebootStatusResponse second_resp = do_reboot_status_rpc ();
425
+ EXPECT_THAT (second_resp, ActiveCountMethod (false , 1 , RebootMethod::WARM));
426
+ EXPECT_THAT (
427
+ second_resp,
428
+ IsStatus (RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, " " ));
429
+ }
430
+
334
431
TEST_P (RebootBEAutoStartTest, TestColdBootDbusError) {
335
432
// Return FAIL from dbus reboot call.
336
433
DbusInterface::DbusResponse dbus_response{
@@ -353,6 +450,28 @@ TEST_P(RebootBEAutoStartTest, TestColdBootDbusError) {
353
450
" dbus reboot failed" ));
354
451
}
355
452
453
+ TEST_P (RebootBEAutoStartTest, TestWarmBootDbusError) {
454
+ // Return FAIL from dbus reboot call.
455
+ DbusInterface::DbusResponse dbus_response{
456
+ DbusInterface::DbusStatus::DBUS_FAIL, " dbus reboot failed" };
457
+ EXPECT_CALL (m_dbus_interface, Reboot (_))
458
+ .Times (1 )
459
+ .WillOnce (Return (dbus_response));
460
+
461
+ RebootRequest request;
462
+ request.set_method (RebootMethod::WARM);
463
+ start_reboot_via_rpc (request);
464
+
465
+ sleep (TWO_SECONDS);
466
+
467
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (), RebootBE::RebManagerStatus::IDLE);
468
+ gnoi::system ::RebootStatusResponse second_resp = do_reboot_status_rpc ();
469
+ EXPECT_THAT (second_resp, ActiveCountMethod (false , 1 , RebootMethod::WARM));
470
+ EXPECT_THAT (second_resp,
471
+ IsStatus (RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE,
472
+ " dbus reboot failed" ));
473
+ }
474
+
356
475
TEST_P (RebootBEAutoStartTest, TestStopDuringColdBoot) {
357
476
set_mock_defaults ();
358
477
@@ -374,12 +493,66 @@ TEST_P(RebootBEAutoStartTest, TestStopDuringColdBoot) {
374
493
IsStatus (RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, " " ));
375
494
}
376
495
496
+ TEST_P (RebootBEAutoStartTest, TestStopDuringWarmBoot) {
497
+ set_mock_defaults ();
498
+
499
+ RebootRequest request;
500
+ request.set_method (RebootMethod::WARM);
501
+ start_reboot_via_rpc (request);
502
+ // std::this_thread::sleep_for(std::chrono::milliseconds(TENTH_SECOND_MS));
503
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (),
504
+ RebootBE::RebManagerStatus::WARM_REBOOT_IN_PROGRESS);
505
+
506
+ send_stop_reboot_thread ();
507
+ std::this_thread::sleep_for (std::chrono::milliseconds (TENTH_SECOND_MS));
508
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (), RebootBE::RebManagerStatus::IDLE);
509
+
510
+ gnoi::system ::RebootStatusResponse response = do_reboot_status_rpc ();
511
+ EXPECT_THAT (response, ActiveCountMethod (false , 1 , RebootMethod::WARM));
512
+ EXPECT_THAT (
513
+ response,
514
+ IsStatus (RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN, " " ));
515
+ }
516
+
377
517
TEST_P (RebootBEAutoStartTest, TestInvalidJsonRebootRequest) {
378
518
std::string json_request = " abcd" ;
379
519
NotificationResponse response = handle_reboot_request (json_request);
380
520
EXPECT_EQ (swss::StatusCode::SWSS_RC_INTERNAL, response.status );
381
521
}
382
522
523
+ TEST_P (RebootBEAutoStartTest, TestWarmFailureFollowedByColdBoot) {
524
+ DbusInterface::DbusResponse dbus_response{
525
+ DbusInterface::DbusStatus::DBUS_SUCCESS, " " };
526
+ overwrite_reboot_timeout (1 );
527
+
528
+ RebootRequest request;
529
+ request.set_method (RebootMethod::WARM);
530
+ start_reboot_via_rpc (request);
531
+
532
+ std::this_thread::sleep_for (std::chrono::milliseconds (TENTH_SECOND_MS));
533
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (),
534
+ RebootBE::RebManagerStatus::WARM_REBOOT_IN_PROGRESS);
535
+
536
+ std::this_thread::sleep_for (std::chrono::milliseconds (TWO_SECONDS_MS));
537
+ gnoi::system ::RebootStatusResponse response = do_reboot_status_rpc ();
538
+ EXPECT_THAT (response, ActiveCountMethod (false , 1 , RebootMethod::WARM));
539
+
540
+
541
+ request.set_method (RebootMethod::COLD);
542
+ start_reboot_via_rpc (request);
543
+
544
+ // We have to wait for the 1 second reboot Timeout
545
+ std::this_thread::sleep_for (std::chrono::milliseconds (TWO_SECONDS_MS));
546
+
547
+ EXPECT_EQ (m_rebootbe.GetCurrentStatus (), RebootBE::RebManagerStatus::IDLE);
548
+ response = do_reboot_status_rpc ();
549
+ EXPECT_THAT (response, ActiveCountMethod (false , 2 , RebootMethod::COLD));
550
+ EXPECT_THAT (response,
551
+ IsStatus (RebootStatus_Status::RebootStatus_Status_STATUS_FAILURE,
552
+ " platform failed to reboot" ));
553
+ }
554
+
555
+
383
556
INSTANTIATE_TEST_SUITE_P (TestWithStartupWarmbootEnabledState,
384
557
RebootBEAutoStartTest, testing::Values(true , false ));
385
558
0 commit comments