def test_get_processor_logger_file_failure():
    """
    Test if processor logger file is not returned then it should throw KeyError.
    """
    with pytest.raises(KeyError):
        config = CORTXS3Config(use_cipher = False)
        del config._config['logconfig']['processor_log_file']
        assert config.get_processor_logger_file()
Esempio n. 2
0
 def __init__(self):
     """Initialise Server, config and create logger."""
     self.server = None
     self.config = CORTXS3Config()
     self.create_logger_directory()
     self.create_logger()
     self.signal = DynamicConfigHandler(self)
     self.logger.info("Initialising the Object Recovery Processor")
def test_get_rabbitmq_durable_failure():
    """
    Test if rabbitmq durable is not specified then it should throw KeyError.
    """
    with pytest.raises(KeyError):
        config = CORTXS3Config(use_cipher = False)
        del config._config['rabbitmq']['durable']
        assert config.get_rabbitmq_durable()
def test_get_processor_logger_name_failure():
    """
    Test if processor logger name is incorrect then it should throw KeyError
    """
    with pytest.raises(KeyError):
        config = CORTXS3Config(use_cipher = False)
        del config._config['logconfig']['processor_logger_name']
        assert config.get_processor_logger_name()
Esempio n. 5
0
def test_get_rabbitmq_durable_failure():
    """
    Test if rabbitmq durable is not specified then it should throw AssertionError.
    """
    with pytest.raises(AssertionError):
        config = CORTXS3Config()
        del config._config['rabbitmq']['durable']
        assert config.s3confstore.get_config('rabbitmq>durable') == ''
Esempio n. 6
0
def test_get_processor_logger_name_failure():
    """
    Test if processor logger name is incorrect then it should throw AssertionError
    """
    with pytest.raises(AssertionError):
        config = CORTXS3Config()
        del config._config['logconfig']['processor_logger_name']
        assert config.s3confstore.get_config('logconfig>processor_logger_name') == ''
Esempio n. 7
0
def test_get_probable_delete_index_id_success():
    """Test if probable delete index id is returned."""
    config = CORTXS3Config()
    config.s3confstore.set_config('indexid>probable_delete_index_id',
                                  'test_index', False)
    index_id = config.s3confstore.get_config(
        'indexid>probable_delete_index_id')
    assert index_id == "test_index"
Esempio n. 8
0
def test_get_log_format_failure():
    """
    Test if log format is not added then it should throw AssertionError.
    """
    with pytest.raises(AssertionError):
        config = CORTXS3Config()
        del config._config['logconfig']['log_format']
        assert config.s3confstore.get_config('logconfig>log_format') == ''
Esempio n. 9
0
def test_get_log_format_success():
    """Test log format in logconfig."""
    config = CORTXS3Config()
    config.s3confstore.set_config(
        'logconfig>log_format',
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s', False)
    log_format = config.s3confstore.get_config('logconfig>log_format')
    assert log_format == "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
Esempio n. 10
0
def test_get_schedule_interval_success():
    """Test if scheduler time interval is returned."""
    config = CORTXS3Config()
    config.s3confstore.set_config('cortx_s3>scheduler_schedule_interval', 900,
                                  False)
    schedule_interval = config.s3confstore.get_config(
        'cortx_s3>scheduler_schedule_interval')
    assert schedule_interval == 900
Esempio n. 11
0
 def __init__(self):
     """Initialise logger and configuration."""
     self.data = None
     self.config = CORTXS3Config()
     self.create_logger_directory()
     self.create_logger()
     self.signal = DynamicConfigHandler(self)
     self.logger.info("Initialising the Object Recovery Scheduler")
Esempio n. 12
0
def test_head_no_layout_id():
    """Test HEAD api without layout id, it should return response as "None"."""
    config = CORTXS3Config()
    response = CORTXS3ObjectApi(config, CONNECTION_TYPE_PRODUCER).head(
        "test_oid1", None)
    if (response is not None):
        assert response[0] is False
        assert response[1] is None
Esempio n. 13
0
def test_delete_no_pvid():
    """Test DELETE api without pvid, it should return response as "None"."""
    config = CORTXS3Config()
    response = CORTXS3ObjectApi(config, CONNECTION_TYPE_PRODUCER).delete(
        "test_oid1", "test_layout_id2", None)
    if (response is not None):
        assert response[0] is False
        assert response[1] is None
Esempio n. 14
0
def test_delete_no_index_id():
    """Test DELETE api without index should return response as "None"."""
    config = CORTXS3Config()
    response = CORTXS3KVApi(config, CONNECTION_TYPE_PRODUCER).delete(
        None, "test_key1")
    if (response is not None):
        assert response[0] is False
        assert response[1] is None
def test_get_log_level_failure():
    """
    Test if log level of file is not returned then it should throw KeyError.
    """
    with pytest.raises(KeyError):
        config = CORTXS3Config(use_cipher = False)
        del config._config['logconfig']['file_log_level']
        assert config.get_file_log_level()
Esempio n. 16
0
def test_get_log_level_failure():
    """
    Test if log level of file is not returned then it should throw AssertionError.
    """
    with pytest.raises(AssertionError):
        config = CORTXS3Config()
        del config._config['logconfig']['file_log_level']
        assert config.s3confstore.get_config('logconfig>file_log_level') == ''
def test_get_log_format_failure():
    """
    Test if log format is not added then it should throw KeyError.
    """
    with pytest.raises(KeyError):
        config = CORTXS3Config(use_cipher = False)
        del config._config['logconfig']['log_format']
        assert config.get_log_format()
Esempio n. 18
0
def test_get_cortx_s3_endpoint_failure():
    """
    Test if endpoint is not configured then it should throw AssertionError.
    """
    with pytest.raises(AssertionError):
        config = CORTXS3Config()
        del config._config['cortx_s3']['endpoint']
        assert config.s3confstore.get_config('cortx_s3>endpoint') == ''
def test_get_cortx_s3_endpoint_failure():
    """
    Test if endpoint is not configured then it should throw KeyError.
    """
    with pytest.raises(KeyError):
        config = CORTXS3Config(use_cipher = False)
        del config._config['cortx_s3']['endpoint']
        assert config.get_cortx_s3_endpoint()
Esempio n. 20
0
def test_get_scheduler_logger_file_failure():
    """
    Test if scheduler logger file is not returned then it should throw AssertionError.
    """
    with pytest.raises(AssertionError):
        config = CORTXS3Config()
        del config._config['logconfig']['scheduler_log_file']
        assert config.s3confstore.get_config('logconfig>scheduler_log_file') == ''
Esempio n. 21
0
def test_put_no_object_key_name():
    """Test PUT api without key should return response as "None"."""
    config = CORTXS3Config()
    response = CORTXS3KVApi(config,
                            CONNECTION_TYPE_PRODUCER).put("test_index1", None)
    if (response is not None):
        assert response[0] is False
        assert response[1] is None
def test_object_metadata_not_exists():
    """Test to check if ObjectRecoveryValidator attempts delete for object oid """
    index_api_mock = Mock(spec=CORTXS3IndexApi)
    kv_api_mock = Mock(spec=CORTXS3KVApi)
    object_api_mock = Mock(spec=CORTXS3ObjectApi)

    ol_res_val = {
        'ACL': '',
        'Bucket-Name': 'mybucket',
        'Object-Name': 'test_object',
        'Object-URI': 'mybucket\\test_object',
        'create_timestamp': '2020-03-17T11:02:13.000Z',
        'layout_id': 9,
        'motr_oid': 'Tgj8AgAAAAA=-dQAAAAAABCY='
    }

    index_content = {
        'Delimiter': '',
        'Index-Id': 'AAAAAAAAAHg=-BAAQAAAAAAA=',
        'IsTruncated': 'false',
        'Keys': [{
            'Key': 'test_object',
            'Value': ol_res_val
        }],
        'Marker': '',
        'MaxKeys': '1000',
        'NextMarker': '',
        'Prefix': ''
    }
    index_response = CORTXS3ListIndexResponse(
        json.dumps(index_content).encode())
    error_response = CORTXS3ErrorResponse(404, "Not found", "Not found")

    index_api_mock.list.return_value = True, index_response
    kv_api_mock.get.return_value = False, error_response
    object_api_mock.delete.return_value = True, {}

    config = CORTXS3Config()
    probable_delete_records = {'Key': 'TAcGAQAAAAA=-AwAAAAAAhEs=', \
        'Value':'{"motr_process_fid":"<0x7200000000000000:0>","create_timestamp":"2020-03-16T16:24:04.000Z", \
        "force_delete":"false","global_instance_id":"TAifBwAAAAA=-AAAAAAAA2lk=","is_multipart":"false", \
        "object_key_in_index":"object_1","object_layout_id":9,"pv_id":"AQAAAAAAAHYKAAAAAAAAAA==","object_list_index_oid":"TAifBwAAAHg=-AQAAAAAA2lk=", \
        "objects_version_list_index_oid":"TAifBwAAAHg=-AwAAAAAA2lk=","old_oid":"Tgj8AgAAAAA=-kwAAAAAABCY=", \
        "version_key_in_index":"object_1/18446742489333709430"}\n'                                                                  }

    validator = ObjectRecoveryValidator(config,
                                        probable_delete_records,
                                        objectapi=object_api_mock,
                                        kvapi=kv_api_mock,
                                        indexapi=index_api_mock)
    #Mock call to 'process_probable_delete_record'
    validator.process_probable_delete_record = MagicMock(return_value=True)

    validator.process_results()

    # Assert that object oid delete and leak index entry delete
    # is triggered if metadata doesn't exists.
    validator.process_probable_delete_record.assert_called_with(True, True)
def test_get_threshold_failure():
    """
    Test if threshold is not specified
    then it should throw AssertionError.
    """
    with pytest.raises(AssertionError):
        config = CORTXS3Config()
        del config._config['indexid']['threshold']
        assert config.s3confstore.get_config('indexid>threshold') == ''
def test_get_cortx_s3_service_failure():
    """
    Test if service is not configured in cortxs3 configuration
    then it should throw AssertionError.
    """
    with pytest.raises(AssertionError):
        config = CORTXS3Config()
        del config._config['cortx_s3']['service']
        assert config.s3confstore.get_config('cortx_s3>service') == ''
def test_get_cortx_s3_region_failure():
    """
    Test if default_region is not configured in cortxs3 configuration
    then it should throw AssertionError.
    """
    with pytest.raises(AssertionError):
        config = CORTXS3Config()
        del config._config['cortx_s3']['default_region']
        assert config.s3confstore.get_config('cortx_s3>default_region') == ''
Esempio n. 26
0
def test_get_probable_delete_index_id_failure():
    """
    Test if probable delete index id is not specified
    then it should throw KeyError.
    """
    with pytest.raises(KeyError):
        config = CORTXS3Config()
        del config._config['indexid']['probable_delete_index_id']
        assert config.get_probable_delete_index_id()
Esempio n. 27
0
def test_get_schedule_interval_failure():
    """
    Test if scheduler time interval is not specified
    then it should throw KeyError.
    """
    with pytest.raises(KeyError):
        config = CORTXS3Config()
        del config._config['rabbitmq']['schedule_interval_secs']
        assert config.get_schedule_interval()
Esempio n. 28
0
def test_get_rabbitmq_exchange_type_failure():
    """
    Test if rabbitmq exchange type is not specified
    then it should throw KeyError.
    """
    with pytest.raises(KeyError):
        config = CORTXS3Config()
        del config._config['rabbitmq']['exchange_type']
        assert config.get_rabbitmq_exchange_type()
Esempio n. 29
0
def test_get_cortx_s3_secret_key_failure():
    """
    Test if secret_key is not configured in cortxs3 configuration
    then it should throw KeyError.
    """
    with pytest.raises(KeyError):
        config = CORTXS3Config()
        del config._config['cortx_s3']['background_account_secret_key']
        assert config.get_cortx_s3_secret_key()
Esempio n. 30
0
def test_get_probable_delete_index_id_failure():
    """
    Test if probable delete index id is not specified
    then it should throw AssertionError.
    """
    with pytest.raises(AssertionError):
        config = CORTXS3Config()
        del config._config['indexid']['probable_delete_index_id']
        assert config.s3confstore.get_config('indexid>probable_delete_index_id') == ''