Skip to content

Commit 95fa5db

Browse files
committedJan 12, 2025·
Fixed the code style
1 parent f933d46 commit 95fa5db

File tree

1 file changed

+214
-214
lines changed

1 file changed

+214
-214
lines changed
 

‎hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneTenantShell.java

+214-214
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public class TestOzoneTenantShell {
102102
private static OzoneShell ozoneSh = null;
103103
private static TenantShell tenantShell = null;
104104

105-
private static final StringWriter out = new StringWriter();
106-
private static final StringWriter err = new StringWriter();
105+
private static final StringWriter OUT = new StringWriter();
106+
private static final StringWriter ERR = new StringWriter();
107107

108108
private static String omServiceId;
109109
private static int numOfOMs;
@@ -171,10 +171,10 @@ public static void shutdown() {
171171

172172
@BeforeEach
173173
public void setup() throws UnsupportedEncodingException {
174-
tenantShell.getCmd().setOut(new PrintWriter(out));
175-
tenantShell.getCmd().setErr(new PrintWriter(err));
176-
ozoneSh.getCmd().setOut(new PrintWriter(out));
177-
ozoneSh.getCmd().setErr(new PrintWriter(err));
174+
tenantShell.getCmd().setOut(new PrintWriter(OUT));
175+
tenantShell.getCmd().setErr(new PrintWriter(ERR));
176+
ozoneSh.getCmd().setOut(new PrintWriter(OUT));
177+
ozoneSh.getCmd().setErr(new PrintWriter(ERR));
178178
// Suppress OMNotLeaderException in the log
179179
GenericTestUtils.setLogLevel(RetryInvocationHandler.LOG, Level.WARN);
180180
// Enable debug logging for interested classes
@@ -189,8 +189,8 @@ public void setup() throws UnsupportedEncodingException {
189189
@AfterEach
190190
public void reset() {
191191
// reset stream after each unit test
192-
out.getBuffer().setLength(0);
193-
err.getBuffer().setLength(0);
192+
OUT.getBuffer().setLength(0);
193+
ERR.getBuffer().setLength(0);
194194
}
195195

196196
/**
@@ -201,7 +201,7 @@ private int execute(GenericCli shell, String[] args) {
201201
CommandLine cmd = shell.getCmd();
202202
CommandLine.IExecutionExceptionHandler exceptionHandler =
203203
(ex, commandLine, parseResult) -> {
204-
new PrintWriter(err).println(ex.getMessage());
204+
new PrintWriter(ERR).println(ex.getMessage());
205205
return commandLine.getCommandSpec().exitCodeOnExecutionException();
206206
};
207207

@@ -336,8 +336,8 @@ private void checkOutput(String str, String stringToMatch,
336336

337337
private void deleteVolume(String volumeName) throws IOException {
338338
int exitC = execute(ozoneSh, new String[] {"volume", "delete", volumeName});
339-
checkOutput(out, "Volume " + volumeName + " is deleted\n", true);
340-
checkOutput(err, "", true);
339+
checkOutput(OUT, "Volume " + volumeName + " is deleted\n", true);
340+
checkOutput(ERR, "", true);
341341
// Exit code should be 0
342342
assertEquals(0, exitC);
343343
}
@@ -349,48 +349,48 @@ public void testAssignAdmin() throws IOException {
349349
final String userName = "alice";
350350

351351
executeHA(tenantShell, new String[] {"create", tenantName});
352-
checkOutput(out, "", true);
353-
checkOutput(err, "", true);
352+
checkOutput(OUT, "", true);
353+
checkOutput(ERR, "", true);
354354

355355
// Loop assign-revoke 4 times
356356
for (int i = 0; i < 4; i++) {
357357
executeHA(tenantShell, new String[] {
358358
"user", "assign", userName, "--tenant=" + tenantName});
359-
checkOutput(out, "export AWS_ACCESS_KEY_ID=", false);
360-
checkOutput(err, "", true);
359+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID=", false);
360+
checkOutput(ERR, "", true);
361361

362362
executeHA(tenantShell, new String[] {"--verbose", "user", "assign-admin",
363363
tenantName + "$" + userName, "--tenant=" + tenantName,
364364
"--delegated=true"});
365-
checkOutput(out, "{\n" + " \"accessId\" : \"devaa$alice\",\n"
365+
checkOutput(OUT, "{\n" + " \"accessId\" : \"devaa$alice\",\n"
366366
+ " \"tenantId\" : \"devaa\",\n" + " \"isAdmin\" : true,\n"
367367
+ " \"isDelegatedAdmin\" : true\n" + "}\n", true, true);
368-
checkOutput(err, "", true);
368+
checkOutput(ERR, "", true);
369369

370370
// Clean up
371371
executeHA(tenantShell, new String[] {"--verbose", "user", "revoke-admin",
372372
tenantName + "$" + userName, "--tenant=" + tenantName});
373-
checkOutput(out, "{\n" + " \"accessId\" : \"devaa$alice\",\n"
373+
checkOutput(OUT, "{\n" + " \"accessId\" : \"devaa$alice\",\n"
374374
+ " \"tenantId\" : \"devaa\",\n" + " \"isAdmin\" : false,\n"
375375
+ " \"isDelegatedAdmin\" : false\n" + "}\n", true, true);
376-
checkOutput(err, "", true);
376+
checkOutput(ERR, "", true);
377377

378378
executeHA(tenantShell, new String[] {
379379
"user", "revoke", tenantName + "$" + userName});
380-
checkOutput(out, "", true);
381-
checkOutput(err, "", true);
380+
checkOutput(OUT, "", true);
381+
checkOutput(ERR, "", true);
382382
}
383383

384384
// Clean up
385385
executeHA(tenantShell, new String[] {"delete", tenantName});
386-
checkOutput(out, "", true);
387-
checkOutput(err, "Deleted tenant '" + tenantName + "'.\n", false);
386+
checkOutput(OUT, "", true);
387+
checkOutput(ERR, "Deleted tenant '" + tenantName + "'.\n", false);
388388
deleteVolume(tenantName);
389389

390390
// Sanity check: tenant list should be empty
391391
executeHA(tenantShell, new String[] {"list"});
392-
checkOutput(out, "", true);
393-
checkOutput(err, "", true);
392+
checkOutput(OUT, "", true);
393+
checkOutput(ERR, "", true);
394394
}
395395

396396
/**
@@ -405,19 +405,19 @@ public void testOzoneTenantBasicOperations() throws IOException {
405405
assertEquals(0, lines.size());
406406

407407
executeHA(tenantShell, new String[] {"list"});
408-
checkOutput(out, "", true);
409-
checkOutput(err, "", true);
408+
checkOutput(OUT, "", true);
409+
checkOutput(ERR, "", true);
410410

411411
// Create tenants
412412
// Equivalent to `ozone tenant create finance`
413413
executeHA(tenantShell, new String[] {"create", "finance"});
414-
checkOutput(out, "", true);
415-
checkOutput(err, "", true);
414+
checkOutput(OUT, "", true);
415+
checkOutput(ERR, "", true);
416416

417417
executeHA(tenantShell, new String[] {"list"});
418-
String test = out.toString();
419-
checkOutput(out, "finance\n", true);
420-
checkOutput(err, "", true);
418+
String test = OUT.toString();
419+
checkOutput(OUT, "finance\n", true);
420+
checkOutput(ERR, "", true);
421421

422422
lines = FileUtils.readLines(AUDIT_LOG_FILE, (String)null);
423423
assertThat(lines.size()).isGreaterThan(0);
@@ -429,93 +429,93 @@ public void testOzoneTenantBasicOperations() throws IOException {
429429

430430
// Creating the tenant with the same name again should fail
431431
executeHA(tenantShell, new String[] {"create", "finance"});
432-
checkOutput(out, "", true);
433-
checkOutput(err, "Tenant 'finance' already exists\n", true);
432+
checkOutput(OUT, "", true);
433+
checkOutput(ERR, "Tenant 'finance' already exists\n", true);
434434

435435
executeHA(tenantShell, new String[] {"create", "research"});
436-
checkOutput(out, "", true);
437-
checkOutput(err, "", true);
436+
checkOutput(OUT, "", true);
437+
checkOutput(ERR, "", true);
438438

439439
executeHA(tenantShell, new String[] {"create", "dev"});
440-
checkOutput(out, "", true);
441-
checkOutput(err, "", true);
440+
checkOutput(OUT, "", true);
441+
checkOutput(ERR, "", true);
442442

443443
executeHA(tenantShell, new String[] {"ls"});
444-
checkOutput(out, "dev\nfinance\nresearch\n", true);
445-
checkOutput(err, "", true);
444+
checkOutput(OUT, "dev\nfinance\nresearch\n", true);
445+
checkOutput(ERR, "", true);
446446

447447
executeHA(tenantShell, new String[] {"list", "--json"});
448448
// Not checking the full output here
449-
checkOutput(out, "\"tenantId\" : \"dev\",", false);
450-
checkOutput(err, "", true);
449+
checkOutput(OUT, "\"tenantId\" : \"dev\",", false);
450+
checkOutput(ERR, "", true);
451451

452452
// Attempt user getsecret before assignment, should fail
453453
executeHA(tenantShell, new String[] {
454454
"user", "getsecret", "finance$bob"});
455-
checkOutput(out, "", false);
456-
checkOutput(err, "accessId 'finance$bob' doesn't exist\n",
455+
checkOutput(OUT, "", false);
456+
checkOutput(ERR, "accessId 'finance$bob' doesn't exist\n",
457457
true);
458458

459459
// Assign user accessId
460460
// Equivalent to `ozone tenant user assign bob --tenant=finance`
461461
executeHA(tenantShell, new String[] {
462462
"--verbose", "user", "assign", "bob", "--tenant=finance"});
463-
checkOutput(out, "export AWS_ACCESS_KEY_ID='finance$bob'\n"
463+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='finance$bob'\n"
464464
+ "export AWS_SECRET_ACCESS_KEY='", false);
465-
checkOutput(err, "Assigned 'bob' to 'finance' with accessId"
465+
checkOutput(ERR, "Assigned 'bob' to 'finance' with accessId"
466466
+ " 'finance$bob'.\n", true);
467467

468468
// Try user getsecret again after assignment, should succeed
469469
executeHA(tenantShell, new String[] {
470470
"user", "getsecret", "finance$bob"});
471-
checkOutput(out, "export AWS_ACCESS_KEY_ID='finance$bob'\n",
471+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='finance$bob'\n",
472472
false);
473-
checkOutput(err, "", true);
473+
checkOutput(ERR, "", true);
474474

475475
executeHA(tenantShell, new String[] {
476476
"--verbose", "user", "assign", "bob", "--tenant=research"});
477-
checkOutput(out, "export AWS_ACCESS_KEY_ID='research$bob'\n"
477+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='research$bob'\n"
478478
+ "export AWS_SECRET_ACCESS_KEY='", false);
479-
checkOutput(err, "Assigned 'bob' to 'research' with accessId"
479+
checkOutput(ERR, "Assigned 'bob' to 'research' with accessId"
480480
+ " 'research$bob'.\n", true);
481481

482482
executeHA(tenantShell, new String[] {
483483
"user", "assign", "bob", "--tenant=dev"});
484-
checkOutput(out, "export AWS_ACCESS_KEY_ID='dev$bob'\n"
484+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='dev$bob'\n"
485485
+ "export AWS_SECRET_ACCESS_KEY='", false);
486-
checkOutput(err, "", true);
486+
checkOutput(ERR, "", true);
487487

488488
// accessId length exceeding limit, should fail
489489
executeHA(tenantShell, new String[] {
490490
"user", "assign", StringUtils.repeat('a', 100), "--tenant=dev"});
491-
checkOutput(out, "", true);
492-
checkOutput(err, "accessId length (104) exceeds the maximum length "
491+
checkOutput(OUT, "", true);
492+
checkOutput(ERR, "accessId length (104) exceeds the maximum length "
493493
+ "allowed (100)\n", true);
494494

495495
// Get user info
496496
// Equivalent to `ozone tenant user info bob`
497497
executeHA(tenantShell, new String[] {
498498
"user", "info", "bob"});
499-
checkOutput(out, "User 'bob' is assigned to:\n"
499+
checkOutput(OUT, "User 'bob' is assigned to:\n"
500500
+ "- Tenant 'research' with accessId 'research$bob'\n"
501501
+ "- Tenant 'finance' with accessId 'finance$bob'\n"
502502
+ "- Tenant 'dev' with accessId 'dev$bob'\n", true);
503-
checkOutput(err, "", true);
503+
checkOutput(ERR, "", true);
504504

505505
// Assign admin
506506
executeHA(tenantShell, new String[] {
507507
"user", "assign-admin", "dev$bob", "--tenant=dev", "--delegated"});
508-
checkOutput(out, "", true);
509-
checkOutput(err, "", true);
508+
checkOutput(OUT, "", true);
509+
checkOutput(ERR, "", true);
510510

511511
executeHA(tenantShell, new String[] {
512512
"user", "info", "bob"});
513-
checkOutput(out, "Tenant 'dev' delegated admin with accessId", false);
514-
checkOutput(err, "", true);
513+
checkOutput(OUT, "Tenant 'dev' delegated admin with accessId", false);
514+
checkOutput(ERR, "", true);
515515

516516
executeHA(tenantShell, new String[] {
517517
"user", "info", "--json", "bob"});
518-
checkOutput(out,
518+
checkOutput(OUT,
519519
"{\n" +
520520
" \"user\" : \"bob\",\n" +
521521
" \"tenants\" : [ {\n" +
@@ -536,97 +536,97 @@ public void testOzoneTenantBasicOperations() throws IOException {
536536
" } ]\n" +
537537
"}\n",
538538
true, true);
539-
checkOutput(err, "", true);
539+
checkOutput(ERR, "", true);
540540

541541
// Revoke admin
542542
executeHA(tenantShell, new String[] {
543543
"user", "revoke-admin", "dev$bob", "--tenant=dev"});
544-
checkOutput(out, "", true);
545-
checkOutput(err, "", true);
544+
checkOutput(OUT, "", true);
545+
checkOutput(ERR, "", true);
546546

547547
executeHA(tenantShell, new String[] {
548548
"user", "info", "bob"});
549-
checkOutput(out, "User 'bob' is assigned to:\n"
549+
checkOutput(OUT, "User 'bob' is assigned to:\n"
550550
+ "- Tenant 'research' with accessId 'research$bob'\n"
551551
+ "- Tenant 'finance' with accessId 'finance$bob'\n"
552552
+ "- Tenant 'dev' with accessId 'dev$bob'\n", true);
553-
checkOutput(err, "", true);
553+
checkOutput(ERR, "", true);
554554

555555
// Revoke user accessId
556556
executeHA(tenantShell, new String[] {
557557
"user", "revoke", "research$bob"});
558-
checkOutput(out, "", true);
559-
checkOutput(err, "", true);
558+
checkOutput(OUT, "", true);
559+
checkOutput(ERR, "", true);
560560

561561
executeHA(tenantShell, new String[] {
562562
"user", "info", "bob"});
563-
checkOutput(out, "User 'bob' is assigned to:\n"
563+
checkOutput(OUT, "User 'bob' is assigned to:\n"
564564
+ "- Tenant 'finance' with accessId 'finance$bob'\n"
565565
+ "- Tenant 'dev' with accessId 'dev$bob'\n", true);
566-
checkOutput(err, "", true);
566+
checkOutput(ERR, "", true);
567567

568568
// Assign user again
569569
executeHA(tenantShell, new String[] {
570570
"user", "assign", "bob", "--tenant=research"});
571-
checkOutput(out, "export AWS_ACCESS_KEY_ID='research$bob'\n"
571+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='research$bob'\n"
572572
+ "export AWS_SECRET_ACCESS_KEY='", false);
573-
checkOutput(err, "", true);
573+
checkOutput(ERR, "", true);
574574

575575
// Attempt to assign the user to the tenant again
576576
executeHA(tenantShell, new String[] {
577577
"user", "assign", "bob", "--tenant=research",
578578
"--accessId=research$bob"});
579-
checkOutput(out, "", false);
580-
checkOutput(err, "accessId 'research$bob' already exists!\n", true);
579+
checkOutput(OUT, "", false);
580+
checkOutput(ERR, "accessId 'research$bob' already exists!\n", true);
581581

582582
// Attempt to assign the user to the tenant with a custom accessId
583583
executeHA(tenantShell, new String[] {
584584
"user", "assign", "bob", "--tenant=research",
585585
"--accessId=research$bob42"});
586-
checkOutput(out, "", false);
586+
checkOutput(OUT, "", false);
587587
// HDDS-6366: Disallow specifying custom accessId.
588-
checkOutput(err, "Invalid accessId 'research$bob42'. "
588+
checkOutput(ERR, "Invalid accessId 'research$bob42'. "
589589
+ "Specifying a custom access ID disallowed. "
590590
+ "Expected accessId to be assigned is 'research$bob'\n", true);
591591

592592
executeHA(tenantShell, new String[] {"list"});
593-
checkOutput(out, "dev\nfinance\nresearch\n", true);
594-
checkOutput(err, "", true);
593+
checkOutput(OUT, "dev\nfinance\nresearch\n", true);
594+
checkOutput(ERR, "", true);
595595

596596
// Clean up
597597
executeHA(tenantShell, new String[] {
598598
"user", "revoke", "research$bob"});
599-
checkOutput(out, "", true);
600-
checkOutput(err, "", true);
599+
checkOutput(OUT, "", true);
600+
checkOutput(ERR, "", true);
601601

602602
executeHA(tenantShell, new String[] {"delete", "research"});
603-
checkOutput(out, "", true);
604-
checkOutput(err, "Deleted tenant 'research'.\n", false);
603+
checkOutput(OUT, "", true);
604+
checkOutput(ERR, "Deleted tenant 'research'.\n", false);
605605
deleteVolume("research");
606606

607607
executeHA(tenantShell, new String[] {
608608
"user", "revoke", "finance$bob"});
609-
checkOutput(out, "", true);
610-
checkOutput(err, "", true);
609+
checkOutput(OUT, "", true);
610+
checkOutput(ERR, "", true);
611611

612612
executeHA(tenantShell, new String[] {"list"});
613-
checkOutput(out, "dev\nfinance\n", true);
614-
checkOutput(err, "", true);
613+
checkOutput(OUT, "dev\nfinance\n", true);
614+
checkOutput(ERR, "", true);
615615

616616
executeHA(tenantShell, new String[] {"delete", "finance"});
617-
checkOutput(out, "", true);
618-
checkOutput(err, "Deleted tenant 'finance'.\n", false);
617+
checkOutput(OUT, "", true);
618+
checkOutput(ERR, "Deleted tenant 'finance'.\n", false);
619619
deleteVolume("finance");
620620

621621
executeHA(tenantShell, new String[] {"list"});
622-
checkOutput(out, "dev\n", true);
623-
checkOutput(err, "", true);
622+
checkOutput(OUT, "dev\n", true);
623+
checkOutput(ERR, "", true);
624624

625625
// Attempt to delete tenant with accessIds still assigned to it, should fail
626626
int exitCode = executeHA(tenantShell, new String[] {"delete", "dev"});
627627
assertNotEquals(0, exitCode, "Tenant delete should fail!");
628-
checkOutput(out, "", true);
629-
checkOutput(err, "Tenant 'dev' is not empty. All accessIds associated "
628+
checkOutput(OUT, "", true);
629+
checkOutput(ERR, "Tenant 'dev' is not empty. All accessIds associated "
630630
+ "to this tenant must be revoked before the tenant can be deleted. "
631631
+ "See `ozone tenant user revoke`\n", true);
632632

@@ -643,113 +643,113 @@ public void testOzoneTenantBasicOperations() throws IOException {
643643
// Delete dev volume should fail because the volume reference count > 0L
644644
exitCode = execute(ozoneSh, new String[] {"volume", "delete", "dev"});
645645
assertNotEquals(0, exitCode, "Volume delete should fail!");
646-
checkOutput(out, "", true);
647-
checkOutput(err, "Volume reference count is not zero (1). "
646+
checkOutput(OUT, "", true);
647+
checkOutput(ERR, "Volume reference count is not zero (1). "
648648
+ "Ozone features are enabled on this volume. "
649649
+ "Try `ozone tenant delete <tenantId>` first.\n", true);
650650

651651
executeHA(tenantShell, new String[] {"list"});
652-
checkOutput(out, "dev\n", true);
653-
checkOutput(err, "", true);
652+
checkOutput(OUT, "dev\n", true);
653+
checkOutput(ERR, "", true);
654654

655655
// Revoke accessId first
656656
executeHA(tenantShell, new String[] {
657657
"user", "revoke", "dev$bob"});
658-
checkOutput(out, "", true);
659-
checkOutput(err, "", true);
658+
checkOutput(OUT, "", true);
659+
checkOutput(ERR, "", true);
660660

661661
// Then delete tenant, should succeed
662662
executeHA(tenantShell, new String[] {"--verbose", "delete", "dev"});
663-
checkOutput(out, "{\n" + " \"tenantId\" : \"dev\",\n"
663+
checkOutput(OUT, "{\n" + " \"tenantId\" : \"dev\",\n"
664664
+ " \"volumeName\" : \"dev\",\n" + " \"volumeRefCount\" : 0\n" + "}\n",
665665
true, true);
666-
checkOutput(err, "Deleted tenant 'dev'.\n", false);
666+
checkOutput(ERR, "Deleted tenant 'dev'.\n", false);
667667
deleteVolume("dev");
668668

669669
// Sanity check: tenant list should be empty
670670
executeHA(tenantShell, new String[] {"list"});
671-
checkOutput(out, "", true);
672-
checkOutput(err, "", true);
671+
checkOutput(OUT, "", true);
672+
checkOutput(ERR, "", true);
673673
}
674674

675675
@Test
676676
public void testListTenantUsers() throws IOException {
677677
executeHA(tenantShell, new String[] {"--verbose", "create", "tenant1"});
678-
checkOutput(out, "{\n" +
678+
checkOutput(OUT, "{\n" +
679679
" \"tenantId\" : \"tenant1\"\n" + "}\n", true, true);
680-
checkOutput(err, "", true);
680+
checkOutput(ERR, "", true);
681681

682682
executeHA(tenantShell, new String[] {
683683
"--verbose", "user", "assign", "alice", "--tenant=tenant1"});
684-
checkOutput(out, "export AWS_ACCESS_KEY_ID='tenant1$alice'\n"
684+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='tenant1$alice'\n"
685685
+ "export AWS_SECRET_ACCESS_KEY='", false);
686-
checkOutput(err, "Assigned 'alice' to 'tenant1'" +
686+
checkOutput(ERR, "Assigned 'alice' to 'tenant1'" +
687687
" with accessId 'tenant1$alice'.\n", true);
688688

689689
executeHA(tenantShell, new String[] {
690690
"user", "assign", "bob", "--tenant=tenant1"});
691-
checkOutput(out, "export AWS_ACCESS_KEY_ID='tenant1$bob'\n"
691+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='tenant1$bob'\n"
692692
+ "export AWS_SECRET_ACCESS_KEY='", false);
693-
checkOutput(err, "", true);
693+
checkOutput(ERR, "", true);
694694

695695
executeHA(tenantShell, new String[] {
696696
"user", "list", "tenant1"});
697-
checkOutput(out, "- User 'bob' with accessId 'tenant1$bob'\n" +
697+
checkOutput(OUT, "- User 'bob' with accessId 'tenant1$bob'\n" +
698698
"- User 'alice' with accessId 'tenant1$alice'\n", true);
699-
checkOutput(err, "", true);
699+
checkOutput(ERR, "", true);
700700

701701
executeHA(tenantShell, new String[] {
702702
"user", "list", "tenant1", "--json"});
703-
checkOutput(out,
703+
checkOutput(OUT,
704704
"[ {\n" +
705705
" \"user\" : \"bob\",\n" +
706706
" \"accessId\" : \"tenant1$bob\"\n" +
707707
"}, {\n" +
708708
" \"user\" : \"alice\",\n" +
709709
" \"accessId\" : \"tenant1$alice\"\n" +
710710
"} ]\n", true);
711-
checkOutput(err, "", true);
711+
checkOutput(ERR, "", true);
712712

713713
executeHA(tenantShell, new String[] {
714714
"user", "list", "tenant1", "--prefix=b"});
715-
checkOutput(out, "- User 'bob' with accessId " +
715+
checkOutput(OUT, "- User 'bob' with accessId " +
716716
"'tenant1$bob'\n", true);
717-
checkOutput(err, "", true);
717+
checkOutput(ERR, "", true);
718718

719719
executeHA(tenantShell, new String[] {
720720
"user", "list", "tenant1", "--prefix=b", "--json"});
721-
checkOutput(out, "[ {\n" +
721+
checkOutput(OUT, "[ {\n" +
722722
" \"user\" : \"bob\",\n" +
723723
" \"accessId\" : \"tenant1$bob\"\n" +
724724
"} ]\n", true);
725-
checkOutput(err, "", true);
725+
checkOutput(ERR, "", true);
726726

727727
int exitCode = executeHA(tenantShell, new String[] {
728728
"user", "list", "unknown"});
729729
assertNotEquals(0, exitCode, "Expected non-zero exit code");
730-
checkOutput(out, "", true);
731-
checkOutput(err, "Tenant 'unknown' doesn't exist.\n", true);
730+
checkOutput(OUT, "", true);
731+
checkOutput(ERR, "Tenant 'unknown' doesn't exist.\n", true);
732732

733733
// Clean up
734734
executeHA(tenantShell, new String[] {
735735
"user", "revoke", "tenant1$alice"});
736-
checkOutput(out, "", true);
737-
checkOutput(err, "", true);
736+
checkOutput(OUT, "", true);
737+
checkOutput(ERR, "", true);
738738

739739
executeHA(tenantShell, new String[] {
740740
"--verbose", "user", "revoke", "tenant1$bob"});
741-
checkOutput(out, "", true);
742-
checkOutput(err, "Revoked accessId", false);
741+
checkOutput(OUT, "", true);
742+
checkOutput(ERR, "Revoked accessId", false);
743743

744744
executeHA(tenantShell, new String[] {"delete", "tenant1"});
745-
checkOutput(out, "", true);
746-
checkOutput(err, "Deleted tenant 'tenant1'.\n", false);
745+
checkOutput(OUT, "", true);
746+
checkOutput(ERR, "Deleted tenant 'tenant1'.\n", false);
747747
deleteVolume("tenant1");
748748

749749
// Sanity check: tenant list should be empty
750750
executeHA(tenantShell, new String[] {"list"});
751-
checkOutput(out, "", true);
752-
checkOutput(err, "", true);
751+
checkOutput(OUT, "", true);
752+
checkOutput(ERR, "", true);
753753
}
754754

755755
@Test
@@ -759,44 +759,44 @@ public void testTenantSetSecret() throws IOException, InterruptedException {
759759

760760
// Create test tenant
761761
executeHA(tenantShell, new String[] {"create", tenantName});
762-
checkOutput(out, "", true);
763-
checkOutput(err, "", true);
762+
checkOutput(OUT, "", true);
763+
checkOutput(ERR, "", true);
764764

765765
// Set secret for non-existent accessId. Expect failure
766766
executeHA(tenantShell, new String[] {
767767
"user", "set-secret", tenantName + "$alice", "--secret=somesecret0"});
768-
checkOutput(out, "", true);
769-
checkOutput(err, "accessId '" + tenantName + "$alice' not found.\n", true);
768+
checkOutput(OUT, "", true);
769+
checkOutput(ERR, "accessId '" + tenantName + "$alice' not found.\n", true);
770770

771771
// Assign a user to the tenant so that we have an accessId entry
772772
executeHA(tenantShell, new String[] {
773773
"user", "assign", "alice", "--tenant=" + tenantName});
774-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
774+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
775775
"export AWS_SECRET_ACCESS_KEY='", false);
776-
checkOutput(err, "", true);
776+
checkOutput(ERR, "", true);
777777

778778
// Set secret as OM admin should succeed
779779
executeHA(tenantShell, new String[] {
780780
"user", "setsecret", tenantName + "$alice",
781781
"--secret=somesecret1"});
782-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
782+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
783783
"export AWS_SECRET_ACCESS_KEY='somesecret1'\n", true);
784-
checkOutput(err, "", true);
784+
checkOutput(ERR, "", true);
785785

786786
// Set empty secret key should fail
787787
int exitCode = executeHA(tenantShell, new String[] {
788788
"user", "setsecret", tenantName + "$alice",
789789
"--secret=short"});
790790
assertNotEquals(0, exitCode, "Expected non-zero exit code");
791-
checkOutput(out, "", true);
792-
checkOutput(err, "Secret key length should be at least 8 characters\n",
791+
checkOutput(OUT, "", true);
792+
checkOutput(ERR, "Secret key length should be at least 8 characters\n",
793793
true);
794794

795795
// Get secret should still give the previous secret key
796796
executeHA(tenantShell, new String[] {
797797
"user", "getsecret", tenantName + "$alice"});
798-
checkOutput(out, "somesecret1", false);
799-
checkOutput(err, "", true);
798+
checkOutput(OUT, "somesecret1", false);
799+
checkOutput(ERR, "", true);
800800

801801
// Set secret as alice should succeed
802802
final UserGroupInformation ugiAlice = UserGroupInformation
@@ -806,18 +806,18 @@ public void testTenantSetSecret() throws IOException, InterruptedException {
806806
executeHA(tenantShell, new String[] {
807807
"user", "setsecret", tenantName + "$alice",
808808
"--secret=somesecret2"});
809-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
809+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
810810
"export AWS_SECRET_ACCESS_KEY='somesecret2'\n", true);
811-
checkOutput(err, "", true);
811+
checkOutput(ERR, "", true);
812812
return null;
813813
});
814814

815815
// Set secret as bob should fail
816816
executeHA(tenantShell, new String[] {
817817
"user", "assign", "bob", "--tenant=" + tenantName});
818-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$bob'\n" +
818+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$bob'\n" +
819819
"export AWS_SECRET_ACCESS_KEY='", false);
820-
checkOutput(err, "", true);
820+
checkOutput(ERR, "", true);
821821

822822
final UserGroupInformation ugiBob = UserGroupInformation
823823
.createUserForTesting("bob", new String[] {"usergroup"});
@@ -827,8 +827,8 @@ public void testTenantSetSecret() throws IOException, InterruptedException {
827827
"user", "setsecret", tenantName + "$alice",
828828
"--secret=somesecret2"});
829829
assertNotEquals(0, exitC, "Should return non-zero exit code!");
830-
checkOutput(out, "", true);
831-
checkOutput(err, "Requested accessId 'tenant-test-set-secret$alice'"
830+
checkOutput(OUT, "", true);
831+
checkOutput(ERR, "Requested accessId 'tenant-test-set-secret$alice'"
832832
+ " doesn't belong to current user 'bob', nor does current user"
833833
+ " have Ozone or tenant administrator privilege\n", true);
834834
return null;
@@ -839,45 +839,45 @@ public void testTenantSetSecret() throws IOException, InterruptedException {
839839
executeHA(tenantShell, new String[] {"user", "assign-admin",
840840
tenantName + "$" + ugiBob.getShortUserName(),
841841
"--tenant=" + tenantName, "--delegated=false"});
842-
checkOutput(out, "", true);
843-
checkOutput(err, "", true);
842+
checkOutput(OUT, "", true);
843+
checkOutput(ERR, "", true);
844844

845845
// Set secret should succeed now
846846
ugiBob.doAs((PrivilegedExceptionAction<Void>) () -> {
847847
executeHA(tenantShell, new String[] {
848848
"user", "setsecret", tenantName + "$alice",
849849
"--secret=somesecret2"});
850-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
850+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
851851
"export AWS_SECRET_ACCESS_KEY='somesecret2'\n", true);
852-
checkOutput(err, "", true);
852+
checkOutput(ERR, "", true);
853853
return null;
854854
});
855855

856856
// Clean up
857857
executeHA(tenantShell, new String[] {"user", "revoke-admin",
858858
tenantName + "$" + ugiBob.getShortUserName()});
859-
checkOutput(out, "", true);
860-
checkOutput(err, "", true);
859+
checkOutput(OUT, "", true);
860+
checkOutput(ERR, "", true);
861861

862862
executeHA(tenantShell, new String[] {
863863
"user", "revoke", tenantName + "$bob"});
864-
checkOutput(out, "", true);
865-
checkOutput(err, "", true);
864+
checkOutput(OUT, "", true);
865+
checkOutput(ERR, "", true);
866866

867867
executeHA(tenantShell, new String[] {
868868
"user", "revoke", tenantName + "$alice"});
869-
checkOutput(out, "", true);
870-
checkOutput(err, "", true);
869+
checkOutput(OUT, "", true);
870+
checkOutput(ERR, "", true);
871871

872872
executeHA(tenantShell, new String[] {"delete", tenantName});
873-
checkOutput(out, "", true);
874-
checkOutput(err, "Deleted tenant '" + tenantName + "'.\n", false);
873+
checkOutput(OUT, "", true);
874+
checkOutput(ERR, "Deleted tenant '" + tenantName + "'.\n", false);
875875
deleteVolume(tenantName);
876876

877877
// Sanity check: tenant list should be empty
878878
executeHA(tenantShell, new String[] {"list"});
879-
checkOutput(out, "", true);
880-
checkOutput(err, "", true);
879+
checkOutput(OUT, "", true);
880+
checkOutput(ERR, "", true);
881881
}
882882

883883
@Test
@@ -895,35 +895,35 @@ public void testTenantAdminOperations()
895895

896896
// Create test tenant
897897
executeHA(tenantShell, new String[] {"create", tenantName});
898-
checkOutput(out, "", true);
899-
checkOutput(err, "", true);
898+
checkOutput(OUT, "", true);
899+
checkOutput(ERR, "", true);
900900

901901
// Assign alice and bob as tenant users
902902
executeHA(tenantShell, new String[] {
903903
"user", "assign", "alice", "--tenant=" + tenantName});
904-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
904+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
905905
"export AWS_SECRET_ACCESS_KEY='", false);
906-
checkOutput(err, "", true);
906+
checkOutput(ERR, "", true);
907907

908908
executeHA(tenantShell, new String[] {
909909
"user", "assign", "bob", "--tenant=" + tenantName});
910-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$bob'\n" +
910+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$bob'\n" +
911911
"export AWS_SECRET_ACCESS_KEY='", false);
912-
checkOutput(err, "", true);
912+
checkOutput(ERR, "", true);
913913

914914
// Make alice a delegated tenant admin
915915
executeHA(tenantShell, new String[] {"user", "assign-admin",
916916
tenantName + "$" + ugiAlice.getShortUserName(),
917917
"--tenant=" + tenantName, "--delegated=true"});
918-
checkOutput(out, "", true);
919-
checkOutput(err, "", true);
918+
checkOutput(OUT, "", true);
919+
checkOutput(ERR, "", true);
920920

921921
// Make bob a non-delegated tenant admin
922922
executeHA(tenantShell, new String[] {"user", "assign-admin",
923923
tenantName + "$" + ugiBob.getShortUserName(),
924924
"--tenant=" + tenantName, "--delegated=false"});
925-
checkOutput(out, "", true);
926-
checkOutput(err, "", true);
925+
checkOutput(OUT, "", true);
926+
checkOutput(ERR, "", true);
927927

928928
// Start test matrix
929929

@@ -935,49 +935,49 @@ public void testTenantAdminOperations()
935935
// Assign carol as a new tenant user
936936
executeHA(tenantShell, new String[] {
937937
"user", "assign", "carol", "--tenant=" + tenantName});
938-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$carol'\n"
938+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$carol'\n"
939939
+ "export AWS_SECRET_ACCESS_KEY='", false);
940-
checkOutput(err, "", true);
940+
checkOutput(ERR, "", true);
941941

942942
// Set secret should work
943943
executeHA(tenantShell, new String[] {
944944
"user", "setsecret", tenantName + "$alice",
945945
"--secret=somesecret2"});
946-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
946+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
947947
"export AWS_SECRET_ACCESS_KEY='somesecret2'\n", true);
948-
checkOutput(err, "", true);
948+
checkOutput(ERR, "", true);
949949

950950
// Make carol a tenant delegated tenant admin
951951
executeHA(tenantShell, new String[] {"user", "assign-admin",
952952
tenantName + "$carol",
953953
"--tenant=" + tenantName, "--delegated=true"});
954-
checkOutput(out, "", true);
955-
checkOutput(err, "", true);
954+
checkOutput(OUT, "", true);
955+
checkOutput(ERR, "", true);
956956

957957
// Revoke carol's tenant admin privilege
958958
executeHA(tenantShell, new String[] {"user", "revoke-admin",
959959
tenantName + "$carol"});
960-
checkOutput(out, "", true);
961-
checkOutput(err, "", true);
960+
checkOutput(OUT, "", true);
961+
checkOutput(ERR, "", true);
962962

963963
// Make carol a tenant non-delegated tenant admin
964964
executeHA(tenantShell, new String[] {"user", "assign-admin",
965965
tenantName + "$carol",
966966
"--tenant=" + tenantName, "--delegated=false"});
967-
checkOutput(out, "", true);
968-
checkOutput(err, "", true);
967+
checkOutput(OUT, "", true);
968+
checkOutput(ERR, "", true);
969969

970970
// Revoke carol's tenant admin privilege
971971
executeHA(tenantShell, new String[] {"user", "revoke-admin",
972972
tenantName + "$carol"});
973-
checkOutput(out, "", true);
974-
checkOutput(err, "", true);
973+
checkOutput(OUT, "", true);
974+
checkOutput(ERR, "", true);
975975

976976
// Revoke carol's accessId from this tenant
977977
executeHA(tenantShell, new String[] {
978978
"user", "revoke", tenantName + "$carol"});
979-
checkOutput(out, "", true);
980-
checkOutput(err, "", true);
979+
checkOutput(OUT, "", true);
980+
checkOutput(ERR, "", true);
981981
return null;
982982
});
983983

@@ -991,73 +991,73 @@ public void testTenantAdminOperations()
991991
// Assign carol as a new tenant user
992992
executeHA(tenantShell, new String[] {
993993
"user", "assign", "carol", "--tenant=" + tenantName});
994-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$carol'\n"
994+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$carol'\n"
995995
+ "export AWS_SECRET_ACCESS_KEY='", false);
996-
checkOutput(err, "", true);
996+
checkOutput(ERR, "", true);
997997

998998
// Set secret should work, even for a non-delegated admin
999999
executeHA(tenantShell, new String[] {
10001000
"user", "setsecret", tenantName + "$alice",
10011001
"--secret=somesecret2"});
1002-
checkOutput(out, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
1002+
checkOutput(OUT, "export AWS_ACCESS_KEY_ID='" + tenantName + "$alice'\n" +
10031003
"export AWS_SECRET_ACCESS_KEY='somesecret2'\n", true);
1004-
checkOutput(err, "", true);
1004+
checkOutput(ERR, "", true);
10051005

10061006
// Attempt to make carol a tenant delegated tenant admin, should fail
10071007
executeHA(tenantShell, new String[] {"user", "assign-admin",
10081008
tenantName + "$carol",
10091009
"--tenant=" + tenantName, "--delegated=true"});
1010-
checkOutput(out, "", true);
1011-
checkOutput(err, "User 'bob' is neither an Ozone admin "
1010+
checkOutput(OUT, "", true);
1011+
checkOutput(ERR, "User 'bob' is neither an Ozone admin "
10121012
+ "nor a delegated admin of tenant", false);
10131013

10141014
// Attempt to make carol a tenant non-delegated tenant admin, should fail
10151015
executeHA(tenantShell, new String[] {"user", "assign-admin",
10161016
tenantName + "$carol",
10171017
"--tenant=" + tenantName, "--delegated=false"});
1018-
checkOutput(out, "", true);
1019-
checkOutput(err, "User 'bob' is neither an Ozone admin "
1018+
checkOutput(OUT, "", true);
1019+
checkOutput(ERR, "User 'bob' is neither an Ozone admin "
10201020
+ "nor a delegated admin of tenant", false);
10211021

10221022
// Attempt to revoke tenant admin, should fail at the permission check
10231023
executeHA(tenantShell, new String[] {"user", "revoke-admin",
10241024
tenantName + "$carol"});
1025-
checkOutput(out, "", true);
1026-
checkOutput(err, "User 'bob' is neither an Ozone admin "
1025+
checkOutput(OUT, "", true);
1026+
checkOutput(ERR, "User 'bob' is neither an Ozone admin "
10271027
+ "nor a delegated admin of tenant", false);
10281028

10291029
// Revoke carol's accessId from this tenant
10301030
executeHA(tenantShell, new String[] {
10311031
"user", "revoke", tenantName + "$carol"});
1032-
checkOutput(out, "", true);
1033-
checkOutput(err, "", true);
1032+
checkOutput(OUT, "", true);
1033+
checkOutput(ERR, "", true);
10341034
return null;
10351035
});
10361036

10371037
// Clean up
10381038
executeHA(tenantShell, new String[] {"user", "revoke-admin",
10391039
tenantName + "$" + ugiAlice.getShortUserName()});
1040-
checkOutput(out, "", true);
1041-
checkOutput(err, "", true);
1040+
checkOutput(OUT, "", true);
1041+
checkOutput(ERR, "", true);
10421042

10431043
executeHA(tenantShell, new String[] {
10441044
"user", "revoke", tenantName + "$" + ugiAlice.getShortUserName()});
1045-
checkOutput(out, "", true);
1046-
checkOutput(err, "", true);
1045+
checkOutput(OUT, "", true);
1046+
checkOutput(ERR, "", true);
10471047

10481048
executeHA(tenantShell, new String[] {"user", "revoke-admin",
10491049
tenantName + "$" + ugiBob.getShortUserName()});
1050-
checkOutput(out, "", true);
1051-
checkOutput(err, "", true);
1050+
checkOutput(OUT, "", true);
1051+
checkOutput(ERR, "", true);
10521052

10531053
executeHA(tenantShell, new String[] {
10541054
"user", "revoke", tenantName + "$" + ugiBob.getShortUserName()});
1055-
checkOutput(out, "", true);
1056-
checkOutput(err, "", true);
1055+
checkOutput(OUT, "", true);
1056+
checkOutput(ERR, "", true);
10571057

10581058
executeHA(tenantShell, new String[] {"delete", tenantName});
1059-
checkOutput(out, "", true);
1060-
checkOutput(err, "Deleted tenant '" + tenantName + "'.\n", false);
1059+
checkOutput(OUT, "", true);
1060+
checkOutput(ERR, "Deleted tenant '" + tenantName + "'.\n", false);
10611061
deleteVolume(tenantName);
10621062
}
10631063

@@ -1067,29 +1067,29 @@ public void testCreateTenantOnExistingVolume() throws IOException {
10671067
int exitC = execute(ozoneSh, new String[] {"volume", "create", testVolume});
10681068
// Volume create should succeed
10691069
assertEquals(0, exitC);
1070-
checkOutput(out, "", true);
1071-
checkOutput(err, "", true);
1070+
checkOutput(OUT, "", true);
1071+
checkOutput(ERR, "", true);
10721072

10731073
// Try to create tenant on the same volume, should fail by default
10741074
executeHA(tenantShell, new String[] {"create", testVolume});
1075-
checkOutput(out, "", true);
1076-
checkOutput(err, "Volume already exists\n", true);
1075+
checkOutput(OUT, "", true);
1076+
checkOutput(ERR, "Volume already exists\n", true);
10771077

10781078
// Try to create tenant on the same volume with --force, should work
10791079
executeHA(tenantShell, new String[] {"create", testVolume, "--force"});
1080-
checkOutput(out, "", true);
1081-
checkOutput(err, "", true);
1080+
checkOutput(OUT, "", true);
1081+
checkOutput(ERR, "", true);
10821082

10831083
// Try to create the same tenant one more time, should fail even
10841084
// with --force because the tenant already exists.
10851085
executeHA(tenantShell, new String[] {"create", testVolume, "--force"});
1086-
checkOutput(out, "", true);
1087-
checkOutput(err, "Tenant '" + testVolume + "' already exists\n", true);
1086+
checkOutput(OUT, "", true);
1087+
checkOutput(ERR, "Tenant '" + testVolume + "' already exists\n", true);
10881088

10891089
// Clean up
10901090
executeHA(tenantShell, new String[] {"delete", testVolume});
1091-
checkOutput(out, "", true);
1092-
checkOutput(err, "Deleted tenant '" + testVolume + "'.\n", false);
1091+
checkOutput(OUT, "", true);
1092+
checkOutput(ERR, "Deleted tenant '" + testVolume + "'.\n", false);
10931093
deleteVolume(testVolume);
10941094
}
10951095
}

0 commit comments

Comments
 (0)
Please sign in to comment.