Exemple #1
0
    def test_write_singularity_infos(self):
        '''test_get_fullpath will test the get_fullpath function
        '''
        print("Testing utils.write_singuarity_infos...")
        from sutils import write_singularity_infos
        base_dir = '%s/ROOTFS' % self.tmpdir
        prefix = 'docker'
        start_number = 0
        content = "export HELLO=MOTO"

        print("Case 1: Metadata base doesn't exist, should return error")
        with self.assertRaises(SystemExit) as cm:
            info_file = write_singularity_infos(base_dir=base_dir,
                                                prefix=prefix,
                                                start_number=start_number,
                                                content=content)
        self.assertEqual(cm.exception.code, 1)

        print("Case 2: Metadata base does exist, should return path.")
        os.mkdir(base_dir)
        info_file = write_singularity_infos(base_dir=base_dir,
                                            prefix=prefix,
                                            start_number=start_number,
                                            content=content)
        self.assertEqual(info_file, "%s/%s-%s" % (base_dir,
                                                  start_number,
                                                  prefix))

        print("Case 3: Adding another equivalent prefix should return next")
        info_file = write_singularity_infos(base_dir=base_dir,
                                            prefix=prefix,
                                            start_number=start_number,
                                            content=content)
        self.assertEqual(info_file, "%s/%s-%s" % (base_dir,
                                                  start_number+1,
                                                  prefix))

        print("Case 4: Files have correct content.")
        with open(info_file, 'r') as filey:
            written_content = filey.read()
        self.assertEqual(content, written_content)
Exemple #2
0
    def test_write_singularity_infos(self):
        '''test_get_fullpath will test the get_fullpath function
        '''
        print("Testing utils.write_singuarity_infos...")
        from sutils import write_singularity_infos
        base_dir = '%s/ROOTFS' % self.tmpdir
        prefix = 'docker'
        start_number = 0
        content = "export HELLO=MOTO"

        print("Case 1: Metadata base doesn't exist, should return error")
        with self.assertRaises(SystemExit) as cm:
            info_file = write_singularity_infos(base_dir=base_dir,
                                                prefix=prefix,
                                                start_number=start_number,
                                                content=content)
        self.assertEqual(cm.exception.code, 1)

        print("Case 2: Metadata base does exist, should return path.")
        os.mkdir(base_dir)
        info_file = write_singularity_infos(base_dir=base_dir,
                                            prefix=prefix,
                                            start_number=start_number,
                                            content=content)
        self.assertEqual(info_file, "%s/%s-%s" % (base_dir,
                                                  start_number,
                                                  prefix))

        print("Case 3: Adding another equivalent prefix should return next")
        info_file = write_singularity_infos(base_dir=base_dir,
                                            prefix=prefix,
                                            start_number=start_number,
                                            content=content)
        self.assertEqual(info_file, "%s/%s-%s" % (base_dir,
                                                  start_number+1,
                                                  prefix))

        print("Case 4: Files have correct content.")
        with open(info_file, 'r') as filey:
            written_content = filey.read()
        self.assertEqual(content, written_content)
Exemple #3
0
def env_extract_image(manifest):
    '''env_extract_image will write a file of key value pairs
    of the environment to export. The manner to export must
    be determined by the calling process depending on the OS type.
    :param manifest: the manifest to use
    '''
    environ = extract_env(manifest)
    if environ is not None:
        environ_file = write_singularity_infos(base_dir=ENV_BASE,
                                               prefix=DOCKER_PREFIX,
                                               start_number=DOCKER_NUMBER,
                                               content=environ,
                                               extension='sh')
    return environ
Exemple #4
0
def env_extract_image(manifest):
    '''env_extract_image will write a file of key value pairs
    of the environment to export. The manner to export must
    be determined by the calling process depending on the OS type.
    :param manifest: the manifest to use
    '''
    environ = extract_env(manifest)
    if environ is not None:
        environ_file = write_singularity_infos(base_dir=ENV_BASE,
                                               prefix=DOCKER_PREFIX,
                                               start_number=DOCKER_NUMBER,
                                               content=environ,
                                               extension='sh')
    return environ