Exemple #1
0
 def _assert_correct_mn_call(self, block, expected_call):
     if block:
         self._logger.debug(
             'Waiting for call from MN: {}'.format(expected_call))
     try:
         call = self._queue.get(block, self._options.timeout_sec)
     except Queue.Empty:
         raise replication_error.ReplicationTesterError(
             'MN did not make expected call: {}'.format(expected_call))
     else:
         if call != expected_call:
             raise replication_error.ReplicationTesterError(
                 'MN made an unexpected call: {}.\nExpected: {}'.format(
                     call, expected_call))
Exemple #2
0
 def _call_src_get_replica(self, pid):
     mn_client = self._create_mn_client_for_get_replica()
     try:
         return mn_client.getReplica(pid).content
     except socket.error:
         raise replication_error.ReplicationTesterError(
             'Unable to connect to Source MN')
Exemple #3
0
 def _test_MNReplication_replicate_with_existing_pid(self):
     """The destination MN correctly rejects a replication request in which the
 identifier already exists on the MN.
 """
     try:
         self._call_dst_replicate(self._dst_existing_pid)
     except d1_common.types.exceptions.IdentifierNotUnique:
         pass
     except d1_common.types.exceptions.DataONEException as e:
         raise replication_error.ReplicationTesterError(
             'MNReplication.replicate()(existing PID): '
             'Expected exception IdentifierNotUnique. Received: {}'.format(
                 e))
     else:
         raise replication_error.ReplicationTesterError(
             'MNReplication.replicate()(existing PID): '
             'Failed to raise exception')
Exemple #4
0
 def _call_dst_replicate(self, pid):
     mn_client = self._create_mn_client_for_replicate()
     sys_meta = test_object_generator.generate_science_object_with_sysmeta(
         pid)[0]
     try:
         mn_client.replicate(sys_meta, TEST_MN_NODE_ID)
     except socket.error:
         raise replication_error.ReplicationTesterError(
             'Unable to connect to Destination MN')
Exemple #5
0
 def _test_getReplica_with_approved_pid(self):
     """Source MN responds correctly on MNRead.getReplica()
 in which the identifier is valid and replication is approved by the CN.
 """
     try:
         self._call_src_get_replica(self._src_existing_pid_approve)
     except d1_common.types.exceptions.DataONEException as e:
         raise replication_error.ReplicationTesterError(
             'Source MNRead.getReplica(valid PID with replication approved): '
             'Expected OctetStream. Received exception: {}'.format(e))
     self._assert_correct_mn_call_instant('isNodeAuthorized_approved',
                                          self._src_existing_pid_approve,
                                          'public')
Exemple #6
0
 def _test_getReplica_with_unknown_pid(self):
     """Source MN responds correctly to MNRead.getReplica() in which the
 identifier is unknown.
 """
     try:
         self._call_src_get_replica(self._pid_unknown)
     except d1_common.types.exceptions.NotFound:
         pass
     except (
             d1_common.types.exceptions.DataONEException,
             replication_error.ReplicationTesterError,
     ) as e:
         raise replication_error.ReplicationTesterError(
             'Source MNRead.getReplica(unknown PID): '
             'Expected NotFound exception. Received: {}'.format(str(e)))
Exemple #7
0
 def _test_MNReplication_replicate_with_authorized_pid(self):
     """Test that the destination MN responds correctly on
 MNReplication.replicate() with an object that is both valid for replication
 and approved for replication by the CN.
 """
     try:
         self._call_dst_replicate(self._pid_known_and_authorized)
     except d1_common.types.exceptions.DataONEException as e:
         raise replication_error.ReplicationTesterError(
             'MNReplication.replicate()(PID_KNOWN_AND_AUTHORIZED): '
             'Expected MN to accept replication request. Instead, received exception: {}'
             .format(e))
     self._assert_correct_mn_call_with_wait('getReplica_OctetStream',
                                            self._pid_known_and_authorized)
     self._assert_correct_mn_call_with_wait('setReplicationStatus',
                                            self._pid_known_and_authorized,
                                            'completed')
Exemple #8
0
 def _test_MNReplication_replicate_with_unauthorized_pid(self):
     """The destination MN responds correctly on MNReplication.replicate() with
 an object that is valid for replication but for which the CN denies
 replication.
 """
     try:
         self._call_dst_replicate(self._pid_not_authorized)
     except d1_common.types.exceptions.DataONEException as e:
         raise replication_error.ReplicationTesterError(
             'MNReplication.replicate(PID_NOT_AUTHORIZED): '
             'Expected MN to accept replication request. Instead, received exception: {}'
             .format(e))
     self._assert_correct_mn_call_with_wait('getReplica_NotAuthorized',
                                            self._pid_not_authorized)
     self._assert_correct_mn_call_with_wait('setReplicationStatus',
                                            self._pid_not_authorized,
                                            'failed')
Exemple #9
0
 def _test_getReplica_with_rejected_pid(self):
     """Source MN responds correctly on MNRead.getReplica()
 in which the identifier is valid but replication is rejected by the CN.
 """
     try:
         self._call_src_get_replica(self._src_existing_pid_deny)
     except d1_common.types.exceptions.NotAuthorized:
         pass
     except (
             d1_common.types.exceptions.DataONEException,
             replication_error.ReplicationTesterError,
     ) as e:
         raise replication_error.ReplicationTesterError(
             'Source MNRead.getReplica(valid PID with replication rejected): '
             'Expected NotAuthorized exception. Received: {}'.format(e))
     self._assert_correct_mn_call_instant('isNodeAuthorized_rejected',
                                          self._src_existing_pid_deny,
                                          'public')
Exemple #10
0
 def _assert_if_invalid(self, path):
     if path is not None and not os.path.isfile(path):
         raise replication_error.ReplicationTesterError(
             'No certificate or key at path: {}'.format(path))