Пример #1
0
    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()
Пример #2
0
    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,
                ),
            )
Пример #3
0
from os.path import join, dirname
import time
import subprocess
import shlex
PYTHON_DIR = join(dirname(__file__), "../../../")
sys.path.append(PYTHON_DIR)

from unittest import TestCase
import xmlrpclib
from openflow.tests import test_settings as settings
from openflow.tests.helpers import parse_rspec, create_random_resv, \
    kill_old_procs
from expedient.common.utils.certtransport import SafeTransportWithCert
from expedient.common.tests.commands import call_env_command, Env

ch_env = Env(settings.CH_PROJECT_DIR)
ch_env.switch_to()

if settings.SHOW_PROCESSES_IN_XTERM:
    from expedient.common.tests.utils import run_cmd_in_xterm as run_cmd
else:
    from expedient.common.tests.utils import run_cmd
from expedient.common.tests.utils import wrap_xmlrpc_call, drop_to_shell
from expedient.common.tests.client import Browser

import logging
logger = logging.getLogger("openflow.tests.gapi")

SCHEME = "https" if settings.USE_HTTPS else "http"