Skip to content

Commit 0eb5814

Browse files
author
Sudhansu
committed
CLOUDSTACK-9630: Cannot use listNics API as advertised
added missing details for listNics API response.
1 parent b931b79 commit 0eb5814

File tree

2 files changed

+179
-0
lines changed

2 files changed

+179
-0
lines changed

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,6 +3453,7 @@ public NicResponse createNicResponse(Nic result) {
34533453
NicResponse response = new NicResponse();
34543454
NetworkVO network = _entityMgr.findById(NetworkVO.class, result.getNetworkId());
34553455
VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, result.getInstanceId());
3456+
UserVmJoinVO userVm = _entityMgr.findById(UserVmJoinVO.class, result.getInstanceId());
34563457

34573458
response.setId(result.getUuid());
34583459
response.setNetworkid(network.getUuid());
@@ -3461,6 +3462,14 @@ public NicResponse createNicResponse(Nic result) {
34613462
response.setVmId(vm.getUuid());
34623463
}
34633464

3465+
if (userVm != null){
3466+
if (userVm.getTrafficType() != null) {
3467+
response.setTrafficType(userVm.getTrafficType().toString());
3468+
}
3469+
if (userVm.getGuestType() != null) {
3470+
response.setType(userVm.getGuestType().toString());
3471+
}
3472+
}
34643473
response.setIpaddress(result.getIPv4Address());
34653474

34663475
if (result.getSecondaryIp()) {
@@ -3481,10 +3490,21 @@ public NicResponse createNicResponse(Nic result) {
34813490
response.setNetmask(result.getIPv4Netmask());
34823491
response.setMacAddress(result.getMacAddress());
34833492

3493+
if (result.getBroadcastUri() != null) {
3494+
response.setBroadcastUri(result.getBroadcastUri().toString());
3495+
}
3496+
if (result.getIsolationUri() != null) {
3497+
response.setIsolationUri(result.getIsolationUri().toString());
3498+
}
3499+
34843500
if (result.getIPv6Address() != null) {
34853501
response.setIp6Address(result.getIPv6Address());
34863502
}
34873503

3504+
if (result.getIPv6Cidr() != null) {
3505+
response.setIp6Cidr(result.getIPv6Cidr());
3506+
}
3507+
34883508
response.setDeviceId(String.valueOf(result.getDeviceId()));
34893509

34903510
response.setIsDefault(result.isDefaultNic());
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
#Test from the Marvin - Testing in Python wiki
19+
from marvin.codes import FAILED
20+
21+
#All tests inherit from cloudstackTestCase
22+
from marvin.cloudstackTestCase import cloudstackTestCase
23+
24+
#Import Integration Libraries
25+
26+
#base - contains all resources as entities and defines create, delete, list operations on them
27+
from marvin.lib.base import Account, VirtualMachine, ServiceOffering
28+
29+
#utils - utility classes for common cleanup, external library wrappers etc
30+
from marvin.lib.utils import cleanup_resources
31+
32+
#common - commonly used methods for all tests are listed here
33+
from marvin.lib.common import get_zone, get_domain, get_template
34+
35+
from marvin.cloudstackAPI.listNics import listNicsCmd
36+
37+
38+
from nose.plugins.attrib import attr
39+
40+
class TestDeployVM(cloudstackTestCase):
41+
"""Test deploy a VM into a user account
42+
"""
43+
44+
def setUp(self):
45+
self.testdata = self.testClient.getParsedTestDataConfig()
46+
self.apiclient = self.testClient.getApiClient()
47+
48+
# Get Zone, Domain and Default Built-in template
49+
self.domain = get_domain(self.apiclient)
50+
self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
51+
self.testdata["mode"] = self.zone.networktype
52+
self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])
53+
54+
if self.template == FAILED:
55+
assert False, "get_template() failed to return template with description %s" % self.testdata["ostype"]
56+
57+
#create a user account
58+
self.account = Account.create(
59+
self.apiclient,
60+
self.testdata["account"],
61+
domainid=self.domain.id
62+
)
63+
#create a service offering
64+
self.service_offering = ServiceOffering.create(
65+
self.apiclient,
66+
self.testdata["service_offerings"]["small"]
67+
)
68+
#build cleanup list
69+
self.cleanup = [
70+
self.service_offering,
71+
self.account
72+
]
73+
74+
# Validate the following:
75+
# 1. Virtual Machine is accessible via SSH
76+
# 2. listVirtualMachines returns accurate information
77+
78+
self.virtual_machine = VirtualMachine.create(
79+
self.apiclient,
80+
self.testdata["virtual_machine"],
81+
accountid=self.account.name,
82+
zoneid=self.zone.id,
83+
domainid=self.account.domainid,
84+
serviceofferingid=self.service_offering.id,
85+
templateid=self.template.id
86+
)
87+
88+
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
89+
90+
self.debug(
91+
"Verify listVirtualMachines response for virtual machine: %s"\
92+
% self.virtual_machine.id
93+
)
94+
95+
self.assertEqual(
96+
isinstance(list_vms, list),
97+
True,
98+
"List VM response was not a valid list"
99+
)
100+
self.assertNotEqual(
101+
len(list_vms),
102+
0,
103+
"List VM response was empty"
104+
)
105+
106+
vm = list_vms[0]
107+
self.assertEqual(
108+
vm.id,
109+
self.virtual_machine.id,
110+
"Virtual Machine ids do not match"
111+
)
112+
self.assertEqual(
113+
vm.name,
114+
self.virtual_machine.name,
115+
"Virtual Machine names do not match"
116+
)
117+
self.assertEqual(
118+
vm.state,
119+
"Running",
120+
msg="VM is not in Running state"
121+
)
122+
123+
@attr(tags = ['advanced', 'basic'], required_hardware="false")
124+
def test_list_nics(self):
125+
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
126+
vmid = self.virtual_machine.id
127+
cmd = listNicsCmd()
128+
cmd.virtualmachineid = vmid
129+
list_nics = self.apiclient.listNics(cmd)
130+
131+
nic = list_nics[0]
132+
133+
self.assertIsNotNone(
134+
nic.type,
135+
"Nic Type is %s" % nic.type
136+
)
137+
138+
self.assertIsNotNone(
139+
nic.traffictype,
140+
"Nic traffictype is %s" % nic.traffictype
141+
)
142+
143+
self.assertIsNotNone(
144+
nic.broadcasturi,
145+
"Nic broadcasturi is %s" % nic.broadcasturi
146+
)
147+
148+
self.assertIsNotNone(
149+
nic.isolationuri,
150+
"Nic isolationuri is %s" % nic.isolationuri
151+
)
152+
153+
154+
def tearDown(self):
155+
try:
156+
cleanup_resources(self.apiclient, self.cleanup)
157+
except Exception as e:
158+
self.debug("Warning! Exception in tearDown: %s" % e)
159+
return

0 commit comments

Comments
 (0)