예제 #1
0
    def test_crud_bucket_object_properties(self):
        # Create a new bucket, upload some contents into the bucket, and
        # check whether list properly detects the new content.
        # Delete everything afterwards.
        name = "cbtestbucketobjs-{0}".format(helpers.get_uuid())
        test_bucket = self.provider.storage.buckets.create(name)

        # ensure that the bucket is empty
        objects = test_bucket.objects.list()
        self.assertEqual([], objects)

        with cb_helpers.cleanup_action(lambda: test_bucket.delete()):
            obj_name_prefix = "hello"
            obj_name = obj_name_prefix + "_world.txt"
            obj = test_bucket.objects.create(obj_name)

            with cb_helpers.cleanup_action(lambda: obj.delete()):
                # TODO: This is wrong. We shouldn't have to have a separate
                # call to upload some content before being able to delete
                # the content. Maybe the create_object method should accept
                # the file content as a parameter.
                obj.upload("dummy content")
                objs = test_bucket.objects.list()

                self.assertTrue(
                    isinstance(objs[0].size, int),
                    "Object size property needs to be a int, not {0}".format(
                        type(objs[0].size)))
                # GET an object as the size property implementation differs
                # for objects returned by LIST and GET.
                obj = test_bucket.objects.get(objs[0].id)
                self.assertTrue(
                    isinstance(objs[0].size, int),
                    "Object size property needs to be an int, not {0}".format(
                        type(obj.size)))
                self.assertTrue(
                    datetime.strptime(objs[0].last_modified[:23],
                                      "%Y-%m-%dT%H:%M:%S.%f"),
                    "Object's last_modified field format {0} not matching.".
                    format(objs[0].last_modified))

                # check iteration
                iter_objs = list(test_bucket.objects)
                self.assertListEqual(iter_objs, objs)

                obj_too = test_bucket.objects.get(obj_name)
                self.assertTrue(
                    isinstance(obj_too, BucketObject),
                    "Did not get object {0} of expected type.".format(obj_too))

                prefix_filtered_list = test_bucket.objects.list(
                    prefix=obj_name_prefix)
                self.assertTrue(
                    len(objs) == len(prefix_filtered_list) == 1,
                    'The number of objects returned by list function, '
                    'with and without a prefix, are expected to be equal, '
                    'but its detected otherwise.')

            sit.check_delete(self, test_bucket.objects, obj)
예제 #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)
    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)
예제 #4
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)