Exemple #1
0
def test_delete_no_index_id():
    """Test DELETE api without index should return response as "None"."""
    config = CORTXS3Config()
    response = CORTXS3KVApi(config).delete(None, "test_key1")
    if (response is not None):
        assert response[0] is False
        assert response[1] is None
Exemple #2
0
def test_delete_no_object_key_name():
    """Test DELETE api without object key name should return response as "None"."""
    config = CORTXS3Config()
    response = CORTXS3KVApi(config).delete("test_index1", None)
    if (response is not None):
        assert response[0] is False
        assert response[1] is None
Exemple #3
0
def test_put_no_object_key_name():
    """Test PUT api without key should return response as "None"."""
    config = CORTXS3Config()
    response = CORTXS3KVApi(config).put("test_index1", None)
    if (response is not None):
        assert response[0] is False
        assert response[1] is None
Exemple #4
0
def test_get_no_index_id():
    """Test GET api without index_id should return response as "None"."""
    config = CORTXS3Config()
    response = CORTXS3KVApi(config).get(None, "test_key1")
    if (response is not None):
        assert response[0] is False
        assert response[1] is None
Exemple #5
0
 def __init__(self,
              config,
              probable_delete_records,
              logger=None,
              objectapi=None,
              kvapi=None,
              indexapi=None):
     """Initialise Validator"""
     self.config = config
     self.current_obj_in_VersionList = None
     self.probable_delete_records = probable_delete_records
     if (logger is None):
         self._logger = logging.getLogger("ObjectRecoveryValidator")
     else:
         self._logger = logger
     if (objectapi is None):
         self._objectapi = CORTXS3ObjectApi(self.config,
                                            logger=self._logger)
     else:
         self._objectapi = objectapi
     if (kvapi is None):
         self._kvapi = CORTXS3KVApi(self.config, logger=self._logger)
     else:
         self._kvapi = kvapi
     if (indexapi is None):
         self._indexapi = CORTXS3IndexApi(self.config, logger=self._logger)
     else:
         self._indexapi = indexapi
Exemple #6
0
def test_get_no_object_key_name():
    """Test GET api without object_key_name should return response as "None"."""
    config = CORTXS3Config()
    response = CORTXS3KVApi(config,
                            CONNECTION_TYPE_PRODUCER).get("test_index1", None)
    if (response is not None):
        assert response[0] is False
Exemple #7
0
def test_put_no_index_id():
    """Test PUT api without index_id should return response as "None"."""
    config = CORTXS3Config()
    response = CORTXS3KVApi(config,
                            CONNECTION_TYPE_PRODUCER).put(None, "test_key1")
    if (response is not None):
        assert response[0] is False
        assert response[1] is None
Exemple #8
0
def test_put_success():
    """Test PUT api, it should return success response."""
    httpconnection = Mock(spec=HTTPConnection)
    httpresponse = Mock(spec=HTTPResponse)
    httpresponse.status = 200
    httpresponse.getheaders.return_value = \
        'Content-Type:text/html;Content-Length:14'
    httpresponse.read.return_value = b'{}'
    httpresponse.reason = 'CREATED'
    httpconnection.getresponse.return_value = httpresponse

    config = CORTXS3Config()
    response = CORTXS3KVApi(config, connection=httpconnection).put(
        "test_index1", "test_key1")
    if (response is not None):
        assert response[0] is True
Exemple #9
0
def test_get_success():
    """Test GET api, it should return success response."""
    result = b'{"Key": "test_key1", "Value": "testValue1"}'
    httpconnection = Mock(spec=HTTPConnection)
    httpresponse = Mock(spec=HTTPResponse)
    httpresponse.status = 200
    httpresponse.getheaders.return_value = \
        'Content-Type:text/html;Content-Length:14'
    httpresponse.read.return_value = result
    httpresponse.reason = 'OK'
    httpconnection.getresponse.return_value = httpresponse

    config = CORTXS3Config()
    response = CORTXS3KVApi(config, connection=httpconnection).get(
        "test_index1", "test_key1")
    if (response is not None):
        assert response[0] is True
Exemple #10
0
def test_delete_success():
    """Test DELETE api, it should return success response."""
    httpconnection = Mock(spec=HTTPConnection)
    httpresponse = Mock(spec=HTTPResponse)
    httpresponse.status = 204
    httpresponse.getheaders.return_value = \
        'Content-Type:text/html;Content-Length:14'
    httpresponse.read.return_value = b'{}'
    httpresponse.reason = 'NO CONTENT'
    httpconnection.getresponse.return_value = httpresponse

    config = CORTXS3Config()
    response = CORTXS3KVApi(config,
                            CONNECTION_TYPE_PRODUCER,
                            connection=httpconnection).delete(
                                "test_index1", "test_key1")
    if (response is not None):
        assert response[0] is True
Exemple #11
0
def test_get_failure():
    """
    Test if index or key is not present then
    GET should return failure response.
    """
    httpconnection = Mock(spec=HTTPConnection)
    httpresponse = Mock(spec=HTTPResponse)
    httpresponse.status = 404
    httpresponse.getheaders.return_value = \
        'Content-Type:text/html;Content-Length:14'
    httpresponse.read.return_value = b'{}'
    httpresponse.reason = 'NOT FOUND'
    httpconnection.getresponse.return_value = httpresponse

    config = CORTXS3Config()
    response = CORTXS3KVApi(config, connection=httpconnection).get(
        "test_index2", "test_key2")
    if (response is not None):
        assert response[0] is False
Exemple #12
0
def test_put_failure():
    """
    Test if index_id and object key name is already present then
    PUT should return failure response.
    """
    httpconnection = Mock(spec=HTTPConnection)
    httpresponse = Mock(spec=HTTPResponse)
    httpresponse.status = 409
    httpresponse.getheaders.return_value = \
        'Content-Type:text/html;Content-Length:14'
    httpresponse.read.return_value = b'{}'
    httpresponse.reason = 'CONFLICT'
    httpconnection.getresponse.return_value = httpresponse

    config = CORTXS3Config()
    response = CORTXS3KVApi(config, connection=httpconnection).put(
        "test_index2", "test_key2")
    if (response is not None):
        assert response[0] is False
Exemple #13
0
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For any questions about this software or licensing,
# please email [email protected] or [email protected].
""" To Get KV for a key you need to execute this file as:

    python36 get_kv.py index_id key it's like 
    python36 get_kv.py sys.argv[1] sys.argv[2] """

import sys
from s3backgrounddelete.cortx_s3_config import CORTXS3Config
from s3backgrounddelete.cortx_s3_kv_api import CORTXS3KVApi
from s3backgrounddelete.cortx_s3_constants import CONNECTION_TYPE_PRODUCER

CONFIG = CORTXS3Config()
kv_api = CORTXS3KVApi(CONFIG, CONNECTION_TYPE_PRODUCER)
response, data = kv_api.get(sys.argv[1], sys.argv[2])
if (response):
    get_kv_response = data.get_value()
    print(get_kv_response)
else:
    print("Error")
    print(str(data.get_error_status()))
    print(str(data.get_error_message()))
Exemple #14
0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For any questions about this software or licensing,
# please email [email protected] or [email protected].
""" To delete KV for a key you need to execute this file as:

    python36 delete_kv.py index_id key it's like 
    python36 delete_kv.py sys.argv[1] sys.argv[2] """
import sys
from s3backgrounddelete.cortx_s3_config import CORTXS3Config
from s3backgrounddelete.cortx_s3_kv_api import CORTXS3KVApi
CONFIG = CORTXS3Config()
kv_api = CORTXS3KVApi(CONFIG)
response, data = kv_api.delete(sys.argv[1], sys.argv[2])
if (response):
    print("Success")
else:
    print("Error")
    print(data.get_error_message())
Exemple #15
0
 def __init__(self):
     self.config = CORTXS3Config(s3recovery_flag=True)
     self.index_api = CORTXS3IndexApi(self.config)
     self.kv_api = CORTXS3KVApi(self.config)
     self.log_result = False
     self.logger = None