Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create HostAggregate #932

Closed
wants to merge 19 commits into from
Closed

Cannot create HostAggregate #932

wants to merge 19 commits into from

Conversation

Cherry522
Copy link
Contributor

I just tested the 3.0.4-SNAPSHOT version, but it still cannot create HostAggregate.
Error messages:
org.openstack4j.api.exceptions.ClientResponseException: Invalid input for field/attribute aggregate. Value: {u'deleted': False, u'name': u'aggregate_cy_test', u'avaiablityZone': u'uec_zone_1', u'availability_zone': u'uec_zone_1'}. Additional properties are not allowed (u'deleted', u'avaiablityZone' were unexpected)

I modified the source code to solve this problem.

@auhlig
Copy link
Member

auhlig commented Feb 14, 2017

Hi @Cherry522,
Very cool. Many thanks for addressing the various issue. Looks good so far.
Could you also add some tests for the "bigger changes", meaning for the new classes, methods and actions?

@auhlig auhlig added this to the 3.0.4 Release milestone Feb 14, 2017
@Cherry522
Copy link
Contributor Author

Hi @auhlig,
I'd like to add some tests,but I don't known how to run the tests.Is there a document or demo to guide do it?

test-1pro and others added 6 commits February 15, 2017 15:42
ex)
ServerPassword password =
os.compute().servers().evacuate("1427b0a6-e6a1-496",
EvacuateOptions.create().host("compute1").onSharedStorage(false));	
		System.out.println(password.getPassword());
@auhlig
Copy link
Member

auhlig commented Feb 15, 2017

You can use mvn clean verifyto run the tests using JDK8.
If you're on JDK7 you need to skip some modules using mvn clean verify -B -pl !org.pacesys.openstack4j.connectors:openstack4j-http-connector,!org.pacesys.openstack4j.connectors:openstack4j-jersey2,!org.pacesys:it-jersey2
as show in https://github.com/ContainX/openstack4j/blob/master/.travis.yml .

…)' in 'HostAggregate.java' and 'NovaHostAggregate.java'.
@Cherry522
Copy link
Contributor Author

@auhlig
I used mvn clean verify to run tests using JDK8.
The results are as follows:

cherryMac:core-test chenyan$ mvn clean verify
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building OpenStack4j Test Cases 3.0.4-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ openstack4j-core-test ---
[INFO] Deleting /Users/chenyan/Documents/workspace/openstack4j/core-test/target
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ openstack4j-core-test ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ openstack4j-core-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 282 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ openstack4j-core-test ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 111 source files to /Users/chenyan/Documents/workspace/openstack4j/core-test/target/classes
[WARNING] /Users/chenyan/Documents/workspace/openstack4j/core-test/src/main/java/org/openstack4j/api/murano/v1/ServicesTests.java: /Users/chenyan/Documents/workspace/openstack4j/core-test/src/main/java/org/openstack4j/api/murano/v1/ServicesTests.java使用了未经检查或不安全的操作。
[WARNING] /Users/chenyan/Documents/workspace/openstack4j/core-test/src/main/java/org/openstack4j/api/murano/v1/ServicesTests.java: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ openstack4j-core-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/chenyan/Documents/workspace/openstack4j/core-test/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ openstack4j-core-test ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ openstack4j-core-test ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ openstack4j-core-test ---
[INFO] Building jar: /Users/chenyan/Documents/workspace/openstack4j/core-test/target/openstack4j-core-test-2.0.0.jar
[INFO] 
[INFO] --- maven-source-plugin:2.2.1:jar-no-fork (attach-sources) @ openstack4j-core-test ---
[INFO] Building jar: /Users/chenyan/Documents/workspace/openstack4j/core-test/target/openstack4j-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.142 s
[INFO] Finished at: 2017-02-16T14:14:36+08:00
[INFO] Final Memory: 24M/320M
[INFO] ------------------------------------------------------------------------
cherryMac:core-test chenyan$ 

Does this means my tests is OK?

@auhlig
Copy link
Member

auhlig commented Feb 16, 2017

It skipped the tests. Check your environment if you set a flag, etc. which could cause this and try again from project root.

@Cherry522
Copy link
Contributor Author

@auhlig
I run my test use in TestNG,but I got error messages:

[TestNG] Running:
  /private/var/folders/0q/wmckxw9n4xz31wt_ffx5hzph0000gn/T/testng-eclipse-1231076528/testng-customsuite.xml

FAILED CONFIGURATION: @BeforeClass startServer
org.openstack4j.api.exceptions.ConnectorNotFoundException: No OpenStack4j connector found in classpath
	at org.openstack4j.core.transport.internal.HttpExecutor.service(HttpExecutor.java:33)
	at org.openstack4j.core.transport.internal.HttpExecutor.getExecutorName(HttpExecutor.java:43)
	at org.openstack4j.api.AbstractTest.startServer(AbstractTest.java:74)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
	at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
	at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
	at org.testng.TestRunner.privateRun(TestRunner.java:767)
	at org.testng.TestRunner.run(TestRunner.java:617)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
	at org.testng.SuiteRunner.run(SuiteRunner.java:240)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
	at org.testng.TestNG.run(TestNG.java:1031)
	at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

SKIPPED: test

What should I do to run a test?

@auhlig
Copy link
Member

auhlig commented Feb 16, 2017

Maven invokes that. I guess the error is related to your local setup. A default connector should be configured.
A mvn clean verifyin the project root should work.
Travis does the same on your PR https://travis-ci.org/ContainX/openstack4j/jobs/20213767.

@Cherry522
Copy link
Contributor Author

  1. That means I can run the test just by use maven command ?
  2. And you said "the project root",is openstack4j project root,or openstack4j/core-test project root?
  3. And when I used mvn clean verify in openstack4j/core-test project root,why I got message : Tests are skipped.
  4. May I used mvn test -Dtest=src/main/java/org/openstack4j/api/compute/HostAggregateTests#test to test?

@Cherry522
Copy link
Contributor Author

I write some test code,but I down't know how to test it.
org.openstack4j.api.compute.HostAggregateTests.java :

package org.openstack4j.api.compute;

import static org.testng.Assert.assertEquals;

import java.util.List;

import org.openstack4j.api.AbstractTest;
import org.openstack4j.model.compute.HostAggregate;
import org.testng.annotations.Test;

/**
 * Host Aggregate Tests
 * @author chenyan
 *
 */
@Test(suiteName = "HostAggregate")
public class HostAggregateTests extends AbstractTest {
	
	private static final String JSON_HOST_AGGREGATES = "/compute/aggregates.json";
	
	@Test
	public void serviceListingTest() throws Exception {
        respondWith(JSON_HOST_AGGREGATES);

        List<? extends HostAggregate> hostAggregateList = osv3().compute().hostAggregates().list();
        assertEquals(2, hostAggregateList.size());

        HostAggregate aggregate = hostAggregateList.get(0);
        assertEquals("uec_zone_1", aggregate.getAvailabilityZone());
        assertEquals("8", aggregate.getId());
        assertEquals("aggregate_zl_test", aggregate.getName());
    }

	@Override
	protected Service service() {
		return Service.COMPUTE;
	}

}

/openstack4j-core-test/src/main/resources/compute/aggregates.json :

{
    "aggregates": [
        {
            "availabilityZone": "uec_zone_1",
            "create": 1485163578000,
            "createdAt": 1485163578000,
            "deleted": false,
            "hosts": [
                "node-68.domain.tld"
            ],
            "id": "8",
            "metadata": {
                "availability_zone": "uec_zone_1"
            },
            "name": "aggregate_zl_test"
        },
        {
            "availabilityZone": "uec_zone_1",
            "create": 1486968614000,
            "createdAt": 1486968614000,
            "deleted": false,
            "hosts": [],
            "id": "9",
            "metadata": {
                "availability_zone": "uec_zone_1"
            },
            "name": "cyTest01"
        }
    ]
}

@auhlig
Copy link
Member

auhlig commented Feb 16, 2017

  1. That means I can run the test just by use maven command ?

Yes.

  1. And you said "the project root",is openstack4j project root,or openstack4j/core-test project root?

project root is openstack4j. (also both should work in your case)

  1. And when I used mvn clean verify in openstack4j/core-test project root,why I got message : Tests are skipped.

project root is openstack4j

  1. May I used mvn test -Dtest=src/main/java/org/openstack4j/api/compute/HostAggregateTests#test to test?

Might work according to maven documentation. Never tried just running a single test.

@Cherry522
Copy link
Contributor Author

Hi @auhlig,
Many thanks for your answers.I used mvn clean verify to run tests using JDK8,and it's successed.
I commit 2 tests for "hostAggregates".

@auhlig
Copy link
Member

auhlig commented Feb 17, 2017

Yeah 🎉

Copy link
Member

@auhlig auhlig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @Cherry522.
Just a couple of minor comments. Shouldn't take long to fix.
Many thanks for all the work!
I guess we can merge afterwards, if @vinodborole or @gondor does not object?

@@ -32,6 +32,11 @@ public NovaInterfaceAttachment() {
public NovaInterfaceAttachment(String portId) {
this.portId = portId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add null check checkNotNull(portId);

* {@inheritDoc}
*/
@Override
public List<? extends SecurityGroup> list(Map<String,Object> params){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null check

* {@inheritDoc}
*/
@Override
public List<? extends SecurityGroupRule> list(Map<String,Object> param){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add checkNotNull(param);

* @see org.openstack4j.api.storage.BlockVolumeService#attach(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public ActionResponse attach(String volumeId, String instanceId, String mountpoint, String hostName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null check as prerequisite for each argument before call

* @see org.openstack4j.api.storage.BlockVolumeService#forceDetach(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public ActionResponse forceDetach(String volumeId, String initiator, String attachmentId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null check

@auhlig
Copy link
Member

auhlig commented Feb 26, 2017

push Just in case you missed @Cherry522.

@auhlig auhlig modified the milestones: 3.0.5 Release, 3.0.4 Release May 7, 2017
@auhlig auhlig mentioned this pull request May 9, 2017
@auhlig
Copy link
Member

auhlig commented May 9, 2017

Closing in favor of #1017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants