Exemplo n.º 1
0
    def test_app_env(self):
        """
        Test the assignment of APP_ENV in settings_local.
        """

        from VECNet import app_env

        if not self.settings_local_exists:
            print 'Creating "%s"...' % self.settings_local_path
            if os.path.exists(self.settings_local_pyc):
                os.remove(self.settings_local_pyc)  # Make sure a .pyc is generated for the .py file we're about to create
            f = file(self.settings_local_path, 'w')
            f.write('APP_ENV = "%s"' % app_env.QA)
            f.close()

        from VECNet import settings_local
        if self.settings_local_exists and not hasattr(settings_local, 'APP_ENV'):
            print 'Assigning settings_local.APP_ENV = "%s"...' % app_env.QA
            setattr(settings_local, 'APP_ENV', app_env.QA)

        # Try APP_ENV.is_production class method
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "VECNet.settings")
        from django.conf import settings
        self.assertTrue(isinstance(settings.APP_ENV, basestring))
        self.assertEqual(settings.APP_ENV, app_env.QA)
        self.assertTrue(app_env.is_qa())
        self.assertFalse(app_env.is_production())
        self.assertFalse(app_env.is_development())
Exemplo n.º 2
0
    def submit_jobs(self, reps_per_exec):
        """
        Submits a job to the WinHPC cluster for processing. Returns True if submission was successful, and False if it
        wasn't.
        :returns: Boolean
        """
        # check that the run produces a valid manifest
        validate_manifest(self.run, reps_per_exec)

        # check if the environment is production or not
        production = app_env.is_production()

        # retrieve the ingestion url
        #TODO have ingestion url always set in settings, and/or have ingestion url be configurable
        ingest_url = (settings.INGESTION_URL if hasattr(settings, 'INGESTION_URL') else "")
        #TODO this type checking should be done in settings
        if not isinstance(ingest_url, (str, unicode)):
            raise TypeError("INGESTION_URL in settings must be a string or unicode")
        secrets_dict = {
            "host": self.cluster.server,
            "password": self.cluster.password,
            "username": self.cluster.username
        }

        # base_dir = getattr(settings, "JOB_SERVICES_BASE_DIR", None)
        # status = psc_submit_manifest(str(self.run.id),
        #                              self.user.username,
        #                              secrets_dict,
        #                              use_prod_site=production,
        #                              alt_ingest_url=ingest_url,
        #                              base_dir=base_dir)
        if self.run.model_version == emod_id.EMOD15:
            script_path = getattr(settings, "JOB_SERVICES_START_SIMGROUP_SCRIPT_PATH", None)
            if script_path is None:
                raise ImproperlyConfigured("JOB_SERVICES_START_SIMGROUP_SCRIPT_PATH_EMOD is not configured")
        elif self.run.model_version == emod_id.EMOD161: # or self.run.model_version == emod_id.EMOD167
            script_path = getattr(settings, "JOB_SERVICES_START_SIMGROUP_SCRIPT_PATH_EMOD_161", None)
            if script_path is None:
                raise ImproperlyConfigured("JOB_SERVICES_START_SIMGROUP_SCRIPT_PATH_EMOD_161 is not configured")
        elif self.run.model_version == emod_id.EMOD167: # or self.run.model_version == emod_id.EMOD167
            script_path = getattr(settings, "JOB_SERVICES_START_SIMGROUP_SCRIPT_PATH_EMOD_167", None)
            if script_path is None:
                raise ImproperlyConfigured("JOB_SERVICES_START_SIMGROUP_SCRIPT_PATH_EMOD_167 is not configured")
        elif self.run.model_version == emod_id.EMOD18: # or self.run.model_version == emod_id.EMOD167
            script_path = getattr(settings, "JOB_SERVICES_START_SIMGROUP_SCRIPT_PATH_EMOD_18", None)
            if script_path is None:
                raise ImproperlyConfigured("JOB_SERVICES_START_SIMGROUP_SCRIPT_PATH_EMOD_18 is not configured")
        else:
            raise RuntimeError("Unsupported model version %s (DimRun %s)" % (self.run.model_version, self.run.id))

        status = winhpc_submit(self.run.id,
                               self.user.username,
                               script_path,
                               secrets_dict["host"],
                               secrets_dict["username"],
                               secrets_dict["password"],
                               ingest_url # To be replaced with ALT_INGEST_URL
                               )


        if status == -1:
            logger.error("Run %s was not launched, received -1 from submit method" % self.run.id )
            return False
        logger.info("Run %s was launched successfully" % self.run.id)
        self.run.time_launched = datetime.datetime.now()
        self.run.save()
        return True