예제 #1
0
파일: manual.py 프로젝트: cargious/ocf
    def setUp(self):
        """
        Load up a DB for the OM.
        Create a client to talk to the OM.
        """
        
        
        call_env_command(test_settings.OM_PROJECT_DIR, "flush",
                         interactive=False)
        self.om_env = Env(test_settings.OM_PROJECT_DIR)
        self.om_env.switch_to()
        
        from openflow.optin_manager.dummyfv.models import DummyFV
        from openflow.optin_manager.xmlrpc_server.models import FVServerProxy
        from openflow.optin_manager.users.models import UserProfile, Priority
        from django.contrib.auth.models import User 

        # Create the clearinghouse user
        username = "******"
        password = "******"
        u = User.objects.create(username=username)
        u.set_password(password)
        u.save()
        
        profile = UserProfile.get_or_create_profile(u) 
        profile.is_clearinghouse_user = True
        profile.save()
        self.om_client = xmlrpclib.ServerProxy(
            SCHEME + "://%s:%s@%s:%s/xmlrpc/xmlrpc/" % (
                username, password, test_settings.HOST, test_settings.OM_PORT
            )
        )
        
        #create admin user: use this to look at DBs through admin interface
        username = "******"
        password = "******"
        u = User.objects.create_superuser(username, "*****@*****.**", password)
        u.save()
        profile = UserProfile.get_or_create_profile(u) 
        profile.is_net_admin = True
        profile.supervisor = u
        profile.max_priority_level = Priority.Aggregate_Admin
        profile.admin_position = "Stanford Aggregate Admin"
        profile.save()      
         
         
        # Create dummy FVs
        for i in range(test_settings.NUM_DUMMY_FVS):
            fv = DummyFV.objects.create()
            # Load up a fake topology in the Dummy FV
            fv.populateTopology(10, 20, use_random=test_settings.USE_RANDOM)
            
            # create fake users for the Dummy FV
            username = "******" % i
            password = "******"
            u = User.objects.create(username=username)
            u.set_password(password)
            u.save()

            # Create the FV proxy connection
            FVServerProxy.objects.create(
                name="Flowvisor %s" % i,
                username=username,
                password=password,
                url = "test://%s:%s/dummyfv/%s/xmlrpc/" % (
                    test_settings.HOST, 8000, fv.id,
                ),
            )
예제 #2
0
파일: gapi.py 프로젝트: cargious/ocf
    def setUp(self):
        """
        Load the DB fixtures for the AM (running using Apache).
        Create an xml-rpc client to talk to the AM Proxy through GAPI.
        Run the test Expedient, and create client to talk to it.
        """

        import time, httplib, os

        call_env_command(settings.CH_PROJECT_DIR, "flush", interactive=False)
        call_env_command(settings.CH_PROJECT_DIR, "syncdb", interactive=False)

        logger.debug("setup started")

        # now we can import django stuff
        from django.core.urlresolvers import reverse
        from django.conf import settings as djangosettings
        from openflow.plugin.models import OpenFlowAggregate

        self.assertEqual(OpenFlowAggregate.objects.all().count(), 0)

        self.create_users()

        self.browser = Browser()
        self.browser.login(get_base_url(reverse("auth_login")),
                           username="******",
                           password="******")

        self.setup_dummy_oms()

        # store the trusted CA dir
        self.before = os.listdir(djangosettings.XMLRPC_TRUSTED_CA_PATH)

        # Create the ssl certificates
        cmd = "make -C %s" % settings.SSL_DIR
        run_cmd(cmd).wait()

        # add the certificate to apache's certificate dir
        try:
            os.unlink(join(settings.APACHE_CERTS_DIR, "test-ca.crt"))
        except OSError as e:
            if "Errno 2" in "%s" % e:
                pass
            else:
                raise
        os.symlink(os.path.abspath(join(settings.SSL_DIR, "ca.crt")),
                   join(settings.APACHE_CERTS_DIR, "test-ca.crt"))
        subprocess.call(shlex.split("make -C %s" % settings.APACHE_CERTS_DIR))

        # run the CH
        kill_old_procs(settings.GCH_PORT, settings.GAM_PORT)
        cmd = "python %s -u %s -r %s -c %s -k %s -p %s --debug -H 0.0.0.0" % (
            join(settings.GCF_DIR, "gch.py"),
            join(settings.SSL_DIR, "experimenter.crt"),
            join(settings.SSL_DIR, "certs"),
            join(settings.SSL_DIR, "ch.crt"),
            join(settings.SSL_DIR, "ch.key"),
            settings.GCH_PORT,
        )
        self.ch_proc = run_cmd(cmd, pause=True)

        #        # run the AM proxy
        #        cmd = "python %s -r %s -c %s -k %s -p %s -u %s --debug -H 0.0.0.0" % (
        #            join(settings.GCF_DIR, "gam.py"),
        #            join(settings.SSL_DIR, "certs"),
        #            join(settings.SSL_DIR, "server.crt"),
        #            join(settings.SSL_DIR, "server.key"),
        #            settings.GAM_PORT,
        #            SCHEME + "://%s:%s/openflow/gapi/" % (settings.HOST, settings.CH_PORT),
        #        )
        #        self.am_proc = run_cmd(cmd, pause=True)

        ch_host = "%s:%s" % (settings.HOST, settings.GCH_PORT)
        cert_transport = SafeTransportWithCert(
            keyfile=join(settings.SSL_DIR, "experimenter.key"),
            certfile=join(settings.SSL_DIR, "experimenter.crt"))
        self.ch_client = xmlrpclib.ServerProxy("https://" + ch_host + "/",
                                               transport=cert_transport)

        am_host = "%s:%s" % (settings.HOST, settings.CH_PORT)
        cert_transport = SafeTransportWithCert(
            keyfile=join(settings.SSL_DIR, "experimenter.key"),
            certfile=join(settings.SSL_DIR, "experimenter.crt"))
        self.am_client = xmlrpclib.ServerProxy("https://" + am_host +
                                               "/openflow/gapi/",
                                               transport=cert_transport)

        logger.debug("setup done")
예제 #3
0
파일: fulltests.py 프로젝트: cargious/ocf
    def prepare_om(self, proj_dir, flowvisor, ch_username, ch_passwd):
        """
        Flush the OM DB and add a flowvisor and user for the CH
        """
        call_env_command(proj_dir, "flush",
                         interactive=False)
        self.om_env = Env(proj_dir)
        self.om_env.switch_to()
        
        from django.contrib.auth.models import User
        from openflow.optin_manager.users.models import UserProfile
        from openflow.optin_manager.xmlrpc_server.models import FVServerProxy
        from openflow.optin_manager.xmlrpc_server.ch_api import om_ch_translate
        from openflow.optin_manager.opts.models import AdminFlowSpace, UserFlowSpace
        import random
        
        # Create the Expedient user
        u = User.objects.create(username=ch_username)
        u.set_password(ch_passwd)
        u.save()
        profile = UserProfile.get_or_create_profile(u) 
        profile.is_clearinghouse_user = True
        profile.save()
        
        # make a normal user on system
        username = "******"
        password = "******"
        u = User.objects.create(username=username, is_active=True)
        u.set_password(password)
        u.save()

        # assign flowspace to the user
        random.seed(0)
        self.user_ip_src_s = random.randint(0,0x80000000) & 0xFFFF0000
        self.user_ip_src_e = random.randint(0x80000000,0xFFFFFFFF) & 0xFFFF0000
        fields=["dl_src","dl_dst","vlan_id","tp_src","tp_dst"]
        random.shuffle(fields)

        (to_str,from_str,width,om_name,of_name) = om_ch_translate.attr_funcs[fields[0]]
        self.user_field_name = om_name
        self.user_field_s = random.randint(0,2**(width)-3)
        self.user_field_e = self.user_field_s + 1

        # assign full flowspace to admin:
        username = "******"
        password = "******"
        adm = User.objects.create(username=username, is_superuser=True,
                                  is_staff=True, is_active=True)
        adm.set_password(password)
        adm.save()
        profile = UserProfile.get_or_create_profile(adm) 
        profile.is_net_admin = True
        profile.supervisor = adm
        profile.max_priority_level = 7000
        profile.save()
        AdminFlowSpace.objects.create(user=adm)
        
        # assign flowspace to user
        ufs = UserFlowSpace(user=u, ip_src_s=self.user_ip_src_s,
                             ip_src_e=self.user_ip_src_e,approver=adm)
        setattr(ufs,"%s_s"%self.user_field_name,self.user_field_s)
        setattr(ufs,"%s_e"%self.user_field_name,self.user_field_e)
        ufs.save()     

        # Create the FV proxy connection
        fv = FVServerProxy(
            name="Flowvisor",
            username=flowvisor["username"],
            password=flowvisor["password"],
            url="https://%s:%s/xmlrpc" % (
                flowvisor["host"], flowvisor["xmlrpc_port"],
            ),
            verify_certs=False,
        )
        fv.save()
        
        self.om_client = xmlrpclib.ServerProxy(
            SCHEME+"://%s:%s@%s:%s/xmlrpc/xmlrpc/" % (
                ch_username, ch_passwd,
                test_settings.HOST, test_settings.OM_PORT,
            )
        )
        
        self.om_env.switch_from()
예제 #4
0
    def setUp(self):
        """
        Load the DB fixtures for the AM (running using Apache).
        Create an xml-rpc client to talk to the AM Proxy through GAPI.
        Run the test Expedient, and create client to talk to it.
        """
        
        import time, httplib, os
        
        call_env_command(settings.CH_PROJECT_DIR, "flush", interactive=False)
        call_env_command(settings.CH_PROJECT_DIR, "syncdb", interactive=False)

        logger.debug("setup started")
        
        # now we can import django stuff
        from django.core.urlresolvers import reverse
        from django.conf import settings as djangosettings
        from openflow.plugin.models import OpenFlowAggregate

        self.assertEqual(OpenFlowAggregate.objects.all().count(), 0)

        self.create_users()
        
        self.browser = Browser()
        self.browser.login(get_base_url(reverse("auth_login")),
                           username="******",
                           password="******")
        
        self.setup_dummy_oms()
        
        # store the trusted CA dir
        self.before = os.listdir(djangosettings.XMLRPC_TRUSTED_CA_PATH)
        
        # Create the ssl certificates
        cmd = "make -C %s" % settings.SSL_DIR
        run_cmd(cmd).wait()
        
        # add the certificate to apache's certificate dir
        try:
            os.unlink(join(settings.APACHE_CERTS_DIR, "test-ca.crt"))
        except OSError as e:
            if "Errno 2" in "%s" % e:
                pass
            else:
                raise
        os.symlink(
            os.path.abspath(join(settings.SSL_DIR, "ca.crt")),
            join(settings.APACHE_CERTS_DIR, "test-ca.crt")
        )
        subprocess.call(shlex.split("make -C %s" % settings.APACHE_CERTS_DIR))
        
        # run the CH
        kill_old_procs(settings.GCH_PORT, settings.GAM_PORT)
        cmd = "python %s -u %s -r %s -c %s -k %s -p %s --debug -H 0.0.0.0" % (
            join(settings.GCF_DIR, "gch.py"),
            join(settings.SSL_DIR, "experimenter.crt"),
            join(settings.SSL_DIR, "certs"),
            join(settings.SSL_DIR, "ch.crt"), join(settings.SSL_DIR, "ch.key"),
            settings.GCH_PORT,
        )
        self.ch_proc = run_cmd(cmd, pause=True)
        
#        # run the AM proxy
#        cmd = "python %s -r %s -c %s -k %s -p %s -u %s --debug -H 0.0.0.0" % (
#            join(settings.GCF_DIR, "gam.py"),
#            join(settings.SSL_DIR, "certs"),
#            join(settings.SSL_DIR, "server.crt"),
#            join(settings.SSL_DIR, "server.key"),
#            settings.GAM_PORT,
#            SCHEME + "://%s:%s/openflow/gapi/" % (settings.HOST, settings.CH_PORT),
#        )
#        self.am_proc = run_cmd(cmd, pause=True)
        
        ch_host = "%s:%s" % (settings.HOST, settings.GCH_PORT)
        cert_transport = SafeTransportWithCert(
            keyfile=join(settings.SSL_DIR, "experimenter.key"),
            certfile=join(settings.SSL_DIR, "experimenter.crt"))
        self.ch_client = xmlrpclib.ServerProxy(
            "https://"+ch_host+"/",
            transport=cert_transport)
        
        am_host = "%s:%s" % (settings.HOST, settings.CH_PORT)
        cert_transport = SafeTransportWithCert(
            keyfile=join(settings.SSL_DIR, "experimenter.key"),
            certfile=join(settings.SSL_DIR, "experimenter.crt"))
        self.am_client = xmlrpclib.ServerProxy(
            "https://"+am_host+"/openflow/gapi/",
            transport=cert_transport)
        
        logger.debug("setup done")