Example #1
0
    def test_chaining(self):
        a = Directory(Directory.LOCAL_SCRATCH, "/path")
        b = a.add_file_servers(FileServer("url",
                                          Operation.PUT)).add_file_servers(
                                              FileServer("url", Operation.GET))

        assert id(a) == id(b)
Example #2
0
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))
Example #3
0
    def test_add_invalid_file_server(self):
        with pytest.raises(TypeError) as e:
            d = Directory(Directory.LOCAL_SCRATCH, "/path")
            d.add_file_servers(123)

            assert "invalid file_server: 123" in str(e)
Example #4
0
 def test_add_valid_file_server(self):
     d = Directory(Directory.LOCAL_SCRATCH, "/path")
     assert d.add_file_servers(FileServer("url", Operation.PUT))