示例#1
0
    def test_service_get_composable_networks(self):
        orm = self.make_coreapi()
        deployment = orm.Deployment(name="test_deployment")
        deployment.save()
        controller = orm.Controller(name="test_controller",
                                    deployment_id=deployment.id)
        controller.save()
        site = orm.Site(name="testsite")
        site.save()
        user = orm.User(
            email="fake_" + "".join(
                random.choice(string.ascii_uppercase + string.digits)
                for _ in range(10)),
            site_id=site.id,
        )
        user.save()
        vsg_access_template = orm.NetworkTemplate(name="vsg_access",
                                                  vtn_kind="VSG")
        vsg_access_template.save()
        service_one = orm.Service(name="service_one")
        service_one.save()
        slice_one = orm.Slice(
            name="testsite_sliceone",
            service_id=service_one.id,
            site_id=site.id,
            creator_id=user.id,
            network="noauto",
        )
        slice_one.save()
        network_one = orm.Network(
            name="testsite_sliceone_access",
            owner_id=slice_one.id,
            template_id=vsg_access_template.id,
        )
        network_one.save()
        ns = orm.NetworkSlice(slice_id=slice_one.id, network_id=network_one.id)
        ns.save()
        cn_one = orm.ControllerNetwork(network_id=network_one.id,
                                       controller_id=controller.id)
        cn_one.save()

        if USE_FAKE_STUB:
            # fake_Stub doesn't handle reverse foreign keys
            service_one.slices_ids = [slice_one.id]
            slice_one.networks_ids = [network_one.id]
            network_one.controllernetworks_ids = [cn_one.id]

        # make sure we're using a fresh copy of the object, with all its foreign keys filled in
        service_one = orm.Service.objects.get(id=service_one.id)

        cns = service_one.get_composable_networks()
        self.assertEqual(len(cns), 1)
        self.assertEqual(cns[0].id, network_one.id)
示例#2
0
    def test_service_get_service_instance_class(self):
        orm = self.make_coreapi()
        deployment = orm.Deployment(name="test_deployment")
        deployment.save()
        controller = orm.Controller(name="test_controller",
                                    deployment_id=deployment.id)
        controller.save()
        site = orm.Site(name="testsite")
        site.save()
        user = orm.User(email="fake_" + ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(10)),
                        site_id=site.id)
        user.save()
        vsg_access_template = orm.NetworkTemplate(name="vsg_access",
                                                  vtn_kind="VSG")
        vsg_access_template.save()
        service_one = orm.Service(name="service_one")
        service_one.save()

        self.assertEqual(service_one.get_service_instance_class().model_name,
                         "ServiceInstance")