slf4j + logback is used for logging in tests

numeric IDs instead of URIs in requests
This commit is contained in:
Dmitri Babaev 2011-04-14 23:48:29 +04:00 committed by Dmitri Babaev
parent 39c642964a
commit eb4dedca62
7 changed files with 95 additions and 251 deletions

View File

@ -79,18 +79,25 @@
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.28</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -53,8 +53,7 @@ public class NovaCreateNodeWithGroupEncodedIntoName implements CreateNodeWithGro
@Override
public NodeMetadata createNodeWithGroupEncodedIntoName(String group, String name, Template template) {
Server from = client.createServer(name, template.getImage().getUri().toString(),
template.getHardware().getUri().toString());
Server from = client.createServer(name, template.getImage().getId(), template.getHardware().getId());
credentialStore.put("node#" + from.getId(), new Credentials("root", from.getAdminPass()));
return serverToNodeMetadata.apply(from);
}

View File

@ -29,7 +29,7 @@ import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payload;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.openstack.nova.domain.*;
import org.jclouds.openstack.nova.options.RebuildServerOptions;
@ -51,7 +51,6 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.nova.PropertyHelper.overridePropertyFromSystemProperty;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails;
import static org.testng.Assert.*;
@ -74,21 +73,12 @@ public class NovaClientLiveTest {
protected String endpoint;
protected String apiversion;
protected Properties setupProperties() throws IOException {
Properties overrides = new Properties();
overrides.load(this.getClass().getResourceAsStream("/test.properties"));
overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".identity");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".credential");
overridePropertyFromSystemProperty(overrides, "test.initializer");
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
return overrides;
private void overridePropertyFromSystemProperty(final Properties properties, String propertyName) {
if ((System.getProperty(propertyName) != null) && !System.getProperty(propertyName).equals("${" + propertyName + "}"))
properties.setProperty(propertyName, System.getProperty(propertyName));
}
protected void setupCredentials(Properties properties) {
identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(properties.getProperty("test." + provider + ".credential"), "test." + provider
@ -106,6 +96,19 @@ public class NovaClientLiveTest {
properties.setProperty(provider + ".apiversion", apiversion);
}
protected Properties setupProperties() throws IOException {
Properties overrides = new Properties();
overrides.load(this.getClass().getResourceAsStream("/test.properties"));
overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".identity");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".credential");
overridePropertyFromSystemProperty(overrides, "test.initializer");
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
return overrides;
}
@BeforeGroups(groups = {"live"})
public void setupClient() throws IOException {
@ -119,7 +122,7 @@ public class NovaClientLiveTest {
// ComputeServiceContext context = contextFactory.createContext(provider, identity, credential, Collections.singleton(new JschSshClientModule()), overrides);
Injector injector = new RestContextFactory().createContextBuilder(provider, identity, credential,
ImmutableSet.<Module>of(new Log4JLoggingModule(), new JschSshClientModule()), overrides)
ImmutableSet.<Module>of(new SLF4JLoggingModule(), new JschSshClientModule()), overrides)
.buildInjector();
client = injector.getInstance(NovaClient.class);
@ -265,7 +268,7 @@ public class NovaClientLiveTest {
@Test(enabled = true)
public void testCreateServer() throws Exception {
String imageRef = "3";
String imageRef = "14362";
String flavorRef = "1";
String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt();
Server server = client.createServer(serverName, imageRef, flavorRef, withFile("/etc/jclouds.txt",

View File

@ -1,16 +1,18 @@
package org.jclouds.openstack.nova;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import java.util.Arrays;
import java.util.Collections;
import java.util.Properties;
import java.util.Set;
@ -18,8 +20,8 @@ import static org.jclouds.Constants.PROPERTY_ENDPOINT;
public class _NovaClient {
static public void main(String[] args) {
//curl -v -H "X-Auth-User:admin" -H "X-Auth-Key: d744752f-20d3-4d75-979f-f62f16033b07" http://172.18.34.40:8774/v1.0/
//curl -v -H "X-Auth-Token: 00cf93fd62df48f9fdc35fa16a7662447e48c513" http://dragon004.hw.griddynamics.net:8774/v1.1/images/detail?format=json
//curl -v -H "X-Auth-User:admin" -H "X-Auth-Key: d744752f-20d3-4d75-979f-f62f16033b07" http://dragon004.hw.griddynamics.net:8774/v1.0/
//curl -v -H "X-Auth-Token: c97b10659008d5a9ce91462f8c6a5c2c80439762" http://dragon004.hw.griddynamics.net:8774/v1.0/images/detail?format=json
String identity = "admin";
String credential = "d744752f-20d3-4d75-979f-f62f16033b07";
@ -30,17 +32,17 @@ public class _NovaClient {
Properties overrides = new Properties();
overrides.setProperty(PROPERTY_ENDPOINT, endpoint);
ComputeServiceContext context = contextFactory.createContext("nova", identity, credential,
Arrays.asList(new JschSshClientModule(), new Log4JLoggingModule()), overrides);
Arrays.asList(new JschSshClientModule(), new SLF4JLoggingModule()), overrides);
ComputeService cs = context.getComputeService();
System.out.println(cs.listImages());
System.out.println(cs.listHardwareProfiles());
//System.out.println(cs.listNodes());
System.out.println(cs.listAssignableLocations());
System.out.println(cs.listNodes());
TemplateOptions options = new TemplateOptions();
//options.authorizePublicKey("");
Template template = cs.templateBuilder().imageId("3").options(options).build();
Template template = cs.templateBuilder().imageId("13").options(options).build();
try {
Set<? extends NodeMetadata> metedata = cs.runNodesWithTag("test", 1, template);
System.out.println(metedata);
@ -48,10 +50,6 @@ public class _NovaClient {
e.printStackTrace();
}
//System.out.println(cs.listNodes());
//System.out.println(cs.listImages());
//System.out.println(cs.listNodes());
//System.out.println(cs.listAssignableLocations());
//System.out.println(cs.listHardwareProfiles());
context.close();
}
}

View File

@ -34,7 +34,7 @@ import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.openstack.nova.NovaAsyncClient;
import org.jclouds.openstack.nova.NovaClient;
@ -74,7 +74,6 @@ import static org.jclouds.compute.options.TemplateOptions.Builder.overrideCreden
import static org.jclouds.compute.predicates.NodePredicates.*;
import static org.jclouds.compute.predicates.NodePredicates.all;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.openstack.nova.PropertyHelper.overridePropertyFromSystemProperty;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@ -109,6 +108,11 @@ public class NovaComputeServiceLiveTest {
}
private void overridePropertyFromSystemProperty(final Properties properties, String propertyName) {
if ((System.getProperty(propertyName) != null) && !System.getProperty(propertyName).equals("${" + propertyName + "}"))
properties.setProperty(propertyName, System.getProperty(propertyName));
}
protected void setupCredentials(Properties properties) {
identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(properties.getProperty("test." + provider + ".credential"), "test." + provider
@ -127,10 +131,13 @@ public class NovaComputeServiceLiveTest {
}
protected Properties setupProperties() throws IOException {
protected Properties setupProperties() {
Properties overrides = new Properties();
try {
overrides.load(this.getClass().getResourceAsStream("/test.properties"));
} catch (IOException e) {
throw new RuntimeException("Can't load properties");
}
overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".identity");
@ -152,7 +159,7 @@ public class NovaComputeServiceLiveTest {
if (context != null)
context.close();
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, ImmutableSet.of(
new Log4JLoggingModule(), getSshModule()), properties);
new SLF4JLoggingModule(), getSshModule()), properties);
client = context.getComputeService();
}
@ -227,7 +234,7 @@ public class NovaComputeServiceLiveTest {
ComputeServiceContext context = null;
try {
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, "MOMMA", "MIA", ImmutableSet
.<Module>of(new Log4JLoggingModule()), overrides);
.<Module>of(new SLF4JLoggingModule()), overrides);
context.getComputeService().listNodes();
} catch (AuthorizationException e) {
throw e;

View File

@ -1,185 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 Cloud Conscious, LLC.
<info@cloudconscious.com>
====================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by
applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions
and limitations under the License.
====================================================================
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
For more configuration infromation and examples see the Apache
Log4j website: http://logging.apache.org/log4j/
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- A time/date based rolling appender -->
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-wire.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="BLOBSTOREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-blobstore.log" />
<param name="Append" value="true" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-compute.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="SSHFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-ssh.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="COMPUTEFILE" />
</appender>
<appender name="ASYNCSSH" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="SSHFILE" />
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="WIREFILE" />
</appender>
<appender name="ASYNCBLOBSTORE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="BLOBSTOREFILE" />
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="DEBUG" />
<appender-ref ref="ASYNC" />
</category>
<category name="jclouds.headers">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.ssh">
<priority value="DEBUG" />
<appender-ref ref="ASYNCSSH" />
</category>
<category name="jclouds.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.blobstore">
<priority value="DEBUG" />
<appender-ref ref="ASYNCBLOBSTORE" />
</category>
<category name="jclouds.compute">
<priority value="TRACE" />
<appender-ref ref="ASYNCCOMPUTE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration>

View File

@ -0,0 +1,15 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
<logger name="org.jclouds" level="debug" />
</configuration>