Search in sources :

Example 1 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testPluginPermissions.

public void testPluginPermissions() throws Exception {
    assumeTrue("posix filesystem", isPosix);
    final Tuple<Path, Environment> env = createEnv(fs, temp);
    final Path pluginDir = createPluginDir(temp);
    final Path resourcesDir = pluginDir.resolve("resources");
    final Path platformDir = pluginDir.resolve("platform");
    final Path platformNameDir = platformDir.resolve("linux-x64");
    final Path platformBinDir = platformNameDir.resolve("bin");
    Files.createDirectories(platformBinDir);
    Files.createFile(pluginDir.resolve("fake-" + Version.CURRENT.toString() + ".jar"));
    Files.createFile(platformBinDir.resolve("fake_executable"));
    Files.createDirectory(resourcesDir);
    Files.createFile(resourcesDir.resolve("resource"));
    final String pluginZip = createPluginUrl("fake", pluginDir);
    installPlugin(pluginZip, env.v1());
    assertPlugin("fake", pluginDir, env.v2());
    final Path fake = env.v2().pluginsFile().resolve("fake");
    final Path resources = fake.resolve("resources");
    final Path platform = fake.resolve("platform");
    final Path platformName = platform.resolve("linux-x64");
    final Path bin = platformName.resolve("bin");
    assert755(fake);
    assert644(fake.resolve("fake-" + Version.CURRENT + ".jar"));
    assert755(resources);
    assert644(resources.resolve("resource"));
    assert755(platform);
    assert755(platformName);
    assert755(bin.resolve("fake_executable"));
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 2 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testInstallFailsIfPreviouslyRemovedPluginFailed.

public void testInstallFailsIfPreviouslyRemovedPluginFailed() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String pluginZip = createPluginUrl("fake", pluginDir);
    final Path removing = env.v2().pluginsFile().resolve(".removing-failed");
    Files.createDirectory(removing);
    final IllegalStateException e = expectThrows(IllegalStateException.class, () -> installPlugin(pluginZip, env.v1()));
    final String expected = String.format(Locale.ROOT, "found file [%s] from a failed attempt to remove the plugin [failed]; execute [opensearch-plugin remove failed]", removing);
    assertThat(e, hasToString(containsString(expected)));
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 3 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testPolicyConfirmation.

public void testPolicyConfirmation() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    writePluginSecurityPolicy(pluginDir, "setAccessible", "setFactory");
    String pluginZip = createPluginUrl("fake", pluginDir);
    assertPolicyConfirmation(env, pluginZip, "plugin requires additional permissions");
    assertPlugin("fake", pluginDir, env.v2());
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 4 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testConfigContainsDir.

public void testConfigContainsDir() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Path dirInConfigDir = pluginDir.resolve("config").resolve("foo");
    Files.createDirectories(dirInConfigDir);
    Files.createFile(dirInConfigDir.resolve("myconfig.yml"));
    String pluginZip = createPluginUrl("fake", pluginDir);
    UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("Directories not allowed in config dir for plugin"));
    assertInstallCleaned(env.v2());
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException)

Example 5 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testExistingPluginWithCustomFolderName.

public void testExistingPluginWithCustomFolderName() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String pluginZip = createPluginUrl("fake", pluginDir, "custom.foldername", "fake-folder");
    installPlugin(pluginZip, env.v1());
    assertPlugin("fake-folder", pluginDir, env.v2());
    UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("already exists"));
    assertInstallCleaned(env.v2());
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException)

Aggregations

Environment (org.opensearch.env.Environment)142 TestEnvironment (org.opensearch.env.TestEnvironment)98 Path (java.nio.file.Path)80 Settings (org.opensearch.common.settings.Settings)79 Matchers.containsString (org.hamcrest.Matchers.containsString)69 Matchers.hasToString (org.hamcrest.Matchers.hasToString)40 NodeEnvironment (org.opensearch.env.NodeEnvironment)32 IOException (java.io.IOException)27 UserException (org.opensearch.cli.UserException)23 ClusterState (org.opensearch.cluster.ClusterState)22 IndexSettings (org.opensearch.index.IndexSettings)22 MockTerminal (org.opensearch.cli.MockTerminal)19 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)19 OpenSearchException (org.opensearch.OpenSearchException)18 Map (java.util.Map)16 OptionSet (joptsimple.OptionSet)15 DiscoverySettings (org.opensearch.node.Node.DiscoverySettings)14 Version (org.opensearch.Version)13 Files (java.nio.file.Files)11 Arrays (java.util.Arrays)11