|
10 | 10 | // limitations under the License. |
11 | 11 | // |
12 | 12 | // Automatically generated by addcopyright.py at 04/03/2012 |
13 | | -package com.cloud.hypervisor.vmware.util; |
14 | | -import java.io.File; |
15 | | - |
16 | | -import junit.framework.Assert; |
17 | | - |
18 | | -import org.apache.log4j.Logger; |
19 | | - |
20 | | -import com.cloud.hypervisor.vmware.resource.SshHelper; |
21 | | -import com.cloud.hypervisor.vmware.resource.VmwareContextFactory; |
22 | | -import com.cloud.utils.Pair; |
23 | | -import com.cloud.utils.testcase.Log4jEnabledTestCase; |
24 | | -import com.vmware.vim25.ManagedObjectReference; |
25 | | - |
26 | | -public class TestVmwareUtil extends Log4jEnabledTestCase { |
27 | | - private static final Logger s_logger = Logger.getLogger(TestVmwareUtil.class); |
28 | | - |
29 | | - public void testContextCreation() { |
30 | | - try { |
31 | | - VmwareContext context = VmwareContextFactory.create("vsphere-1.lab.vmops.com", "Administrator", "Suite219"); |
32 | | - Assert.assertTrue(true); |
33 | | - context.close(); |
34 | | - } catch(Exception e) { |
35 | | - s_logger.error("Unexpected exception : ", e); |
36 | | - } |
37 | | - } |
38 | | - |
39 | | - public void testSearchIndex() { |
40 | | - try { |
41 | | - VmwareContext context = VmwareContextFactory.create("vsphere-1.lab.vmops.com", "Administrator", "Suite219"); |
42 | | - Assert.assertTrue(true); |
43 | | - |
44 | | - ManagedObjectReference morHost = context.getService().findByDnsName(context.getServiceContent().getSearchIndex(), |
45 | | - null, "esxhost-1.lab.vmops.com", false); |
46 | | - Assert.assertTrue(morHost.getType().equalsIgnoreCase("HostSystem")); |
47 | | - |
48 | | - morHost = context.getService().findByIp(context.getServiceContent().getSearchIndex(), |
49 | | - null, "192.168.1.168", false); |
50 | | - Assert.assertTrue(morHost == null); |
51 | | - context.close(); |
52 | | - } catch(Exception e) { |
53 | | - s_logger.error("Unexpected exception : ", e); |
54 | | - } |
55 | | - } |
56 | | - |
57 | | - public void testVmxFileDownload() { |
58 | | - try { |
59 | | - VmwareContext context = VmwareContextFactory.create("vsphere-1.lab.vmops.com", "Administrator", "Suite219"); |
60 | | - byte[] vmxContent = context.getResourceContent("https://vsphere-1.lab.vmops.com/folder/ServerRoom-Fedora32/ServerRoom-Fedora32.vmx?dcPath=cupertino&dsName=NFS%20datastore"); |
61 | | - System.out.print(new String(vmxContent)); |
62 | | - context.close(); |
63 | | - } catch(Exception e) { |
64 | | - s_logger.error("Unexpected exception : ", e); |
65 | | - } |
66 | | - } |
67 | | - |
68 | | - public void testVmxFileParser() { |
69 | | - String[] tokens = "[NFS datastore] Fedora-clone-test/Fedora-clone-test.vmx".split("\\[|\\]|/"); |
70 | | - |
71 | | - for(String str : tokens) { |
72 | | - System.out.println("Token " + str); |
73 | | - } |
74 | | - } |
75 | | - |
76 | | - public void testSsh() { |
77 | | - try { |
78 | | - File file = new File("c:\\temp\\id_rsa.kelven"); |
79 | | - if(!file.exists()) { |
80 | | - System.out.println("key file does not exist!"); |
81 | | - } |
82 | | - |
83 | | - Pair<Boolean, String> result = SshHelper.sshExecute("192.168.1.107", 22, "kelven", file, null, "ls -al"); |
84 | | - System.out.println("Result: " + result.second()); |
85 | | - } catch(Exception e) { |
86 | | - s_logger.error("Unexpected exception : ", e); |
87 | | - } |
88 | | - } |
89 | | - |
90 | | - public void testScp() { |
91 | | - try { |
92 | | - File file = new File("c:\\temp\\id_rsa.kelven"); |
93 | | - if(!file.exists()) { |
94 | | - System.out.println("key file does not exist!"); |
95 | | - } |
96 | | - |
97 | | - SshHelper.scpTo("192.168.1.107", 22, "kelven", file, null, "~", "Hello, world".getBytes(), |
98 | | - "hello.txt", null); |
99 | | - } catch(Exception e) { |
100 | | - s_logger.error("Unexpected exception : ", e); |
101 | | - } |
102 | | - } |
103 | | -} |
| 13 | +package com.cloud.hypervisor.vmware.util; |
| 14 | +import java.io.File; |
| 15 | + |
| 16 | +import junit.framework.Assert; |
| 17 | + |
| 18 | +import org.apache.log4j.Logger; |
| 19 | + |
| 20 | +import com.cloud.hypervisor.vmware.resource.SshHelper; |
| 21 | +import com.cloud.hypervisor.vmware.resource.VmwareContextFactory; |
| 22 | +import com.cloud.utils.Pair; |
| 23 | +import com.cloud.utils.testcase.Log4jEnabledTestCase; |
| 24 | +import com.vmware.vim25.ManagedObjectReference; |
| 25 | + |
| 26 | +public class TestVmwareUtil extends Log4jEnabledTestCase { |
| 27 | + private static final Logger s_logger = Logger.getLogger(TestVmwareUtil.class); |
| 28 | + |
| 29 | + public void testContextCreation() { |
| 30 | + try { |
| 31 | + VmwareContext context = VmwareContextFactory.create("vsphere-1.lab.vmops.com", "Administrator", "Suite219"); |
| 32 | + Assert.assertTrue(true); |
| 33 | + context.close(); |
| 34 | + } catch(Exception e) { |
| 35 | + s_logger.error("Unexpected exception : ", e); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + public void testSearchIndex() { |
| 40 | + try { |
| 41 | + VmwareContext context = VmwareContextFactory.create("vsphere-1.lab.vmops.com", "Administrator", "Suite219"); |
| 42 | + Assert.assertTrue(true); |
| 43 | + |
| 44 | + ManagedObjectReference morHost = context.getService().findByDnsName(context.getServiceContent().getSearchIndex(), |
| 45 | + null, "esxhost-1.lab.vmops.com", false); |
| 46 | + Assert.assertTrue(morHost.getType().equalsIgnoreCase("HostSystem")); |
| 47 | + |
| 48 | + morHost = context.getService().findByIp(context.getServiceContent().getSearchIndex(), |
| 49 | + null, "192.168.1.168", false); |
| 50 | + Assert.assertTrue(morHost == null); |
| 51 | + context.close(); |
| 52 | + } catch(Exception e) { |
| 53 | + s_logger.error("Unexpected exception : ", e); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + public void testVmxFileDownload() { |
| 58 | + try { |
| 59 | + VmwareContext context = VmwareContextFactory.create("vsphere-1.lab.vmops.com", "Administrator", "Suite219"); |
| 60 | + byte[] vmxContent = context.getResourceContent("https://vsphere-1.lab.vmops.com/folder/ServerRoom-Fedora32/ServerRoom-Fedora32.vmx?dcPath=cupertino&dsName=NFS%20datastore"); |
| 61 | + System.out.print(new String(vmxContent)); |
| 62 | + context.close(); |
| 63 | + } catch(Exception e) { |
| 64 | + s_logger.error("Unexpected exception : ", e); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + public void testVmxFileParser() { |
| 69 | + String[] tokens = "[NFS datastore] Fedora-clone-test/Fedora-clone-test.vmx".split("\\[|\\]|/"); |
| 70 | + |
| 71 | + for(String str : tokens) { |
| 72 | + System.out.println("Token " + str); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + public void testSsh() { |
| 77 | + try { |
| 78 | + File file = new File("c:\\temp\\id_rsa.kelven"); |
| 79 | + if(!file.exists()) { |
| 80 | + System.out.println("key file does not exist!"); |
| 81 | + } |
| 82 | + |
| 83 | + Pair<Boolean, String> result = SshHelper.sshExecute("192.168.1.107", 22, "kelven", file, null, "ls -al"); |
| 84 | + System.out.println("Result: " + result.second()); |
| 85 | + } catch(Exception e) { |
| 86 | + s_logger.error("Unexpected exception : ", e); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + public void testScp() { |
| 91 | + try { |
| 92 | + File file = new File("c:\\temp\\id_rsa.kelven"); |
| 93 | + if(!file.exists()) { |
| 94 | + System.out.println("key file does not exist!"); |
| 95 | + } |
| 96 | + |
| 97 | + SshHelper.scpTo("192.168.1.107", 22, "kelven", file, null, "~", "Hello, world".getBytes(), |
| 98 | + "hello.txt", null); |
| 99 | + } catch(Exception e) { |
| 100 | + s_logger.error("Unexpected exception : ", e); |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments