Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
swcurran authored Apr 5, 2023
2 parents e308b74 + 8e6b520 commit b272f7b
Show file tree
Hide file tree
Showing 15 changed files with 464 additions and 114 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
# 0.8.1-rc0
# 0.8.1-rc2

## March 31, 2023
## April 3, 2023

An urgent update to Release 0.8.1 to address an inability to execute the
`upgrade` command. The `upgrade` command is needed for Pull Request [\#2116] -
"UPGRADE: Fix multi-use invitation performance", which is necessary for (at
least) deployments of ACA-Py as a mediator. The important update is Pull Request
[\#2185] (listed below).
least) deployments of ACA-Py as a mediator. The important updates are Pull
Requests [\#2185] and [\#2196] (listed below). Documentation on upgrades in
ACA-Py be included before the final 0.8.1 release is tagged.

[\#2116]: https://github.com/hyperledger/aries-cloudagent-python/pull/2116
[\#2185]: https://github.com/hyperledger/aries-cloudagent-python/pull/2185
[\#2196]: https://github.com/hyperledger/aries-cloudagent-python/pull/2196

### Categorized List of Pull Requests

- Fixes for the `upgrade` Command
- Fix: Indy WalletAlreadyOpenedError during upgrade process [\#2196](https://github.com/hyperledger/aries-cloudagent-python/pull/2196) [shaangill025](https://github.com/shaangill025)
- Fix: Resolve Upgrade Config file in Container [\#2193](https://github.com/hyperledger/aries-cloudagent-python/pull/2193) [shaangill025](https://github.com/shaangill025)
- Update and automate ACA-Py upgrade process [\#2185](https://github.com/hyperledger/aries-cloudagent-python/pull/2185) [shaangill025](https://github.com/shaangill025)
- Adds the upgrade command YML file to the PyPi Release [\#2179](https://github.com/hyperledger/aries-cloudagent-python/pull/2179) [swcurran](https://github.com/swcurran)
- Test and Documentation
- Create UnitTests.md [\#2183](https://github.com/hyperledger/aries-cloudagent-python/pull/2183) [swcurran](https://github.com/swcurran)
- Add link to recorded session about the ACA-Py Integration tests [\#2184](https://github.com/hyperledger/aries-cloudagent-python/pull/2184) [swcurran](https://github.com/swcurran)
- Release management pull requests
- 0.8.1-rc2 [\#2198](https://github.com/hyperledger/aries-cloudagent-python/pull/2198) [swcurran](https://github.com/swcurran)
- 0.8.1-rc1 [\#2194](https://github.com/hyperledger/aries-cloudagent-python/pull/2194) [swcurran](https://github.com/swcurran)
- 0.8.1-rc0 [\#2190](https://github.com/hyperledger/aries-cloudagent-python/pull/2190) [swcurran](https://github.com/swcurran)

# 0.8.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v0.8.0:
v0.8.1:
resave_records:
base_record_path:
- "aries_cloudagent.connections.models.conn_record.ConnRecord"
Expand Down
50 changes: 25 additions & 25 deletions aries_cloudagent/commands/tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def test_upgrade_storage_from_version_included(self):
ConnRecord, "save", async_mock.CoroutineMock()
):
await test_module.upgrade(
{
settings={
"upgrade.config_path": "./aries_cloudagent/commands/default_version_upgrade_config.yml",
"upgrade.from_version": "v0.7.2",
}
Expand All @@ -69,29 +69,21 @@ async def test_upgrade_storage_missing_from_version(self):
), async_mock.patch.object(
ConnRecord, "save", async_mock.CoroutineMock()
):
await test_module.upgrade({})
await test_module.upgrade(settings={})

async def test_upgrade_from_version(self):
self.profile.settings.extend(
{
"upgrade.from_version": "v0.7.2",
}
)
with async_mock.patch.object(
test_module,
"wallet_config",
async_mock.CoroutineMock(
return_value=(
self.profile,
async_mock.CoroutineMock(did="public DID", verkey="verkey"),
)
),
), async_mock.patch.object(
ConnRecord,
"query",
async_mock.CoroutineMock(return_value=[ConnRecord()]),
), async_mock.patch.object(
ConnRecord, "save", async_mock.CoroutineMock()
):
), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()):
await test_module.upgrade(
{
"upgrade.from_version": "v0.7.2",
}
profile=self.profile,
)

async def test_upgrade_callable(self):
Expand Down Expand Up @@ -125,7 +117,7 @@ async def test_upgrade_callable(self):
),
):
await test_module.upgrade(
{
settings={
"upgrade.from_version": "v0.7.2",
}
)
Expand All @@ -146,7 +138,7 @@ async def test_upgrade_x_same_version(self):
),
):
await test_module.upgrade(
{
settings={
"upgrade.config_path": "./aries_cloudagent/commands/default_version_upgrade_config.yml",
}
)
Expand Down Expand Up @@ -174,7 +166,7 @@ async def test_upgrade_missing_from_version(self):
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(
{
settings={
"upgrade.config_path": "./aries_cloudagent/commands/default_version_upgrade_config.yml",
}
)
Expand Down Expand Up @@ -213,7 +205,7 @@ async def test_upgrade_x_callable_not_set(self):
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(
{
settings={
"upgrade.from_version": "v0.6.0",
}
)
Expand Down Expand Up @@ -246,7 +238,7 @@ async def test_upgrade_x_class_not_found(self):
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(
{
settings={
"upgrade.from_version": "v0.7.2",
}
)
Expand Down Expand Up @@ -311,7 +303,7 @@ async def test_upgrade_x_invalid_record_type(self):
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(
{
settings={
"upgrade.from_version": "v0.7.2",
}
)
Expand Down Expand Up @@ -350,7 +342,7 @@ async def test_upgrade_force(self):
),
):
await test_module.upgrade(
{
settings={
"upgrade.from_version": "v0.7.0",
"upgrade.force_upgrade": True,
}
Expand Down Expand Up @@ -381,9 +373,17 @@ async def test_upgrade_x_invalid_config(self):
async_mock.MagicMock(return_value={}),
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade({})
await test_module.upgrade(settings={})
assert "No version configs found in" in str(ctx.exception)

async def test_upgrade_x_params(self):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(profile=self.profile, settings={})
assert "upgrade requires either profile or settings" in str(ctx.exception)
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(profile=self.profile, settings={"...": "..."})
assert "upgrade requires either profile or settings" in str(ctx.exception)

def test_main(self):
with async_mock.patch.object(
test_module, "__name__", "__main__"
Expand Down
76 changes: 49 additions & 27 deletions aries_cloudagent/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

import asyncio
import logging
import os
import yaml

from configargparse import ArgumentParser
from packaging import version as package_version
from typing import Callable, Sequence, Optional, List
from typing import (
Callable,
Sequence,
Optional,
List,
Union,
Mapping,
Any,
)

from ..core.profile import Profile
from ..config import argparse as arg
from ..config.default_context import DefaultContextBuilder
from ..config.base import BaseError
from ..config.base import BaseError, BaseSettings
from ..config.util import common_config
from ..config.wallet import wallet_config
from ..messaging.models.base_record import BaseRecord
Expand All @@ -23,9 +32,7 @@

from . import PROG

DEFAULT_UPGRADE_CONFIG_PATH = (
"./aries_cloudagent/commands/default_version_upgrade_config.yml"
)
DEFAULT_UPGRADE_CONFIG_FILE_NAME = "default_version_upgrade_config.yml"
LOGGER = logging.getLogger(__name__)


Expand All @@ -43,7 +50,12 @@ def __init__(self, config_path: str = None):
if config_path:
self.setup_version_upgrade_config(config_path)
else:
self.setup_version_upgrade_config(DEFAULT_UPGRADE_CONFIG_PATH)
self.setup_version_upgrade_config(
os.path.join(
os.path.dirname(os.path.realpath(__file__)),
DEFAULT_UPGRADE_CONFIG_FILE_NAME,
)
)

def setup_version_upgrade_config(self, path: str):
"""Set ups config dict from the provided YML file."""
Expand Down Expand Up @@ -134,65 +146,74 @@ async def add_version_record(profile: Profile, version: str):
LOGGER.info(f"{RECORD_TYPE_ACAPY_VERSION} storage record set to {version}")


async def upgrade(settings: dict):
async def upgrade(
settings: Optional[Union[Mapping[str, Any], BaseSettings]] = None,
profile: Optional[Profile] = None,
):
"""Perform upgradation steps."""
context_builder = DefaultContextBuilder(settings)
context = await context_builder.build_context()
try:
if profile and (settings or settings == {}):
raise UpgradeError("upgrade requires either profile or settings, not both.")
if profile:
root_profile = profile
settings = profile.settings
else:
context_builder = DefaultContextBuilder(settings)
context = await context_builder.build_context()
root_profile, _ = await wallet_config(context)
version_upgrade_config_inst = VersionUpgradeConfig(
settings.get("upgrade.config_path")
)
upgrade_configs = version_upgrade_config_inst.upgrade_configs
root_profile, _ = await wallet_config(context)
upgrade_to_version = f"v{__version__}"
versions_found_in_config = upgrade_configs.keys()
sorted_versions_found_in_config = sorted(
versions_found_in_config, key=lambda x: package_version.parse(x)
)
upgrade_from_version_storage = None
upgrade_from_version_config = None
upgrade_from_version_setting = None
upgrade_from_version = None
async with root_profile.session() as session:
storage = session.inject(BaseStorage)
try:
version_storage_record = await storage.find_record(
type_filter=RECORD_TYPE_ACAPY_VERSION, tag_query={}
)
upgrade_from_version_config = version_storage_record.value
upgrade_from_version_storage = version_storage_record.value
except StorageNotFoundError:
LOGGER.info("No ACA-Py version found in wallet storage.")
version_storage_record = None

if "upgrade.from_version" in settings:
upgrade_from_version_setting = settings.get("upgrade.from_version")
upgrade_from_version_config = settings.get("upgrade.from_version")
LOGGER.info(
(
f"Selecting {upgrade_from_version_setting} as "
f"Selecting {upgrade_from_version_config} as "
"--from-version from the config."
)
)

force_upgrade_flag = settings.get("upgrade.force_upgrade") or False
if upgrade_from_version_config and upgrade_from_version_setting:
if upgrade_from_version_storage and upgrade_from_version_config:
if (
package_version.parse(upgrade_from_version_config)
> package_version.parse(upgrade_from_version_setting)
package_version.parse(upgrade_from_version_storage)
> package_version.parse(upgrade_from_version_config)
) and force_upgrade_flag:
upgrade_from_version = upgrade_from_version_setting
else:
upgrade_from_version = upgrade_from_version_config
else:
upgrade_from_version = upgrade_from_version_storage
if (
not upgrade_from_version
and not upgrade_from_version_config
and upgrade_from_version_setting
and not upgrade_from_version_storage
and upgrade_from_version_config
):
upgrade_from_version = upgrade_from_version_setting
upgrade_from_version = upgrade_from_version_config
if (
not upgrade_from_version
and upgrade_from_version_config
and not upgrade_from_version_setting
and upgrade_from_version_storage
and not upgrade_from_version_config
):
upgrade_from_version = upgrade_from_version_config
upgrade_from_version = upgrade_from_version_storage
if not upgrade_from_version:
raise UpgradeError(
"No upgrade from version found in wallet or settings [--from-version]"
Expand Down Expand Up @@ -285,7 +306,8 @@ async def upgrade(settings: dict):
f"{RECORD_TYPE_ACAPY_VERSION} storage record "
f"set to {upgrade_to_version}"
)
await root_profile.close()
if not profile:
await root_profile.close()
except BaseError as e:
raise UpgradeError(f"Error during upgrade: {e}")

Expand All @@ -310,7 +332,7 @@ def execute(argv: Sequence[str] = None):
settings = get_settings(args)
common_config(settings)
loop = asyncio.get_event_loop()
loop.run_until_complete(upgrade(settings))
loop.run_until_complete(upgrade(settings=settings))


def main():
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ def get_settings(self, args: Namespace):
return settings


@group(CAT_UPGRADE)
@group(CAT_START, CAT_UPGRADE)
class UpgradeGroup(ArgumentGroup):
"""ACA-Py Upgrade process settings."""

Expand Down
Loading

0 comments on commit b272f7b

Please sign in to comment.