Ejemplo n.º 1
0
    def test_vm_types_standard(self):
        # Searching for an instance by name should return an
        # VMType object and searching for a non-existent
        # object should return an empty iterator
        vm_type_name = helpers.get_provider_test_data(self.provider, "vm_type")
        vm_type = self.provider.compute.vm_types.find(name=vm_type_name)[0]

        sit.check_standard_behaviour(self, self.provider.compute.vm_types,
                                     vm_type)
Ejemplo n.º 2
0
    def test_crud_router(self):
        def _cleanup(net, subnet, router, gateway):
            with helpers.cleanup_action(lambda: net.delete()):
                with helpers.cleanup_action(lambda: router.delete()):
                    with helpers.cleanup_action(lambda: subnet.delete()):
                        with helpers.cleanup_action(lambda: gateway.delete()):
                            router.detach_subnet(subnet)
                            router.detach_gateway(gateway)

        label = 'cb-crudrouter-{0}'.format(helpers.get_uuid())
        # Declare these variables and late binding will allow
        # the cleanup method access to the most current values
        net = None
        sn = None
        router = None
        gteway = None
        with helpers.cleanup_action(lambda: _cleanup(net, sn, router, gteway)):
            net = self.provider.networking.networks.create(
                label=label, cidr_block=BaseNetwork.CB_DEFAULT_IPV4RANGE)
            router = self.provider.networking.routers.create(label=label,
                                                             network=net)
            cidr = '10.0.15.0/24'
            sn = net.create_subnet(label=label,
                                   cidr_block=cidr,
                                   zone=helpers.get_provider_test_data(
                                       self.provider, 'placement'))

            # Check basic router properties
            sit.check_standard_behaviour(self,
                                         self.provider.networking.routers,
                                         router)
            if (self.provider.PROVIDER_ID != 'gce'):
                self.assertEqual(
                    router.state, RouterState.DETACHED,
                    "Router {0} state {1} should be {2}.".format(
                        router.id, router.state, RouterState.DETACHED))

                self.assertFalse(
                    router.network_id,
                    "Router {0} should not be assoc. with network {1}".format(
                        router.id, router.network_id))

            self.assertTrue(
                len(router.subnets) == 0,
                "No subnet should be attached to router {1}".format(
                    sn, router))
            router.attach_subnet(sn)
            self.assertTrue(
                len(router.subnets) == 1,
                "Subnet {0} not attached to router {1}".format(sn, router))
            gteway = net.gateways.get_or_create_inet_gateway()
            router.attach_gateway(gteway)
            # TODO: add a check for routes after that's been implemented

        sit.check_delete(self, self.provider.networking.routers, router)
Ejemplo n.º 3
0
    def test_get_and_list_regions(self):
        regions = list(self.provider.compute.regions)
        sit.check_standard_behaviour(
            self, self.provider.compute.regions, regions[-1])

        for region in regions:
            self.assertIsInstance(
                region,
                Region,
                "regions.list() should return a cloudbridge Region")
            self.assertTrue(
                region.name,
                "Region name should be a non-empty string")
    def test_instance_types_standard(self):
        """
        Searching for an instance by name should return an
        InstanceType object and searching for a non-existent
        object should return an empty iterator
        """
        instance_type_name = helpers.get_provider_test_data(
            self.provider, "instance_type")
        inst_type = self.provider.compute.instance_types.find(
            name=instance_type_name)[0]

        sit.check_standard_behaviour(self,
                                     self.provider.compute.instance_types,
                                     inst_type)
Ejemplo n.º 5
0
    def test_get_and_list_regions(self):
        """
        Test whether the region listing methods work,
        and whether zones are returned appropriately.
        """
        regions = list(self.provider.compute.regions)
        sit.check_standard_behaviour(self, self.provider.compute.regions,
                                     regions[-1])

        for region in regions:
            self.assertIsInstance(
                region, Region,
                "regions.list() should return a cloudbridge Region")
            self.assertTrue(region.name,
                            "Region name should be a non-empty string")
    def test_crud_router(self):
        def _cleanup(net, subnet, router, gateway):
            with helpers.cleanup_action(lambda: net.delete()):
                with helpers.cleanup_action(lambda: subnet.delete()):
                    with helpers.cleanup_action(lambda: gateway.delete()):
                        with helpers.cleanup_action(lambda: router.delete()):
                            router.detach_subnet(subnet)
                            router.detach_gateway(gateway)

        name = 'cb_crudrouter-{0}'.format(helpers.get_uuid())
        # Declare these variables and late binding will allow
        # the cleanup method access to the most current values
        net = None
        sn = None
        router = None
        gteway = None
        with helpers.cleanup_action(lambda: _cleanup(net, sn, router, gteway)):
            net = self.provider.networking.networks.create(
                name=name, cidr_block='10.0.0.0/16')
            router = self.provider.networking.routers.create(network=net,
                                                             name=name)
            cidr = '10.0.1.0/24'
            sn = net.create_subnet(name=name,
                                   cidr_block=cidr,
                                   zone=helpers.get_provider_test_data(
                                       self.provider, 'placement'))

            # Check basic router properties
            sit.check_standard_behaviour(self,
                                         self.provider.networking.routers,
                                         router)
            self.assertEqual(
                router.state, RouterState.DETACHED,
                "Router {0} state {1} should be {2}.".format(
                    router.id, router.state, RouterState.DETACHED))

            #             self.assertFalse(
            #                 router.network_id,
            #                 "Router {0} should not be assoc. with a network {1}".format(
            #                     router.id, router.network_id))

            router.attach_subnet(sn)
            gteway = (self.provider.networking.gateways.
                      get_or_create_inet_gateway(name))
            router.attach_gateway(gteway)
            # TODO: add a check for routes after that's been implemented

        sit.check_delete(self, self.provider.networking.routers, router)
Ejemplo n.º 7
0
    def test_crud_router(self):

        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)

        label = 'cb-crudrouter-{0}'.format(helpers.get_uuid())
        # Declare these variables and late binding will allow
        # the cleanup method access to the most current values
        net = None
        sn = None
        router = None
        gteway = None
        with cb_helpers.cleanup_action(
                lambda: _cleanup(net, sn, router, gteway)):
            net = self.provider.networking.networks.create(
                label=label, cidr_block=BaseNetwork.CB_DEFAULT_IPV4RANGE)
            router = self.provider.networking.routers.create(label=label,
                                                             network=net)
            cidr = '10.0.15.0/24'
            sn = net.subnets.create(label=label, cidr_block=cidr)

            # Check basic router properties
            sit.check_standard_behaviour(
                self, self.provider.networking.routers, router)
            if (self.provider.PROVIDER_ID != 'gcp'):
                self.assertEqual(
                    router.state, RouterState.DETACHED,
                    "Router {0} state {1} should be {2}.".format(
                        router.id, router.state, RouterState.DETACHED))

#                 self.assertEqual(
#                     router.network_id, net.id,  "Router {0} should be assoc."
#                     " with network {1}, but is associated with {2}"
#                     .format(router.id, net.id, router.network_id))

                self.assertTrue(
                    len(router.subnets) == 0,
                    "No subnet should be attached to router {1}".format(
                        sn, router)
                )
                router.attach_subnet(sn)
                self.assertTrue(
                    len(router.subnets) == 1,
                    "Subnet {0} not attached to router {1}".format(sn, router)
                )
            gteway = net.gateways.get_or_create()
            router.attach_gateway(gteway)
            # TODO: add a check for routes after that's been implemented

        sit.check_delete(self, self.provider.networking.routers, router)
        # Also make sure that linked resources were properly cleaned up
        sit.check_delete(self, self.provider.networking.subnets, sn)
        sit.check_delete(self, self.provider.networking.networks, net)