Skip to content

Commit

Permalink
Merge pull request #1161 from weaviate/tenant_rename
Browse files Browse the repository at this point in the history
Update tenant names
  • Loading branch information
dirkkul authored Jul 5, 2024
2 parents 6d6e80c + 9f7d86b commit 4602a26
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
WEAVIATE_123: 1.23.15
WEAVIATE_124: 1.24.19
WEAVIATE_125: 1.25.5
WEAVIATE_126: preview-range-roaring-set-index-rename-indexrangeble-to-indexrangefilters-1083432
WEAVIATE_126: preview-allow-new-tenant-names-as-input-for-add-and-update-b6f5b8e

jobs:
lint-and-format:
Expand Down
76 changes: 46 additions & 30 deletions integration/test_tenants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
import uuid
from typing import List, Union

import pytest

from integration.conftest import CollectionFactory
from weaviate.collections.classes.config import (
Configure,
Expand Down Expand Up @@ -116,15 +117,15 @@ def test_tenants(collection_factory: CollectionFactory) -> None:

tenants = collection.tenants.get()
assert len(tenants) == 2
assert type(tenants["tenant1"]) is Tenant
assert type(tenants["tenant2"]) is Tenant
assert isinstance(tenants["tenant1"], Tenant)
assert isinstance(tenants["tenant2"], Tenant)
assert tenants["tenant1"].name == "tenant1"
assert tenants["tenant2"].name == "tenant2"

if collection._connection._weaviate_version.supports_tenants_get_grpc:
tenants = collection.tenants.get_by_names(tenants=["tenant2"])
assert len(tenants) == 1
assert type(tenants["tenant2"]) is Tenant
assert isinstance(tenants["tenant2"], Tenant)
assert tenants["tenant2"].name == "tenant2"
else:
pytest.raises(
Expand Down Expand Up @@ -228,31 +229,54 @@ def test_tenant_with_activity(collection_factory: CollectionFactory) -> None:
vectorizer_config=Configure.Vectorizer.none(),
multi_tenancy_config=Configure.multi_tenancy(enabled=True),
)
collection.tenants.create(
[
Tenant(name="1", activity_status=TenantActivityStatus.HOT),
Tenant(name="2", activity_status=TenantActivityStatus.COLD),
Tenant(name="3"),
]
)

with pytest.warns(DeprecationWarning) as recwarn:
collection.tenants.create(
[
Tenant(name="1", activity_status=TenantActivityStatus.HOT),
Tenant(name="2", activity_status=TenantActivityStatus.COLD),
Tenant(name="3", activity_status=TenantActivityStatus.ACTIVE),
Tenant(name="4", activity_status=TenantActivityStatus.INACTIVE),
Tenant(name="5"),
]
)
assert len(recwarn) == 2
assert any("HOT is deprecated" in warn.message.args[0] for warn in recwarn.list)
assert any("COLD is deprecated" in warn.message.args[0] for warn in recwarn.list)
tenants = collection.tenants.get()
assert tenants["1"].activity_status == TenantActivityStatus.HOT
assert tenants["2"].activity_status == TenantActivityStatus.COLD
assert tenants["3"].activity_status == TenantActivityStatus.HOT
assert tenants["1"].activity_status == TenantActivityStatus.ACTIVE
assert tenants["2"].activity_status == TenantActivityStatus.INACTIVE
assert tenants["3"].activity_status == TenantActivityStatus.ACTIVE
assert tenants["4"].activity_status == TenantActivityStatus.INACTIVE
assert tenants["5"].activity_status == TenantActivityStatus.ACTIVE


def test_update_tenant(collection_factory: CollectionFactory) -> None:
collection = collection_factory(
vectorizer_config=Configure.Vectorizer.none(),
multi_tenancy_config=Configure.multi_tenancy(enabled=True),
)
collection.tenants.create(Tenant(name="1", activity_status=TenantActivityStatus.HOT))
with pytest.warns(DeprecationWarning) as recwarn:
collection.tenants.create(Tenant(name="1", activity_status=TenantActivityStatus.HOT))
assert len(recwarn) == 1
assert any("HOT is deprecated" in warn.message.args[0] for warn in recwarn.list)
tenants = collection.tenants.get()
assert tenants["1"].activity_status == TenantActivityStatus.ACTIVE

with pytest.warns(DeprecationWarning) as recwarn:
collection.tenants.update(Tenant(name="1", activity_status=TenantActivityStatus.COLD))
assert len(recwarn) == 1
assert any("COLD is deprecated" in warn.message.args[0] for warn in recwarn.list)
tenants = collection.tenants.get()
assert tenants["1"].activity_status == TenantActivityStatus.INACTIVE

collection.tenants.update(Tenant(name="1", activity_status=TenantActivityStatus.ACTIVE))
tenants = collection.tenants.get()
assert tenants["1"].activity_status == TenantActivityStatus.HOT
assert tenants["1"].activity_status == TenantActivityStatus.ACTIVE

collection.tenants.update(Tenant(name="1", activity_status=TenantActivityStatus.COLD))
collection.tenants.update(Tenant(name="1", activity_status=TenantActivityStatus.INACTIVE))
tenants = collection.tenants.get()
assert tenants["1"].activity_status == TenantActivityStatus.COLD
assert tenants["1"].activity_status == TenantActivityStatus.INACTIVE


def test_tenant_exists(collection_factory: CollectionFactory) -> None:
Expand Down Expand Up @@ -373,14 +397,8 @@ def test_tenants_remove(
@pytest.mark.parametrize(
"tenants",
[
Tenant(name="1", activity_status=TenantActivityStatus.FREEZING),
Tenant(name="1", activity_status=TenantActivityStatus.UNFREEZING),
Tenant(name="1", activity_status=TenantActivityStatus.UNFROZEN),
Tenant(name="1", activity_status=TenantActivityStatus.FROZEN),
[
Tenant(name="1", activity_status=TenantActivityStatus.FREEZING),
Tenant(name="2", activity_status=TenantActivityStatus.UNFREEZING),
Tenant(name="3", activity_status=TenantActivityStatus.UNFROZEN),
Tenant(name="4", activity_status=TenantActivityStatus.FROZEN),
],
],
Expand All @@ -399,13 +417,11 @@ def test_tenants_create_with_read_only_activity_status(
@pytest.mark.parametrize(
"tenants",
[
Tenant(name="1", activity_status=TenantActivityStatus.FREEZING),
Tenant(name="1", activity_status=TenantActivityStatus.UNFREEZING),
Tenant(name="1", activity_status=TenantActivityStatus.UNFROZEN),
Tenant(name="1", activity_status=TenantActivityStatus.OFFLOADING),
Tenant(name="1", activity_status=TenantActivityStatus.ONLOADING),
[
Tenant(name="1", activity_status=TenantActivityStatus.FREEZING),
Tenant(name="2", activity_status=TenantActivityStatus.UNFREEZING),
Tenant(name="3", activity_status=TenantActivityStatus.UNFROZEN),
Tenant(name="1", activity_status=TenantActivityStatus.OFFLOADING),
Tenant(name="2", activity_status=TenantActivityStatus.ONLOADING),
],
],
)
Expand Down
16 changes: 15 additions & 1 deletion mock_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,21 @@ def TenantsGet(
activity_status=tenants_pb2.TENANT_ACTIVITY_STATUS_UNFREEZING,
),
tenants_pb2.Tenant(
name="tenant6", activity_status=tenants_pb2.TENANT_ACTIVITY_STATUS_UNFROZEN
name="tenant6", activity_status=tenants_pb2.TENANT_ACTIVITY_STATUS_ACTIVE
),
tenants_pb2.Tenant(
name="tenant7", activity_status=tenants_pb2.TENANT_ACTIVITY_STATUS_INACTIVE
),
tenants_pb2.Tenant(
name="tenant8", activity_status=tenants_pb2.TENANT_ACTIVITY_STATUS_OFFLOADED
),
tenants_pb2.Tenant(
name="tenant9",
activity_status=tenants_pb2.TENANT_ACTIVITY_STATUS_OFFLOADING,
),
tenants_pb2.Tenant(
name="tenant10",
activity_status=tenants_pb2.TENANT_ACTIVITY_STATUS_ONLOADING,
),
]
)
Expand Down
26 changes: 19 additions & 7 deletions mock_tests/test_tenants_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@

def test_tenants_get(tenants_collection: weaviate.collections.Collection) -> None:
tenants = list(tenants_collection.tenants.get().values())
assert len(tenants) == 6
assert len(tenants) == 10

assert tenants[0].name == "tenant1"
assert tenants[0].activity_status == TenantActivityStatus.HOT
assert tenants[0].activity_status == TenantActivityStatus.ACTIVE

assert tenants[1].name == "tenant2"
assert tenants[1].activity_status == TenantActivityStatus.COLD
assert tenants[1].activity_status == TenantActivityStatus.INACTIVE

assert tenants[2].name == "tenant3"
assert tenants[2].activity_status == TenantActivityStatus.FROZEN
assert tenants[2].activity_status == TenantActivityStatus.OFFLOADED

assert tenants[3].name == "tenant4"
assert tenants[3].activity_status == TenantActivityStatus.FREEZING
assert tenants[3].activity_status == TenantActivityStatus.OFFLOADING

assert tenants[4].name == "tenant5"
assert tenants[4].activity_status == TenantActivityStatus.UNFREEZING
assert tenants[4].activity_status == TenantActivityStatus.ONLOADING

assert tenants[5].name == "tenant6"
assert tenants[5].activity_status == TenantActivityStatus.UNFROZEN
assert tenants[5].activity_status == TenantActivityStatus.ACTIVE

assert tenants[6].name == "tenant7"
assert tenants[6].activity_status == TenantActivityStatus.INACTIVE

assert tenants[7].name == "tenant8"
assert tenants[7].activity_status == TenantActivityStatus.OFFLOADED

assert tenants[8].name == "tenant9"
assert tenants[8].activity_status == TenantActivityStatus.OFFLOADING

assert tenants[9].name == "tenant10"
assert tenants[9].activity_status == TenantActivityStatus.ONLOADING
Loading

0 comments on commit 4602a26

Please sign in to comment.