summaryrefslogtreecommitdiffstats
path: root/node-admin
diff options
context:
space:
mode:
authorHarald Musum <musum@oath.com>2018-08-30 13:33:41 +0200
committerHarald Musum <musum@oath.com>2018-08-30 13:33:41 +0200
commit617f3253fa8498accff3e750fa7ef635594cda2d (patch)
tree48f203c3f2406af5faf146de9482b4defc28c05a /node-admin
parent602b7f0d4d72b8f31154a69e1488b535486b36ad (diff)
AddYumRepo is not used anymore, remove it
Diffstat (limited to 'node-admin')
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/AddYumRepo.java75
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/AddYumRepoTest.java55
2 files changed, 0 insertions, 130 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/AddYumRepo.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/AddYumRepo.java
deleted file mode 100644
index 5df790f9105..00000000000
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/AddYumRepo.java
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.hosted.node.admin.task.util.yum;
-
-import com.yahoo.vespa.hosted.node.admin.component.TaskContext;
-import com.yahoo.vespa.hosted.node.admin.task.util.file.FileWriter;
-
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
-import java.nio.file.Path;
-import java.util.regex.Pattern;
-
-/**
- * @author hakonhall
- */
-public class AddYumRepo {
- private static final Pattern REPOSITORY_ID_PATTERN = Pattern.compile("^[a-zA-Z0-9_-]+$");
-
- private final String repositoryId; // e.g. "platform_rpms-latest"
- private final String name; // e.g. "Platform RPM Latest Repo"
- private final String baseurl;
- private final boolean enabled;
- private final FileSystem fileSystem;
-
- public AddYumRepo(String repositoryId,
- String name,
- String baseurl,
- boolean enabled) {
- this(repositoryId, name, baseurl, enabled, FileSystems.getDefault());
- }
-
- public boolean converge(TaskContext context) {
- Path path = fileSystem.getPath("/etc/yum.repos.d",repositoryId + ".repo");
-
- FileWriter fileWriter = new FileWriter(path, this::getRepoFileContent)
- .withOwner("root")
- .withGroup("root")
- .withPermissions("rw-r--r--")
- .onlyIfFileDoesNotAlreadyExist();
-
- return fileWriter.converge(context);
- }
-
- private String getRepoFileContent() {
- return String.join("\n",
- "# This file was generated by node admin",
- "# Do NOT modify this file by hand",
- "",
- "[" + repositoryId + "]",
- "name=" + name,
- "baseurl=" + baseurl,
- "enabled=" + (enabled ? 1 : 0),
- "gpgcheck=0"
- ) + "\n";
- }
-
- private static void validateRepositoryId(String repositoryId) {
- if (!REPOSITORY_ID_PATTERN.matcher(repositoryId).matches()) {
- throw new IllegalArgumentException("Invalid repository ID '" + repositoryId + "'");
- }
- }
-
- // For testing
- public AddYumRepo(String repositoryId,
- String name,
- String baseurl,
- boolean enabled,
- FileSystem fileSystem) {
- this.repositoryId = repositoryId;
- this.name = name;
- this.baseurl = baseurl;
- this.enabled = enabled;
- this.fileSystem = fileSystem;
- validateRepositoryId(repositoryId);
- }
-}
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/AddYumRepoTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/AddYumRepoTest.java
deleted file mode 100644
index c6314439003..00000000000
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/AddYumRepoTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-package com.yahoo.vespa.hosted.node.admin.task.util.yum;
-
-import com.yahoo.vespa.hosted.node.admin.component.TaskContext;
-import com.yahoo.vespa.hosted.node.admin.task.util.file.UnixPath;
-import com.yahoo.vespa.test.file.TestFileSystem;
-import org.junit.Test;
-
-import java.nio.file.FileSystem;
-import java.time.Instant;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-public class AddYumRepoTest {
- @Test
- public void converge() {
- String repositoryId = "repoid";
- String name = "name";
- String baseurl = "http://foo.com/bar";
- boolean enabled = true;
-
- FileSystem fileSystem = TestFileSystem.create();
- AddYumRepo addYumRepo = new AddYumRepo(
- repositoryId,
- name,
- baseurl,
- enabled,
- fileSystem);
-
- TaskContext context = mock(TaskContext.class);
-
- assertTrue(addYumRepo.converge(context));
-
- UnixPath unixPath = new UnixPath(fileSystem.getPath("/etc/yum.repos.d/" + repositoryId + ".repo"));
- String content = unixPath.readUtf8File();
- assertEquals("# This file was generated by node admin\n" +
- "# Do NOT modify this file by hand\n" +
- "\n" +
- "[repoid]\n" +
- "name=name\n" +
- "baseurl=http://foo.com/bar\n" +
- "enabled=1\n" +
- "gpgcheck=0\n", content);
- Instant lastModifiedTime = unixPath.getLastModifiedTime();
-
- // Second time is a no-op
- assertFalse(addYumRepo.converge(context));
- assertEquals(lastModifiedTime, unixPath.getLastModifiedTime());
- }
-
-} \ No newline at end of file