def __init__(self, *args, **kwargs): """Submission Constructor""" # Call Parent Construtor super(Run, self).__init__(*args, **kwargs) # Setup Factories self.AssignmentFactory = backend.UUIDFactory(Assignment) self.SubmissionFactory = backend.UUIDFactory(Submission) self.TestFactory = backend.UUIDFactory(Test)
def test_init(self): # Test w/o Prefix of = backend.UUIDFactory(backend.TypedObject) o = of.from_new() self.assertTrue(o) # Test w/ Prefix p = "testprefix_{:03d}".format(random.randint(0, 999)) of = backend.UUIDFactory(backend.TypedObject, prefix=p) o = of.from_new() self.assertTrue(o)
def from_new(cls, data, **kwargs): """New Constructor""" # Process Args asn_uuid = data.get('assignment', None) if not asn_uuid: raise KeyError("Requires assignment") tst_uuid = data.get('test', None) if not tst_uuid: raise KeyError("Requires test") sub_uuid = data.get('submission', None) if not sub_uuid: raise KeyError("Requires submission") # Get Objects AssignmentFactory = backend.UUIDFactory(Assignment) SubmissionFactory = backend.UUIDFactory(Submission) TestFactory = backend.UUIDFactory(Test) tst = TestFactory.from_existing(tst_uuid) sub = SubmissionFactory.from_existing(sub_uuid) asn = AssignmentFactory.from_existing(asn_uuid) # Check Invariants assert (str(asn.uuid).lower() == tst['assignment'].lower()) assert (str(asn.uuid).lower() == sub['assignment'].lower()) # Set Schema schema = set(_RUN_SCHEMA) kwargs['schema'] = schema # Create New Object data = copy.copy(data) # Setup Dict data['status'] = "queued" data['score'] = "" data['retcode'] = "" data['output'] = "" # Create Run run = super(Run, cls).from_new(data, **kwargs) run_uuid = str(run.uuid).lower() # Add Task to Pool testrun.test(asn, sub, tst, run) # Return Run return run
def __init__(self): """Base Constructor""" # Call Parent Construtor super(Server, self).__init__() # Call Setups File.setup() # Setup Factories self.FileFactory = FileUUIDFactory() self.ReporterFactory = backend.UUIDFactory(Reporter) self.AssignmentFactory = backend.UUIDFactory(Assignment) self.SubmissionFactory = backend.UUIDFactory(Submission) self.TestFactory = backend.UUIDFactory(Test) self.RunFactory = backend.UUIDFactory(Run)
def __init__(self, *args, **kwargs): """Submission Constructor""" # Call Parent Construtor super(Submission, self).__init__(*args, **kwargs) # Setup Factories self.AssignmentFactory = backend.UUIDFactory(Assignment) self.RunFactory = backend.UUIDFactory(Run) self.FileFactory = FileUUIDFactory() # Setup Lists FileListFactory = backend.PrefixedFactory(FileList, prefix=self.full_key) self.files = FileListFactory.from_raw(key='files') RunListFactory = backend.PrefixedFactory(RunList, prefix=self.full_key) self.runs = RunListFactory.from_raw(key='runs')
def __init__(self, *args, **kwargs): """Assignment Constructor""" # Call Parent Construtor super(Assignment, self).__init__(*args, **kwargs) # Setup Factories self.SubmissionFactory = backend.UUIDFactory(Submission) self.TestFactory = backend.UUIDFactory(Test) # Setup Lists TestListFactory = backend.PrefixedFactory(TestList, prefix=self.full_key) self.tests = TestListFactory.from_raw(key='tests') SubmissionListFactory = backend.PrefixedFactory(SubmissionList, prefix=self.full_key) self.submissions = SubmissionListFactory.from_raw(key='submissions')
def __init__(self, *args, **kwargs): """Test Constructor""" # Call Parent Construtor super(Test, self).__init__(**kwargs) # Setup Factories self.AssignmentFactory = backend.UUIDFactory(Assignment) self.FileFactory = FileUUIDFactory() self.ReporterFactory = backend.UUIDFactory(Reporter) # Setup Lists FileListFactory = backend.PrefixedFactory(FileList, prefix=self.full_key) self.files = FileListFactory.from_raw(key='files') ReporterListFactory = backend.PrefixedFactory(ReporterList, prefix=self.full_key) self.reporters = ReporterListFactory.from_raw(key='reporters')
def __init__(self, prefix=None): # Call Parent super(Auth, self).__init__() # Save vars self.prefix = prefix # Setup Factories passthrough = {'auth': self} self.UserFactory = backend.UUIDFactory(User, prefix=self.prefix, passthrough=passthrough) self.GroupFactory = backend.UUIDFactory(Group, prefix=self.prefix, passthrough=passthrough) self.AllowedGroupsFactory = backend.PrefixedFactory(AllowedGroups, prefix=self.prefix, passthrough=passthrough) # Setup Lists UsernameMapFactory = backend.PrefixedFactory(UsernameMap, prefix=self.prefix, passthrough=passthrough) self.username_map = UsernameMapFactory.from_raw() TokenMapFactory = backend.PrefixedFactory(TokenMap, prefix=self.prefix, passthrough=passthrough) self.token_map = TokenMapFactory.from_raw()
def setUp(self): super(RedisUUIDSetTestCase, self).setUp() self.UUIDSetFactory = backend.UUIDFactory(backend.Set)
def setUp(self): super(RedisUUIDHashTestCase, self).setUp() self.UUIDHashFactory = backend.UUIDFactory(backend.Hash)
def test_list(self): val = 'val' pre = 'test' cls = backend.TypedObject.__name__.lower() # Add Parents w/o Prefix self.db.flushdb() parents = ['p01', 'p02', 'p03'] for p in parents: self.db.set("{:s}+{:s}".format(cls, p).lower(), val) # Test Parents w/o Prefix hf = backend.UUIDFactory(backend.TypedObject) fam = hf.list_family() self.assertEqual(set(parents), fam) sib = hf.list_siblings() self.assertEqual(set(parents), sib) chd = hf.list_children() self.assertFalse(chd) # Add Parents w/ Prefix self.db.flushdb() parents = ['p01', 'p02', 'p03'] for p in parents: self.db.set("{:s}:{:s}+{:s}".format(pre, cls, p), val) # Test Parents w/ Prefix hf = backend.UUIDFactory(backend.TypedObject, prefix=pre) fam = hf.list_family() self.assertEqual(set(parents), fam) sib = hf.list_siblings() self.assertEqual(set(parents), sib) chd = hf.list_children() self.assertEqual(set([]), chd) # Add Parents + Children w/o Prefix self.db.flushdb() parents = ['p01', 'p02', 'p03'] for p in parents: self.db.set("{:s}+{:s}".format(cls, p), val) p1_children = ['c01', 'c02', 'c03'] full_children = [] for c in p1_children: child = "{:s}:{:s}+{:s}".format(parents[0], cls, c) self.db.set("{:s}+{:s}".format(cls, child), val) full_children.append(child) # Test Parents + Children w/o Prefix hf = backend.UUIDFactory(backend.TypedObject) fam = hf.list_family() self.assertEqual(set(parents + full_children), fam) sib = hf.list_siblings() self.assertEqual(set(parents), sib) chd = hf.list_children() self.assertEqual(set(full_children), chd) # Test Children w/o Prefix chd_pre = "{:s}+{:s}".format(cls, parents[0]) hf = backend.UUIDFactory(backend.TypedObject, prefix=chd_pre) fam = hf.list_family() self.assertEqual(set(p1_children), fam) sib = hf.list_siblings() self.assertEqual(set(p1_children), sib) chd = hf.list_children() self.assertEqual(set([]), chd) # Add Parents + Children w/ Prefix self.db.flushdb() parents = ['p01', 'p02', 'p03'] for p in parents: self.db.set("{:s}:{:s}+{:s}".format(pre, cls, p), val) p1_children = ['c01', 'c02', 'c03'] full_children = [] for c in p1_children: child = "{:s}:{:s}+{:s}".format(parents[0], cls, c) self.db.set("{:s}:{:s}+{:s}".format(pre, cls, child), val) full_children.append(child) # Test Parents + Children w/ Prefix hf = backend.UUIDFactory(backend.TypedObject, prefix=pre) fam = hf.list_family() self.assertEqual(set(parents + full_children), fam) sib = hf.list_siblings() self.assertEqual(set(parents), sib) chd = hf.list_children() self.assertEqual(set(full_children), chd) # Test Children w/ Prefix chd_pre = "{:s}:{:s}+{:s}".format(pre, cls, parents[0]) hf = backend.UUIDFactory(backend.TypedObject, prefix=chd_pre) fam = hf.list_family() self.assertEqual(set(p1_children), fam) sib = hf.list_siblings() self.assertEqual(set(p1_children), sib) chd = hf.list_children() self.assertEqual(set([]), chd)
def __init__(self, asn, sub, tst, run): # Call Parent super(Env, self).__init__(asn, sub, tst, run) msg = "envmod_local: Initializing environment" logger.info(self._format_msg(msg)) # Setup Factory FileFactory = backend.UUIDFactory(structs.File) # Get Files sub_file_uuids = sub.list_files() sub_files = [ FileFactory.from_existing(file_uuid) for file_uuid in sub_file_uuids ] tst_file_uuids = tst.list_files() tst_files = [ FileFactory.from_existing(file_uuid) for file_uuid in tst_file_uuids ] # Setup Directories self.wd = os.path.abspath( os.path.join(config.ENV_LOCAL_TMP_PATH, str(run).lower())) self.wd_tst = os.path.join(self.wd, _TST_DIR) self.wd_sub = os.path.join(self.wd, _SUB_DIR) self.wd_wrk = os.path.join(self.wd, _WRK_DIR) os.makedirs(self.wd) os.makedirs(self.wd_tst) os.makedirs(self.wd_sub) os.makedirs(self.wd_wrk) os.chmod(self.wd_sub, 0777) # TODO: Remove this os.chmod(self.wd_wrk, 0777) # Copy Tester Files self.tst_files = [] for fle in tst_files: fle_cpy = self.copy_fle(fle.get_dict(), self.wd_tst) self.tst_files.append(fle_cpy) # Copy Submission Files self.sub_files = [] for fle in sub_files: fle_cpy = self.copy_fle(fle.get_dict(), self.wd_sub) self.sub_files.append(fle_cpy) # Sanitze Files for fle in (self.tst_files + self.sub_files): for pgm in _FILE_SANITIZERS: cmd_sanitize = [pgm, fle['path']] p = subprocess.Popen(cmd_sanitize, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() ret = p.returncode if stdout: msg = "envmod_local: '{:s}' stdout: {:s}".format( pgm, stdout) logger.debug(self._format_msg(msg)) if stderr: msg = "envmod_local: '{:s}' stderr: {:s}".format( pgm, stderr) logger.debug(self._format_msg(msg)) if (ret != 0): msg = "envmod_local: " msg += "Sanitize pgm '{:s}' failed ".format(pgm) msg += "on file '{:s}': ".format(fle_cpy['name']) msg += "{:s}".format(stderr) logger.warning(self._format_msg(msg)) # Clean and Setup Env Vars self._env_vars = {} for var in os.environ: if var.startswith("COGS"): pass elif var.startswith("APACHE"): pass else: self._env_vars[var] = os.environ[var] self._env_vars['LANG'] = "C.UTF-8" self._env_vars['HOME'] = self.wd_wrk msg = "env_vars: {:s}".format(self._env_vars) logger.info(self._format_msg(msg))