def test_tojson_with_profiles(self): site = Site( "s", arch=Arch.X86_64, os_type=OS.LINUX, os_release="release", os_version="1.2.3", ) site.add_directories( Directory(Directory.LOCAL_SCRATCH, "/path").add_file_servers( FileServer("url", Operation.GET))) site.add_grids( Grid( Grid.GT5, "smarty.isi.edu/jobmanager-pbs", Scheduler.PBS, job_type=SupportedJobs.AUXILLARY, )) site.add_env(JAVA_HOME="/usr/bin/java") result = json.loads(json.dumps(site, cls=_CustomEncoder)) expected = { "name": "s", "arch": "x86_64", "os.type": "linux", "os.release": "release", "os.version": "1.2.3", "directories": [{ "type": "localScratch", "path": "/path", "fileServers": [{ "url": "url", "operation": "get" }], }], "grids": [{ "type": "gt5", "contact": "smarty.isi.edu/jobmanager-pbs", "scheduler": "pbs", "jobtype": "auxillary", }], "profiles": { "env": { "JAVA_HOME": "/usr/bin/java" } }, } assert result == expected
def test_add_valid_grid(self): site = Site("s") site.add_grids( Grid( Grid.GT5, "smarty.isi.edu/jobmanager-pbs", Scheduler.PBS, job_type=SupportedJobs.AUXILLARY, )) site.add_grids( Grid( Grid.GT5, "smarty.isi.edu/jobmanager-pbs", Scheduler.PBS, job_type=SupportedJobs.COMPUTE, )) assert len(site.grids) == 2
def test_chaining(self): site = Site("s") a = site.add_directories(Directory(Directory.LOCAL_SCRATCH, "/path")) b = site.add_grids( Grid( Grid.GT5, "smarty.isi.edu/jobmanager-pbs", Scheduler.PBS, job_type=SupportedJobs.AUXILLARY, )) assert id(a) == id(b)
def _to_sc(d: dict) -> SiteCatalog: """Convert dict to SiteCatalog :param d: SiteCatalog represented as a dict :type d: dict :raises PegasusError: encountered error parsing :return: a SiteCatalog object based on d :rtype: SiteCatalog """ try: sc = SiteCatalog() for s in d["sites"]: site = Site( s["name"], arch=getattr(Arch, s.get("arch").upper()) if s.get("arch") else None, os_type=getattr(OS, s.get("os.type").upper()) if s.get("os.type") else None, os_release=s.get("os.release"), os_version=s.get("os.version"), ) # add directories for _dir in s["directories"]: dir_type = None for enum_name, enum in _DirectoryType.__members__.items(): if _dir["type"] == enum.value: dir_type = enum_name break directory = Directory(getattr(Directory, dir_type), _dir["path"]) # add file servers for fs in _dir["fileServers"]: file_server = FileServer( fs["url"], getattr(Operation, fs["operation"].upper())) # add profiles if fs.get("profiles"): file_server.profiles = defaultdict( dict, fs.get("profiles")) # add file server to this directory directory.add_file_servers(file_server) # add directory to this site site.add_directories(directory) # add grids if s.get("grids"): for gr in s.get("grids"): grid = Grid( getattr(Grid, gr["type"].upper()), gr["contact"], getattr(Scheduler, gr["scheduler"].upper()), job_type=getattr(SupportedJobs, gr.get("jobtype").upper()) if gr.get("jobtype") else None, ) # add grid to this site site.add_grids(grid) # add profiles if s.get("profiles"): site.profiles = defaultdict(dict, s.get("profiles")) # add site to sc sc.add_sites(site) return sc except KeyError: raise PegasusError("error parsing {}".format(d))
def test_add_invalid_grid(self): with pytest.raises(TypeError) as e: site = Site("s") site.add_grids("badgrid") assert "invalid grid: badgrid" in str(e)