コード例 #1
0
    def test_brain_reset_from_storage(self, mock_get_exp_data,
                                      mock_get_model_path,
                                      mock_get_experiment_path):
        simulations.append(
            Simulation(3, 'experiments/experiment_data/test_5.exc', None,
                       'default-owner', 'created'))
        simulations[2].cle = mock.MagicMock()
        simulations[2].cle.set_simulation_brain.return_value = Mock(
            error_message="")

        mock_get_experiment_path.return_value = PATH
        mock_get_model_path.return_value = os.path.join(PATH, 'models')

        bibi_path = os.path.join(PATH,
                                 'experiments/experiment_data/bibi_4.bibi')
        experiment_file_path = os.path.join(
            PATH, 'experiments/experiment_data/test_5.exc')

        with open(experiment_file_path) as exd_file:
            experiment = exp_conf_api_gen.CreateFromDocument(exd_file.read())

        with open(bibi_path) as b_file:
            bibi = bibi_api_gen.CreateFromDocument(b_file.read())

        mock_get_exp_data.return_value = experiment, bibi

        with patch("__builtin__.open", mock_open(read_data="data")) as mock_file, \
                patch('os.listdir', return_value=['nrpTemp']) as mock_tempfile:
            response = self.client.put('/simulation/2/reset',
                                       data=json.dumps({
                                           'resetType':
                                           ResetSimulationRequest.RESET_BRAIN
                                       }))
            self.assertEqual(200, response.status_code)
コード例 #2
0
 def setUp(self):
     del simulations[:]
     simulations.append(
         Simulation(0, 'experiment_0', 'default-owner', 'local', 'created'))
     self.sim = simulations[0]
     self.sim.cle = MagicMock()
     self.sim.cle.extend_simulation_timeout = MagicMock(return_value=True)
コード例 #3
0
 def setUp(self):
     del simulations[:]
     simulations.append(
         Simulation(0, 'experiments/experiment_data/test_1.exc', None,
                    'default-owner', 'created'))
     simulations.append(
         Simulation(1, 'experiments/experiment_data/test_1.exc', None,
                    'im-not-the-owner', 'created'))
コード例 #4
0
 def setUp(self):
     del simulations[:]
     simulations.append(
         Simulation(0,
                    'experiment1',
                    'default-owner',
                    'local',
                    'view',
                    state='paused'))
コード例 #5
0
    def setUp(self):
        rospy.ServiceProxy = MockServiceProxy
        rospy.wait_for_service = mock.Mock(return_value=mock.Mock())

        self.mc = MaterialControl()
        self.lc = LightControl()

        del simulations[:]
        simulations.append(Simulation(0, 'test', 'default-owner', 'created'))
コード例 #6
0
    def setUp(self):
        del simulations[:]
        simulations.append(Simulation(0, 'experiment1', 'default-owner', 'created'))
        simulations[0].cle = mock.MagicMock()
        simulations[0].cle.set_simulation_populations = mock.MagicMock(return_value=set_ret_ok)
        simulations[0].cle.get_populations = mock.MagicMock(return_value=neurons)

        self.path_can_view = mock.patch('hbp_nrp_backend.__UserAuthentication.UserAuthentication.can_view')
        self.path_can_view.start().return_value = True
コード例 #7
0
 def setUp(self):
     del simulations[:]
     simulations.append(Simulation(0, 'experiment_0', None,
                                   'default-owner', 'local', 'created'))
     simulations.append(Simulation(1, 'experiment_1', None,
                                   'untrusted-owner', 'local', 'created'))
     self.sim = simulations[0]
     self.sim.cle = MagicMock()
     self.sim.cle.edit_simulation_transfer_function = MagicMock(
         return_value='')
コード例 #8
0
    def setUp(self):

        del simulations[:]
        simulations.append(
            Simulation(0, 'experiment1', None, 'default-owner', 'created'))
        simulations.append(
            Simulation(1, 'experiment2', None, 'other-owner', 'created'))

        for s in simulations:
            s.cle = MagicMock()
            s.cle.command_simulation_recorder = MagicMock(
                return_value=srv.SimulationRecorderResponse())
コード例 #9
0
    def setUp(self):
        del simulations[:]
        simulations.append(
            Simulation(0, 'experiment_0', None, 'default-owner', 'local',
                       'created'))
        simulations.append(
            Simulation(1, 'experiment_1', None, 'untrusted-owner', 'local',
                       'created'))

        self.sim = simulations[0]
        self.sim.cle = MagicMock()
        self.sim.cle.get_simulation_brain = MagicMock(return_value=brain_data)
        self.sim.cle.set_simulation_brain = MagicMock(return_value=set_ret_ok)
コード例 #10
0
    def setUp(self):
        patch_StorageClient =\
            patch('hbp_nrp_backend.storage_client_api.StorageClient.StorageClient')
        self.addCleanup(patch_StorageClient.stop)
        self.mock_StorageClient = patch_StorageClient.start()
        self.mock_storageClient_instance = self.mock_StorageClient.return_value

        del simulations[:]
        simulations.append(Simulation(
            0, 'experiments/experiment_data/test_1.exc', None, 'default-owner', 'created'))
        simulations.append(Simulation(
            1, 'experiments/experiment_data/test_1.exc', None, 'im-not-the-owner', 'created'))

        self.experiment_id = "0000-0000"
        # Correct request
        self.correct_reset_url = '/simulation/0/' + self.experiment_id + '/reset'
コード例 #11
0
    def setUp(self):
        del simulations[:]
        simulations.append(
            Simulation(0, 'experiment_0', 'default-owner', 'local', 'created'))
        simulations.append(
            Simulation(1, 'experiment_1', 'untrusted-owner', 'local',
                       'created'))

        self.sim = simulations[0]
        self.sim.cle = MagicMock()
        self.sim.cle.get_simulation_brain = MagicMock(return_value=brain_data)
        self.sim.cle.set_simulation_brain = MagicMock(return_value=set_ret_ok)

        self.path_can_view = patch(
            'hbp_nrp_backend.__UserAuthentication.UserAuthentication.can_view')
        self.path_can_view.start().return_value = True
コード例 #12
0
    def setUp(self):
        self.storage_client = SimulationResetStorage.storage_client
        self.mock_storage_client = mock.MagicMock()

        SimulationResetStorage.storage_client = self.mock_storage_client
        del simulations[:]
        simulations.append(
            Simulation(0, 'experiments/experiment_data/test_1.exc',
                       'default-owner', 'created'))
        simulations.append(
            Simulation(1, 'experiments/experiment_data/test_1.exc',
                       'im-not-the-owner', 'created'))

        self.experiment_id = "0000-0000"
        # Correct request
        self.correct_reset_url = '/simulation/0/{exp_id}/reset'.format(
            exp_id=self.experiment_id)
コード例 #13
0
    def setUp(self):
        del simulations[:]
        simulations.append(Simulation(
            0, 'experiment1', None, 'default-owner', 'created'))
        simulations[0].cle = MagicMock()
        self.test_directory = os.path.split(__file__)[0]
        csv_path = os.path.join(self.test_directory,
                                "csv_mock", "csv_mock.csv")
        self.files = MagicMock(name='left_wheel_join_position.csv',
                               temporary_path=csv_path)

        simulations[0].cle.get_simulation_CSV_recorders_files = MagicMock(
            return_value=self.files)
        patch_StorageClient = patch(
            'hbp_nrp_backend.storage_client_api.StorageClient.StorageClient')
        self.addCleanup(patch_StorageClient.stop)
        self.mock_StorageClient = patch_StorageClient.start()
        self.mock_storageClient_instance = self.mock_StorageClient.return_value
コード例 #14
0
ファイル: test_health.py プロジェクト: dcam0050/NRP_Docker
 def setUp(self):
     del simulations[:]
     simulations.append(
         self._create_simulation(0, 'experiment_0', 'default-owner',
                                 'local', 'created'))
     simulations.append(
         self._create_simulation(1, 'experiment_1', 'untrusted-owner',
                                 'local', 'created'))
     simulations.append(
         self._create_simulation(2, 'experiment_2', 'untrusted-owner',
                                 'local', 'created'))
コード例 #15
0
    def setUp(self):
        del simulations[:]
        simulations.append(Simulation(0, 'experiment_0', 'default-owner', 'local', 'created'))
        simulations.append(Simulation(1, 'experiment_1', 'untrusted-owner', 'local', 'created'))
        self.sim = simulations[0]
        self.sim.cle = MagicMock()

        self.object_tfs = [
            MockObject({
                "devices": [
                    MockObject({
                        'name': 'foo',
                        'type': 'footype',
                        'neurons': MockObject({
                          'name': 'foopop',
                            'type': 'foopoptype',
                            'ids': [0,8,15],
                            'start': 0,
                            'stop': 8,
                            'step': 15
                        })
                    })
                ],
                'topics': [
                    MockObject({
                        'name': 'bar',
                        'topic': 'bartopic',
                        'type': 'bartype',
                        'publishing': 'barpub'
                    })
                ],
                'variables': [
                    MockObject({
                        'name': 'varname',
                        'type': 'vartype',
                        'initial_value': 'varvalue'
                    })
                ],
                'name': 'tf',
                'type': 'tf_type',
                'code': 'pass'
            })
        ]

        self.dict_tf = {
                    u'name': u'tf',
                    u'type': u'tf_type',
                    u'code': u'pass',
                    u'devices': [{
                        u'name': u'foo',
                        u'type': u'footype',
                        u'neurons': {
                            u'name': u'foopop',
                            u'type': u'foopoptype',
                            u'ids': [
                                {u'id': 0},
                                {u'id': 8},
                                {u'id': 15}
                            ],
                            u'start': 0,
                            u'stop': 8,
                            u'step': 15
                        }
                    }],
                    u'topics': [{
                        u'name': u'bar',
                        u'topic': u'bartopic',
                        u'type': u'bartype',
                        u'publishing': u'barpub'
                    }],
                    u'variables': [{
                        u'name': u'varname',
                        u'type': u'vartype',
                        u'initial_value': u'varvalue'
                    }]
                }
コード例 #16
0
    def post(self):
        """
        Creates a new simulation which is neither 'initialized' nor 'started'.
        :< json int brainProcesses: Number of brain processes to use (overrides ExD Configuration)
        :< json string experimentConfiguration: Path and name of the experiment configuration file
        :< json string experimentID: The experiment ID of the experiment
        :< json string environmentConfiguration: Path of the custom SDF environment (optional)
        :< json string gzserverHost: The host where gzserver will be run: local for using the same
                                     machine of the backend
        :< json string reservation: the name of the cluster reservation subsequently used to
                                    allocate a job
        :< json string state: The initial state of the simulation
        :< json boolean private: Defines whether the simulation is based on a private experiment
        :< json string playbackPath: The simulation recording to playback (Path to recording root)
        :< json string ctx-id: The context id of the collab if we are running a collab based
                               simulation

        :> json string owner: The simulation owner (Unified Portal user name or 'hbp-default')
        :> json string state: The current state of the simulation (always 'created')
        :> json integer simulationID: The id of the simulation (needed for further REST calls)
        :> json string experimentConfiguration: Path and name of the experiment configuration file
        :> json string environmentConfiguration: Path and name of the environment configuration file
        :> json string creationDate: Date of creation of this simulation
        :> json string gzserverHost: The host where gzserver will be run: local for using the same
                                     machine of the backend, lugano to use a dedicated instance on
                                     the Lugano viz cluster
        :> json string reservation: the name of the cluster reservation subsequently used to
                                    allocate a job
        :> json string experimentID: The experiment ID if the experiment is using the storage
        :> json integer brainProcesses: Number of brain processes for simulation, overrides the
                                        number specified in the experiment configuration file
        :> json string creationUniqueID: The simulation unique creation ID that is used by the
                                         Frontend to identify this simulation
        :>json string playbackPath: Path to simulation recording to play (optional)
        :>json boolean private: Simulation is based on a private experiment

        :status 400: Experiment configuration is not valid
        :status 401: gzserverHost is not valid
        :status 402: Another simulation is already running on the server
        :status 201: Simulation created successfully
        """
        body = request.get_json(force=True)
        sim_id = len(simulations)
        if 'experimentConfiguration' not in body:
            raise NRPServicesClientErrorException('Experiment configuration not given.')

        if ('gzserverHost' in body) and (body.get('gzserverHost') not in ['local', 'lugano']):
            raise NRPServicesClientErrorException('Invalid gazebo server host.', error_code=401)

        if True in [s.state not in ['stopped', 'failed'] for s in simulations]:
            raise NRPServicesClientErrorException(
                'Another simulation is already running on the server.', error_code=409)

        if 'brainProcesses' in body and \
           (not isinstance(body.get('brainProcesses'), int) or body.get('brainProcesses') < 1):
            raise NRPServicesClientErrorException('Invalid number of brain processes.')

        sim_gzserver_host = body.get('gzserverHost', 'local')
        sim_reservation = body.get('reservation', None)
        sim_experiment_id = body.get('experimentID', None)
        sim_state = body.get('state', 'created')
        playback_path = body.get('playbackPath', None)
        sim_owner = UserAuthentication.get_x_user_name_header(request)
        sim_brain_processes = body.get('brainProcesses', 1)
        private = body.get('private', None)
        ctx_id = body.get('ctxId', None)

        sim = Simulation(sim_id,
                         body['experimentConfiguration'],
                         body.get('environmentConfiguration', None),
                         sim_owner,
                         sim_gzserver_host,
                         sim_reservation,
                         sim_brain_processes,
                         sim_experiment_id,
                         sim_state,
                         playback_path=playback_path,
                         private=private,
                         ctx_id=ctx_id)

        sim.creationUniqueID = body.get(
            'creationUniqueID', str(time.time() + random.random()))

        sim.state = "initialized"
        simulations.append(sim)

        return marshal(simulations[sim_id], Simulation.resource_fields), 201, {
            'location': api.url_for(SimulationControl, sim_id=sim_id),
            'gzserverHost': sim_gzserver_host
        }
コード例 #17
0
 def setUp(self):
     del simulations[:]
     simulations.append(
         Simulation(0, 'experiment1', None, 'default-owner', 'created'))