Esempio n. 1
0
 def _cleanup(net, subnet, router, gateway):
     with cb_helpers.cleanup_action(
             lambda: helpers.cleanup_network(net)):
         with cb_helpers.cleanup_action(
                 lambda: helpers.cleanup_subnet(subnet)):
             with cb_helpers.cleanup_action(lambda: router.delete()):
                 with cb_helpers.cleanup_action(
                         lambda: helpers.cleanup_gateway(gateway)):
                     router.detach_subnet(subnet)
                     router.detach_gateway(gateway)
Esempio n. 2
0
    def test_network_properties(self):
        label = 'cb-propnetwork-{0}'.format(helpers.get_uuid())
        subnet_label = 'cb-propsubnet-{0}'.format(helpers.get_uuid())
        net = self.provider.networking.networks.create(
            label=label, cidr_block=BaseNetwork.CB_DEFAULT_IPV4RANGE)
        with cb_helpers.cleanup_action(lambda: helpers.cleanup_network(net)):
            net.wait_till_ready()
            self.assertEqual(
                net.state, 'available',
                "Network in state '%s', yet should be 'available'" % net.state)

            sit.check_repr(self, net)

            self.assertIn(
                net.cidr_block, ['', BaseNetwork.CB_DEFAULT_IPV4RANGE],
                "Network CIDR %s does not contain the expected value %s." %
                (net.cidr_block, BaseNetwork.CB_DEFAULT_IPV4RANGE))

            cidr = '10.0.20.0/24'
            sn = net.subnets.create(label=subnet_label, cidr_block=cidr)
            with cb_helpers.cleanup_action(lambda: helpers.cleanup_subnet(sn)):
                self.assertTrue(
                    sn in net.subnets,
                    "Subnet ID %s should be listed in network subnets %s." %
                    (sn.id, net.subnets))

                self.assertTrue(
                    sn in self.provider.networking.subnets.list(network=net),
                    "Subnet ID %s should be included in the subnets list %s." %
                    (sn.id, self.provider.networking.subnets.list(net)))

                self.assertListEqual(
                    list(net.subnets), [sn],
                    "Network should have exactly one subnet: %s." % sn.id)

                self.assertEqual(
                    net.id, sn.network_id,
                    "Network ID %s and subnet's network id %s should be"
                    " equal." % (net.id, sn.network_id))

                self.assertEqual(
                    net, sn.network,
                    "Network obj %s and subnet's parent net obj %s"
                    " should be equal." % (net, sn.network))

                self.assertEqual(
                    cidr, sn.cidr_block,
                    "Should be exact cidr block that was requested")

                self.assertTrue(
                    BaseNetwork.cidr_blocks_overlap(cidr, sn.cidr_block),
                    "Subnet's CIDR %s should overlap the specified one %s." %
                    (sn.cidr_block, cidr))