Esempio n. 1
0
 def generate_resolv_conf(self):
     """generate a resolv.conf file to bind to the containers.
        We use the template provided by scompose.
     """
     resolv_conf = os.path.join(self.working_dir, "resolv.conf")
     if not os.path.exists(resolv_conf):
         template = read_file(get_template("resolv.conf"))
         write_file(resolv_conf, template)
     return resolv_conf
def test_write_read_files(tmp_path):
    '''test_write_read_files will test the functions write_file and read_file
    '''
    print("Testing utils.write_file...")
    from scompose.utils import write_file
    tmpfile = str(tmp_path / 'written_file.txt')
    assert not os.path.exists(tmpfile)
    write_file(tmpfile, "hello!")
    assert os.path.exists(tmpfile)

    print("Testing utils.read_file...")
    from scompose.utils import read_file
    content = read_file(tmpfile)[0]
    assert content == "hello!"
Esempio n. 3
0
    def create_hosts(self, lookup):
        """create a hosts file to bind to all containers, where we define the
           correct hostnames to correspond with the ip addresses created.
           Note: This function is terrible. Singularity should easily expose 
                 these addresses. See issue here:
                 https://github.com/sylabs/singularity/issues/3751

           Parameters
           ==========
           lookup: a lookup of ip addresses to assign the containers
        """
        template = read_file(get_template("hosts"))
        hosts_file = os.path.join(self.working_dir, "etc.hosts")

        # Add an entry for each instance hostname to see the others
        for name, ip_address in lookup.items():
            template = ["%s\t%s\n" % (ip_address, name)] + template

        # Add the host file to be mounted
        write_file(hosts_file, template)
        return hosts_file