Add support for Ubuntu20 on kokoro (#2279)

This commit is contained in:
Pavlo Tkach 2024-01-10 14:32:34 -05:00 committed by GitHub
parent 265d69051b
commit d7edd27cdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 25 deletions

View file

@ -16,11 +16,9 @@ package google.registry.tools;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import org.flywaydb.core.Flyway; import org.flywaydb.core.Flyway;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.Container; import org.testcontainers.containers.Container;
/** /**
@ -36,9 +34,6 @@ public class DumpGoldenSchemaCommand extends PostgresqlCommand {
// The mount point in the container. // The mount point in the container.
private static final String CONTAINER_MOUNT_POINT = "/tmp/pg_dump.out"; private static final String CONTAINER_MOUNT_POINT = "/tmp/pg_dump.out";
// Temporary workaround to fix permission issues on certain Linux distro (e. g. Arch Linux).
private static final String CONTAINER_MOUNT_POINT_TMP = "/tmp/pg_dump.tmp";
@Parameter( @Parameter(
names = {"--output", "-o"}, names = {"--output", "-o"},
description = "Output file", description = "Output file",
@ -64,19 +59,7 @@ public class DumpGoldenSchemaCommand extends PostgresqlCommand {
if (result.getExitCode() != 0) { if (result.getExitCode() != 0) {
throw new RuntimeException(result.toString()); throw new RuntimeException(result.toString());
} }
result = postgresContainer.copyFileFromContainer(CONTAINER_MOUNT_POINT, output.toString());
postgresContainer.execInContainer("cp", CONTAINER_MOUNT_POINT_TMP, CONTAINER_MOUNT_POINT);
if (result.getExitCode() != 0) {
throw new RuntimeException(result.toString());
}
}
@Override
protected void onContainerCreate() throws IOException {
// open the output file for write so we can mount it.
new FileOutputStream(output.toFile()).close();
postgresContainer.withFileSystemBind(
output.toString(), CONTAINER_MOUNT_POINT, BindMode.READ_WRITE);
} }
private static String[] getSchemaDumpCommand(String username, String dbName) { private static String[] getSchemaDumpCommand(String username, String dbName) {
@ -87,7 +70,7 @@ public class DumpGoldenSchemaCommand extends PostgresqlCommand {
"-U", "-U",
username, username,
"-f", "-f",
CONTAINER_MOUNT_POINT_TMP, CONTAINER_MOUNT_POINT,
"--schema-only", "--schema-only",
"--no-owner", "--no-owner",
"--no-privileges", "--no-privileges",

View file

@ -38,6 +38,8 @@ class PathParameterTest {
private final PathParameter vanilla = new PathParameter(); private final PathParameter vanilla = new PathParameter();
private static final Boolean isRoot = "root".equals(System.getProperty("user.name"));
@Test @Test
void testConvert_etcPasswd_returnsPath() { void testConvert_etcPasswd_returnsPath() {
assertThat((Object) vanilla.convert("/etc/passwd")).isEqualTo(Paths.get("/etc/passwd")); assertThat((Object) vanilla.convert("/etc/passwd")).isEqualTo(Paths.get("/etc/passwd"));
@ -105,9 +107,15 @@ class PathParameterTest {
void testInputFileValidate_unreadableFile_throws() throws Exception { void testInputFileValidate_unreadableFile_throws() throws Exception {
Path file = Files.createFile(tmpDir.resolve("tmpfile.txt")); Path file = Files.createFile(tmpDir.resolve("tmpfile.txt"));
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("-w-------")); Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("-w-------"));
ParameterException thrown = // This test doesn't take into account the fact that root user has access to read/write the
assertThrows(ParameterException.class, () -> inputFile.validate("input", file.toString())); // file even if posix permissions disallow it.
assertThat(thrown).hasMessageThat().contains("not readable"); // For the environmnent that run strictly under root, we will ignore the test results.
if (!isRoot) {
ParameterException thrown =
assertThrows(
ParameterException.class, () -> inputFile.validate("input", file.toString()));
assertThat(thrown).hasMessageThat().contains("not readable");
}
} }
// =========================== Test OutputFile Validate ======================================== // =========================== Test OutputFile Validate ========================================
@ -142,9 +150,15 @@ class PathParameterTest {
void testOutputFileValidate_notWritable_throws() throws Exception { void testOutputFileValidate_notWritable_throws() throws Exception {
Path file = Files.createFile(tmpDir.resolve("newFile.dat")); Path file = Files.createFile(tmpDir.resolve("newFile.dat"));
Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("r--------")); Files.setPosixFilePermissions(file, PosixFilePermissions.fromString("r--------"));
ParameterException thrown = // This test doesn't take into account the fact that root user has access to read/write the
assertThrows(ParameterException.class, () -> outputFile.validate("input", file.toString())); // file even if posix permissions disallow it.
assertThat(thrown).hasMessageThat().contains("not writable"); // For the environmnent that run strictly under root, we will ignore the test results.
if (!isRoot) {
ParameterException thrown =
assertThrows(
ParameterException.class, () -> outputFile.validate("input", file.toString()));
assertThat(thrown).hasMessageThat().contains("not writable");
}
} }
@Test @Test