Skip to content

Commit b83aa2a

Browse files
abhinandanprateekRohit Yadav
authored andcommitted
CLOUDSTACK-10021: Marvin test to check VR internal DNS Service (#1784)
1 parent 623ca0d commit b83aa2a

1 file changed

Lines changed: 275 additions & 0 deletions

File tree

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
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+
import logging
19+
import dns.resolver
20+
21+
from nose.plugins.attrib import attr
22+
from marvin.cloudstackTestCase import cloudstackTestCase
23+
from marvin.lib.utils import cleanup_resources
24+
from marvin.lib.base import (ServiceOffering,
25+
VirtualMachine,
26+
Account,
27+
NATRule,
28+
FireWallRule,
29+
NetworkOffering,
30+
Network)
31+
from marvin.lib.common import (get_zone,
32+
get_template,
33+
get_domain,
34+
list_routers,
35+
list_nat_rules,
36+
list_publicIP)
37+
38+
VM1_NAME="drump"
39+
VM2_NAME="dilton"
40+
41+
class TestRouterDnsService(cloudstackTestCase):
42+
43+
44+
@classmethod
45+
def setUpClass(cls):
46+
cls.logger = logging.getLogger('TestRouterDnsService')
47+
cls.stream_handler = logging.StreamHandler()
48+
cls.logger.setLevel(logging.DEBUG)
49+
cls.logger.addHandler(cls.stream_handler)
50+
51+
cls.testClient = super(TestRouterDnsService, cls).getClsTestClient()
52+
cls.api_client = cls.testClient.getApiClient()
53+
cls.services = cls.testClient.getParsedTestDataConfig()
54+
55+
cls.domain = get_domain(cls.api_client)
56+
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
57+
cls.services['mode'] = cls.zone.networktype
58+
cls.template = get_template(
59+
cls.api_client,
60+
cls.zone.id,
61+
cls.services["ostype"]
62+
)
63+
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
64+
65+
cls.logger.debug("Creating Admin Account for domain %s on zone %s" % (cls.domain.id, cls.zone.id))
66+
cls.account = Account.create(
67+
cls.api_client,
68+
cls.services["account"],
69+
admin=True,
70+
domainid=cls.domain.id
71+
)
72+
73+
cls.logger.debug("Creating Service Offering on zone %s" % (cls.zone.id))
74+
cls.service_offering = ServiceOffering.create(
75+
cls.api_client,
76+
cls.services["service_offering"]
77+
)
78+
79+
cls.logger.debug("Creating Network Offering on zone %s" % (cls.zone.id))
80+
cls.services["isolated_network_offering"]["egress_policy"] = "true"
81+
cls.network_offering = NetworkOffering.create(cls.api_client,
82+
cls.services["isolated_network_offering"],
83+
conservemode=True)
84+
cls.network_offering.update(cls.api_client, state='Enabled')
85+
86+
cls.logger.debug("Creating Network for Account %s using offering %s" % (cls.account.name, cls.network_offering.id))
87+
cls.network = Network.create(cls.api_client,
88+
cls.services["network"],
89+
accountid=cls.account.name,
90+
domainid=cls.account.domainid,
91+
networkofferingid=cls.network_offering.id,
92+
zoneid=cls.zone.id)
93+
94+
cls.logger.debug("Creating guest VM for Account %s using offering %s" % (cls.account.name, cls.service_offering.id))
95+
cls.services["virtual_machine"]["displayname"] = VM1_NAME;
96+
cls.services["virtual_machine"]["name"] = VM1_NAME;
97+
cls.vm1 = VirtualMachine.create(cls.api_client,
98+
cls.services["virtual_machine"],
99+
templateid=cls.template.id,
100+
accountid=cls.account.name,
101+
domainid=cls.domain.id,
102+
serviceofferingid=cls.service_offering.id,
103+
networkids=[str(cls.network.id)])
104+
cls.vm1.password = "password"
105+
cls.logger.debug("Created VM named %s" % VM1_NAME);
106+
107+
cls.services["virtual_machine"]["displayname"] = VM2_NAME;
108+
cls.services["virtual_machine"]["name"] = VM2_NAME;
109+
cls.vm2 = VirtualMachine.create(cls.api_client,
110+
cls.services["virtual_machine"],
111+
templateid=cls.template.id,
112+
accountid=cls.account.name,
113+
domainid=cls.domain.id,
114+
serviceofferingid=cls.service_offering.id,
115+
networkids=[str(cls.network.id)])
116+
cls.vm2.password = "password"
117+
cls.logger.debug("Created VM named %s" % VM2_NAME);
118+
119+
cls.services["natrule1"] = {
120+
"privateport": 22,
121+
"publicport": 22,
122+
"protocol": "TCP"
123+
}
124+
125+
cls.services["configurableData"] = {
126+
"host": {
127+
"password": "password",
128+
"username": "root",
129+
"port": 22
130+
},
131+
"input": "INPUT",
132+
"forward": "FORWARD"
133+
}
134+
135+
cls._cleanup = [
136+
cls.vm1,
137+
cls.vm2,
138+
cls.network,
139+
cls.network_offering,
140+
cls.service_offering,
141+
cls.account
142+
]
143+
144+
145+
@classmethod
146+
def tearDownClass(cls):
147+
try:
148+
cleanup_resources(cls.api_client, cls._cleanup)
149+
except Exception as e:
150+
raise Exception("Warning: Exception during cleanup : %s" % e)
151+
152+
153+
def setUp(self):
154+
self.apiclient = self.testClient.getApiClient()
155+
self.cleanup = []
156+
157+
158+
def tearDown(self):
159+
try:
160+
cleanup_resources(self.apiclient, self.cleanup)
161+
except Exception as e:
162+
raise Exception("Warning: Exception during cleanup : %s" % e)
163+
164+
165+
def test_router_common(self):
166+
"""Performs common router tests and returns router public_ips"""
167+
168+
routers = list_routers(
169+
self.apiclient,
170+
account=self.account.name,
171+
domainid=self.account.domainid
172+
)
173+
174+
self.assertEqual(
175+
isinstance(routers, list),
176+
True,
177+
"Check for list routers response return valid data"
178+
)
179+
180+
self.assertTrue(
181+
len(routers) >= 1,
182+
"Check list router response"
183+
)
184+
185+
router = routers[0]
186+
187+
self.assertEqual(
188+
router.state,
189+
'Running',
190+
"Check list router response for router state"
191+
)
192+
193+
public_ips = list_publicIP(
194+
self.apiclient,
195+
account=self.account.name,
196+
domainid=self.account.domainid,
197+
zoneid=self.zone.id
198+
)
199+
200+
self.assertEqual(
201+
isinstance(public_ips, list),
202+
True,
203+
"Check for list public IPs response return valid data"
204+
)
205+
206+
self.assertTrue(
207+
len(public_ips) >= 1,
208+
"Check public IP list has at least one IP"
209+
)
210+
return public_ips
211+
212+
213+
@attr(tags=["advanced", "advancedns", "ssh"], required_hardware="true")
214+
def test_router_dns_guestipquery(self):
215+
"""Checks that guest VM can query VR DNS"""
216+
217+
self.logger.debug("Starting test_router_dns_guestipquery...")
218+
public_ip = self.test_router_common()[0]
219+
220+
self.logger.debug("Creating Firewall rule for VM ID: %s" % self.vm1.id)
221+
FireWallRule.create(
222+
self.apiclient,
223+
ipaddressid=public_ip.id,
224+
protocol=self.services["natrule1"]["protocol"],
225+
cidrlist=['0.0.0.0/0'],
226+
startport=self.services["natrule1"]["publicport"],
227+
endport=self.services["natrule1"]["publicport"]
228+
)
229+
230+
self.logger.debug("Creating NAT rule for VM ID: %s" % self.vm1.id)
231+
nat_rule1 = NATRule.create(
232+
self.apiclient,
233+
self.vm1,
234+
self.services["natrule1"],
235+
public_ip.id
236+
)
237+
nat_rules = list_nat_rules(
238+
self.apiclient,
239+
id=nat_rule1.id
240+
)
241+
self.assertEqual(
242+
isinstance(nat_rules, list),
243+
True,
244+
"Check for list NAT rules response return valid data"
245+
)
246+
self.assertTrue(
247+
len(nat_rules) >= 1,
248+
"Check for list NAT rules to have at least one rule"
249+
)
250+
self.assertEqual(
251+
nat_rules[0].state,
252+
'Active',
253+
"Check list port forwarding rules"
254+
)
255+
256+
result1 = None
257+
try:
258+
self.logger.debug("SSH into guest VM with IP: %s" % nat_rule1.ipaddress)
259+
ssh = self.vm1.get_ssh_client(ipaddress=nat_rule1.ipaddress, port=self.services['natrule1']["publicport"], retries=8)
260+
result1 = str(ssh.execute("nslookup %s" % VM1_NAME))
261+
self.logger.debug("nslookup %s: %s " % (VM1_NAME, result1))
262+
result2 = str(ssh.execute("nslookup %s" % VM2_NAME))
263+
self.logger.debug("nslookup %s: %s " % (VM2_NAME, result2))
264+
except Exception as e:
265+
self.fail("Failed to SSH into VM - %s due to exception: %s" % (nat_rule1.ipaddress, e))
266+
267+
if not result1:
268+
self.fail("Did not to receive any response from the guest VM, failing.")
269+
270+
self.assertTrue(VM1_NAME in result1 and "#53" in result1,
271+
"VR DNS should serve requests from guest network, ping for %s successful." % VM1_NAME)
272+
self.assertTrue(VM2_NAME in result2 and "#53" in result2,
273+
"VR DNS should serve requests from guest network, ping for %s successful." % VM2_NAME)
274+
275+
return

0 commit comments

Comments
 (0)