Skip to content

Commit

Permalink
Fix NPE when recording state of same master and build namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
mocenas authored and mnovak1 committed Jan 21, 2021
1 parent 49d1b85 commit c390155
Showing 1 changed file with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void beforeAll(ExtensionContext context) {
new EventsFilterBuilder().setExcludedUntil(ResourcesTimestampHelper.timeOfLastEvent(master)));

// builds namespace (if not same)
if (!OpenShifts.master().getNamespace().equals(BuildManagers.get().openShift().getNamespace())) {
if (!isMasterAndBuildNamespaceSame()) {
initClassFilter(context, POD_FILTER_BUILDS, bm, Pod.class);
initClassFilter(context, BUILD_FILTER_BUILDS, bm, Build.class);
initClassFilter(context, BC_FILTER_BUILDS, bm, BuildConfig.class);
Expand Down Expand Up @@ -175,7 +175,7 @@ public void beforeEach(ExtensionContext context) throws Exception {
updateClassFilterBeforeAllResources(context, EVENT_FILTER_MASTER, master, Event.class);

// builds namespace (if not same)
if (!OpenShifts.master().getNamespace().equals(BuildManagers.get().openShift().getNamespace())) {
if (!isMasterAndBuildNamespaceSame()) {
updateClassFilterBeforeAllResources(context, POD_FILTER_BUILDS, bm, Pod.class);
updateClassFilterBeforeAllResources(context, BUILD_FILTER_BUILDS, bm, Build.class);
updateClassFilterBeforeAllResources(context, BC_FILTER_BUILDS, bm, BuildConfig.class);
Expand All @@ -202,7 +202,7 @@ public void beforeEach(ExtensionContext context) throws Exception {
initMethodFilter(context, EVENT_FILTER_MASTER, master, Event.class);

// builds namespace (if not same)
if (!OpenShifts.master().getNamespace().equals(BuildManagers.get().openShift().getNamespace())) {
if (!isMasterAndBuildNamespaceSame()) {
initMethodFilter(context, POD_FILTER_BUILDS, bm, Pod.class);
initMethodFilter(context, BUILD_FILTER_BUILDS, bm, Build.class);
initMethodFilter(context, BC_FILTER_BUILDS, bm, BuildConfig.class);
Expand Down Expand Up @@ -262,18 +262,24 @@ public void testSuccessful(ExtensionContext context) {
}

private void recordState(ExtensionContext context) throws IOException {
savePods(context, getFilter(context, POD_FILTER_MASTER), getFilter(context, POD_FILTER_BUILDS));
savePods(context, getFilter(context, POD_FILTER_MASTER),
!isMasterAndBuildNamespaceSame() ? getFilter(context, POD_FILTER_BUILDS) : null);
saveDCs(context, getFilter(context, DC_FILTER_MASTER));
saveBuilds(context, getFilter(context, BUILD_FILTER_MASTER), getFilter(context, BUILD_FILTER_BUILDS));
saveBCs(context, getFilter(context, BC_FILTER_MASTER), getFilter(context, BC_FILTER_BUILDS));
saveISs(context, getFilter(context, IS_FILTER_MASTER), getFilter(context, IS_FILTER_BUILDS));
saveBuilds(context, getFilter(context, BUILD_FILTER_MASTER),
!isMasterAndBuildNamespaceSame() ? getFilter(context, BUILD_FILTER_BUILDS) : null);
saveBCs(context, getFilter(context, BC_FILTER_MASTER),
!isMasterAndBuildNamespaceSame() ? getFilter(context, BC_FILTER_BUILDS) : null);
saveISs(context, getFilter(context, IS_FILTER_MASTER),
!isMasterAndBuildNamespaceSame() ? getFilter(context, IS_FILTER_BUILDS) : null);
saveStatefulsets(context, getFilter(context, SS_FILTER_MASTER));
saveRoutes(context, getFilter(context, ROUTE_FILTER_MASTER));
saveConfigMaps(context, getFilter(context, CONFIGMAP_FILTER_MASTER));
saveServices(context, getFilter(context, SERVICE_FILTER_MASTER));
saveSecrets(context);
savePodLogs(context, getFilter(context, POD_FILTER_MASTER), getFilter(context, POD_FILTER_BUILDS));
saveEvents(context, getFilter(context, EVENT_FILTER_MASTER), getFilter(context, EVENT_FILTER_BUILDS));
savePodLogs(context, getFilter(context, POD_FILTER_MASTER),
!isMasterAndBuildNamespaceSame() ? getFilter(context, POD_FILTER_BUILDS) : null);
saveEvents(context, getFilter(context, EVENT_FILTER_MASTER),
!isMasterAndBuildNamespaceSame() ? getFilter(context, EVENT_FILTER_BUILDS) : null);
}

private <E extends HasMetadata> ResourcesFilterBuilder<E> getFilter(ExtensionContext context, String key) {
Expand Down Expand Up @@ -332,7 +338,7 @@ private void saveISs(ExtensionContext context, ResourcesFilterBuilder<ImageStrea
.forEach(printer::row);
}
// builds namespace (if not same)
if (!OpenShifts.master().getNamespace().equals(BuildManagers.get().openShift().getNamespace())) {
if (!isMasterAndBuildNamespaceSame()) {
final Path imageStreamsBMLogPath = Paths.get(attachmentsDir(), dirNameForTest(context),
"imageStreams-" + BuildManagers.get().openShift().getNamespace() + ".log");
try (final ResourcesPrinterHelper<ImageStream> printer = ResourcesPrinterHelper.forISs(imageStreamsBMLogPath)) {
Expand All @@ -353,7 +359,7 @@ private void saveBCs(ExtensionContext context, ResourcesFilterBuilder<BuildConfi
.forEach(printer::row);
}
// builds namespace (if not same)
if (!OpenShifts.master().getNamespace().equals(BuildManagers.get().openShift().getNamespace())) {
if (!isMasterAndBuildNamespaceSame()) {
final Path bcBMLogPath = Paths.get(attachmentsDir(), dirNameForTest(context),
"buildConfigs-" + BuildManagers.get().openShift().getNamespace() + ".log");
try (final ResourcesPrinterHelper<BuildConfig> printer = ResourcesPrinterHelper.forBCs(bcBMLogPath)) {
Expand All @@ -375,7 +381,7 @@ private void saveBuilds(ExtensionContext context, ResourcesFilterBuilder<Build>
.forEach(printer::row);
}
// builds namespace (if not same)
if (!OpenShifts.master().getNamespace().equals(BuildManagers.get().openShift().getNamespace())) {
if (!isMasterAndBuildNamespaceSame()) {
final Path buildsBMLogPath = Paths.get(attachmentsDir(), dirNameForTest(context),
"builds-" + BuildManagers.get().openShift().getNamespace() + ".log");
try (final ResourcesPrinterHelper<Build> printer = ResourcesPrinterHelper.forBuilds(buildsBMLogPath)) {
Expand Down Expand Up @@ -433,7 +439,7 @@ private void savePods(ExtensionContext context, ResourcesFilterBuilder<Pod> mast
.forEach(printer::row);
}
// builds namespace (if not same)
if (!OpenShifts.master().getNamespace().equals(BuildManagers.get().openShift().getNamespace())) {
if (!isMasterAndBuildNamespaceSame()) {
final Path podsBMLogPath = Paths.get(attachmentsDir(), dirNameForTest(context),
"pods-" + BuildManagers.get().openShift().getNamespace() + ".log");
try (final ResourcesPrinterHelper<Pod> printer = ResourcesPrinterHelper.forPods(podsBMLogPath)) {
Expand Down Expand Up @@ -481,7 +487,7 @@ private void savePodLogs(ExtensionContext context, ResourcesFilterBuilder<Pod> m
});

podPrinter.accept(OpenShifts.master(), masterFilter);
if (!OpenShifts.master().getNamespace().equals(BuildManagers.get().openShift().getNamespace())) {
if (!isMasterAndBuildNamespaceSame()) {
podPrinter.accept(BuildManagers.get().openShift(), buildsFilter);
}
}
Expand All @@ -507,7 +513,7 @@ private void saveEvents(ExtensionContext context, ResourcesFilterBuilder<Event>
.forEach(printer::row);
}
// builds namespace (if not same)
if (!OpenShifts.master().getNamespace().equals(BuildManagers.get().openShift().getNamespace())) {
if (!isMasterAndBuildNamespaceSame()) {
final Path eventsBMLogPath = Paths.get(attachmentsDir(), dirNameForTest(context),
"events-" + BuildManagers.get().openShift().getNamespace() + ".log");
try (final ResourcesPrinterHelper<Event> printer = ResourcesPrinterHelper.forEvents(eventsBMLogPath)) {
Expand All @@ -522,4 +528,8 @@ private void saveEvents(ExtensionContext context, ResourcesFilterBuilder<Event>
private String attachmentsDir() {
return JUnitConfig.recordDir() != null ? JUnitConfig.recordDir() : System.getProperty("user.dir");
}

private boolean isMasterAndBuildNamespaceSame() {
return OpenShifts.master().getNamespace().equals(BuildManagers.get().openShift().getNamespace());
}
}

0 comments on commit c390155

Please sign in to comment.