예제 #1
0
 def run_example(self):
     r"""This runs an example in the correct language."""
     if self.yaml is None:
         if self.name is not None:
             raise unittest.SkipTest("Could not locate example %s in language %s." %
                                     (self.name, self.language))
     else:
         # Copy platform specific makefile
         if self.language == 'make':
             makefile = os.path.join(self.yamldir, 'src', 'Makefile')
             if platform._is_win:  # pragma: windows
                 make_ext = '_windows'
             else:
                 make_ext = '_linux'
             shutil.copy(makefile + make_ext, makefile)
         # Check that language is installed
         for x in self.languages_tested:
             if not tools.is_lang_installed(x):
                 raise unittest.SkipTest("%s not installed." % x)
         # Check that comm is installed
         if self.comm in ['ipc', 'IPCComm']:
             from yggdrasil.communication.IPCComm import (
                 ipcrm_queues, ipc_queues)
             qlist = ipc_queues()
             if qlist:  # pragma: debug
                 print('Existing queues:', qlist)
                 ipcrm_queues()
         # Run
         os.environ.update(self.env)
         self.runner = runner.get_runner(self.yaml, namespace=self.namespace)
         self.runner.run()
         if self.expects_error:
             assert(self.runner.error_flag)
         else:
             assert(not self.runner.error_flag)
         try:
             self.check_results()
         finally:
             self.cleanup()
             # Remove copied makefile
             if self.language == 'make':
                 makefile = os.path.join(self.yamldir, 'src', 'Makefile')
                 if os.path.isfile(makefile):
                     os.remove(makefile)
예제 #2
0
 def test_example(self, example_name, language, namespace, yaml, setup_env,
                  expects_error, on_mpi, mpi_rank, check_results,
                  example_cleanup, adv_global_mpi_tag,
                  optionally_disable_verify_count_fds):
     r"""This runs an example in the correct language."""
     if example_name.startswith('timesync'):
         # Timesync examples include ploting in the verification script
         # which opens file descriptors that are not promptly cleaned up
         optionally_disable_verify_count_fds()
     assert (yaml is not None)
     # Run
     mpi_tag_start = None
     if on_mpi:
         mpi_tag_start = adv_global_mpi_tag(1000)
     r = runner.get_runner(yaml,
                           namespace=namespace,
                           production_run=True,
                           mpi_tag_start=mpi_tag_start)
     try:
         try:
             r.run()
         except runner.IntegrationError:
             pass
         r.printStatus()
         r.printStatus(return_str=True)
         if mpi_rank != 0:
             return
         if expects_error:
             assert (r.error_flag)
         else:
             assert (not r.error_flag)
         try:
             check_results()
         except BaseException:  # pragma: debug
             if r is not None:
                 r.printStatus()
             raise
     finally:
         if mpi_rank == 0:
             example_cleanup()
예제 #3
0
        def start_integration(self, client_id, x, yamls, **kwargs):
            r"""Start an integration if it is not already running.

            Args:
                client_id (str): ID associated with the client requesting the
                    integration be started.
                x (str, tuple): Hashable object that should be used to
                    identify the integration being started in the registry of
                    running integrations.
                yamls (list): Set of YAML specification files defining the
                    integration that should be run as as service.
                **kwargs: Additional keyword arguments are passed to get_runner.

            Returns:
                bool: True if the integration started, False otherwise.

            """
            integrations = self.integrations[client_id]
            stopped_integrations = self.stopped_integrations[client_id]
            if (x in integrations) and (not integrations[x].is_alive):
                if not self.stop_integration(client_id, x):
                    return False
            if x in stopped_integrations:
                if not self.stop_integration(client_id, x):
                    return False
                stopped_integrations.pop(x)
            if x not in integrations:
                partial_commtype = {'commtype': self.commtype}
                if self.commtype == 'rest':
                    partial_commtype['client_id'] = client_id
                integrations[x] = runner.get_runner(
                    yamls,
                    complete_partial=True,
                    as_service=True,
                    partial_commtype=partial_commtype,
                    **kwargs)
                integrations[x].run(signal_handler=False)
            return True
예제 #4
0
 def call_integration_service(self,
                              cli,
                              yamls,
                              test_yml,
                              copy_yml=None,
                              name='test',
                              yaml_param=None):
     r"""Call an integration that includes a service."""
     remote_yml = '_remote'.join(os.path.splitext(test_yml))
     yamls = copy.copy(yamls)
     yamls.remove(test_yml)
     if copy_yml:
         yamls.remove(copy_yml)
     yamls.append(remote_yml)
     service_type = cli.service_type
     try:
         address = cli.address
         if copy_yml:
             shutil.copy(copy_yml, remote_yml)
             remote_code = 'a'
         else:
             remote_code = 'w'
         lines = [
             'service:', f'    name: {name}', f'    yamls: [{test_yml}]',
             f'    type: {service_type}', f'    address: {address}'
         ]
         if yaml_param:
             lines.append('    yaml_param:')
             for k, v in yaml_param.items():
                 lines.append(f'        {k}: "{v}"')
         with open(remote_yml, remote_code) as fd:
             fd.write('\n'.join(lines))
         r = runner.get_runner(yamls)
         r.run()
         assert (not r.error_flag)
     finally:
         if os.path.isfile(remote_yml):
             os.remove(remote_yml)
예제 #5
0
def test_matlab_runner():  # pragma: matlab
    r"""Use get_runner to start a Matlab run."""
    cr = runner.get_runner([ex_yamls['hello']['matlab']])
    cr.run()
예제 #6
0
def test_get_runner():
    r"""Use get_runner to start a run."""
    namespace = "test_get_runner_%s" % str(uuid.uuid4)
    cr = runner.get_runner([ex_yamls['hello']['python']], namespace=namespace)
    cr.run()
    cr.sleep()