Skip to content

Commit

Permalink
unit tests + doc update
Browse files Browse the repository at this point in the history
Signed-off-by: Shaanjot Gill <gill.shaanjots@gmail.com>
  • Loading branch information
shaangill025 committed Oct 5, 2023
1 parent 9387824 commit ef30678
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 6 deletions.
12 changes: 12 additions & 0 deletions UpgradingACA-Py.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ In case, running multiple tags [say test1 & test2]:
./scripts/run_docker upgrade --force-upgrade --named-tag test1 --named-tag test2
```

## Subwallet upgrades
With multitenant enabled, there is a subwallet associated with each tenant profile, so there is a need to upgrade those sub wallets in addition to the base wallet associated with root profile.

There are 2 options to perform such upgrades:
- `--upgrade-all-subwallets`

This will apply the upgrade steps to all sub wallets [tenant profiles] and the base wallet [root profiles].

- `--upgrade-subwallet`

This will apply the upgrade steps to specified sub wallets [identified by wallet id] and the base wallet.

Note: multiple specification allowed

## Exceptions

Expand Down
74 changes: 74 additions & 0 deletions aries_cloudagent/commands/tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ...storage.base import BaseStorage
from ...storage.record import StorageRecord
from ...version import __version__
from ...wallet.models.wallet_record import WalletRecord

from .. import upgrade as test_module
from ..upgrade import UpgradeError
Expand All @@ -22,6 +23,24 @@ async def setUp(self):
"v0.7.2",
)
await self.storage.add_record(record)
recs = [
WalletRecord(
key_management_mode=[
WalletRecord.MODE_UNMANAGED,
WalletRecord.MODE_MANAGED,
][i],
settings={
"wallet.name": f"my-wallet-{i}",
"wallet.type": "indy",
"wallet.key": f"dummy-wallet-key-{i}",
},
wallet_name=f"my-wallet-{i}",
)
for i in range(2)
]
async with self.profile.session() as session:
for rec in recs:
await rec.save(session)

def test_bad_calls(self):
with self.assertRaises(SystemExit):
Expand Down Expand Up @@ -85,6 +104,61 @@ async def test_upgrade_from_version(self):
profile=self.profile,
)

async def test_upgrade_all_subwallets(self):
self.profile.settings.extend(
{
"upgrade.from_version": "v0.7.2",
"upgrade.upgrade_all_subwallets": True,
"upgrade.force_upgrade": True,
}
)
with async_mock.patch.object(
ConnRecord,
"query",
async_mock.CoroutineMock(return_value=[ConnRecord()]),
), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()):
await test_module.upgrade(
profile=self.profile,
)

async def test_upgrade_specified_subwallets(self):
wallet_ids = []
async with self.profile.session() as session:
wallet_recs = await WalletRecord.query(session, tag_filter={})
for wallet_rec in wallet_recs:
wallet_ids.append(wallet_rec.wallet_id)
self.profile.settings.extend(
{
"upgrade.named_tags": "fix_issue_rev_reg",
"upgrade.upgrade_subwallets": [wallet_ids[0]],
"upgrade.force_upgrade": True,
}
)
with async_mock.patch.object(
ConnRecord,
"query",
async_mock.CoroutineMock(return_value=[ConnRecord()]),
), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()):
await test_module.upgrade(
profile=self.profile,
)

self.profile.settings.extend(
{
"upgrade.named_tags": "fix_issue_rev_reg",
"upgrade.upgrade_subwallets": wallet_ids,
"upgrade.force_upgrade": True,
}
)
with async_mock.patch.object(
ConnRecord,
"query",
async_mock.CoroutineMock(return_value=[ConnRecord()]),
), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()):
await test_module.upgrade(
profile=self.profile,
)

async def test_upgrade_callable(self):
version_storage_record = await self.storage.find_record(
type_filter="acapy_version", tag_query={}
Expand Down
11 changes: 5 additions & 6 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2152,18 +2152,17 @@ def add_arguments(self, parser: ArgumentParser):
"--upgrade-all-subwallets",
action="store_true",
env_var="ACAPY_UPGRADE_ALL_SUBWALLETS",
help=(
"Forces the '—from-version' argument to override the version "
"retrieved from secure storage when calculating upgrades to "
"be run."
),
help="Apply upgrade to all subwallets and the base wallet",
)

parser.add_argument(
"--upgrade-subwallet",
action="append",
env_var="ACAPY_UPGRADE_SUBWALLETS",
help=("Runs upgrade steps associated with tags provided in the config"),
help=(
"Apply upgrade to specified subwallets (identified by wallet id)"
" and the base wallet"
),
)

def get_settings(self, args: Namespace) -> dict:
Expand Down
69 changes: 69 additions & 0 deletions aries_cloudagent/config/tests/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,75 @@ async def test_upgrade_config(self):
== "./aries_cloudagent/config/tests/test-acapy-upgrade-config.yml"
)

result = parser.parse_args(
[
"--named-tag",
"test_tag_1",
"--named-tag",
"test_tag_2",
"--force-upgrade",
]
)

assert result.named_tag == ["test_tag_1", "test_tag_2"]
assert result.force_upgrade is True

settings = group.get_settings(result)

assert settings.get("upgrade.named_tags") == ["test_tag_1", "test_tag_2"]
assert settings.get("upgrade.force_upgrade") is True

result = parser.parse_args(
[
"--upgrade-config-path",
"./aries_cloudagent/config/tests/test-acapy-upgrade-config.yml",
"--from-version",
"v0.7.2",
"--upgrade-all-subwallets",
"--force-upgrade",
]
)

assert (
result.upgrade_config_path
== "./aries_cloudagent/config/tests/test-acapy-upgrade-config.yml"
)
assert result.force_upgrade is True
assert result.upgrade_all_subwallets is True

settings = group.get_settings(result)

assert (
settings.get("upgrade.config_path")
== "./aries_cloudagent/config/tests/test-acapy-upgrade-config.yml"
)
assert settings.get("upgrade.force_upgrade") is True
assert settings.get("upgrade.upgrade_all_subwallets") is True

result = parser.parse_args(
[
"--named-tag",
"fix_issue_rev_reg",
"--upgrade-subwallet",
"test_wallet_id_1",
"--upgrade-subwallet",
"test_wallet_id_2",
"--force-upgrade",
]
)

assert result.named_tag == ["fix_issue_rev_reg"]
assert result.force_upgrade is True
assert result.upgrade_subwallet == ["test_wallet_id_1", "test_wallet_id_2"]

settings = group.get_settings(result)
assert settings.get("upgrade.named_tags") == ["fix_issue_rev_reg"]
assert settings.get("upgrade.force_upgrade") is True
assert settings.get("upgrade.upgrade_subwallets") == [
"test_wallet_id_1",
"test_wallet_id_2",
]

async def test_outbound_is_required(self):
"""Test that either -ot or -oq are required"""
parser = argparse.create_argument_parser()
Expand Down

0 comments on commit ef30678

Please sign in to comment.