How to use check_networks method in tempest

Best Python code snippet using tempest_python

test_network_validation.py

Source:test_network_validation.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Copyright 2013 Mirantis, Inc.3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15import json16from netaddr import IPAddress17from netaddr import IPNetwork18from nailgun.db.sqlalchemy.models import NetworkGroup19from nailgun.test.base import BaseIntegrationTest20from nailgun.test.base import reverse21class TestNetworkChecking(BaseIntegrationTest):22 def find_net_by_name(self, name):23 for net in self.nets['networks']:24 if net['name'] == name:25 return net26class TestNovaHandlers(TestNetworkChecking):27 def setUp(self):28 super(TestNovaHandlers, self).setUp()29 meta = self.env.default_metadata()30 self.env.set_interfaces_in_meta(meta, [31 {"name": "eth0", "mac": "00:00:00:00:00:66"},32 {"name": "eth1", "mac": "00:00:00:00:00:77"}])33 self.env.create(34 cluster_kwargs={},35 nodes_kwargs=[36 {"api": True,37 "meta": meta,38 "pending_addition": True},39 ]40 )41 self.cluster = self.env.clusters[0]42 resp = self.env.nova_networks_get(self.cluster.id)43 self.nets = json.loads(resp.body)44 def test_network_checking(self):45 resp = self.env.nova_networks_put(self.cluster.id, self.nets)46 self.assertEquals(resp.status, 202)47 task = json.loads(resp.body)48 self.assertEquals(task['status'], 'ready')49 self.assertEquals(task['progress'], 100)50 self.assertEquals(task['name'], 'check_networks')51 ngs_created = self.db.query(NetworkGroup).filter(52 NetworkGroup.name.in_([n['name'] for n in self.nets['networks']])53 ).all()54 self.assertEquals(len(ngs_created), len(self.nets['networks']))55 def test_network_checking_fails_if_admin_intersection(self):56 admin_ng = self.env.network_manager.get_admin_network_group()57 self.find_net_by_name('fixed')["cidr"] = admin_ng.cidr58 resp = self.env.nova_networks_put(self.cluster.id, self.nets,59 expect_errors=True)60 self.assertEquals(resp.status, 202)61 task = json.loads(resp.body)62 self.assertEquals(task['status'], 'error')63 self.assertEquals(task['progress'], 100)64 self.assertEquals(task['name'], 'check_networks')65 self.assertIn(66 "Address space intersection between networks:\n",67 task['message'])68 self.assertIn("admin (PXE)", task['message'])69 self.assertIn("fixed", task['message'])70 def test_network_checking_fails_if_admin_intersection_ip_range(self):71 admin_ng = self.env.network_manager.get_admin_network_group()72 cidr = IPNetwork(admin_ng.cidr)73 self.find_net_by_name('floating')['ip_ranges'] = [74 [str(IPAddress(cidr.first + 2)), str(IPAddress(cidr.last))]75 ]76 resp = self.env.nova_networks_put(self.cluster.id, self.nets,77 expect_errors=True)78 self.assertEquals(resp.status, 202)79 task = json.loads(resp.body)80 self.assertEquals(task['status'], 'error')81 self.assertEquals(task['progress'], 100)82 self.assertEquals(task['name'], 'check_networks')83 self.assertIn(84 "Address space intersection between networks:\n",85 task['message'])86 self.assertIn("admin (PXE)", task['message'])87 self.assertIn("floating", task['message'])88 def test_fails_if_netmask_for_public_network_not_set_or_not_valid(self):89 net_without_netmask = self.find_net_by_name('public')90 net_with_invalid_netmask = self.find_net_by_name('public')91 net_without_netmask['netmask'] = None92 net_with_invalid_netmask['netmask'] = '255.255.255.2'93 for net in [net_without_netmask, net_with_invalid_netmask]:94 resp = self.env.nova_networks_put(self.cluster.id,95 {'networks': [net]},96 expect_errors=True)97 self.assertEquals(resp.status, 202)98 task = json.loads(resp.body)99 self.assertEquals(task['status'], 'error')100 self.assertEquals(task['progress'], 100)101 self.assertEquals(task['name'], 'check_networks')102 self.assertEquals(103 task['message'],104 'Invalid gateway or netmask for public network')105 def test_network_checking_fails_if_networks_cidr_intersection(self):106 self.find_net_by_name('management')["cidr"] = \107 self.find_net_by_name('storage')["cidr"]108 resp = self.env.nova_networks_put(self.cluster.id, self.nets,109 expect_errors=True)110 self.assertEquals(resp.status, 202)111 task = json.loads(resp.body)112 self.assertEquals(task['status'], 'error')113 self.assertEquals(task['progress'], 100)114 self.assertEquals(task['name'], 'check_networks')115 self.assertIn(116 "Address space intersection between networks:\n",117 task['message'])118 self.assertIn("management", task['message'])119 self.assertIn("storage", task['message'])120 def test_network_checking_fails_if_untagged_intersection(self):121 self.find_net_by_name('management')["vlan_start"] = None122 self.env.nova_networks_put(self.cluster.id, self.nets)123 resp = self.env.cluster_changes_put(self.cluster.id)124 self.assertEquals(resp.status, 200)125 task = json.loads(resp.body)126 self.assertEquals(task['status'], 'error')127 self.assertEquals(task['progress'], 100)128 self.assertEquals(task['name'], 'deploy')129 self.assertIn(130 'Some untagged networks are assigned to the same physical '131 'interface. You should assign them to different physical '132 'interfaces. Affected:\n',133 task['message'])134 self.assertIn('"management"', task['message'])135 self.assertIn('"floating"', task['message'])136 self.assertIn('"public"', task['message'])137 self.assertIn(' networks at node "Untitled', task['message'])138 def test_network_checking_fails_if_networks_cidr_range_intersection(self):139 self.find_net_by_name('public')["ip_ranges"] = \140 [['192.18.17.65', '192.18.17.143']]141 self.find_net_by_name('public')["gateway"] = '192.18.17.1'142 self.find_net_by_name('public')["netmask"] = '255.255.255.0'143 self.find_net_by_name('management')["cidr"] = '192.18.17.0/25'144 resp = self.env.nova_networks_put(self.cluster.id, self.nets,145 expect_errors=True)146 self.assertEquals(resp.status, 202)147 task = json.loads(resp.body)148 self.assertEquals(task['status'], 'error')149 self.assertEquals(task['progress'], 100)150 self.assertEquals(task['name'], 'check_networks')151 self.assertIn(152 "Address space intersection between networks:\n",153 task['message'])154 self.assertIn("public", task['message'])155 self.assertIn("management", task['message'])156 def test_network_checking_no_public_floating_ranges_intersection(self):157 self.find_net_by_name('public')["ip_ranges"] = \158 [['192.18.17.5', '192.18.17.43'],159 ['192.18.17.59', '192.18.17.90']]160 self.find_net_by_name('floating')["ip_ranges"] = \161 [['192.18.17.125', '192.18.17.143'],162 ['192.18.17.159', '192.18.17.190']]163 self.find_net_by_name('public')["gateway"] = '192.18.17.1'164 self.find_net_by_name('public')["netmask"] = '255.255.255.0'165 resp = self.env.nova_networks_put(self.cluster.id, self.nets,166 expect_errors=True)167 self.assertEquals(resp.status, 202)168 task = json.loads(resp.body)169 self.assertEquals(task['status'], 'ready')170 self.assertEquals(task['progress'], 100)171 self.assertEquals(task['name'], 'check_networks')172 def test_network_checking_fails_if_public_ranges_intersection(self):173 self.find_net_by_name('public')["ip_ranges"] = \174 [['192.18.17.65', '192.18.17.143'],175 ['192.18.17.129', '192.18.17.190']]176 self.find_net_by_name('public')["gateway"] = '192.18.17.1'177 resp = self.env.nova_networks_put(self.cluster.id, self.nets,178 expect_errors=True)179 self.assertEquals(resp.status, 202)180 task = json.loads(resp.body)181 self.assertEquals(task['status'], 'error')182 self.assertEquals(task['progress'], 100)183 self.assertEquals(task['name'], 'check_networks')184 self.assertEquals(185 task['message'],186 "Address space intersection between ranges of public network."187 )188 def test_network_checking_fails_if_public_gateway_not_in_cidr(self):189 self.find_net_by_name('public')["ip_ranges"] = \190 [['192.18.17.5', '192.18.17.43'],191 ['192.18.17.59', '192.18.17.90']]192 self.find_net_by_name('public')["gateway"] = '192.18.18.1'193 self.find_net_by_name('public')["netmask"] = '255.255.255.0'194 resp = self.env.nova_networks_put(self.cluster.id, self.nets,195 expect_errors=True)196 self.assertEquals(resp.status, 202)197 task = json.loads(resp.body)198 self.assertEquals(task['status'], 'error')199 self.assertEquals(task['progress'], 100)200 self.assertEquals(task['name'], 'check_networks')201 self.assertEquals(202 task['message'],203 "Public gateway and public ranges are not in one CIDR."204 )205 def test_network_checking_fails_if_public_gateway_range_intersection(self):206 self.find_net_by_name('public')["ip_ranges"] = \207 [['192.18.17.5', '192.18.17.43'],208 ['192.18.17.59', '192.18.17.90']]209 self.find_net_by_name('public')["gateway"] = '192.18.17.77'210 self.find_net_by_name('public')["netmask"] = '255.255.255.0'211 resp = self.env.nova_networks_put(self.cluster.id, self.nets,212 expect_errors=True)213 self.assertEquals(resp.status, 202)214 task = json.loads(resp.body)215 self.assertEquals(task['status'], 'error')216 self.assertEquals(task['progress'], 100)217 self.assertEquals(task['name'], 'check_networks')218 self.assertEquals(219 task['message'],220 "Address intersection between public gateway and IP range of "221 "public network."222 )223 def test_network_checking_fails_if_floating_ranges_intersection(self):224 self.find_net_by_name('floating')["ip_ranges"] = \225 [['192.18.17.65', '192.18.17.143'],226 ['192.18.17.129', '192.18.17.190']]227 resp = self.env.nova_networks_put(self.cluster.id, self.nets,228 expect_errors=True)229 self.assertEquals(resp.status, 202)230 task = json.loads(resp.body)231 self.assertEquals(task['status'], 'error')232 self.assertEquals(task['progress'], 100)233 self.assertEquals(task['name'], 'check_networks')234 self.assertEquals(235 task['message'],236 "Address space intersection between ranges of floating network."237 )238 def test_network_checking_fails_if_amount_flatdhcp(self):239 net = self.find_net_by_name('fixed')240 net["amount"] = 2241 net["cidr"] = "10.10.0.0/23"242 resp = self.env.nova_networks_put(self.cluster.id, {'networks': [net]},243 expect_errors=True)244 self.assertEquals(resp.status, 202)245 task = json.loads(resp.body)246 self.assertEquals(task['status'], 'error')247 self.assertEquals(task['progress'], 100)248 self.assertEquals(task['name'], 'check_networks')249 self.assertEquals(250 task['message'],251 "Network amount for 'fixed' is more than 1 "252 "while using FlatDHCP manager."253 )254 def test_network_checking_fails_if_vlan_ids_intersection(self):255 self.find_net_by_name('public')["vlan_start"] = 111256 self.find_net_by_name('management')["vlan_start"] = 111257 resp = self.env.nova_networks_put(self.cluster.id, self.nets,258 expect_errors=True)259 self.assertEquals(resp.status, 202)260 task = json.loads(resp.body)261 self.assertEquals(task['status'], 'error')262 self.assertEquals(task['progress'], 100)263 self.assertEquals(task['name'], 'check_networks')264 self.assertIn(265 " networks use the same VLAN ID(s). "266 "You should assign different VLAN IDs to every network.",267 task['message'])268 self.assertIn("management", task['message'])269 self.assertIn("public", task['message'])270 def test_network_checking_fails_if_vlan_id_in_fixed_vlan_range(self):271 self.nets['net_manager'] = 'VLANManager'272 self.find_net_by_name('public')["vlan_start"] = 1111273 self.find_net_by_name('fixed')["vlan_start"] = 1100274 self.find_net_by_name('fixed')["amount"] = 20275 resp = self.env.nova_networks_put(self.cluster.id, self.nets,276 expect_errors=True)277 self.assertEquals(resp.status, 202)278 task = json.loads(resp.body)279 self.assertEquals(task['status'], 'error')280 self.assertEquals(task['progress'], 100)281 self.assertEquals(task['name'], 'check_networks')282 self.assertIn(283 " networks use the same VLAN ID(s). "284 "You should assign different VLAN IDs to every network.",285 task['message'])286 self.assertIn("fixed", task['message'])287 self.assertIn("public", task['message'])288 def test_network_checking_fails_if_vlan_id_not_in_allowed_range(self):289 self.find_net_by_name('public')["vlan_start"] = 5555290 resp = self.env.nova_networks_put(self.cluster.id, self.nets,291 expect_errors=True)292 self.assertEquals(resp.status, 202)293 task = json.loads(resp.body)294 self.assertEquals(task['status'], 'error')295 self.assertEquals(task['progress'], 100)296 self.assertEquals(task['name'], 'check_networks')297 self.assertEquals(298 task['message'],299 "VLAN ID(s) is out of range for public network."300 )301 def test_network_checking_fails_if_public_floating_vlan_not_equal(self):302 self.find_net_by_name('public')["vlan_start"] = 111303 self.find_net_by_name('floating')["vlan_start"] = 112304 resp = self.env.nova_networks_put(self.cluster.id, self.nets,305 expect_errors=True)306 self.assertEquals(resp.status, 202)307 task = json.loads(resp.body)308 self.assertEquals(task['status'], 'error')309 self.assertEquals(task['progress'], 100)310 self.assertEquals(task['name'], 'check_networks')311 self.assertIn(312 " networks don't use the same VLAN ID(s). "313 "These networks must use the same VLAN ID(s).",314 task['message']315 )316 self.assertIn("floating", task['message'])317 self.assertIn("public", task['message'])318 def test_network_checking_fails_if_public_floating_not_on_one_nic(self):319 self.find_net_by_name('public')["vlan_start"] = 111320 self.find_net_by_name('floating')["vlan_start"] = 111321 resp = self.env.nova_networks_put(self.cluster.id, self.nets,322 expect_errors=True)323 self.assertEquals(resp.status, 202)324 task = json.loads(resp.body)325 self.assertEquals(task['status'], 'ready')326 node_db = self.env.nodes[0]327 resp = self.app.get(reverse('NodeNICsHandler',328 kwargs={'node_id': node_db.id}),329 headers=self.default_headers)330 nics = json.loads(resp.body)331 for nic in nics:332 for net in nic['assigned_networks']:333 if net['name'] == 'fuelweb_admin':334 admin_nic = nic335 else:336 other_nic = nic337 if net['name'] == 'public':338 public = net339 other_nic['assigned_networks'].remove(public)340 admin_nic['assigned_networks'].append(public)341 resp = self.app.put(reverse('NodeNICsHandler',342 kwargs={'node_id': node_db.id}),343 json.dumps(nics),344 headers=self.default_headers)345 self.assertEquals(resp.status, 200)346 resp = self.env.cluster_changes_put(self.cluster.id)347 self.assertEquals(resp.status, 200)348 task = json.loads(resp.body)349 self.assertEquals(task['status'], 'error')350 self.assertEquals(task['progress'], 100)351 self.assertEquals(task['name'], 'deploy')352 self.assertIn(353 "Public and floating networks are not assigned to the "354 "same physical interface. These networks must be assigned "355 "to the same physical interface. Affected nodes:\nUntitled",356 task['message']357 )358 def test_network_size_and_amount_not_fit_cidr(self):359 net = self.find_net_by_name('fixed')360 net["amount"] = 1361 net["cidr"] = "10.10.0.0/24"362 net["network_size"] = "128"363 resp = self.env.nova_networks_put(self.cluster.id, self.nets,364 expect_errors=True)365 self.assertEquals(resp.status, 202)366 task = json.loads(resp.body)367 self.assertEquals(task['status'], 'ready')368 net["network_size"] = "512"369 resp = self.env.nova_networks_put(self.cluster.id, self.nets,370 expect_errors=True)371 self.assertEquals(resp.status, 202)372 task = json.loads(resp.body)373 self.assertEquals(task['status'], 'error')374 self.assertEquals(task['progress'], 100)375 self.assertEquals(task['name'], 'check_networks')376 self.assertEquals(377 task['message'],378 "Number of fixed networks (1) doesn't fit into "379 "fixed CIDR (10.10.0.0/24) and size of one fixed network (512)."380 )381 self.nets['net_manager'] = 'VlanManager'382 net["amount"] = 8383 net["network_size"] = "32"384 resp = self.env.nova_networks_put(self.cluster.id, self.nets,385 expect_errors=True)386 self.assertEquals(resp.status, 202)387 task = json.loads(resp.body)388 self.assertEquals(task['status'], 'ready')389 net["amount"] = 32390 resp = self.env.nova_networks_put(self.cluster.id, self.nets,391 expect_errors=True)392 self.assertEquals(resp.status, 202)393 task = json.loads(resp.body)394 self.assertEquals(task['status'], 'error')395 self.assertEquals(task['progress'], 100)396 self.assertEquals(task['name'], 'check_networks')397 self.assertEquals(398 task['message'],399 "Number of fixed networks (32) doesn't fit into "400 "fixed CIDR (10.10.0.0/24) and size of one fixed network (32)."401 )402 def test_network_fit_abc_classes_exclude_loopback(self):403 self.find_net_by_name('management')['cidr'] = '127.19.216.0/24'404 resp = self.env.nova_networks_put(self.cluster.id, self.nets,405 expect_errors=True)406 self.assertEquals(resp.status, 202)407 task = json.loads(resp.body)408 self.assertEquals(task['status'], 'error')409 self.assertEquals(task['progress'], 100)410 self.assertEquals(task['name'], 'check_networks')411 self.assertEquals(412 task['message'],413 "management network address space is inside loopback range "414 "(127.0.0.0/8). It must have no intersection with "415 "loopback range."416 )417 self.find_net_by_name('management')['cidr'] = '227.19.216.0/24'418 resp = self.env.nova_networks_put(self.cluster.id, self.nets,419 expect_errors=True)420 self.assertEquals(resp.status, 202)421 task = json.loads(resp.body)422 self.assertEquals(task['status'], 'error')423 self.assertEquals(task['progress'], 100)424 self.assertEquals(task['name'], 'check_networks')425 self.assertEquals(426 task['message'],427 "management network address space does not belong to "428 "A, B, C network classes. It must belong to either "429 "A, B or C network class."430 )431 def test_network_gw_and_ranges_intersect_w_subnet_or_broadcast(self):432 self.find_net_by_name('public')['gateway'] = '172.16.0.0'433 resp = self.env.nova_networks_put(self.cluster.id, self.nets,434 expect_errors=True)435 self.assertEquals(resp.status, 202)436 task = json.loads(resp.body)437 self.assertEquals(task['status'], 'error')438 self.assertEquals(task['progress'], 100)439 self.assertEquals(task['name'], 'check_networks')440 self.assertEquals(441 task['message'],442 "public network gateway address is equal to either subnet address "443 "or broadcast address of the network."444 )445 self.find_net_by_name('public')['gateway'] = '172.16.0.255'446 resp = self.env.nova_networks_put(self.cluster.id, self.nets,447 expect_errors=True)448 self.assertEquals(resp.status, 202)449 task = json.loads(resp.body)450 self.assertEquals(task['status'], 'error')451 self.assertEquals(task['progress'], 100)452 self.assertEquals(task['name'], 'check_networks')453 self.assertEquals(454 task['message'],455 "public network gateway address is equal to either subnet address "456 "or broadcast address of the network."457 )458 self.find_net_by_name('public')['gateway'] = '172.16.0.125'459 self.find_net_by_name('public')['ip_ranges'] = [['172.16.0.0',460 '172.16.0.122']]461 resp = self.env.nova_networks_put(self.cluster.id, self.nets,462 expect_errors=True)463 self.assertEquals(resp.status, 202)464 task = json.loads(resp.body)465 self.assertEquals(task['status'], 'error')466 self.assertEquals(task['progress'], 100)467 self.assertEquals(task['name'], 'check_networks')468 self.assertEquals(469 task['message'],470 "public network IP range [172.16.0.0-172.16.0.122] intersect "471 "with either subnet address or broadcast address of the network."472 )473 self.find_net_by_name('public')['ip_ranges'] = [['172.16.0.255',474 '172.16.0.255']]475 resp = self.env.nova_networks_put(self.cluster.id, self.nets,476 expect_errors=True)477 self.assertEquals(resp.status, 202)478 task = json.loads(resp.body)479 self.assertEquals(task['status'], 'error')480 self.assertEquals(task['progress'], 100)481 self.assertEquals(task['name'], 'check_networks')482 self.assertEquals(483 task['message'],484 "public network IP range [172.16.0.255-172.16.0.255] intersect "485 "with either subnet address or broadcast address of the network."486 )487 self.find_net_by_name('public')['ip_ranges'] = [['172.16.0.2',488 '172.16.0.122']]489 self.find_net_by_name('fixed')['gateway'] = '10.0.0.0'490 resp = self.env.nova_networks_put(self.cluster.id, self.nets,491 expect_errors=True)492 self.assertEquals(resp.status, 202)493 task = json.loads(resp.body)494 self.assertEquals(task['status'], 'error')495 self.assertEquals(task['progress'], 100)496 self.assertEquals(task['name'], 'check_networks')497 self.assertEquals(498 task['message'],499 "fixed network gateway address is equal to either subnet address "500 "or broadcast address of the network."501 )502 self.find_net_by_name('fixed')['gateway'] = '10.0.255.255'503 resp = self.env.nova_networks_put(self.cluster.id, self.nets,504 expect_errors=True)505 self.assertEquals(resp.status, 202)506 task = json.loads(resp.body)507 self.assertEquals(task['status'], 'error')508 self.assertEquals(task['progress'], 100)509 self.assertEquals(task['name'], 'check_networks')510 self.assertEquals(511 task['message'],512 "fixed network gateway address is equal to either subnet address "513 "or broadcast address of the network."514 )515class TestNeutronHandlersGre(TestNetworkChecking):516 def setUp(self):517 super(TestNeutronHandlersGre, self).setUp()518 meta = self.env.default_metadata()519 self.env.set_interfaces_in_meta(meta, [520 {"name": "eth0", "mac": "00:00:00:00:00:66"},521 {"name": "eth1", "mac": "00:00:00:00:00:77"}])522 self.env.create(523 cluster_kwargs={524 'net_provider': 'neutron',525 'net_segment_type': 'gre'526 },527 nodes_kwargs=[528 {'api': True,529 'pending_addition': True,530 'meta': meta}531 ]532 )533 self.cluster = self.env.clusters[0]534 resp = self.env.neutron_networks_get(self.cluster.id)535 self.nets = json.loads(resp.body)536 def test_network_checking(self):537 resp = self.env.neutron_networks_put(self.cluster.id, self.nets)538 self.assertEquals(resp.status, 202)539 task = json.loads(resp.body)540 self.assertEquals(task['status'], 'ready')541 self.assertEquals(task['progress'], 100)542 self.assertEquals(task['name'], 'check_networks')543 ngs_created = self.db.query(NetworkGroup).filter(544 NetworkGroup.name.in_([n['name'] for n in self.nets['networks']])545 ).all()546 self.assertEquals(len(ngs_created), len(self.nets['networks']))547 def test_network_checking_fails_if_network_is_at_admin_iface(self):548 node_db = self.env.nodes[0]549 resp = self.env.node_nics_get(node_db.id)550 ifaces = json.loads(resp.body)551 admin_if = [iface for iface in ifaces552 if len(iface["assigned_networks"]) == 1 and553 iface["assigned_networks"][0]["name"] == "fuelweb_admin"]554 self.assertEquals(len(admin_if), 1)555 other_if = [iface for iface in ifaces556 if iface != admin_if[0]]557 self.assertGreaterEqual(len(other_if), 1)558 admin_if[0]["assigned_networks"].extend(559 other_if[0]["assigned_networks"])560 other_if[0]["assigned_networks"] = []561 self.env.node_collection_nics_put(562 node_db.id,563 [{"interfaces": ifaces, "id": node_db.id}])564 resp = self.env.cluster_changes_put(self.cluster.id)565 self.assertEquals(resp.status, 200)566 task = json.loads(resp.body)567 self.assertEquals(task['status'], 'error')568 self.assertEquals(task['progress'], 100)569 self.assertEquals(task['name'], 'deploy')570 self.assertEquals(571 task['message'].find(572 "Some networks are "573 "assigned to the same physical interface as "574 "admin (PXE) network. You should move them to "575 "another physical interfaces:"),576 0577 )578 def test_network_checking_fails_if_admin_intersection(self):579 admin_ng = self.env.network_manager.get_admin_network_group()580 self.find_net_by_name('storage')["cidr"] = admin_ng.cidr581 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,582 expect_errors=True)583 self.assertEquals(resp.status, 202)584 task = json.loads(resp.body)585 self.assertEquals(task['status'], 'error')586 self.assertEquals(task['progress'], 100)587 self.assertEquals(task['name'], 'check_networks')588 self.assertIn(589 "Address space intersection between networks:\n",590 task['message'])591 self.assertIn("admin (PXE)", task['message'])592 self.assertIn("storage", task['message'])593 def test_network_checking_fails_if_untagged_intersection(self):594 for n in self.nets['networks']:595 n['vlan_start'] = None596 self.env.neutron_networks_put(self.cluster.id, self.nets)597 resp = self.env.cluster_changes_put(self.cluster.id)598 self.assertEquals(resp.status, 200)599 task = json.loads(resp.body)600 self.assertEquals(task['status'], 'error')601 self.assertEquals(task['progress'], 100)602 self.assertEquals(task['name'], 'deploy')603 self.assertEquals(604 task['message'].find(605 "Some untagged networks are "606 "assigned to the same physical interface. "607 "You should assign them to "608 "different physical interfaces:"),609 0610 )611 def test_network_checking_fails_if_public_gateway_not_in_cidr(self):612 self.find_net_by_name('public')['gateway'] = '172.16.10.1'613 virt_nets = self.nets['neutron_parameters']['predefined_networks']614 virt_nets['net04_ext']['L3']['floating'] = ['172.16.10.130',615 '172.16.10.254']616 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,617 expect_errors=True)618 self.assertEquals(resp.status, 202)619 task = json.loads(resp.body)620 self.assertEquals(task['status'], 'error')621 self.assertEquals(task['progress'], 100)622 self.assertEquals(task['name'], 'check_networks')623 self.assertEquals(624 task['message'],625 "Public gateway and public ranges are not in one CIDR."626 )627 def test_network_checking_fails_if_public_float_range_not_in_cidr(self):628 self.find_net_by_name('public')['cidr'] = '172.16.10.0/24'629 self.find_net_by_name('public')['gateway'] = '172.16.10.1'630 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,631 expect_errors=True)632 self.assertEquals(resp.status, 202)633 task = json.loads(resp.body)634 self.assertEquals(task['status'], 'error')635 self.assertEquals(task['progress'], 100)636 self.assertEquals(task['name'], 'check_networks')637 self.assertEquals(638 task['message'],639 "Floating address range 172.16.0.130:172.16.0.254 is not in "640 "public address space 172.16.10.0/24."641 )642 def test_network_checking_fails_if_network_ranges_intersect(self):643 self.find_net_by_name('management')['cidr'] = \644 self.find_net_by_name('storage')['cidr']645 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,646 expect_errors=True)647 self.assertEquals(resp.status, 202)648 task = json.loads(resp.body)649 self.assertEquals(task['status'], 'error')650 self.assertEquals(task['progress'], 100)651 self.assertEquals(task['name'], 'check_networks')652 self.assertIn(653 "Address space intersection between networks:\n",654 task['message'])655 self.assertIn("management", task['message'])656 self.assertIn("storage", task['message'])657 def test_network_checking_fails_if_public_gw_ranges_intersect(self):658 self.find_net_by_name('public')['gateway'] = '172.16.0.11'659 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,660 expect_errors=True)661 self.assertEquals(resp.status, 202)662 task = json.loads(resp.body)663 self.assertEquals(task['status'], 'error')664 self.assertEquals(task['progress'], 100)665 self.assertEquals(task['name'], 'check_networks')666 self.assertEquals(667 task['message'],668 "Address intersection between public gateway "669 "and IP range of public network."670 )671 def test_network_checking_fails_if_public_ranges_intersect(self):672 self.find_net_by_name('public')['ip_ranges'] = \673 [['172.16.0.2', '172.16.0.77'],674 ['172.16.0.55', '172.16.0.121']]675 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,676 expect_errors=True)677 self.assertEquals(resp.status, 202)678 task = json.loads(resp.body)679 self.assertEquals(task['status'], 'error')680 self.assertEquals(task['progress'], 100)681 self.assertEquals(task['name'], 'check_networks')682 self.assertEquals(683 task['message'],684 "Address space intersection between ranges "685 "of public network."686 )687 def test_network_checking_fails_if_public_float_ranges_intersect(self):688 self.find_net_by_name('public')['ip_ranges'] = \689 [['172.16.0.2', '172.16.0.33'],690 ['172.16.0.55', '172.16.0.222']]691 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,692 expect_errors=True)693 self.assertEquals(resp.status, 202)694 task = json.loads(resp.body)695 self.assertEquals(task['status'], 'error')696 self.assertEquals(task['progress'], 100)697 self.assertEquals(task['name'], 'check_networks')698 self.assertEquals(699 task['message'],700 "Address space intersection between ranges "701 "of public and external network."702 )703 def test_network_checking_fails_if_network_cidr_too_small(self):704 self.find_net_by_name('management')['cidr'] = '192.168.0.0/25'705 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,706 expect_errors=True)707 self.assertEquals(resp.status, 202)708 task = json.loads(resp.body)709 self.assertEquals(task['status'], 'error')710 self.assertEquals(task['progress'], 100)711 self.assertEquals(task['name'], 'check_networks')712 self.assertEquals(713 task['message'],714 "CIDR size for network 'management' "715 "is less than required"716 )717 def test_network_checking_public_network_cidr_became_smaller(self):718 self.assertEquals(self.find_net_by_name('public')['network_size'], 256)719 self.find_net_by_name('public')['netmask'] = '255.255.255.128'720 self.find_net_by_name('public')['gateway'] = '172.16.0.1'721 self.find_net_by_name('public')['ip_ranges'] = [['172.16.0.2',722 '172.16.0.77']]723 virt_nets = self.nets['neutron_parameters']['predefined_networks']724 virt_nets['net04_ext']['L3']['floating'] = ['172.16.0.99',725 '172.16.0.111']726 resp = self.env.neutron_networks_put(self.cluster.id, self.nets)727 self.assertEquals(resp.status, 202)728 task = json.loads(resp.body)729 self.assertEquals(task['status'], 'ready')730 resp = self.env.neutron_networks_get(self.cluster.id)731 self.nets = json.loads(resp.body)732 self.assertEquals(self.find_net_by_name('public')['cidr'],733 '172.16.0.0/25')734 self.assertEquals(self.find_net_by_name('public')['network_size'], 128)735 def test_network_checking_fails_on_network_vlan_match(self):736 self.find_net_by_name('management')['vlan_start'] = '111'737 self.find_net_by_name('storage')['vlan_start'] = '111'738 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,739 expect_errors=True)740 self.assertEquals(resp.status, 202)741 task = json.loads(resp.body)742 self.assertEquals(task['status'], 'error')743 self.assertEquals(task['progress'], 100)744 self.assertEquals(task['name'], 'check_networks')745 self.assertIn(746 " networks use the same VLAN tags. "747 "You should assign different VLAN tag "748 "to every network.",749 task['message'])750 self.assertIn("management", task['message'])751 self.assertIn("storage", task['message'])752 def test_network_checking_fails_if_internal_gateway_not_in_cidr(self):753 int = self.nets['neutron_parameters']['predefined_networks']['net04']754 int['L3']['gateway'] = '172.16.10.1'755 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,756 expect_errors=True)757 self.assertEquals(resp.status, 202)758 task = json.loads(resp.body)759 self.assertEquals(task['status'], 'error')760 self.assertEquals(task['progress'], 100)761 self.assertEquals(task['name'], 'check_networks')762 self.assertEquals(763 task['message'],764 "Internal gateway 172.16.10.1 is not in "765 "internal address space 192.168.111.0/24."766 )767 def test_network_checking_fails_if_internal_w_floating_intersection(self):768 int = self.nets['neutron_parameters']['predefined_networks']['net04']769 int['L3']['cidr'] = '172.16.0.128/26'770 int['L3']['gateway'] = '172.16.0.129'771 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,772 expect_errors=True)773 self.assertEquals(resp.status, 202)774 task = json.loads(resp.body)775 self.assertEquals(task['status'], 'error')776 self.assertEquals(task['progress'], 100)777 self.assertEquals(task['name'], 'check_networks')778 self.assertEquals(779 task['message'],780 "Intersection between internal CIDR and floating range."781 )782 def test_network_fit_abc_classes_exclude_loopback(self):783 self.find_net_by_name('management')['cidr'] = '127.19.216.0/24'784 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,785 expect_errors=True)786 self.assertEquals(resp.status, 202)787 task = json.loads(resp.body)788 self.assertEquals(task['status'], 'error')789 self.assertEquals(task['progress'], 100)790 self.assertEquals(task['name'], 'check_networks')791 self.assertEquals(792 task['message'],793 "management network address space is inside loopback range "794 "(127.0.0.0/8). It must have no intersection with "795 "loopback range."796 )797 self.find_net_by_name('management')['cidr'] = '227.19.216.0/24'798 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,799 expect_errors=True)800 self.assertEquals(resp.status, 202)801 task = json.loads(resp.body)802 self.assertEquals(task['status'], 'error')803 self.assertEquals(task['progress'], 100)804 self.assertEquals(task['name'], 'check_networks')805 self.assertEquals(806 task['message'],807 "management network address space does not belong to "808 "A, B, C network classes. It must belong to either "809 "A, B or C network class."810 )811 def test_network_gw_and_ranges_intersect_w_subnet_or_broadcast(self):812 self.find_net_by_name('public')['gateway'] = '172.16.0.0'813 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,814 expect_errors=True)815 self.assertEquals(resp.status, 202)816 task = json.loads(resp.body)817 self.assertEquals(task['status'], 'error')818 self.assertEquals(task['progress'], 100)819 self.assertEquals(task['name'], 'check_networks')820 self.assertEquals(821 task['message'],822 "public network gateway address is equal to either subnet address "823 "or broadcast address of the network."824 )825 self.find_net_by_name('public')['gateway'] = '172.16.0.255'826 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,827 expect_errors=True)828 self.assertEquals(resp.status, 202)829 task = json.loads(resp.body)830 self.assertEquals(task['status'], 'error')831 self.assertEquals(task['progress'], 100)832 self.assertEquals(task['name'], 'check_networks')833 self.assertEquals(834 task['message'],835 "public network gateway address is equal to either subnet address "836 "or broadcast address of the network."837 )838 self.find_net_by_name('public')['gateway'] = '172.16.0.125'839 self.find_net_by_name('public')['ip_ranges'] = [['172.16.0.0',840 '172.16.0.122']]841 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,842 expect_errors=True)843 self.assertEquals(resp.status, 202)844 task = json.loads(resp.body)845 self.assertEquals(task['status'], 'error')846 self.assertEquals(task['progress'], 100)847 self.assertEquals(task['name'], 'check_networks')848 self.assertEquals(849 task['message'],850 "public network IP range [172.16.0.0-172.16.0.122] intersect "851 "with either subnet address or broadcast address of the network."852 )853 self.find_net_by_name('public')['ip_ranges'] = [['172.16.0.255',854 '172.16.0.255']]855 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,856 expect_errors=True)857 self.assertEquals(resp.status, 202)858 task = json.loads(resp.body)859 self.assertEquals(task['status'], 'error')860 self.assertEquals(task['progress'], 100)861 self.assertEquals(task['name'], 'check_networks')862 self.assertEquals(863 task['message'],864 "public network IP range [172.16.0.255-172.16.0.255] intersect "865 "with either subnet address or broadcast address of the network."866 )867 self.find_net_by_name('public')['ip_ranges'] = [['172.16.0.55',868 '172.16.0.99']]869 virt_nets = self.nets['neutron_parameters']['predefined_networks']870 virt_nets['net04_ext']['L3']['floating'] = ['172.16.0.0',871 '172.16.0.33']872 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,873 expect_errors=True)874 self.assertEquals(resp.status, 202)875 task = json.loads(resp.body)876 self.assertEquals(task['status'], 'error')877 self.assertEquals(task['progress'], 100)878 self.assertEquals(task['name'], 'check_networks')879 self.assertEquals(880 task['message'],881 "Neutron L3 external floating range [172.16.0.0-172.16.0.33] "882 "intersect with either subnet address or broadcast address "883 "of public network."884 )885 virt_nets['net04_ext']['L3']['floating'] = ['172.16.0.155',886 '172.16.0.255']887 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,888 expect_errors=True)889 self.assertEquals(resp.status, 202)890 task = json.loads(resp.body)891 self.assertEquals(task['status'], 'error')892 self.assertEquals(task['progress'], 100)893 self.assertEquals(task['name'], 'check_networks')894 self.assertEquals(895 task['message'],896 "Neutron L3 external floating range [172.16.0.155-172.16.0.255] "897 "intersect with either subnet address or broadcast address "898 "of public network."899 )900 virt_nets['net04_ext']['L3']['floating'] = ['172.16.0.155',901 '172.16.0.199']902 virt_nets['net04']['L3']['cidr'] = '192.168.111.0/24'903 virt_nets['net04']['L3']['gateway'] = '192.168.111.0'904 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,905 expect_errors=True)906 self.assertEquals(resp.status, 202)907 task = json.loads(resp.body)908 self.assertEquals(task['status'], 'error')909 self.assertEquals(task['progress'], 100)910 self.assertEquals(task['name'], 'check_networks')911 self.assertEquals(912 task['message'],913 "Neutron L3 internal network gateway address is equal to "914 "either subnet address or broadcast address of the network."915 )916 virt_nets['net04']['L3']['gateway'] = '192.168.111.255'917 resp = self.env.neutron_networks_put(self.cluster.id, self.nets,918 expect_errors=True)919 self.assertEquals(resp.status, 202)920 task = json.loads(resp.body)921 self.assertEquals(task['status'], 'error')922 self.assertEquals(task['progress'], 100)923 self.assertEquals(task['name'], 'check_networks')924 self.assertEquals(925 task['message'],926 "Neutron L3 internal network gateway address is equal to "927 "either subnet address or broadcast address of the network."928 )929class TestNeutronHandlersVlan(TestNetworkChecking):930 def setUp(self):931 super(TestNeutronHandlersVlan, self).setUp()932 meta = self.env.default_metadata()933 self.env.set_interfaces_in_meta(meta, [934 {"name": "eth0", "mac": "00:00:00:00:00:66"},935 {"name": "eth1", "mac": "00:00:00:00:00:77"},936 {"name": "eth2", "mac": "00:00:00:00:00:88"}])937 self.env.create(938 cluster_kwargs={939 'net_provider': 'neutron',940 'net_segment_type': 'vlan'941 },942 nodes_kwargs=[943 {'api': True,944 'pending_addition': True,945 'meta': meta}946 ]947 )948 self.cluster = self.env.clusters[0]949 resp = self.env.neutron_networks_get(self.cluster.id)950 self.nets = json.loads(resp.body)951 def test_network_checking(self):952 resp = self.env.neutron_networks_put(self.cluster.id, self.nets)953 self.assertEquals(resp.status, 202)954 task = json.loads(resp.body)955 self.assertEquals(task['status'], 'ready')956 self.assertEquals(task['progress'], 100)957 self.assertEquals(task['name'], 'check_networks')958 ngs_created = self.db.query(NetworkGroup).filter(959 NetworkGroup.name.in_([n['name'] for n in self.nets['networks']])960 ).all()961 self.assertEquals(len(ngs_created), len(self.nets['networks']))962 def test_network_checking_failed_if_private_paired_w_other_network(self):963 resp = self.env.node_nics_get(self.env.nodes[0].id)964 ifaces = json.loads(resp.body)965 priv_nic = [nic for nic in ifaces966 if len(nic["assigned_networks"]) == 1 and967 nic["assigned_networks"][0]["name"] == "private"]968 self.assertEqual(len(priv_nic), 1)969 # only 'private' should be here in default configuration970 priv_net = priv_nic[0]["assigned_networks"][0]971 others_nic = [nic for nic in ifaces972 if len(nic["assigned_networks"]) > 1]973 # all networks except 'admin' and 'private' should be here974 # in default configuration975 self.assertEqual(len(others_nic), 1)976 others_nic_net_names = [net['name']977 for net in others_nic[0]["assigned_networks"]]978 priv_nic[0]["assigned_networks"].remove(priv_net)979 others_nic[0]["assigned_networks"].append(priv_net)980 self.env.node_collection_nics_put(981 self.env.nodes[0].id,982 [{"interfaces": ifaces, "id": self.env.nodes[0].id}])983 resp = self.env.cluster_changes_put(self.cluster.id)984 self.assertEquals(resp.status, 200)985 task = json.loads(resp.body)986 self.assertEquals(task['status'], 'error')987 self.assertEquals(task['progress'], 100)988 self.assertEquals(task['name'], 'deploy')989 self.assertIn(990 "Some networks are "991 "assigned to the same physical interface as "992 "private network. You should move them to "993 "another physical interfaces:",994 task['message'])995 for net in others_nic_net_names:996 self.assertIn(net, task['message'])997 def test_network_checking_failed_if_networks_tags_in_neutron_range(self):998 self.find_net_by_name('storage')['vlan_start'] = 1000999 resp = self.env.neutron_networks_put(self.cluster.id, self.nets)1000 self.assertEquals(resp.status, 202)1001 task = json.loads(resp.body)1002 self.assertEquals(task['status'], 'error')1003 self.assertEquals(task['progress'], 100)1004 self.assertEquals(task['name'], 'check_networks')1005 self.assertEquals(1006 task['message'],1007 "VLAN tags of storage network(s) intersect with "1008 "VLAN ID range defined for Neutron L2. "1009 "Networks VLAN tags must not intersect "...

Full Screen

Full Screen

Wifi-Password-Finder.py

Source:Wifi-Password-Finder.py Github

copy

Full Screen

1#This script can only find wifi passwords stored on your computer.2import subprocess, re3item = subprocess.run(["netsh","wlan","show","profiles"],capture_output=True).stdout.decode()4prof_names = (re.findall("All User Profile : (.*)\r", item))5passwords = []6check_networks = []7for i in prof_names:8 item = subprocess.run(["netsh", "wlan", "show", "profiles",i], capture_output=True).stdout.decode()9 security_key = False10 security_key_present = (re.findall("Security key : (.*)\r", item))11 if security_key_present[0] == "Present":12 check_networks.append(i)13 else:14 pass15for i in check_networks:16 item = subprocess.run(["netsh","wlan","show","profiles",i,"key=clear"],capture_output=True).stdout.decode()17 wifi_pass = (re.findall("Key Content : (.*)\r",item))18 wifi_pass = wifi_pass[0]19 info = {'ssid': i, 'key': wifi_pass}20 passwords.append(info)21for i in passwords:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful