1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 from snaps.openstack import create_router
18 from snaps.openstack.create_network import NetworkSettings, SubnetSettings, \
20 from snaps.openstack.create_security_group import SecurityGroupSettings, \
21 SecurityGroupRuleSettings, Direction
22 from snaps.openstack.tests import openstack_tests
23 from snaps.openstack.tests import validation_utils
24 from snaps.openstack.tests.os_source_file_test import OSComponentTestCase
25 from snaps.openstack.utils import keystone_utils
26 from snaps.openstack.utils import neutron_utils
27 from snaps.openstack.utils.neutron_utils import NeutronException
29 __author__ = 'spisarski'
35 class NeutronSmokeTests(OSComponentTestCase):
37 Tests to ensure that the neutron client can communicate with the cloud
40 def test_neutron_connect_success(self):
42 Tests to ensure that the proper credentials can connect.
44 neutron = neutron_utils.neutron_client(self.os_creds)
46 networks = neutron.list_networks()
49 networks = networks.get('networks')
50 for network in networks:
51 if network.get('name') == self.ext_net_name:
53 self.assertTrue(found)
55 def test_neutron_connect_fail(self):
57 Tests to ensure that the improper credentials cannot connect.
59 from snaps.openstack.os_credentials import OSCreds
61 with self.assertRaises(Exception):
62 neutron = neutron_utils.neutron_client(
63 OSCreds(username='user', password='pass', auth_url='url',
64 project_name='project'))
65 neutron.list_networks()
67 def test_retrieve_ext_network_name(self):
69 Tests the neutron_utils.get_external_network_names to ensure the
70 configured self.ext_net_name is contained within the returned list
73 neutron = neutron_utils.neutron_client(self.os_creds)
74 ext_networks = neutron_utils.get_external_networks(neutron)
76 for network in ext_networks:
77 if network.name == self.ext_net_name:
80 self.assertTrue(found)
83 class NeutronUtilsNetworkTests(OSComponentTestCase):
85 Test for creating networks via neutron_utils.py
89 guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
90 self.port_name = str(guid) + '-port'
91 self.neutron = neutron_utils.neutron_client(self.os_creds)
93 self.net_config = openstack_tests.get_pub_net_config(
94 net_name=guid + '-pub-net')
98 Cleans the remote OpenStack objects
101 neutron_utils.delete_network(self.neutron, self.network)
103 def test_create_network(self):
105 Tests the neutron_utils.create_neutron_net() function
107 self.network = neutron_utils.create_network(
108 self.neutron, self.os_creds, self.net_config.network_settings)
109 self.assertEqual(self.net_config.network_settings.name,
111 self.assertTrue(validate_network(
112 self.neutron, self.net_config.network_settings.name, True))
114 def test_create_network_empty_name(self):
116 Tests the neutron_utils.create_neutron_net() function with an empty
119 with self.assertRaises(Exception):
120 self.network = neutron_utils.create_network(
121 self.neutron, self.os_creds,
122 network_settings=NetworkSettings(name=''))
124 def test_create_network_null_name(self):
126 Tests the neutron_utils.create_neutron_net() function when the network
129 with self.assertRaises(Exception):
130 self.network = neutron_utils.create_network(
131 self.neutron, self.os_creds,
132 network_settings=NetworkSettings())
135 class NeutronUtilsSubnetTests(OSComponentTestCase):
137 Test for creating networks with subnets via neutron_utils.py
141 guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
142 self.port_name = str(guid) + '-port'
143 self.neutron = neutron_utils.neutron_client(self.os_creds)
146 self.net_config = openstack_tests.get_pub_net_config(
147 net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet',
148 external_net=self.ext_net_name)
152 Cleans the remote OpenStack objects
156 neutron_utils.delete_subnet(self.neutron, self.subnet)
161 neutron_utils.delete_network(self.neutron, self.network)
165 def test_create_subnet(self):
167 Tests the neutron_utils.create_neutron_net() function
169 self.network = neutron_utils.create_network(
170 self.neutron, self.os_creds, self.net_config.network_settings)
171 self.assertEqual(self.net_config.network_settings.name,
173 self.assertTrue(validate_network(
174 self.neutron, self.net_config.network_settings.name, True))
176 subnet_setting = self.net_config.network_settings.subnet_settings[0]
177 self.subnet = neutron_utils.create_subnet(
178 self.neutron, subnet_setting, self.os_creds, network=self.network)
179 self.assertTrue(validate_subnet(
180 self.neutron, subnet_setting.name, subnet_setting.cidr, True))
182 subnet_query1 = neutron_utils.get_subnet(
183 self.neutron, subnet_name=subnet_setting.name)
184 self.assertEqual(self.subnet, subnet_query1)
186 subnet_query2 = neutron_utils.get_subnets_by_network(self.neutron,
188 self.assertIsNotNone(subnet_query2)
189 self.assertEqual(1, len(subnet_query2))
190 self.assertEqual(self.subnet, subnet_query2[0])
192 def test_create_subnet_null_name(self):
194 Tests the neutron_utils.create_neutron_subnet() function for an
195 Exception when the subnet name is None
197 self.network = neutron_utils.create_network(
198 self.neutron, self.os_creds, self.net_config.network_settings)
199 self.assertEqual(self.net_config.network_settings.name,
201 self.assertTrue(validate_network(
202 self.neutron, self.net_config.network_settings.name, True))
204 with self.assertRaises(Exception):
205 SubnetSettings(cidr=self.net_config.subnet_cidr)
207 def test_create_subnet_empty_name(self):
209 Tests the neutron_utils.create_neutron_net() function with an empty
212 self.network = neutron_utils.create_network(
213 self.neutron, self.os_creds, self.net_config.network_settings)
214 self.assertEqual(self.net_config.network_settings.name,
216 self.assertTrue(validate_network(
217 self.neutron, self.net_config.network_settings.name, True))
219 subnet_setting = self.net_config.network_settings.subnet_settings[0]
220 self.subnet = neutron_utils.create_subnet(
221 self.neutron, subnet_setting, self.os_creds, network=self.network)
222 self.assertTrue(validate_subnet(
223 self.neutron, subnet_setting.name, subnet_setting.cidr, True))
224 self.assertFalse(validate_subnet(
225 self.neutron, '', subnet_setting.cidr, True))
227 subnet_query1 = neutron_utils.get_subnet(
228 self.neutron, subnet_name=subnet_setting.name)
229 self.assertEqual(self.subnet, subnet_query1)
231 subnet_query2 = neutron_utils.get_subnets_by_network(self.neutron,
233 self.assertIsNotNone(subnet_query2)
234 self.assertEqual(1, len(subnet_query2))
235 self.assertEqual(self.subnet, subnet_query2[0])
237 def test_create_subnet_null_cidr(self):
239 Tests the neutron_utils.create_neutron_subnet() function for an
240 Exception when the subnet CIDR value is None
242 self.network = neutron_utils.create_network(
243 self.neutron, self.os_creds, self.net_config.network_settings)
244 self.assertEqual(self.net_config.network_settings.name,
246 self.assertTrue(validate_network(
247 self.neutron, self.net_config.network_settings.name, True))
249 with self.assertRaises(Exception):
250 sub_sets = SubnetSettings(
251 cidr=None, name=self.net_config.subnet_name)
252 neutron_utils.create_subnet(
253 self.neutron, sub_sets, self.os_creds, network=self.network)
255 def test_create_subnet_empty_cidr(self):
257 Tests the neutron_utils.create_neutron_subnet() function for an
258 Exception when the subnet CIDR value is empty
260 self.network = neutron_utils.create_network(
261 self.neutron, self.os_creds, self.net_config.network_settings)
262 self.assertEqual(self.net_config.network_settings.name,
264 self.assertTrue(validate_network(
265 self.neutron, self.net_config.network_settings.name, True))
267 with self.assertRaises(Exception):
268 sub_sets = SubnetSettings(
269 cidr='', name=self.net_config.subnet_name)
270 neutron_utils.create_subnet(self.neutron, sub_sets, self.os_creds,
271 network=self.network)
274 class NeutronUtilsRouterTests(OSComponentTestCase):
276 Test for creating routers via neutron_utils.py
280 guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
281 self.port_name = str(guid) + '-port'
282 self.neutron = neutron_utils.neutron_client(self.os_creds)
287 self.interface_router = None
288 self.net_config = openstack_tests.get_pub_net_config(
289 net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet',
290 router_name=guid + '-pub-router', external_net=self.ext_net_name)
294 Cleans the remote OpenStack objects
296 if self.interface_router:
297 neutron_utils.remove_interface_router(self.neutron, self.router,
302 neutron_utils.delete_router(self.neutron, self.router)
303 validate_router(self.neutron, self.router.name, False)
309 neutron_utils.delete_port(self.neutron, self.port)
315 neutron_utils.delete_subnet(self.neutron, self.subnet)
321 neutron_utils.delete_network(self.neutron, self.network)
325 def test_create_router_simple(self):
327 Tests the neutron_utils.create_neutron_net() function when an external
330 self.router = neutron_utils.create_router(
331 self.neutron, self.os_creds, self.net_config.router_settings)
332 validate_router(self.neutron, self.net_config.router_settings.name,
335 def test_create_router_with_public_interface(self):
337 Tests the neutron_utils.create_neutron_net() function when an external
340 subnet_setting = self.net_config.network_settings.subnet_settings[0]
341 self.net_config = openstack_tests.OSNetworkConfig(
342 self.net_config.network_settings.name,
345 self.net_config.router_settings.name,
347 self.router = neutron_utils.create_router(
348 self.neutron, self.os_creds, self.net_config.router_settings)
349 validate_router(self.neutron, self.net_config.router_settings.name,
352 ext_net = neutron_utils.get_network(
353 self.neutron, network_name=self.ext_net_name)
355 self.router.external_gateway_info['network_id'], ext_net.id)
357 def test_create_router_empty_name(self):
359 Tests the neutron_utils.create_neutron_net() function
361 with self.assertRaises(Exception):
362 this_router_settings = create_router.RouterSettings(name='')
363 self.router = neutron_utils.create_router(self.neutron,
365 this_router_settings)
367 def test_create_router_null_name(self):
369 Tests the neutron_utils.create_neutron_subnet() function when the
370 subnet CIDR value is None
372 with self.assertRaises(Exception):
373 this_router_settings = create_router.RouterSettings()
374 self.router = neutron_utils.create_router(self.neutron,
376 this_router_settings)
377 validate_router(self.neutron, None, True)
379 def test_add_interface_router(self):
381 Tests the neutron_utils.add_interface_router() function
383 self.network = neutron_utils.create_network(
384 self.neutron, self.os_creds, self.net_config.network_settings)
385 self.assertEqual(self.net_config.network_settings.name,
387 self.assertTrue(validate_network(
388 self.neutron, self.net_config.network_settings.name, True))
390 subnet_setting = self.net_config.network_settings.subnet_settings[0]
391 self.subnet = neutron_utils.create_subnet(
392 self.neutron, subnet_setting,
393 self.os_creds, self.network)
394 self.assertTrue(validate_subnet(
395 self.neutron, subnet_setting.name, subnet_setting.cidr, True))
397 self.router = neutron_utils.create_router(
398 self.neutron, self.os_creds, self.net_config.router_settings)
399 validate_router(self.neutron, self.net_config.router_settings.name,
402 self.interface_router = neutron_utils.add_interface_router(
403 self.neutron, self.router, self.subnet)
404 validate_interface_router(self.interface_router, self.router,
407 def test_add_interface_router_null_router(self):
409 Tests the neutron_utils.add_interface_router() function for an
410 Exception when the router value is None
412 self.network = neutron_utils.create_network(
413 self.neutron, self.os_creds, self.net_config.network_settings)
414 self.assertEqual(self.net_config.network_settings.name,
416 self.assertTrue(validate_network(
417 self.neutron, self.net_config.network_settings.name, True))
419 subnet_setting = self.net_config.network_settings.subnet_settings[0]
420 self.subnet = neutron_utils.create_subnet(
421 self.neutron, subnet_setting,
422 self.os_creds, self.network)
423 self.assertTrue(validate_subnet(
424 self.neutron, subnet_setting.name, subnet_setting.cidr, True))
426 with self.assertRaises(NeutronException):
427 self.interface_router = neutron_utils.add_interface_router(
428 self.neutron, self.router, self.subnet)
430 def test_add_interface_router_null_subnet(self):
432 Tests the neutron_utils.add_interface_router() function for an
433 Exception when the subnet value is None
435 self.network = neutron_utils.create_network(
436 self.neutron, self.os_creds, self.net_config.network_settings)
437 self.assertEqual(self.net_config.network_settings.name,
439 self.assertTrue(validate_network(
440 self.neutron, self.net_config.network_settings.name, True))
442 self.router = neutron_utils.create_router(
443 self.neutron, self.os_creds, self.net_config.router_settings)
444 validate_router(self.neutron, self.net_config.router_settings.name,
447 with self.assertRaises(NeutronException):
448 self.interface_router = neutron_utils.add_interface_router(
449 self.neutron, self.router, self.subnet)
451 def test_create_port(self):
453 Tests the neutron_utils.create_port() function
455 self.network = neutron_utils.create_network(
456 self.neutron, self.os_creds, self.net_config.network_settings)
457 self.assertEqual(self.net_config.network_settings.name,
459 self.assertTrue(validate_network(
460 self.neutron, self.net_config.network_settings.name, True))
462 subnet_setting = self.net_config.network_settings.subnet_settings[0]
463 self.subnet = neutron_utils.create_subnet(
464 self.neutron, subnet_setting, self.os_creds, self.network)
465 self.assertTrue(validate_subnet(
466 self.neutron, subnet_setting.name, subnet_setting.cidr, True))
468 self.port = neutron_utils.create_port(
469 self.neutron, self.os_creds, PortSettings(
472 'subnet_name': subnet_setting.name,
474 network_name=self.net_config.network_settings.name))
475 validate_port(self.neutron, self.port, self.port_name)
477 def test_create_port_empty_name(self):
479 Tests the neutron_utils.create_port() function
481 self.network = neutron_utils.create_network(
482 self.neutron, self.os_creds, self.net_config.network_settings)
483 self.assertEqual(self.net_config.network_settings.name,
485 self.assertTrue(validate_network(
486 self.neutron, self.net_config.network_settings.name, True))
488 subnet_setting = self.net_config.network_settings.subnet_settings[0]
489 self.subnet = neutron_utils.create_subnet(
490 self.neutron, subnet_setting, self.os_creds, self.network)
491 self.assertTrue(validate_subnet(self.neutron, subnet_setting.name,
492 subnet_setting.cidr, True))
494 self.port = neutron_utils.create_port(
495 self.neutron, self.os_creds, PortSettings(
497 network_name=self.net_config.network_settings.name,
499 'subnet_name': subnet_setting.name,
501 validate_port(self.neutron, self.port, self.port_name)
503 def test_create_port_null_name(self):
505 Tests the neutron_utils.create_port() function for an Exception when
506 the port name value is None
508 self.network = neutron_utils.create_network(
509 self.neutron, self.os_creds, self.net_config.network_settings)
510 self.assertEqual(self.net_config.network_settings.name,
512 self.assertTrue(validate_network(
513 self.neutron, self.net_config.network_settings.name, True))
515 subnet_setting = self.net_config.network_settings.subnet_settings[0]
516 self.subnet = neutron_utils.create_subnet(
517 self.neutron, subnet_setting,
518 self.os_creds, self.network)
519 self.assertTrue(validate_subnet(
520 self.neutron, subnet_setting.name, subnet_setting.cidr, True))
522 with self.assertRaises(Exception):
523 self.port = neutron_utils.create_port(
524 self.neutron, self.os_creds,
526 network_name=self.net_config.network_settings.name,
528 'subnet_name': subnet_setting.name,
531 def test_create_port_null_network_object(self):
533 Tests the neutron_utils.create_port() function for an Exception when
534 the network object is None
536 with self.assertRaises(Exception):
537 self.port = neutron_utils.create_port(
538 self.neutron, self.os_creds,
541 network_name=self.net_config.network_settings.name,
544 self.net_config.network_settings.subnet_settings[
548 def test_create_port_null_ip(self):
550 Tests the neutron_utils.create_port() function for an Exception when
553 self.network = neutron_utils.create_network(
554 self.neutron, self.os_creds, self.net_config.network_settings)
555 self.assertEqual(self.net_config.network_settings.name,
557 self.assertTrue(validate_network(
558 self.neutron, self.net_config.network_settings.name, True))
560 subnet_setting = self.net_config.network_settings.subnet_settings[0]
561 self.subnet = neutron_utils.create_subnet(
562 self.neutron, subnet_setting,
563 self.os_creds, self.network)
564 self.assertTrue(validate_subnet(
565 self.neutron, subnet_setting.name, subnet_setting.cidr, True))
567 with self.assertRaises(Exception):
568 self.port = neutron_utils.create_port(
569 self.neutron, self.os_creds,
572 network_name=self.net_config.network_settings.name,
574 'subnet_name': subnet_setting.name,
577 def test_create_port_invalid_ip(self):
579 Tests the neutron_utils.create_port() function for an Exception when
582 self.network = neutron_utils.create_network(
583 self.neutron, self.os_creds, self.net_config.network_settings)
584 self.assertEqual(self.net_config.network_settings.name,
586 self.assertTrue(validate_network(
587 self.neutron, self.net_config.network_settings.name, True))
589 subnet_setting = self.net_config.network_settings.subnet_settings[0]
590 self.subnet = neutron_utils.create_subnet(
591 self.neutron, subnet_setting, self.os_creds, self.network)
592 self.assertTrue(validate_subnet(
593 self.neutron, subnet_setting.name, subnet_setting.cidr, True))
595 with self.assertRaises(Exception):
596 self.port = neutron_utils.create_port(
597 self.neutron, self.os_creds,
600 network_name=self.net_config.network_settings.name,
602 'subnet_name': subnet_setting.name,
605 def test_create_port_invalid_ip_to_subnet(self):
607 Tests the neutron_utils.create_port() function for an Exception when
610 self.network = neutron_utils.create_network(
611 self.neutron, self.os_creds, self.net_config.network_settings)
612 self.assertEqual(self.net_config.network_settings.name,
614 self.assertTrue(validate_network(
615 self.neutron, self.net_config.network_settings.name, True))
617 subnet_setting = self.net_config.network_settings.subnet_settings[0]
618 self.subnet = neutron_utils.create_subnet(
619 self.neutron, subnet_setting, self.os_creds, self.network)
620 self.assertTrue(validate_subnet(
621 self.neutron, subnet_setting.name, subnet_setting.cidr, True))
623 with self.assertRaises(Exception):
624 self.port = neutron_utils.create_port(
625 self.neutron, self.os_creds,
628 network_name=self.net_config.network_settings.name,
630 'subnet_name': subnet_setting.name,
631 'ip': '10.197.123.100'}]))
634 class NeutronUtilsSecurityGroupTests(OSComponentTestCase):
636 Test for creating security groups via neutron_utils.py
640 guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
641 self.sec_grp_name = guid + 'name'
643 self.security_groups = list()
644 self.security_group_rules = list()
645 self.neutron = neutron_utils.neutron_client(self.os_creds)
646 self.keystone = keystone_utils.keystone_client(self.os_creds)
650 Cleans the remote OpenStack objects
652 for rule in self.security_group_rules:
653 neutron_utils.delete_security_group_rule(self.neutron, rule)
655 for security_group in self.security_groups:
657 neutron_utils.delete_security_group(self.neutron,
662 def test_create_delete_simple_sec_grp(self):
664 Tests the neutron_utils.create_security_group() function
666 sec_grp_settings = SecurityGroupSettings(name=self.sec_grp_name)
667 security_group = neutron_utils.create_security_group(self.neutron,
671 self.assertTrue(sec_grp_settings.name, security_group.name)
673 sec_grp_get = neutron_utils.get_security_group(
674 self.neutron, sec_grp_settings=sec_grp_settings)
675 self.assertIsNotNone(sec_grp_get)
676 self.assertTrue(validation_utils.objects_equivalent(
677 security_group, sec_grp_get))
679 neutron_utils.delete_security_group(self.neutron, security_group)
680 sec_grp_get = neutron_utils.get_security_group(
681 self.neutron, sec_grp_settings=sec_grp_settings)
682 self.assertIsNone(sec_grp_get)
684 def test_create_sec_grp_no_name(self):
686 Tests the SecurityGroupSettings constructor and
687 neutron_utils.create_security_group() function to ensure that
688 attempting to create a security group without a name will raise an
691 with self.assertRaises(Exception):
692 sec_grp_settings = SecurityGroupSettings()
693 self.security_groups.append(
694 neutron_utils.create_security_group(self.neutron,
698 def test_create_sec_grp_no_rules(self):
700 Tests the neutron_utils.create_security_group() function
702 sec_grp_settings = SecurityGroupSettings(name=self.sec_grp_name,
703 description='hello group')
704 self.security_groups.append(
705 neutron_utils.create_security_group(self.neutron, self.keystone,
708 self.assertTrue(sec_grp_settings.name, self.security_groups[0].name)
709 self.assertEqual(sec_grp_settings.name, self.security_groups[0].name)
711 sec_grp_get = neutron_utils.get_security_group(
712 self.neutron, sec_grp_settings=sec_grp_settings)
713 self.assertIsNotNone(sec_grp_get)
714 self.assertEqual(self.security_groups[0], sec_grp_get)
716 def test_create_sec_grp_one_rule(self):
718 Tests the neutron_utils.create_security_group() function
721 sec_grp_rule_settings = SecurityGroupRuleSettings(
722 sec_grp_name=self.sec_grp_name, direction=Direction.ingress)
723 sec_grp_settings = SecurityGroupSettings(
724 name=self.sec_grp_name, description='hello group',
725 rule_settings=[sec_grp_rule_settings])
727 self.security_groups.append(
728 neutron_utils.create_security_group(self.neutron, self.keystone,
730 free_rules = neutron_utils.get_rules_by_security_group(
731 self.neutron, self.security_groups[0])
732 for free_rule in free_rules:
733 self.security_group_rules.append(free_rule)
735 self.security_group_rules.append(
736 neutron_utils.create_security_group_rule(
737 self.neutron, sec_grp_settings.rule_settings[0]))
739 # Refresh object so it is populated with the newly added rule
740 security_group = neutron_utils.get_security_group(
741 self.neutron, sec_grp_settings=sec_grp_settings)
743 rules = neutron_utils.get_rules_by_security_group(self.neutron,
747 validation_utils.objects_equivalent(
748 self.security_group_rules, rules))
750 self.assertTrue(sec_grp_settings.name, security_group.name)
752 sec_grp_get = neutron_utils.get_security_group(
753 self.neutron, sec_grp_settings=sec_grp_settings)
754 self.assertIsNotNone(sec_grp_get)
755 self.assertEqual(security_group, sec_grp_get)
757 def test_get_sec_grp_by_id(self):
759 Tests the neutron_utils.create_security_group() function
762 self.security_groups.append(neutron_utils.create_security_group(
763 self.neutron, self.keystone,
764 SecurityGroupSettings(name=self.sec_grp_name + '-1',
765 description='hello group')))
766 self.security_groups.append(neutron_utils.create_security_group(
767 self.neutron, self.keystone,
768 SecurityGroupSettings(name=self.sec_grp_name + '-2',
769 description='hello group')))
771 sec_grp_1b = neutron_utils.get_security_group_by_id(
772 self.neutron, self.security_groups[0].id)
773 sec_grp_2b = neutron_utils.get_security_group_by_id(
774 self.neutron, self.security_groups[1].id)
776 self.assertEqual(self.security_groups[0].id, sec_grp_1b.id)
777 self.assertEqual(self.security_groups[1].id, sec_grp_2b.id)
780 class NeutronUtilsFloatingIpTests(OSComponentTestCase):
782 Test basic nova keypair functionality
787 Instantiates the CreateImage object that is responsible for downloading
788 and creating an OS image file within OpenStack
790 self.neutron = neutron_utils.neutron_client(self.os_creds)
791 self.floating_ip = None
795 Cleans the image and downloaded image file
799 neutron_utils.delete_floating_ip(
800 self.neutron, self.floating_ip)
804 def test_floating_ips(self):
806 Tests the creation of a floating IP
809 initial_fips = neutron_utils.get_floating_ips(self.neutron)
811 self.floating_ip = neutron_utils.create_floating_ip(self.neutron,
813 all_fips = neutron_utils.get_floating_ips(self.neutron)
814 self.assertEqual(len(initial_fips) + 1, len(all_fips))
815 returned = neutron_utils.get_floating_ip(self.neutron,
817 self.assertEqual(self.floating_ip.id, returned.id)
818 self.assertEqual(self.floating_ip.ip, returned.ip)
826 def validate_network(neutron, name, exists):
828 Returns true if a network for a given name DOES NOT exist if the exists
829 parameter is false conversely true. Returns false if a network for a given
830 name DOES exist if the exists parameter is true conversely false.
831 :param neutron: The neutron client
832 :param name: The expected network name
833 :param exists: Whether or not the network name should exist or not
836 network = neutron_utils.get_network(neutron, network_name=name)
837 if exists and network:
839 if not exists and not network:
844 def validate_subnet(neutron, name, cidr, exists):
846 Returns true if a subnet for a given name DOES NOT exist if the exists
847 parameter is false conversely true. Returns false if a subnet for a given
848 name DOES exist if the exists parameter is true conversely false.
849 :param neutron: The neutron client
850 :param name: The expected subnet name
851 :param cidr: The expected CIDR value
852 :param exists: Whether or not the network name should exist or not
855 subnet = neutron_utils.get_subnet(neutron, subnet_name=name)
856 if exists and subnet and subnet.name == name:
857 return subnet.cidr == cidr
858 if not exists and not subnet:
863 def validate_router(neutron, name, exists):
865 Returns true if a router for a given name DOES NOT exist if the exists
866 parameter is false conversely true. Returns false if a router for a given
867 name DOES exist if the exists parameter is true conversely false.
868 :param neutron: The neutron client
869 :param name: The expected router name
870 :param exists: Whether or not the network name should exist or not
873 router = neutron_utils.get_router(neutron, router_name=name)
874 if exists and router:
879 def validate_interface_router(interface_router, router, subnet):
881 Returns true if the router ID & subnet ID have been properly included into
882 the interface router object
883 :param interface_router: the SNAPS-OO InterfaceRouter domain object
884 :param router: to validate against the interface_router
885 :param subnet: to validate against the interface_router
886 :return: True if both IDs match else False
888 subnet_id = interface_router.subnet_id
889 router_id = interface_router.port_id
891 return subnet.id == subnet_id and router.id == router_id
894 def validate_port(neutron, port_obj, this_port_name):
896 Returns true if a port for a given name DOES NOT exist if the exists
897 parameter is false conversely true. Returns false if a port for a given
898 name DOES exist if the exists parameter is true conversely false.
899 :param neutron: The neutron client
900 :param port_obj: The port object to lookup
901 :param this_port_name: The expected router name
904 os_ports = neutron.list_ports()
905 for os_port, os_port_insts in os_ports.items():
906 for os_inst in os_port_insts:
907 if os_inst['id'] == port_obj.id:
908 return os_inst['name'] == this_port_name