Example #1
0
 def run_proc_cmd(self, cmd, wait=False):
     """
     Run a command in a subprocess, return the new process.
     """
     if test_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
         
     if wait:
         return run_cmd(cmd).wait()
     else:
         return run_cmd(cmd)
Example #2
0
    def test_UserOptIn1(self):
        """
        Test a user opting in.
        """
        from expedient.common.tests.client import Browser
        
        #create an experiment through CH
        self.create_sliver_core(fs_randomness=False)
        
        logger.debug("Done creating sliver")

        # Get user to opt in
        logger.debug("Logging into browser")
        b = Browser()
        logged_in = b.login(SCHEME+"://%s:%s/accounts/login/"%
                            (test_settings.HOST, test_settings.OM_PORT),
                            "user","password")
        self.assertTrue(logged_in,"Could not log in")
        logger.debug("Login success")
#        drop_to_shell(local=locals())

        f = b.get_and_post_form(SCHEME+"://%s:%s/opts/opt_in"%
                                (test_settings.HOST, test_settings.OM_PORT),
                                dict(experiment=1))
        logger.debug("Posted opt-in request, reading response.")
        res = f.read()
        self.assertEqual(f.code, 200)
        self.assertTrue("successfully" in res, "Did not get successful opt in message: %s" % res)
        
        
        # test if FV has the expected flowspace match entries
        from expedient.common.tests.utils import run_cmd
        fvctl = run_cmd(
            "sh %s/scripts/fvctl.sh listFlowSpace" % (
                test_settings.FLOWVISOR_DIR,
            ),
        )
        data = fvctl.communicate(input="rootpassword")
        fv_rules = data[0].split("\n")
        print(fv_rules)
        #for fv_rule in fv_rules
        
        logger.debug("Response fine, opting out.")
        # now test opt out:
        f = b.get_and_post_form(SCHEME+"://%s:%s/opts/opt_out"%
                                (test_settings.HOST, test_settings.OM_PORT),
                                {"1":"checked"})
        res = f.read()
        self.assertEqual(f.code, 200)
        self.assertTrue("Successful" in res, "Returned %s"%res)        
Example #3
0
File: gapi.py Project: 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")
    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")