mirror of
https://github.com/OpenNebula/one.git
synced 2025-08-24 17:49:28 +03:00
@ -1,202 +0,0 @@
|
|||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
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.
|
|
@ -1,5 +0,0 @@
|
|||||||
Apache XML-RPC
|
|
||||||
Copyright 1999-2009 The Apache Software Foundation
|
|
||||||
|
|
||||||
This product includes software developed at
|
|
||||||
The Apache Software Foundation (http://www.apache.org/).
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,306 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.acl.*;
|
|
||||||
|
|
||||||
public class AclTest
|
|
||||||
{
|
|
||||||
|
|
||||||
private static Acl acl;
|
|
||||||
private static AclPool aclPool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
aclPool = new AclPool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
for(Acl rule : aclPool)
|
|
||||||
{
|
|
||||||
if( rule.id() > 4 )
|
|
||||||
{
|
|
||||||
rule.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void defaultRules()
|
|
||||||
{
|
|
||||||
res = aclPool.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertEquals(5, aclPool.getLength());
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
@Test
|
|
||||||
public void hexAllocate()
|
|
||||||
{
|
|
||||||
// Allocate rule "#1 VM+HOST/@1 INFO+CREATE"
|
|
||||||
res = Acl.allocate(client, "0x100000001", "0x3200000001", "0x8");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
aclPool.info();
|
|
||||||
acl = aclPool.getById( res.getIntMessage() );
|
|
||||||
|
|
||||||
assertNotNull(acl);
|
|
||||||
|
|
||||||
assertEquals(res.getIntMessage(), acl.id());
|
|
||||||
assertEquals(0x100000001L, acl.user());
|
|
||||||
assertEquals(0x3200000001L, acl.resource());
|
|
||||||
assertEquals(0x8L, acl.rights());
|
|
||||||
assertEquals("#1 VM+HOST/@1 CREATE",acl.toString());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
@Test
|
|
||||||
public void numericAllocate()
|
|
||||||
{
|
|
||||||
// Allocate rule "#1 VM+HOST/@1 USE"
|
|
||||||
res = Acl.allocate(client, 0x100000001L, 214748364801L, 0x1L);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
aclPool.info();
|
|
||||||
acl = aclPool.getById( res.getIntMessage() );
|
|
||||||
|
|
||||||
assertNotNull(acl);
|
|
||||||
|
|
||||||
assertEquals(res.getIntMessage(), acl.id());
|
|
||||||
assertEquals(0x100000001L, acl.user());
|
|
||||||
assertEquals(0x3200000001L, acl.resource());
|
|
||||||
assertEquals(0x1L, acl.rights());
|
|
||||||
assertEquals("#1 VM+HOST/@1 USE", acl.toString());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void ruleAllocate()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
res = Acl.allocate(client, "@507 IMAGE/#456 MANAGE #102");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
aclPool.info();
|
|
||||||
acl = aclPool.getById( res.getIntMessage() );
|
|
||||||
|
|
||||||
assertNotNull(acl);
|
|
||||||
|
|
||||||
assertEquals(res.getIntMessage(), acl.id());
|
|
||||||
assertEquals(0x2000001fbL, acl.user());
|
|
||||||
assertEquals(0x81000001c8L, acl.resource());
|
|
||||||
assertEquals(0x2L, acl.rights());
|
|
||||||
assertEquals("@507 IMAGE/#456 MANAGE #102", acl.toString());
|
|
||||||
}
|
|
||||||
catch (RuleParseException e)
|
|
||||||
{
|
|
||||||
assertTrue( false );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parseRules()
|
|
||||||
{
|
|
||||||
String[] rules = {
|
|
||||||
"#3 TEMPLATE/#0 USE",
|
|
||||||
"#2 IMAGE/#0 USE",
|
|
||||||
"@107 IMAGE+TEMPLATE/@100 USE",
|
|
||||||
"* VM+IMAGE+TEMPLATE/@100 CREATE+USE",
|
|
||||||
"#2345 VM+IMAGE+TEMPLATE/* CREATE+USE",
|
|
||||||
"@7 HOST/#100 USE+MANAGE",
|
|
||||||
"* HOST+DATASTORE/%100 MANAGE+USE",
|
|
||||||
"@107 NET/%100 USE"
|
|
||||||
};
|
|
||||||
|
|
||||||
long[] users = {
|
|
||||||
0x100000003L,
|
|
||||||
0x100000002L,
|
|
||||||
0x20000006bL,
|
|
||||||
0x400000000L,
|
|
||||||
0x100000929L,
|
|
||||||
0x200000007L,
|
|
||||||
0x400000000L,
|
|
||||||
0x20000006bL
|
|
||||||
};
|
|
||||||
|
|
||||||
long[] resources = {
|
|
||||||
0x20100000000L,
|
|
||||||
0x8100000000L,
|
|
||||||
0x28200000064L,
|
|
||||||
0x29200000064L,
|
|
||||||
0x29400000000L,
|
|
||||||
0x2100000064L,
|
|
||||||
0x102800000064L,
|
|
||||||
0x4800000064L
|
|
||||||
};
|
|
||||||
|
|
||||||
long[] rights = {
|
|
||||||
0x1L,
|
|
||||||
0x1L,
|
|
||||||
0x1L,
|
|
||||||
0x9L,
|
|
||||||
0x9L,
|
|
||||||
0x3L,
|
|
||||||
0x3L,
|
|
||||||
0x1L
|
|
||||||
};
|
|
||||||
|
|
||||||
for( int i = 0; i < rules.length; i++ )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
res = Acl.allocate(client, rules[i]);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
aclPool.info();
|
|
||||||
acl = aclPool.getById( res.getIntMessage() );
|
|
||||||
|
|
||||||
assertNotNull(acl);
|
|
||||||
|
|
||||||
assertEquals(res.getIntMessage(), acl.id());
|
|
||||||
assertEquals(users[i], acl.user());
|
|
||||||
assertEquals(resources[i], acl.resource());
|
|
||||||
assertEquals(rights[i], acl.rights());
|
|
||||||
}
|
|
||||||
catch (RuleParseException e)
|
|
||||||
{
|
|
||||||
assertTrue(
|
|
||||||
"Rule " + rules[i]
|
|
||||||
+ " has been wrongly reported as invalid; "
|
|
||||||
+ e.getMessage(),
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
catch (AssertionError e)
|
|
||||||
{
|
|
||||||
assertTrue(
|
|
||||||
"Rule " + rules[i]
|
|
||||||
+ " assert failure; "
|
|
||||||
+ e.getMessage(),
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
res = Acl.allocate(client, "#1 HOST/#2 USE");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
aclPool.info();
|
|
||||||
assertEquals( 6, aclPool.getLength() );
|
|
||||||
|
|
||||||
res = Acl.delete(client, res.getIntMessage());
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
aclPool.info();
|
|
||||||
assertEquals( 5, aclPool.getLength() );
|
|
||||||
}
|
|
||||||
catch (RuleParseException e)
|
|
||||||
{
|
|
||||||
assertTrue(
|
|
||||||
"Rule has been wrongly reported as invalid; "
|
|
||||||
+ e.getMessage(),
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void wrongRules()
|
|
||||||
{
|
|
||||||
String[] rules = {
|
|
||||||
"#-3 TEMPLATE/#0 USE",
|
|
||||||
"#+3 TEMPLATE/#0 USE",
|
|
||||||
"@3+ TEMPLATE/#0 USE",
|
|
||||||
"*3 TEMPLATE/#0 USE",
|
|
||||||
"# TEMPLATE/#0 USE",
|
|
||||||
"@@ TEMPLATE/#0 USE",
|
|
||||||
"@#3 TEMPLATE/#0 USE",
|
|
||||||
"#3 TEMPLATE+HOS/#0 USE",
|
|
||||||
"#3 /#0 USE",
|
|
||||||
"#3 TEMPLATE/# USE",
|
|
||||||
"#3 TEMPLATE/% USE",
|
|
||||||
"#3 TEMPLATE/#5 USE CREATE",
|
|
||||||
"#3 TEMPLATE/#5",
|
|
||||||
"#3 ",
|
|
||||||
"",
|
|
||||||
"#2 IMAGE @10654 USE",
|
|
||||||
"#2 IMAGE/ USE",
|
|
||||||
"#2 IMAGE#0 USE",
|
|
||||||
"#2 IMAGE/# USE",
|
|
||||||
"#2 IMAGE/@- USE",
|
|
||||||
"#2 IMAGE/#0/#0 USE",
|
|
||||||
"#2 IMAGE/#0/USE CREATE",
|
|
||||||
"#2 IMAGE/#0/USE+CREATE",
|
|
||||||
"#2 IMAGE/#0 IFO",
|
|
||||||
"#2 IMAGE/#0 USE+CREAT",
|
|
||||||
};
|
|
||||||
|
|
||||||
for( int i = 0; i < rules.length; i++ )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
res = Acl.allocate(client, rules[i]);
|
|
||||||
|
|
||||||
assertTrue( "Rule " + rules[i] +
|
|
||||||
" should have thrown an exception",
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
catch (RuleParseException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,163 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
|
|
||||||
|
|
||||||
public class DocumentTest
|
|
||||||
{
|
|
||||||
private static GenericObjA objA;
|
|
||||||
private static GenericObjB objB;
|
|
||||||
private static GenericObjAPool objAPool;
|
|
||||||
private static GenericObjBPool objBPool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
|
|
||||||
private static String nameA = "obj_one";
|
|
||||||
private static String nameB = "obj_two";
|
|
||||||
|
|
||||||
private static String template_one =
|
|
||||||
"NAME = \"" + nameA + "\"\n" +
|
|
||||||
"ATT1 = \"VAL1\"\n" +
|
|
||||||
"ATT2 = \"VAL2\"";
|
|
||||||
|
|
||||||
private static String template_two =
|
|
||||||
"NAME = \"" + nameB + "\"\n" +
|
|
||||||
"ATT1 = \"VAL1\"\n" +
|
|
||||||
"ATT2 = \"VAL2\"";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
objAPool = new GenericObjAPool(client);
|
|
||||||
objBPool = new GenericObjBPool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = GenericObjA.allocate(client, template_one);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int oidA = Integer.parseInt(res.getMessage());
|
|
||||||
objA = new GenericObjA(oidA, client);
|
|
||||||
|
|
||||||
res = GenericObjB.allocate(client, template_two);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int oidB = Integer.parseInt(res.getMessage());
|
|
||||||
objB = new GenericObjB(oidB, client);
|
|
||||||
|
|
||||||
res = objA.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = objB.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
objA.delete();
|
|
||||||
objB.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void sameOidSpace()
|
|
||||||
{
|
|
||||||
assertTrue(
|
|
||||||
"objA id : " + objA.getId() + "; objB id : " + objB.getId(),
|
|
||||||
objB.id() == objA.id()+1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void differentPools()
|
|
||||||
{
|
|
||||||
res = objAPool.infoAll();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
boolean foundA = false;
|
|
||||||
boolean foundB = false;
|
|
||||||
|
|
||||||
for(GenericObjA ob : objAPool)
|
|
||||||
{
|
|
||||||
foundA = foundA || ob.getName().equals(nameA);
|
|
||||||
foundB = foundB || ob.getName().equals(nameB);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( foundA );
|
|
||||||
assertTrue( !foundB );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
res = objBPool.infoMine();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
foundA = false;
|
|
||||||
foundB = false;
|
|
||||||
|
|
||||||
for(GenericObjB ob : objBPool)
|
|
||||||
{
|
|
||||||
foundA = foundA || ob.getName().equals(nameA);
|
|
||||||
foundB = foundB || ob.getName().equals(nameB);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( !foundA );
|
|
||||||
assertTrue( foundB );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lock()
|
|
||||||
{
|
|
||||||
res = objA.lock("doctest");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( res.getMessage(), res.getBooleanMessage() == true );
|
|
||||||
|
|
||||||
res = objA.lock("doctest");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( res.getMessage(), res.getBooleanMessage() == false );
|
|
||||||
|
|
||||||
res = objA.unlock("doctest");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.document.Document;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
|
|
||||||
public class GenericObjA extends Document
|
|
||||||
{
|
|
||||||
private static final int TYPE = 200;
|
|
||||||
|
|
||||||
public GenericObjA(int id, Client client)
|
|
||||||
{
|
|
||||||
super(id, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericObjA(Node xmlElement, Client client)
|
|
||||||
{
|
|
||||||
super(xmlElement, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static OneResponse allocate(Client client, String description)
|
|
||||||
{
|
|
||||||
return Document.allocate(client, description, TYPE);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
import java.util.AbstractList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.document.DocumentPool;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
|
|
||||||
|
|
||||||
public class GenericObjAPool extends DocumentPool implements Iterable<GenericObjA>
|
|
||||||
{
|
|
||||||
private static final int TYPE = 200;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int type()
|
|
||||||
{
|
|
||||||
return TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericObjAPool(Client client)
|
|
||||||
{
|
|
||||||
super(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericObjAPool(Client client, int filter)
|
|
||||||
{
|
|
||||||
super(client, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GenericObjA factory(Node node)
|
|
||||||
{
|
|
||||||
return new GenericObjA(node, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<GenericObjA> iterator()
|
|
||||||
{
|
|
||||||
AbstractList<GenericObjA> ab = new AbstractList<GenericObjA>()
|
|
||||||
{
|
|
||||||
public int size()
|
|
||||||
{
|
|
||||||
return getLength();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericObjA get(int index)
|
|
||||||
{
|
|
||||||
return (GenericObjA) item(index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return ab.iterator();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.document.Document;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
|
|
||||||
public class GenericObjB extends Document
|
|
||||||
{
|
|
||||||
private static final int TYPE = 201;
|
|
||||||
|
|
||||||
public GenericObjB(int id, Client client)
|
|
||||||
{
|
|
||||||
super(id, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericObjB(Node xmlElement, Client client)
|
|
||||||
{
|
|
||||||
super(xmlElement, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static OneResponse allocate(Client client, String description)
|
|
||||||
{
|
|
||||||
return Document.allocate(client, description, TYPE);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
import java.util.AbstractList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.document.DocumentPool;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
|
|
||||||
|
|
||||||
public class GenericObjBPool extends DocumentPool implements Iterable<GenericObjB>
|
|
||||||
{
|
|
||||||
private static final int TYPE = 201;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int type()
|
|
||||||
{
|
|
||||||
return TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericObjBPool(Client client)
|
|
||||||
{
|
|
||||||
super(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericObjBPool(Client client, int filter)
|
|
||||||
{
|
|
||||||
super(client, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GenericObjB factory(Node node)
|
|
||||||
{
|
|
||||||
return new GenericObjB(node, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<GenericObjB> iterator()
|
|
||||||
{
|
|
||||||
AbstractList<GenericObjB> ab = new AbstractList<GenericObjB>()
|
|
||||||
{
|
|
||||||
public int size()
|
|
||||||
{
|
|
||||||
return getLength();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GenericObjB get(int index)
|
|
||||||
{
|
|
||||||
return (GenericObjB) item(index);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return ab.iterator();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,306 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import javax.xml.xpath.XPath;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
import javax.xml.xpath.XPathFactory;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.OneSystem;
|
|
||||||
import org.opennebula.client.group.Group;
|
|
||||||
import org.opennebula.client.group.GroupPool;
|
|
||||||
import org.opennebula.client.user.*;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
|
|
||||||
public class GroupTest
|
|
||||||
{
|
|
||||||
|
|
||||||
private static Group group;
|
|
||||||
private static GroupPool groupPool;
|
|
||||||
private static User user;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
|
|
||||||
private static String group_name = "test_group";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
groupPool = new GroupPool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = Group.allocate(client, group_name);
|
|
||||||
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int group_id = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
group = new Group(group_id, client);
|
|
||||||
|
|
||||||
res = User.allocate(client, "new_test_user", "new_test_password");
|
|
||||||
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int uid = Integer.parseInt(res.getMessage());
|
|
||||||
user = new User(uid, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
user.delete();
|
|
||||||
group.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
group.delete();
|
|
||||||
|
|
||||||
res = Group.allocate(client, group_name);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int group_id = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
group = new Group(group_id, client);
|
|
||||||
|
|
||||||
|
|
||||||
groupPool.info();
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(Group img : groupPool)
|
|
||||||
{
|
|
||||||
found = found || img.getName().equals(group_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void info()
|
|
||||||
{
|
|
||||||
res = group.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( group.id() >= 100 );
|
|
||||||
assertTrue( group.getName().equals(group_name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
res = group.delete();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = group.info();
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
|
|
||||||
res = groupPool.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(Group g : groupPool)
|
|
||||||
{
|
|
||||||
found = found || g.getName().equals(group_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( !found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void defaultqutoas()
|
|
||||||
{
|
|
||||||
OneSystem system = new OneSystem(client);
|
|
||||||
|
|
||||||
res = system.getGroupQuotas();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = system.setGroupQuotas("VM = [ VMS = 7, MEMORY = 0, CPU = 3, SYSTEM_DISK_SIZE = 1 ]");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
Node node = system.getGroupQuotasXML();
|
|
||||||
XPathFactory factory = XPathFactory.newInstance();
|
|
||||||
XPath xpath = factory.newXPath();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
assertTrue( xpath.evaluate("VM_QUOTA/VM/VMS", node).equals("7") );
|
|
||||||
} catch (XPathExpressionException e)
|
|
||||||
{
|
|
||||||
assertTrue(e.getMessage(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addAdmin()
|
|
||||||
{
|
|
||||||
res = group.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertFalse( group.contains(user.id()) );
|
|
||||||
assertFalse( group.containsAdmin(user.id()) );
|
|
||||||
|
|
||||||
res = group.addAdmin( user.id() );
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
|
|
||||||
group.info();
|
|
||||||
assertFalse( group.contains(user.id()) );
|
|
||||||
assertFalse( group.containsAdmin(user.id()) );
|
|
||||||
|
|
||||||
res = user.chgrp( group.id() );
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
group.info();
|
|
||||||
assertTrue( group.contains(user.id()) );
|
|
||||||
assertFalse( group.containsAdmin(user.id()) );
|
|
||||||
|
|
||||||
res = group.addAdmin( user.id() );
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
group.info();
|
|
||||||
assertTrue( group.contains(user.id()) );
|
|
||||||
assertTrue( group.containsAdmin(user.id()) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delAdmin()
|
|
||||||
{
|
|
||||||
res = group.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = group.delAdmin( user.id() );
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
|
|
||||||
res = user.chgrp( group.id() );
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = group.delAdmin( user.id() );
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
|
|
||||||
res = group.addAdmin( user.id() );
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
group.info();
|
|
||||||
assertTrue( group.contains(user.id()) );
|
|
||||||
assertTrue( group.containsAdmin(user.id()) );
|
|
||||||
|
|
||||||
res = group.delAdmin( user.id() );
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
group.info();
|
|
||||||
assertTrue( group.contains(user.id()) );
|
|
||||||
assertFalse( group.containsAdmin(user.id()) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void userGroupRelations()
|
|
||||||
{
|
|
||||||
Hashtable<String, User> users = new Hashtable<String, User>();
|
|
||||||
Hashtable<String, Group> groups = new Hashtable<String, Group>();
|
|
||||||
|
|
||||||
// Create all users and groups. Add user_* to corresponding group_*
|
|
||||||
String[] names = {"a", "b", "c", "d"};
|
|
||||||
for(String name : names)
|
|
||||||
{
|
|
||||||
res = User.allocate(client, "user_"+name, "password");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
users.put( name,
|
|
||||||
new User(Integer.parseInt(res.getMessage()), client )
|
|
||||||
);
|
|
||||||
|
|
||||||
res = Group.allocate(client, "group_"+name);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
groups.put( name,
|
|
||||||
new Group(Integer.parseInt(res.getMessage()), client )
|
|
||||||
);
|
|
||||||
|
|
||||||
users.get(name).addgroup( groups.get(name).id() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add all users to group_b
|
|
||||||
for( User u : users.values() )
|
|
||||||
{
|
|
||||||
u.addgroup( groups.get("b").id() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change user_c & _d main group
|
|
||||||
users.get("c").chgrp( groups.get("d").id() );
|
|
||||||
users.get("d").chgrp( groups.get("c").id() );
|
|
||||||
|
|
||||||
|
|
||||||
// Check cross-references so far
|
|
||||||
for( User u : users.values() )
|
|
||||||
{
|
|
||||||
assertTrue( !u.info().isError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
for( Group g : groups.values() )
|
|
||||||
{
|
|
||||||
assertTrue( !g.info().isError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( groups.get("a").contains( users.get("a").id() ) );
|
|
||||||
assertFalse( groups.get("a").contains( users.get("b").id() ) );
|
|
||||||
assertFalse( groups.get("a").contains( users.get("c").id() ) );
|
|
||||||
assertFalse( groups.get("a").contains( users.get("d").id() ) );
|
|
||||||
|
|
||||||
assertTrue( groups.get("b").contains( users.get("a").id() ) );
|
|
||||||
assertTrue( groups.get("b").contains( users.get("b").id() ) );
|
|
||||||
assertTrue( groups.get("b").contains( users.get("c").id() ) );
|
|
||||||
assertTrue( groups.get("b").contains( users.get("d").id() ) );
|
|
||||||
|
|
||||||
assertFalse( groups.get("c").contains( users.get("a").id() ) );
|
|
||||||
assertFalse( groups.get("c").contains( users.get("b").id() ) );
|
|
||||||
assertTrue( groups.get("c").contains( users.get("c").id() ) );
|
|
||||||
assertTrue( groups.get("c").contains( users.get("d").id() ) );
|
|
||||||
assertFalse( groups.get("d").contains( users.get("a").id() ) );
|
|
||||||
assertFalse( groups.get("d").contains( users.get("b").id() ) );
|
|
||||||
assertTrue( groups.get("d").contains( users.get("c").id() ) );
|
|
||||||
assertTrue( groups.get("d").contains( users.get("d").id() ) );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,217 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.host.Host;
|
|
||||||
import org.opennebula.client.host.HostPool;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
|
|
||||||
public class HostTest
|
|
||||||
{
|
|
||||||
class HostXML extends Host
|
|
||||||
{
|
|
||||||
public HostXML(Node node, Client client){ super(node, client); }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Host host;
|
|
||||||
private static HostPool hostPool;
|
|
||||||
private static Client client;
|
|
||||||
private OneResponse res;
|
|
||||||
private static String name = "new_test_host";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
hostPool = new HostPool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = Host.allocate(client, name, "dummy", "dummy");
|
|
||||||
|
|
||||||
int hid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1;
|
|
||||||
host = new Host(hid, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
host.delete();
|
|
||||||
Thread.sleep(2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
String name = "allocate_test";
|
|
||||||
|
|
||||||
res = Host.allocate(client, name, "im_dummy", "vmm_dummy");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
// assertTrue( res.getMessage().equals("0") );
|
|
||||||
|
|
||||||
hostPool.info();
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(Host h : hostPool)
|
|
||||||
{
|
|
||||||
found = found || h.getName().equals(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void info()
|
|
||||||
{
|
|
||||||
res = host.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// assertTrue( host.getId().equals("0") );
|
|
||||||
assertTrue( host.id() >= 0 );
|
|
||||||
|
|
||||||
// assertTrue( host.shortStateStr().equals("on") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void enable()
|
|
||||||
{
|
|
||||||
res = host.enable();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
host.info();
|
|
||||||
assertTrue( host.isEnabled() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disable()
|
|
||||||
{
|
|
||||||
res = host.disable();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
host.info();
|
|
||||||
assertTrue( !host.isEnabled() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
String name = host.getName();
|
|
||||||
|
|
||||||
res = host.delete();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = host.info();
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
|
|
||||||
res = hostPool.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(Host h : hostPool)
|
|
||||||
{
|
|
||||||
found = found || h.getName().equals(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( !found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
res = host.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( host.xpath("TEMPLATE/ATT1").equals( "" ) );
|
|
||||||
assertTrue( host.xpath("TEMPLATE/ATT2").equals( "" ) );
|
|
||||||
|
|
||||||
String new_template = "ATT2 = NEW_VAL\n" +
|
|
||||||
"ATT3 = VAL3";
|
|
||||||
|
|
||||||
res = host.update(new_template);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
|
|
||||||
res = host.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( host.xpath("TEMPLATE/ATT1").equals( "" ) );
|
|
||||||
assertTrue( host.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
|
||||||
assertTrue( host.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
@Test
|
|
||||||
public void attributes()
|
|
||||||
{
|
|
||||||
DocumentBuilder builder;
|
|
||||||
Document doc;
|
|
||||||
Element xml;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
|
||||||
|
|
||||||
doc = builder.parse( new File("./fixtures/host.xml") );
|
|
||||||
xml = doc.getDocumentElement();
|
|
||||||
|
|
||||||
host = new HostXML(xml, client);
|
|
||||||
|
|
||||||
assertTrue( host.xpath("ID").equals("7") );
|
|
||||||
assertTrue( host.xpath("NAME").equals("dummyhost") );
|
|
||||||
assertTrue( host.xpath("STATE").equals("2") );
|
|
||||||
assertTrue( host.xpath("IM_MAD").equals("im_dummy") );
|
|
||||||
assertTrue( host.xpath("LAST_MON_TIME").equals("1277733596") );
|
|
||||||
assertTrue( host.xpath("HOST_SHARE/MEM_USAGE").equals("1572864") );
|
|
||||||
assertTrue( host.xpath("HOST_SHARE/CPU_USAGE").equals("300") );
|
|
||||||
assertTrue( host.xpath("HOST_SHARE/FREE_CPU").equals("800") );
|
|
||||||
assertTrue( host.xpath("HOST_SHARE/RUNNING_VMS").equals("3") );
|
|
||||||
assertTrue( host.xpath("TEMPLATE/CPUSPEED").equals("2.2GHz") );
|
|
||||||
assertTrue( host.xpath("TEMPLATE/HYPERVISOR").equals("dummy") );
|
|
||||||
assertTrue( host.xpath("TEMPLATE/TOTALMEMORY").equals("16777216") );
|
|
||||||
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
@ -1,260 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.image.*;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ImageTest
|
|
||||||
{
|
|
||||||
|
|
||||||
private static Image image;
|
|
||||||
private static ImagePool imagePool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
private static int cont = 0;
|
|
||||||
|
|
||||||
private static String template()
|
|
||||||
{
|
|
||||||
cont++;
|
|
||||||
|
|
||||||
return "NAME = \"test_img_" + cont + "\"\n" +
|
|
||||||
"PATH = /etc/hosts\n" +
|
|
||||||
"ATT1 = \"VAL1\"\n" +
|
|
||||||
"ATT2 = \"VAL2\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wait until the Image changes to the specified state.
|
|
||||||
* There is a time-out of 10 seconds.
|
|
||||||
*/
|
|
||||||
static void waitAssert(Image img, String state)
|
|
||||||
{
|
|
||||||
int n_steps = 10;
|
|
||||||
int step = 1000;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
img.info();
|
|
||||||
|
|
||||||
while( !( img.stateString().equals(state) || i > n_steps )
|
|
||||||
&& !img.stateString().equals("ERROR") )
|
|
||||||
{
|
|
||||||
try{ Thread.sleep(step); } catch (Exception e){}
|
|
||||||
|
|
||||||
img.info();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(
|
|
||||||
"Image timeout, wanted state: " + state + "; it is in state "
|
|
||||||
+ img.stateString(), img.stateString().equals(state) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
imagePool = new ImagePool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = Image.allocate(client, template(), 1);
|
|
||||||
|
|
||||||
int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
image = new Image(imgid, client);
|
|
||||||
|
|
||||||
waitAssert(image, "READY");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
image.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
image.delete();
|
|
||||||
|
|
||||||
res = Image.allocate(client, template(), 1);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
image = new Image(imgid, client);
|
|
||||||
|
|
||||||
|
|
||||||
res = imagePool.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(Image img : imagePool)
|
|
||||||
{
|
|
||||||
found = found || img.getName().equals("test_img_"+cont);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void clone_method()
|
|
||||||
{
|
|
||||||
res = image.clone("cloned_image");
|
|
||||||
assertTrue(res.getErrorMessage(), !res.isError());
|
|
||||||
|
|
||||||
int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
Image cloned_image = new Image(imgid, client);
|
|
||||||
|
|
||||||
res = imagePool.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(Image img : imagePool)
|
|
||||||
{
|
|
||||||
found = found || img.getName().equals("cloned_image");
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
|
|
||||||
res = cloned_image.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( cloned_image.getName().equals("cloned_image") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void info()
|
|
||||||
{
|
|
||||||
res = image.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// assertTrue( image.getId().equals("0") );
|
|
||||||
// assertTrue( image.id() == 0 );
|
|
||||||
assertTrue( image.getName().equals("test_img_"+cont) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
res = image.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( image.xpath("TEMPLATE/ATT1").equals( "VAL1" ) );
|
|
||||||
assertTrue( image.xpath("TEMPLATE/ATT2").equals( "VAL2" ) );
|
|
||||||
|
|
||||||
String new_template = "ATT2 = NEW_VAL\n" +
|
|
||||||
"ATT3 = VAL3";
|
|
||||||
|
|
||||||
res = image.update(new_template);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
|
|
||||||
res = image.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( image.xpath("TEMPLATE/ATT1").equals( "" ) );
|
|
||||||
assertTrue( image.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
|
||||||
assertTrue( image.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void enable()
|
|
||||||
{
|
|
||||||
res = image.enable();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
image.info();
|
|
||||||
assertTrue( image.isEnabled() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void disable()
|
|
||||||
{
|
|
||||||
res = image.disable();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
image.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !image.isEnabled() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void publish()
|
|
||||||
{
|
|
||||||
res = image.publish();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
image.info();
|
|
||||||
assertTrue( image.xpath("PERMISSIONS/GROUP_U").equals( "1" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void unpublish()
|
|
||||||
{
|
|
||||||
res = image.unpublish();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
image.info();
|
|
||||||
assertTrue( image.xpath("PERMISSIONS/GROUP_U").equals( "0" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void attributes()
|
|
||||||
{
|
|
||||||
res = image.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// assertTrue( image.xpath("ID").equals("0") );
|
|
||||||
assertTrue( image.xpath("NAME").equals("test_img_"+cont) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
res = image.delete();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// res = image.info();
|
|
||||||
// assertTrue( res.isError() );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,266 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.group.Group;
|
|
||||||
import org.opennebula.client.secgroup.*;
|
|
||||||
import org.opennebula.client.user.User;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class SecurityGroupTest
|
|
||||||
{
|
|
||||||
|
|
||||||
private static SecurityGroup sg;
|
|
||||||
private static SecurityGroupPool pool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
private static String name = "new_test_sg";
|
|
||||||
|
|
||||||
|
|
||||||
private static String template_str =
|
|
||||||
"NAME = \"" + name + "\"\n" +
|
|
||||||
"DESCRIPTION = \"test security group\"\n"+
|
|
||||||
"ATT1 = \"VAL1\"\n" +
|
|
||||||
"ATT2 = \"VAL2\"";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
pool = new SecurityGroupPool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = SecurityGroup.allocate(client, template_str);
|
|
||||||
|
|
||||||
int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
sg = new SecurityGroup(oid, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
sg.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
sg.delete();
|
|
||||||
|
|
||||||
res = SecurityGroup.allocate(client, template_str);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
sg = new SecurityGroup(oid, client);
|
|
||||||
|
|
||||||
|
|
||||||
pool.info();
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(SecurityGroup temp : pool)
|
|
||||||
{
|
|
||||||
found = found || temp.getName().equals(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void info()
|
|
||||||
{
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( sg.getName().equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( sg.xpath("TEMPLATE/ATT1").equals( "VAL1" ) );
|
|
||||||
assertTrue( sg.xpath("TEMPLATE/ATT2").equals( "VAL2" ) );
|
|
||||||
|
|
||||||
String new_sg = "ATT2 = NEW_VAL\n" +
|
|
||||||
"ATT3 = VAL3";
|
|
||||||
|
|
||||||
res = sg.update(new_sg);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( sg.xpath("TEMPLATE/ATT1").equals( "" ) );
|
|
||||||
assertTrue( sg.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
|
||||||
assertTrue( sg.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chmod()
|
|
||||||
{
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
String owner_a = sg.xpath("PERMISSIONS/OWNER_A");
|
|
||||||
String group_a = sg.xpath("PERMISSIONS/GROUP_A");
|
|
||||||
|
|
||||||
res = sg.chmod(0, 1, -1, 1, 0, -1, 1, 1, 0);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OWNER_U").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OWNER_M").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OWNER_A").equals(owner_a) );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/GROUP_A").equals(group_a) );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OTHER_U").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OTHER_M").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OTHER_A").equals("0") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chmod_octet()
|
|
||||||
{
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = sg.chmod(640);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OWNER_U").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OWNER_M").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OWNER_A").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/GROUP_A").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OTHER_U").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OTHER_M").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OTHER_A").equals("0") );
|
|
||||||
|
|
||||||
res = sg.chmod("147");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OWNER_U").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OWNER_M").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OWNER_A").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/GROUP_A").equals("0") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OTHER_U").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OTHER_M").equals("1") );
|
|
||||||
assertTrue( sg.xpath("PERMISSIONS/OTHER_A").equals("1") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void attributes()
|
|
||||||
{
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// assertTrue( sg.xpath("ID").equals("0") );
|
|
||||||
assertTrue( sg.xpath("NAME").equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
res = sg.delete();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chown()
|
|
||||||
{
|
|
||||||
// Create a new User and Group
|
|
||||||
res = User.allocate(client, "sg_test_user", "password");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int uid = Integer.parseInt(res.getMessage());
|
|
||||||
|
|
||||||
res = Group.allocate(client, "sg_test_group");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int gid = Integer.parseInt(res.getMessage());
|
|
||||||
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( sg.uid() == 0 );
|
|
||||||
assertTrue( sg.gid() == 0 );
|
|
||||||
|
|
||||||
res = sg.chown(uid, gid);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( sg.uid() == uid );
|
|
||||||
assertTrue( sg.gid() == gid );
|
|
||||||
|
|
||||||
res = sg.chgrp(0);
|
|
||||||
|
|
||||||
res = sg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( sg.uid() == uid );
|
|
||||||
assertTrue( sg.gid() == 0 );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.*;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
|
|
||||||
public class SessionTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createSession()
|
|
||||||
{
|
|
||||||
Client oneClient = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
oneClient = new Client();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
System.out.println(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
assertNotNull(oneClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void wrong_url()
|
|
||||||
{
|
|
||||||
Client oneClient = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// The HTTP is misspelled
|
|
||||||
oneClient = new Client(null,"HTP://localhost:2633/RPC2");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
// System.out.println(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
assertNull("Client should complain about misspelled url", oneClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void version()
|
|
||||||
{
|
|
||||||
Client oneClient = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
oneClient = new Client();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
assertTrue( e.getMessage(), false );
|
|
||||||
}
|
|
||||||
|
|
||||||
OneSystem system = new OneSystem(oneClient);
|
|
||||||
|
|
||||||
OneResponse res = system.getOnedVersion();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = system.getConfiguration();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
Node config = system.getConfigurationXML();
|
|
||||||
assertTrue( "XML configuration is null", config != null );
|
|
||||||
|
|
||||||
boolean compatible = system.compatibleVersion();
|
|
||||||
assertTrue(
|
|
||||||
"Incompatible version reported, " +
|
|
||||||
OneSystem.VERSION + ", " + system.getOnedVersion().getMessage(),
|
|
||||||
compatible );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,304 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.group.Group;
|
|
||||||
import org.opennebula.client.template.*;
|
|
||||||
import org.opennebula.client.user.User;
|
|
||||||
import org.opennebula.client.vm.VirtualMachine;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class TemplateTest
|
|
||||||
{
|
|
||||||
|
|
||||||
private static Template template;
|
|
||||||
private static TemplatePool templatePool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
private static String name = "new_test_template";
|
|
||||||
|
|
||||||
|
|
||||||
private static String template_str =
|
|
||||||
"NAME = \"" + name + "\"\n" +
|
|
||||||
"CPU = \"1\"\n" +
|
|
||||||
"MEMORY = \"128\"\n" +
|
|
||||||
"ATT1 = \"VAL1\"\n" +
|
|
||||||
"ATT2 = \"VAL2\"";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
templatePool = new TemplatePool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = Template.allocate(client, template_str);
|
|
||||||
|
|
||||||
int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
template = new Template(oid, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
template.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
template.delete();
|
|
||||||
|
|
||||||
res = Template.allocate(client, template_str);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
template = new Template(oid, client);
|
|
||||||
|
|
||||||
|
|
||||||
templatePool.info();
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(Template temp : templatePool)
|
|
||||||
{
|
|
||||||
found = found || temp.getName().equals(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void info()
|
|
||||||
{
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// assertTrue( template.getId().equals("0") );
|
|
||||||
// assertTrue( template.id() == 0 );
|
|
||||||
assertTrue( template.getName().equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( template.xpath("TEMPLATE/ATT1").equals( "VAL1" ) );
|
|
||||||
assertTrue( template.xpath("TEMPLATE/ATT2").equals( "VAL2" ) );
|
|
||||||
|
|
||||||
String new_template = "ATT2 = NEW_VAL\n" +
|
|
||||||
"ATT3 = VAL3";
|
|
||||||
|
|
||||||
res = template.update(new_template);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( template.xpath("TEMPLATE/ATT1").equals( "" ) );
|
|
||||||
assertTrue( template.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
|
||||||
assertTrue( template.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void publish()
|
|
||||||
{
|
|
||||||
res = template.publish();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
template.info();
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void unpublish()
|
|
||||||
{
|
|
||||||
res = template.unpublish();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
template.info();
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_U").equals("0") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chmod()
|
|
||||||
{
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
String owner_a = template.xpath("PERMISSIONS/OWNER_A");
|
|
||||||
String group_a = template.xpath("PERMISSIONS/GROUP_A");
|
|
||||||
|
|
||||||
res = template.chmod(0, 1, -1, 1, 0, -1, 1, 1, 0);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OWNER_U").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OWNER_M").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OWNER_A").equals(owner_a) );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_A").equals(group_a) );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OTHER_U").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OTHER_M").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OTHER_A").equals("0") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chmod_octet()
|
|
||||||
{
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = template.chmod(640);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OWNER_U").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OWNER_M").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OWNER_A").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_A").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OTHER_U").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OTHER_M").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OTHER_A").equals("0") );
|
|
||||||
|
|
||||||
res = template.chmod("147");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OWNER_U").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OWNER_M").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OWNER_A").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/GROUP_A").equals("0") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OTHER_U").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OTHER_M").equals("1") );
|
|
||||||
assertTrue( template.xpath("PERMISSIONS/OTHER_A").equals("1") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void attributes()
|
|
||||||
{
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// assertTrue( template.xpath("ID").equals("0") );
|
|
||||||
assertTrue( template.xpath("NAME").equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
res = template.delete();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chown()
|
|
||||||
{
|
|
||||||
// Create a new User and Group
|
|
||||||
res = User.allocate(client, "template_test_user", "password");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int uid = Integer.parseInt(res.getMessage());
|
|
||||||
|
|
||||||
res = Group.allocate(client, "template_test_group");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int gid = Integer.parseInt(res.getMessage());
|
|
||||||
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( template.uid() == 0 );
|
|
||||||
assertTrue( template.gid() == 0 );
|
|
||||||
|
|
||||||
res = template.chown(uid, gid);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( template.uid() == uid );
|
|
||||||
assertTrue( template.gid() == gid );
|
|
||||||
|
|
||||||
res = template.chgrp(0);
|
|
||||||
|
|
||||||
res = template.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( template.uid() == uid );
|
|
||||||
assertTrue( template.gid() == 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void instantiate()
|
|
||||||
{
|
|
||||||
res = template.instantiate("new_vm_name");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int vm_id = Integer.parseInt(res.getMessage());
|
|
||||||
VirtualMachine vm = new VirtualMachine(vm_id, client);
|
|
||||||
|
|
||||||
res = vm.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vm.getName().equals( "new_vm_name" ) );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,233 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import javax.xml.xpath.XPath;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
import javax.xml.xpath.XPathFactory;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.OneSystem;
|
|
||||||
import org.opennebula.client.user.User;
|
|
||||||
import org.opennebula.client.user.UserPool;
|
|
||||||
import org.opennebula.client.group.Group;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
|
|
||||||
public class UserTest
|
|
||||||
{
|
|
||||||
|
|
||||||
private static User user;
|
|
||||||
private static UserPool userPool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
private static String name = "new_test_user";
|
|
||||||
private static String password = "new_test_password";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
userPool = new UserPool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = User.allocate(client, name, password);
|
|
||||||
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int uid = Integer.parseInt(res.getMessage());
|
|
||||||
user = new User(uid, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
user.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
userPool.info();
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(User u : userPool)
|
|
||||||
{
|
|
||||||
found = found || u.getName().equals(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocateInGroup()
|
|
||||||
{
|
|
||||||
user.delete();
|
|
||||||
|
|
||||||
res = Group.allocate(client, "group_a");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
int group_a_id = Integer.parseInt(res.getMessage());
|
|
||||||
Group group_a = new Group(group_a_id, client);
|
|
||||||
|
|
||||||
res = Group.allocate(client, "group_b");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
int group_b_id = Integer.parseInt(res.getMessage());
|
|
||||||
Group group_b = new Group(group_b_id, client);
|
|
||||||
|
|
||||||
res = Group.allocate(client, "group_c");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
int group_c_id = Integer.parseInt(res.getMessage());
|
|
||||||
Group group_c = new Group(group_c_id, client);
|
|
||||||
|
|
||||||
Integer[] gids = {group_b_id, group_a_id};
|
|
||||||
res = User.allocate(client, "test_user_in_group", "pass", "", gids);
|
|
||||||
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
user = new User(Integer.parseInt(res.getMessage()), client);
|
|
||||||
|
|
||||||
res = user.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( user.gid() == group_b_id );
|
|
||||||
|
|
||||||
group_a.info();
|
|
||||||
group_b.info();
|
|
||||||
group_c.info();
|
|
||||||
|
|
||||||
assertTrue( group_a.contains(user.id()) );
|
|
||||||
assertTrue( group_b.contains(user.id()) );
|
|
||||||
assertFalse( group_c.contains(user.id()) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void info()
|
|
||||||
{
|
|
||||||
res = user.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( user.id() >= 0 );
|
|
||||||
assertTrue( user.getName().equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void attributes()
|
|
||||||
{
|
|
||||||
res = user.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( user.xpath("NAME").equals(name) );
|
|
||||||
assertTrue( user.xpath("ENABLED").equals("1") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chauth()
|
|
||||||
{
|
|
||||||
res = user.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( user.xpath("AUTH_DRIVER").equals("core") );
|
|
||||||
|
|
||||||
res = user.chauth("new_driver", password);
|
|
||||||
|
|
||||||
res = user.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( user.xpath("AUTH_DRIVER").equals("new_driver") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
String new_template = "ATT2 = NEW_VAL\n" +
|
|
||||||
"ATT3 = VAL3";
|
|
||||||
|
|
||||||
res = user.update(new_template);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = user.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( user.xpath("TEMPLATE/ATT1").equals( "" ) );
|
|
||||||
assertTrue( user.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
|
||||||
assertTrue( user.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
res = user.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( user.isEnabled() );
|
|
||||||
|
|
||||||
res = user.delete();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = user.info();
|
|
||||||
assertTrue( res.getErrorMessage(), res.isError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void defaultqutoas()
|
|
||||||
{
|
|
||||||
OneSystem system = new OneSystem(client);
|
|
||||||
|
|
||||||
res = system.getUserQuotas();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = system.setUserQuotas("VM = [ VMS = 7, MEMORY = 0, CPU = 3, SYSTEM_DISK_SIZE = 1 ]");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
Node node = system.getUserQuotasXML();
|
|
||||||
XPathFactory factory = XPathFactory.newInstance();
|
|
||||||
XPath xpath = factory.newXPath();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
assertTrue( xpath.evaluate("VM_QUOTA/VM/VMS", node).equals("7") );
|
|
||||||
} catch (XPathExpressionException e)
|
|
||||||
{
|
|
||||||
assertTrue(e.getMessage(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,266 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.group.Group;
|
|
||||||
import org.opennebula.client.vmgroup.*;
|
|
||||||
import org.opennebula.client.user.User;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class VMGroupTest
|
|
||||||
{
|
|
||||||
|
|
||||||
private static VMGroup vmg;
|
|
||||||
private static VMGroupPool pool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
private static String name = "new_test_vmg";
|
|
||||||
|
|
||||||
|
|
||||||
private static String template_str =
|
|
||||||
"NAME = \"" + name + "\"\n" +
|
|
||||||
"DESCRIPTION = \"test vmgroup\"\n"+
|
|
||||||
"ATT1 = \"VAL1\"\n" +
|
|
||||||
"ATT2 = \"VAL2\"";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
pool = new VMGroupPool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = VMGroup.allocate(client, template_str);
|
|
||||||
|
|
||||||
int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
vmg = new VMGroup(oid, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
vmg.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
vmg.delete();
|
|
||||||
|
|
||||||
res = VMGroup.allocate(client, template_str);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
vmg = new VMGroup(oid, client);
|
|
||||||
|
|
||||||
|
|
||||||
pool.info();
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(VMGroup temp : pool)
|
|
||||||
{
|
|
||||||
found = found || temp.getName().equals(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void info()
|
|
||||||
{
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vmg.getName().equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vmg.xpath("TEMPLATE/ATT1").equals( "VAL1" ) );
|
|
||||||
assertTrue( vmg.xpath("TEMPLATE/ATT2").equals( "VAL2" ) );
|
|
||||||
|
|
||||||
String new_vmg = "ATT2 = NEW_VAL\n" +
|
|
||||||
"ATT3 = VAL3";
|
|
||||||
|
|
||||||
res = vmg.update(new_vmg);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( vmg.xpath("TEMPLATE/ATT1").equals( "" ) );
|
|
||||||
assertTrue( vmg.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
|
||||||
assertTrue( vmg.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chmod()
|
|
||||||
{
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
String owner_a = vmg.xpath("PERMISSIONS/OWNER_A");
|
|
||||||
String group_a = vmg.xpath("PERMISSIONS/GROUP_A");
|
|
||||||
|
|
||||||
res = vmg.chmod(0, 1, -1, 1, 0, -1, 1, 1, 0);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OWNER_U").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OWNER_M").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OWNER_A").equals(owner_a) );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/GROUP_A").equals(group_a) );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OTHER_U").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OTHER_M").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OTHER_A").equals("0") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chmod_octet()
|
|
||||||
{
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vmg.chmod(640);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OWNER_U").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OWNER_M").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OWNER_A").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/GROUP_A").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OTHER_U").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OTHER_M").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OTHER_A").equals("0") );
|
|
||||||
|
|
||||||
res = vmg.chmod("147");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OWNER_U").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OWNER_M").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OWNER_A").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/GROUP_A").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OTHER_U").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OTHER_M").equals("1") );
|
|
||||||
assertTrue( vmg.xpath("PERMISSIONS/OTHER_A").equals("1") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void attributes()
|
|
||||||
{
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// assertTrue( vmg.xpath("ID").equals("0") );
|
|
||||||
assertTrue( vmg.xpath("NAME").equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
res = vmg.delete();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chown()
|
|
||||||
{
|
|
||||||
// Create a new User and Group
|
|
||||||
res = User.allocate(client, "vmg_test_user", "password");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int uid = Integer.parseInt(res.getMessage());
|
|
||||||
|
|
||||||
res = Group.allocate(client, "vmg_test_group");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int gid = Integer.parseInt(res.getMessage());
|
|
||||||
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vmg.uid() == 0 );
|
|
||||||
assertTrue( vmg.gid() == 0 );
|
|
||||||
|
|
||||||
res = vmg.chown(uid, gid);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vmg.uid() == uid );
|
|
||||||
assertTrue( vmg.gid() == gid );
|
|
||||||
|
|
||||||
res = vmg.chgrp(0);
|
|
||||||
|
|
||||||
res = vmg.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vmg.uid() == uid );
|
|
||||||
assertTrue( vmg.gid() == 0 );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,194 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.vdc.*;
|
|
||||||
import org.opennebula.client.group.*;
|
|
||||||
import org.opennebula.client.cluster.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class VdcTest
|
|
||||||
{
|
|
||||||
|
|
||||||
private static Vdc vdc;
|
|
||||||
private static VdcPool vdcPool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
private static int cont = 0;
|
|
||||||
|
|
||||||
private static String template()
|
|
||||||
{
|
|
||||||
cont++;
|
|
||||||
|
|
||||||
return "NAME = \"test_vdc_" + cont + "\"\n" +
|
|
||||||
"ATT1 = \"VAL1\"\n" +
|
|
||||||
"ATT2 = \"VAL2\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
vdcPool = new VdcPool(client);
|
|
||||||
|
|
||||||
Group.allocate(client, "testgroup");
|
|
||||||
Cluster.allocate(client, "testcluster");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = Vdc.allocate(client, template());
|
|
||||||
|
|
||||||
int vdcid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
vdc = new Vdc(vdcid, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
vdc.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
vdc.delete();
|
|
||||||
|
|
||||||
res = Vdc.allocate(client, template());
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int vdcid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
vdc = new Vdc(vdcid, client);
|
|
||||||
|
|
||||||
|
|
||||||
res = vdcPool.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(Vdc vdc : vdcPool)
|
|
||||||
{
|
|
||||||
found = found || vdc.getName().equals("test_vdc_"+cont);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void info()
|
|
||||||
{
|
|
||||||
res = vdc.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// assertTrue( vdc.getId().equals("0") );
|
|
||||||
// assertTrue( vdc.id() == 0 );
|
|
||||||
assertTrue( vdc.getName().equals("test_vdc_"+cont) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
res = vdc.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vdc.xpath("TEMPLATE/ATT1").equals( "VAL1" ) );
|
|
||||||
assertTrue( vdc.xpath("TEMPLATE/ATT2").equals( "VAL2" ) );
|
|
||||||
|
|
||||||
String new_template = "ATT2 = NEW_VAL\n" +
|
|
||||||
"ATT3 = VAL3";
|
|
||||||
|
|
||||||
res = vdc.update(new_template);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
|
|
||||||
res = vdc.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( vdc.xpath("TEMPLATE/ATT1").equals( "" ) );
|
|
||||||
assertTrue( vdc.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
|
||||||
assertTrue( vdc.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void attributes()
|
|
||||||
{
|
|
||||||
res = vdc.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// assertTrue( vdc.xpath("ID").equals("0") );
|
|
||||||
assertTrue( vdc.xpath("NAME").equals("test_vdc_"+cont) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addGroup()
|
|
||||||
{
|
|
||||||
res = vdc.addGroup(100);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vdc.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vdc.xpath("GROUPS/ID").equals("100") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addCluster()
|
|
||||||
{
|
|
||||||
res = vdc.addCluster(0, 100);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vdc.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vdc.xpath("CLUSTERS/CLUSTER/ZONE_ID").equals("0") );
|
|
||||||
assertTrue( vdc.xpath("CLUSTERS/CLUSTER/CLUSTER_ID").equals("100") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
res = vdc.delete();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
// res = vdc.info();
|
|
||||||
// assertTrue( res.isError() );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,361 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.datastore.Datastore;
|
|
||||||
import org.opennebula.client.host.Host;
|
|
||||||
import org.opennebula.client.image.Image;
|
|
||||||
import org.opennebula.client.vm.VirtualMachine;
|
|
||||||
import org.opennebula.client.vm.VirtualMachinePool;
|
|
||||||
|
|
||||||
|
|
||||||
public class VirtualMachineTest
|
|
||||||
{
|
|
||||||
|
|
||||||
private static VirtualMachine vm;
|
|
||||||
private static VirtualMachinePool vmPool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static int hid_A, hid_B;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
private static String name = "new_test_machine";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wait until the VM changes to the specified state.
|
|
||||||
* There is a time-out of 10 seconds.
|
|
||||||
*/
|
|
||||||
void waitAssert(VirtualMachine vm, String state, String lcmState)
|
|
||||||
{
|
|
||||||
int n_steps = 100;
|
|
||||||
int step = 100;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
vm.info();
|
|
||||||
|
|
||||||
while( !( (vm.stateStr().equals(state) && (!state.equals("ACTIVE") || vm.lcmStateStr().equals(lcmState) ))|| i > n_steps ))
|
|
||||||
{
|
|
||||||
try{ Thread.sleep(step); } catch (Exception e){}
|
|
||||||
|
|
||||||
vm.info();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( vm.stateStr().equals(state) );
|
|
||||||
if(state.equals("ACTIVE"))
|
|
||||||
{
|
|
||||||
assertTrue( vm.lcmStateStr().equals(lcmState) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
vmPool = new VirtualMachinePool(client);
|
|
||||||
|
|
||||||
|
|
||||||
res = Host.allocate(client, "host_A",
|
|
||||||
"dummy", "dummy");
|
|
||||||
hid_A = Integer.parseInt( res.getMessage() );
|
|
||||||
|
|
||||||
res = Host.allocate(client, "host_B",
|
|
||||||
"dummy", "dummy");
|
|
||||||
hid_B = Integer.parseInt( res.getMessage() );
|
|
||||||
|
|
||||||
Datastore systemDs = new Datastore(0, client);
|
|
||||||
systemDs.update("TM_MAD = dummy");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
String template = "NAME = " + name + "\n"+
|
|
||||||
"MEMORY = 512\n" +
|
|
||||||
"CPU = 1\n" +
|
|
||||||
"CONTEXT = [DNS = 192.169.1.4]";
|
|
||||||
|
|
||||||
res = VirtualMachine.allocate(client, template);
|
|
||||||
int vmid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1;
|
|
||||||
|
|
||||||
vm = new VirtualMachine(vmid, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
vm.recover(3);
|
|
||||||
waitAssert(vm, "DONE", "-");
|
|
||||||
|
|
||||||
vm = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
res = vmPool.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(VirtualMachine vm : vmPool)
|
|
||||||
{
|
|
||||||
found = found || vm.getName().equals(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
res = vm.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vm.getName().equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hold()
|
|
||||||
{
|
|
||||||
res = vm.hold();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "HOLD", "-");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void release()
|
|
||||||
{
|
|
||||||
vm.hold();
|
|
||||||
|
|
||||||
res = vm.release();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "PENDING", "-");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deploy()
|
|
||||||
{
|
|
||||||
res = vm.deploy(hid_A);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void migrate()
|
|
||||||
{
|
|
||||||
vm.deploy(hid_A);
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
|
|
||||||
res = vm.migrate(hid_B);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void liveMigrate()
|
|
||||||
{
|
|
||||||
vm.deploy(hid_A);
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
|
|
||||||
res = vm.migrate(hid_B, true);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void terminate()
|
|
||||||
{
|
|
||||||
vm.deploy(hid_A);
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
|
|
||||||
res = vm.terminate();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "DONE", "-");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void terminatehard()
|
|
||||||
{
|
|
||||||
vm.deploy(hid_A);
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
|
|
||||||
res = vm.terminate(true);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "DONE", "-");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void stop()
|
|
||||||
{
|
|
||||||
vm.deploy(hid_A);
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
|
|
||||||
res = vm.stop();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "STOPPED", "-");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void suspend()
|
|
||||||
{
|
|
||||||
vm.deploy(hid_A);
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
|
|
||||||
res = vm.suspend();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "SUSPENDED", "-");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void resume()
|
|
||||||
{
|
|
||||||
vm.deploy(hid_A);
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
|
|
||||||
vm.suspend();
|
|
||||||
waitAssert(vm, "SUSPENDED", "-");
|
|
||||||
|
|
||||||
res = vm.resume();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
vm.deploy(hid_A);
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
res = vm.recover(3);
|
|
||||||
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "DONE", "-");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void restart()
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteRecreate()
|
|
||||||
{
|
|
||||||
vm.deploy(hid_A);
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
res = vm.recover(4);
|
|
||||||
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
waitAssert(vm, "PENDING", "-");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void attributes()
|
|
||||||
{
|
|
||||||
res = vm.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vm.xpath("NAME").equals(name) );
|
|
||||||
assertTrue( vm.xpath("TEMPLATE/MEMORY").equals("512") );
|
|
||||||
// assertTrue( vm.xpath("ID").equals("0") );
|
|
||||||
assertTrue( vm.xpath("TEMPLATE/MEMORY").equals("512") );
|
|
||||||
assertTrue( vm.xpath("TEMPLATE/CONTEXT/DNS").equals("192.169.1.4") );
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
/*
|
|
||||||
@Test
|
|
||||||
public void savedisk()
|
|
||||||
{
|
|
||||||
String img_template =
|
|
||||||
"NAME = \"test_img\"\n" +
|
|
||||||
"PATH = /etc/hosts\n" +
|
|
||||||
"ATT1 = \"VAL1\"\n" +
|
|
||||||
"ATT2 = \"VAL2\"";
|
|
||||||
|
|
||||||
res = Image.allocate(client, img_template, 1);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int imgid = Integer.parseInt(res.getMessage());
|
|
||||||
|
|
||||||
Image img = new Image(imgid, client);
|
|
||||||
ImageTest.waitAssert(img, "READY");
|
|
||||||
|
|
||||||
|
|
||||||
String template = "NAME = savedisk_vm\n"+
|
|
||||||
"MEMORY = 512\n" +
|
|
||||||
"CPU = 1\n" +
|
|
||||||
"CONTEXT = [DNS = 192.169.1.4]\n" +
|
|
||||||
"DISK = [ IMAGE = test_img ]";
|
|
||||||
|
|
||||||
res = VirtualMachine.allocate(client, template);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int vmid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1;
|
|
||||||
|
|
||||||
vm = new VirtualMachine(vmid, client);
|
|
||||||
|
|
||||||
res = vm.deploy(hid_A);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
waitAssert(vm, "ACTIVE", "RUNNING");
|
|
||||||
|
|
||||||
res = vm.savedisk(0, "New_image");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int new_imgid = Integer.parseInt(res.getMessage());
|
|
||||||
assertTrue( new_imgid == imgid+1 );
|
|
||||||
|
|
||||||
res = vm.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void resize()
|
|
||||||
{
|
|
||||||
res = vm.resize("CPU = 2.5\nMEMORY = 512\nVCPU = 0", true);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vm.resize("CPU = 1\nMEMORY = 128\nVCPU = 2", false);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,234 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.vnet.VirtualNetwork;
|
|
||||||
import org.opennebula.client.vnet.VirtualNetworkPool;
|
|
||||||
|
|
||||||
public class VirtualNetworkTest
|
|
||||||
{
|
|
||||||
|
|
||||||
private static VirtualNetwork vnet;
|
|
||||||
private static VirtualNetworkPool vnetPool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
private static String name = "new_test_vnet";
|
|
||||||
|
|
||||||
|
|
||||||
private static String template =
|
|
||||||
"NAME = " + name + "\n"+
|
|
||||||
"BRIDGE = vbr0\n" +
|
|
||||||
"VN_MAD = dummy\n" +
|
|
||||||
"NETWORK_ADDRESS = 192.168.0.0\n"+
|
|
||||||
"AR = [ TYPE = IP4, IP = 192.168.0.1, SIZE = 254 ]\n";
|
|
||||||
|
|
||||||
private static String second_template =
|
|
||||||
"NAME = \"Net number one\"\n" +
|
|
||||||
"BRIDGE = br1\n" +
|
|
||||||
"VN_MAD = dummy\n" +
|
|
||||||
"AR = [ TYPE = IP4, IP=130.10.0.1, SIZE = 1]";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
vnetPool = new VirtualNetworkPool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = VirtualNetwork.allocate(client, template);
|
|
||||||
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int vnid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1;
|
|
||||||
vnet = new VirtualNetwork(vnid, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
vnet.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
vnetPool.info();
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(VirtualNetwork vn : vnetPool)
|
|
||||||
{
|
|
||||||
found = found || vn.getName().equals(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void info()
|
|
||||||
{
|
|
||||||
res = vnet.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( vnet.getName().equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void attributes()
|
|
||||||
{
|
|
||||||
res = vnet.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vnet.xpath("NAME").equals(name) );
|
|
||||||
assertTrue( vnet.xpath("BRIDGE").equals("vbr0") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
res = vnet.delete();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vnet.info();
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addAr()
|
|
||||||
{
|
|
||||||
res = VirtualNetwork.allocate(client, second_template);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
VirtualNetwork second_vnet =
|
|
||||||
new VirtualNetwork(Integer.parseInt(res.getMessage()), client);
|
|
||||||
|
|
||||||
res = second_vnet.addAr("AR = [IP = 130.10.0.5, SIZE = 1, TYPE = IP4]");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = second_vnet.addAr("AR = [IP = 130.10.0.6, MAC = 50:20:20:20:20:20, SIZE = 1, TYPE = IP4]");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = second_vnet.addAr("130.10.0.6");
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
|
|
||||||
second_vnet.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void rmAr()
|
|
||||||
{
|
|
||||||
res = VirtualNetwork.allocate(client, second_template);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
VirtualNetwork second_vnet =
|
|
||||||
new VirtualNetwork(Integer.parseInt(res.getMessage()), client);
|
|
||||||
|
|
||||||
res = second_vnet.rmAr(0);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = second_vnet.rmAr(0);
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
|
|
||||||
second_vnet.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateAr()
|
|
||||||
{
|
|
||||||
String new_template =
|
|
||||||
"AR = [ AR_ID = 0, ATT2 = NEW_VAL, ATT3 = VAL3 ]";
|
|
||||||
|
|
||||||
res = vnet.updateAr(new_template);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vnet.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( vnet.xpath("AR_POOL/AR[AR_ID=0]/ATT1").equals( "" ) );
|
|
||||||
assertTrue( vnet.xpath("AR_POOL/AR[AR_ID=0]/ATT2").equals( "NEW_VAL" ) );
|
|
||||||
assertTrue( vnet.xpath("AR_POOL/AR[AR_ID=0]/ATT3").equals( "VAL3" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hold()
|
|
||||||
{
|
|
||||||
res = vnet.hold("192.168.0.10");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vnet.hold("192.168.0.11", 0);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vnet.hold("192.168.100.1");
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
|
|
||||||
res = vnet.release("192.168.0.10");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vnet.release("192.168.0.11", 0);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vnet.release("192.168.0.10");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
vnet.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
String new_template = "ATT2 = NEW_VAL\n" +
|
|
||||||
"ATT3 = VAL3";
|
|
||||||
|
|
||||||
res = vnet.update(new_template);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vnet.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
assertTrue( vnet.xpath("TEMPLATE/ATT1").equals( "" ) );
|
|
||||||
assertTrue( vnet.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
|
||||||
assertTrue( vnet.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: reserve, free
|
|
||||||
|
|
||||||
}
|
|
@ -1,294 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
******************************************************************************/
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.opennebula.client.Client;
|
|
||||||
import org.opennebula.client.OneResponse;
|
|
||||||
import org.opennebula.client.group.Group;
|
|
||||||
import org.opennebula.client.template.*;
|
|
||||||
import org.opennebula.client.vrouter.*;
|
|
||||||
import org.opennebula.client.vm.*;
|
|
||||||
import org.opennebula.client.user.User;
|
|
||||||
import org.opennebula.client.vm.VirtualMachine;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class VirtualRouterTest
|
|
||||||
{
|
|
||||||
private static VirtualRouter vrouter;
|
|
||||||
private static VirtualRouterPool vrouterPool;
|
|
||||||
|
|
||||||
private static Client client;
|
|
||||||
|
|
||||||
private static OneResponse res;
|
|
||||||
private static String name = "new_test_vrouter";
|
|
||||||
|
|
||||||
|
|
||||||
private static String template_str =
|
|
||||||
"NAME = \"" + name + "\"\n" +
|
|
||||||
"VROUTER = YES\n" +
|
|
||||||
"ATT1 = \"VAL1\"\n" +
|
|
||||||
"ATT2 = \"VAL2\"";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
client = new Client();
|
|
||||||
vrouterPool = new VirtualRouterPool(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownAfterClass() throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
res = VirtualRouter.allocate(client, template_str);
|
|
||||||
|
|
||||||
int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
vrouter = new VirtualRouter(oid, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception
|
|
||||||
{
|
|
||||||
vrouter.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void allocate()
|
|
||||||
{
|
|
||||||
vrouter.delete();
|
|
||||||
|
|
||||||
res = VirtualRouter.allocate(client, template_str);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
|
||||||
vrouter = new VirtualRouter(oid, client);
|
|
||||||
|
|
||||||
|
|
||||||
res = vrouterPool.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for(VirtualRouter temp : vrouterPool)
|
|
||||||
{
|
|
||||||
found = found || temp.getName().equals(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue( found );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void info()
|
|
||||||
{
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vrouter.getName().equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void publish()
|
|
||||||
{
|
|
||||||
res = vrouter.publish();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
vrouter.info();
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void unpublish()
|
|
||||||
{
|
|
||||||
res = vrouter.unpublish();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
vrouter.info();
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_U").equals("0") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chmod()
|
|
||||||
{
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
String owner_a = vrouter.xpath("PERMISSIONS/OWNER_A");
|
|
||||||
String group_a = vrouter.xpath("PERMISSIONS/GROUP_A");
|
|
||||||
|
|
||||||
res = vrouter.chmod(0, 1, -1, 1, 0, -1, 1, 1, 0);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OWNER_U").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OWNER_M").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OWNER_A").equals(owner_a) );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_A").equals(group_a) );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OTHER_U").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OTHER_M").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OTHER_A").equals("0") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chmod_octet()
|
|
||||||
{
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vrouter.chmod(640);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OWNER_U").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OWNER_M").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OWNER_A").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_A").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OTHER_U").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OTHER_M").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OTHER_A").equals("0") );
|
|
||||||
|
|
||||||
res = vrouter.chmod("147");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OWNER_U").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OWNER_M").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OWNER_A").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_U").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_M").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/GROUP_A").equals("0") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OTHER_U").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OTHER_M").equals("1") );
|
|
||||||
assertTrue( vrouter.xpath("PERMISSIONS/OTHER_A").equals("1") );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void attributes()
|
|
||||||
{
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vrouter.xpath("NAME").equals(name) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void delete()
|
|
||||||
{
|
|
||||||
res = vrouter.delete();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.isError() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void chown()
|
|
||||||
{
|
|
||||||
// Create a new User and Group
|
|
||||||
res = User.allocate(client, "template_test_user", "password");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int uid = Integer.parseInt(res.getMessage());
|
|
||||||
|
|
||||||
res = Group.allocate(client, "template_test_group");
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int gid = Integer.parseInt(res.getMessage());
|
|
||||||
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vrouter.uid() == 0 );
|
|
||||||
assertTrue( vrouter.gid() == 0 );
|
|
||||||
|
|
||||||
res = vrouter.chown(uid, gid);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vrouter.uid() == uid );
|
|
||||||
assertTrue( vrouter.gid() == gid );
|
|
||||||
|
|
||||||
res = vrouter.chgrp(0);
|
|
||||||
|
|
||||||
res = vrouter.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vrouter.uid() == uid );
|
|
||||||
assertTrue( vrouter.gid() == 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void instantiate()
|
|
||||||
{
|
|
||||||
VirtualMachinePool vmPool = new VirtualMachinePool(client);
|
|
||||||
|
|
||||||
res = vmPool.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vmPool.getLength() == 0 );
|
|
||||||
|
|
||||||
String tmpl_str =
|
|
||||||
"NAME = vrtemplate\n"+
|
|
||||||
"CPU = 0.1\n"+
|
|
||||||
"VROUTER = YES\n"+
|
|
||||||
"MEMORY = 64\n";
|
|
||||||
|
|
||||||
res = Template.allocate(client, tmpl_str);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
int tmplid = Integer.parseInt(res.getMessage());
|
|
||||||
|
|
||||||
res = vrouter.instantiate(3, tmplid);
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
res = vmPool.info();
|
|
||||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
|
||||||
|
|
||||||
assertTrue( vmPool.getLength() == 3 );
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------- #
|
|
||||||
# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems #
|
|
||||||
# #
|
|
||||||
# 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. #
|
|
||||||
#--------------------------------------------------------------------------- #
|
|
||||||
|
|
||||||
if [ -z $ONE_LOCATION ]; then
|
|
||||||
ONEDCONF_LOCATION="/etc/one/oned.conf"
|
|
||||||
else
|
|
||||||
ONEDCONF_LOCATION="$ONE_LOCATION/etc/oned.conf"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f $ONEDCONF_LOCATION ]; then
|
|
||||||
echo "$ONEDCONF_LOCATION has to be overwritten, move it to a safe place."
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z $ONE_LOCATION ]; then
|
|
||||||
sudo cp oned.conf $ONEDCONF_LOCATION
|
|
||||||
else
|
|
||||||
cp oned.conf $ONEDCONF_LOCATION
|
|
||||||
fi
|
|
||||||
|
|
||||||
export ONE_XMLRPC=http://localhost:2633/RPC2
|
|
||||||
|
|
||||||
RC=0
|
|
||||||
|
|
||||||
LOG_FILE="/tmp/one-java-test.txt"
|
|
||||||
|
|
||||||
rm $LOG_FILE
|
|
||||||
|
|
||||||
./test.sh HostTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh ImageTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh SessionTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh UserTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh VirtualMachineTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh VirtualNetworkTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh TemplateTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh GroupTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh AclTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh DocumentTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh VdcTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh SecurityGroupTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh VirtualRouterTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
./test.sh VMGroupTest 2>&1 | tee -a $LOG_FILE
|
|
||||||
let RC=RC+$?
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Output saved in $LOG_FILE"
|
|
||||||
|
|
||||||
exit $RC
|
|
File diff suppressed because it is too large
Load Diff
@ -1,66 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------------- #
|
|
||||||
# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems #
|
|
||||||
# #
|
|
||||||
# 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. #
|
|
||||||
#--------------------------------------------------------------------------- #
|
|
||||||
|
|
||||||
# Usage: test.sh <Test_name>
|
|
||||||
# For instance: test.sh ImageTest
|
|
||||||
|
|
||||||
|
|
||||||
if [ -z $ONE_LOCATION ]; then
|
|
||||||
DB_LOCATION="/var/lib/one/one.db"
|
|
||||||
LOG_LOCATION="/var/log/one"
|
|
||||||
AUTH_LOCATION="/var/lib/one/.one"
|
|
||||||
else
|
|
||||||
DB_LOCATION="$ONE_LOCATION/var/one.db"
|
|
||||||
LOG_LOCATION="$ONE_LOCATION/var"
|
|
||||||
AUTH_LOCATION="$ONE_LOCATION/var/.one"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f $DB_LOCATION ]; then
|
|
||||||
echo "$DB_LOCATION has to be overwritten, move it to a safe place."
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "========================================================================="
|
|
||||||
echo "Doing $1"
|
|
||||||
echo "========================================================================="
|
|
||||||
|
|
||||||
rm -rf $AUTH_LOCATION
|
|
||||||
|
|
||||||
PID=$$
|
|
||||||
|
|
||||||
oned -f &
|
|
||||||
|
|
||||||
sleep 2;
|
|
||||||
|
|
||||||
until grep 'Datastore default (1) successfully monitored' $LOG_LOCATION/oned.log; do
|
|
||||||
sleep 1;
|
|
||||||
done
|
|
||||||
|
|
||||||
echo 'SAFE_DIRS = "/"' > /tmp/one-javatest-ds.txt
|
|
||||||
onedatastore update --append 1 /tmp/one-javatest-ds.txt
|
|
||||||
|
|
||||||
java -cp ../lib/*:../jar/*:. org.junit.runner.JUnitCore $1
|
|
||||||
|
|
||||||
CODE=$?
|
|
||||||
|
|
||||||
pkill -P $PID oned
|
|
||||||
sleep 4s;
|
|
||||||
pkill -9 -P $PID oned
|
|
||||||
rm -f $DB_LOCATION
|
|
||||||
|
|
||||||
exit $CODE
|
|
Reference in New Issue
Block a user