diff --git a/pinecone/control/pinecone.py b/pinecone/control/pinecone.py index 02752571f..ad51b76b8 100644 --- a/pinecone/control/pinecone.py +++ b/pinecone/control/pinecone.py @@ -12,6 +12,8 @@ CreateCollectionRequest, CreateIndexRequest, ConfigureIndexRequest, + ConfigureIndexRequestSpec, + ConfigureIndexRequestSpecPod ) from pinecone.models import ServerlessSpec, PodSpec, IndexList, CollectionList @@ -176,7 +178,11 @@ def configure_index(self, name: str, replicas: Optional[int] = None, pod_type: O config_args.update(pod_type=pod_type) if replicas: config_args.update(replicas=replicas) - configure_index_request = ConfigureIndexRequest(**config_args) + configure_index_request = ConfigureIndexRequest( + spec=ConfigureIndexRequestSpec( + pod=ConfigureIndexRequestSpecPod(**config_args) + ) + ) api_instance.configure_index(name, configure_index_request=configure_index_request) def create_collection(self, name: str, source: str): diff --git a/tests/integ/__init__.py b/tests/integ/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/integ/test_index.py b/tests/integ/test_index.py deleted file mode 100644 index 2df35b986..000000000 --- a/tests/integ/test_index.py +++ /dev/null @@ -1,138 +0,0 @@ -import json - -import pytest -from urllib3_mock import Responses -import responses as req_responses - -import pinecone -from pinecone import PineconeApiTypeError, PineconeApiException - -responses_req = Responses() -responses = Responses("requests.packages.urllib3") - -@pytest.mark.skip() -@req_responses.activate -@responses.activate -def test_invalid_upsert_request_vector_value_type(): - environment = "example-environment" - project_name = "example-project" - req_responses.add( - "GET", - f"https://controller.{environment}.pinecone.io/actions/whoami", - status=200, - content_type="application/json", - body=json.dumps(dict(project_name=project_name, user_label="example-label", user_name="test")), - ) - responses.add( - "POST", - "/vectors/upsert", - status=400, - content_type="text/plain", - adding_headers={ - "content-length": "62", - "date": "Thu, 28 Oct 2021 09:14:51 GMT", - "server": "envoy", - "connection": "close", - }, - body='vectors[0].values[1]: invalid value "type" for type TYPE_FLOAT', - ) - - pinecone.init("example-api-key", environment="example-environment") - with pytest.raises(PineconeApiException) as exc_info: - index = pinecone.Index("example-index") - resp = index.upsert(vectors=[("vec1", [0.1] * 8), ("vec2", [0.2] * 8)]) - - assert len(responses.calls) == 1 - assert responses.calls[0].request.scheme == "https" - assert responses.calls[0].request.host == "example-index-example-project.svc.example-environment.pinecone.io" - assert responses.calls[0].request.url == "/vectors/upsert" - -@pytest.mark.skip() -@req_responses.activate -@responses.activate -def test_multiple_indexes(): - environment = "example-environment" - project_name = "example-project" - index1_name = "index-1" - index2_name = "index-2" - req_responses.add( - "GET", - f"https://controller.{environment}.pinecone.io/actions/whoami", - status=200, - content_type="application/json", - body=json.dumps(dict(project_name=project_name, user_label="example-label", user_name="test")), - ) - responses.add( - "GET", - f"/describe_index_stats", - status=200, - content_type="application/json", - adding_headers={"date": "Thu, 28 Oct 2021 09:14:51 GMT", "server": "envoy"}, - body='{"namespaces":{"":{"vectorCount":50000},"example-namespace-2":{"vectorCount":30000}},"dimension":1024}', - ) - - pinecone.init("example-api-key", environment="example-environment") - - index1 = pinecone.Index(index1_name) - resp1 = index1.describe_index_stats() - assert resp1.dimension == 1024 - assert responses.calls[0].request.host == f"{index1_name}-{project_name}.svc.{environment}.pinecone.io" - - index2 = pinecone.Index(index2_name) - resp2 = index2.describe_index_stats() - assert resp2.dimension == 1024 - assert responses.calls[1].request.host == f"{index2_name}-{project_name}.svc.{environment}.pinecone.io" - -@pytest.mark.skip() -@req_responses.activate -@responses.activate -def test_invalid_delete_response_unrecognized_field(): - # unrecognized response fields are okay, shouldn't raise an exception - environment = "example-environment" - project_name = "example-project" - req_responses.add( - "GET", - f"https://controller.{environment}.pinecone.io/actions/whoami", - status=200, - content_type="application/json", - body=json.dumps(dict(project_name=project_name, user_label="example-label", user_name="test")), - ) - responses.add( - "DELETE", "/vectors/delete", body='{"unexpected_key": "xyzzy"}', status=200, content_type="application/json" - ) - - pinecone.init("example-api-key", environment=environment) - index = pinecone.Index("example-index") - resp = index.delete(ids=["vec1", "vec2"]) - - assert len(req_responses.calls) == 1 - assert responses.calls[0].request.scheme == "https" - assert responses.calls[0].request.host == f"example-index-{project_name}.svc.{environment}.pinecone.io" - assert responses.calls[0].request.url == "/vectors/delete?ids=vec1&ids=vec2" - -@pytest.mark.skip() -@responses.activate -def test_delete_response_missing_field(): - # missing (optional) response fields are okay, shouldn't raise an exception - pinecone.init("example-api-key", environment="example-environment") - responses.add("DELETE", "/vectors/delete", body="{}", status=200, content_type="application/json") - index = pinecone.Index("example-index") - # this should not raise - index.delete(ids=["vec1", "vec2"]) - -@pytest.mark.skip() -@responses.activate -def _test_invalid_delete_response_wrong_type(): - # FIXME: re-enable this test when accepted_count added back to response - # wrong-typed response fields should raise an exception - pinecone.init("example-api-key", environment="example-environment") - - responses.add( - "DELETE", "/vectors/delete", body='{"deleted_count": "foobar"}', status=200, content_type="application/json" - ) - - index = pinecone.Index("example-index") - - with pytest.raises(PineconeApiTypeError) as exc_info: - resp = index.delete(ids=["vec1", "vec2"]) - assert resp.deleted_count == 2 diff --git a/tests/integration/control/conftest.py b/tests/integration/control/conftest.py index b43bde998..07322b99e 100644 --- a/tests/integration/control/conftest.py +++ b/tests/integration/control/conftest.py @@ -35,9 +35,12 @@ def create_sl_index_params(index_name, serverless_cloud, serverless_region): return dict(name=index_name, dimension=10, metric='cosine', spec=spec) @pytest.fixture() -def create_pod_index_params(index_name, environment): - spec = { - 'environment': environment +def create_pod_index_params(index_name, pod_environment): + spec = { + 'pod': { + 'environment': pod_environment, + 'pod_type': 'p1.x1' + } } return dict(name=index_name, dimension=10, metric='cosine', spec=spec, timeout=-1) diff --git a/tests/integration/control/test_configure_pod_index.py b/tests/integration/control/test_configure_pod_index.py new file mode 100644 index 000000000..1167fc481 --- /dev/null +++ b/tests/integration/control/test_configure_pod_index.py @@ -0,0 +1,5 @@ +import time +class TestCreatePodIndex(): + def test_create_pod_index(self, client, ready_pod_index): + time.sleep(30) # Wait a little more, just in case. + client.configure_index(ready_pod_index, replicas=1, pod_type='p1.x1') \ No newline at end of file