예제 #1
0
class TestRemoteData(AiidaTestCase):
    """Test for the RemoteData class."""

    @classmethod
    def setUpClass(cls):
        super(TestRemoteData, cls).setUpClass()
        backend = construct_backend()
        user = backend.users.get_automatic_user()
        authinfo = backend.authinfos.create(cls.computer, user)
        authinfo.store()

    def setUp(self):
        """Create a dummy RemoteData on the default computer."""
        self.tmp_path = tempfile.mkdtemp()
        self.remote = RemoteData(computer=self.computer)
        self.remote.set_remote_path(self.tmp_path)

        with open(os.path.join(self.tmp_path, 'file.txt'), 'w') as handle:
            handle.write('test string')

        self.remote.set_computer(self.computer)
        self.remote.store()

    def tearDown(self):
        """Delete the temporary path for the dummy RemoteData node."""
        try:
            shutil.rmtree(self.tmp_path)
        except OSError as exception:
            if exception.errno == errno.ENOENT:
                pass
            elif exception.errno == errno.ENOTDIR:
                os.remove(the_path)
            else:
                raise IOError(exception)

    def test_clean(self):
        """Try cleaning a RemoteData node."""
        self.assertFalse(self.remote.is_empty())
        self.remote._clean()
        self.assertTrue(self.remote.is_empty())
예제 #2
0
    def test_complex_graph_import_export(self):
        """
        This test checks that a small and bit complex graph can be correctly
        exported and imported.

        It will create the graph, store it to the database, export it to a file
        and import it. In the end it will check if the initial nodes are present
        at the imported graph.
        """
        import tempfile
        import shutil
        import os

        from aiida.orm.calculation.job import JobCalculation
        from aiida.orm.data.folder import FolderData
        from aiida.orm.data.parameter import ParameterData
        from aiida.orm.data.remote import RemoteData
        from aiida.common.links import LinkType
        from aiida.orm.importexport import export, import_data
        from aiida.orm.utils import load_node
        from aiida.common.exceptions import NotExistent

        temp_folder = tempfile.mkdtemp()
        try:
            calc1 = JobCalculation()
            calc1.set_computer(self.computer)
            calc1.set_resources({
                "num_machines": 1,
                "num_mpiprocs_per_machine": 1
            })
            calc1.label = "calc1"
            calc1.store()
            calc1._set_state(u'RETRIEVING')

            pd1 = ParameterData()
            pd1.label = "pd1"
            pd1.store()

            pd2 = ParameterData()
            pd2.label = "pd2"
            pd2.store()

            rd1 = RemoteData()
            rd1.label = "rd1"
            rd1.set_remote_path("/x/y.py")
            rd1.set_computer(self.computer)
            rd1.store()
            rd1.add_link_from(calc1, link_type=LinkType.CREATE)

            calc2 = JobCalculation()
            calc2.set_computer(self.computer)
            calc2.set_resources({
                "num_machines": 1,
                "num_mpiprocs_per_machine": 1
            })
            calc2.label = "calc2"
            calc2.store()
            calc2.add_link_from(pd1, link_type=LinkType.INPUT)
            calc2.add_link_from(pd2, link_type=LinkType.INPUT)
            calc2.add_link_from(rd1, link_type=LinkType.INPUT)
            calc2._set_state(u'SUBMITTING')

            fd1 = FolderData()
            fd1.label = "fd1"
            fd1.store()
            fd1.add_link_from(calc2, link_type=LinkType.CREATE)

            node_uuids_labels = {
                calc1.uuid: calc1.label,
                pd1.uuid: pd1.label,
                pd2.uuid: pd2.label,
                rd1.uuid: rd1.label,
                calc2.uuid: calc2.label,
                fd1.uuid: fd1.label
            }

            filename = os.path.join(temp_folder, "export.tar.gz")
            export([fd1.dbnode], outfile=filename, silent=True)

            self.clean_db()

            import_data(filename, silent=True, ignore_unknown_nodes=True)

            for uuid, label in node_uuids_labels.iteritems():
                try:
                    load_node(uuid)
                except NotExistent:
                    self.fail("Node with UUID {} and label {} was not "
                              "found.".format(uuid, label))

        finally:
            # Deleting the created temporary folder
            shutil.rmtree(temp_folder, ignore_errors=True)
예제 #3
0
class TestVerdiDataRemote(AiidaTestCase):
    """
    Testing verdi data remote 
    """
    @classmethod
    def setUpClass(cls):
        super(TestVerdiDataRemote, cls).setUpClass()
        new_comp = Computer(name='comp',
                            hostname='localhost',
                            transport_type='local',
                            scheduler_type='direct',
                            workdir=tempfile.mkdtemp())
        new_comp.store()
        b = construct_backend()
        aiidauser = b.users.get_automatic_user()
        authinfo = DbAuthInfo(dbcomputer=new_comp.dbcomputer,
                              aiidauser=aiidauser.dbuser)
        authinfo.save()

    def setUp(self):
        comp = Computer.get('comp')
        self.r = RemoteData()
        p = tempfile.mkdtemp()
        self.r.set_remote_path(p)
        with open(p + '/file.txt', 'w') as f:
            f.write("test string")
        self.r.set_computer(comp)
        self.r.store()

        self.cli_runner = CliRunner()

    def test_remoteshowhelp(self):
        output = sp.check_output(['verdi', 'data', 'remote', 'show', '--help'])
        self.assertIn('Usage:', output,
                      "Sub-command verdi data remote show --help failed.")

    def test_remoteshow(self):
        options = [str(self.r.id)]
        res = self.cli_runner.invoke(cmd_remote.show,
                                     options,
                                     catch_exceptions=False)
        self.assertEquals(
            res.exit_code, 0, "The command verdi data remote show did not"
            " finish correctly")
        self.assertIn(
            'Remote computer name:', res.output_bytes,
            'The string "Remote computer name:" was not found in the'
            ' output of verdi data remote show')
        self.assertIn(
            'Remote folder full path:', res.output_bytes,
            'The string "Remote folder full path:" was not found in the'
            ' output of verdi data remote show')

    def test_remotelshelp(self):
        output = sp.check_output(['verdi', 'data', 'remote', 'ls', '--help'])
        self.assertIn('Usage:', output,
                      "Sub-command verdi data remote ls --help failed.")

    def test_remotels(self):
        options = ['--long', str(self.r.id)]
        res = self.cli_runner.invoke(cmd_remote.lsfunction,
                                     options,
                                     catch_exceptions=False)
        self.assertEquals(
            res.exit_code, 0, "The command verdi data remote ls did not"
            " finish correctly")
        self.assertIn(
            'file.txt', res.output_bytes,
            'The file "file.txt" was not found in the output'
            ' of verdi data remote ls')

    def test_remotecathelp(self):
        output = sp.check_output(['verdi', 'data', 'remote', 'cat', '--help'])
        self.assertIn('Usage:', output,
                      "Sub-command verdi data remote cat --help failed.")

    def test_remotecat(self):
        options = [str(self.r.id), 'file.txt']
        res = self.cli_runner.invoke(cmd_remote.cat,
                                     options,
                                     catch_exceptions=False)
        self.assertEquals(
            res.exit_code, 0, "The command verdi data parameter cat did not"
            " finish correctly")
        self.assertIn(
            'test string', res.output_bytes,
            'The string "test string" was not found in the output'
            ' of verdi data remote cat file.txt')