Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACA-Py Upgrade command implementation #1557

Merged
merged 38 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
01c33ee
initial commit
shaangill025 Dec 13, 2021
d5cbf9a
working impl
shaangill025 Dec 14, 2021
23db66a
Merge branch 'main' of https://github.com/hyperledger/aries-cloudagen…
shaangill025 Dec 14, 2021
89118b7
updates
shaangill025 Dec 14, 2021
473e105
updates
shaangill025 Dec 15, 2021
f29b7e7
Merge branch 'main' of https://github.com/hyperledger/aries-cloudagen…
shaangill025 Dec 16, 2021
3d33fa8
Merge branch 'main' into upgrade_cmd
ianco Dec 17, 2021
1d3555e
store acapy version
shaangill025 Dec 17, 2021
fe81261
Merge branch 'main' of https://github.com/hyperledger/aries-cloudagen…
shaangill025 Dec 17, 2021
fe086a4
Merge branch 'upgrade_cmd' of https://github.com/shaangill025/aries-c…
shaangill025 Dec 17, 2021
b233eef
provision changes
shaangill025 Dec 17, 2021
b228187
Merge branch 'main' of https://github.com/hyperledger/aries-cloudagen…
shaangill025 Dec 17, 2021
c2ac5d1
Merge branch 'upgrade_cmd' of https://github.com/shaangill025/aries-c…
shaangill025 Dec 17, 2021
4efe714
updates & test coverage
shaangill025 Dec 17, 2021
6454945
Merge branch 'main' of https://github.com/hyperledger/aries-cloudagen…
shaangill025 Dec 17, 2021
85cb3ab
Merge branch 'main' of https://github.com/hyperledger/aries-cloudagen…
shaangill025 Dec 18, 2021
c97c1ba
final update
shaangill025 Dec 18, 2021
aa7259c
Merge branch 'main' into upgrade_cmd
ianco Dec 20, 2021
96fdbe5
Merge branch 'main' into upgrade_cmd
ianco Dec 21, 2021
92be873
Merge branch 'main' into upgrade_cmd
swcurran Dec 21, 2021
d42c9be
Merge branch 'main' of https://github.com/hyperledger/aries-cloudagen…
shaangill025 Dec 21, 2021
d9e0290
requested changes
shaangill025 Dec 21, 2021
04a0c16
Merge branch 'upgrade_cmd' of https://github.com/shaangill025/aries-c…
shaangill025 Dec 21, 2021
e04578d
error msg update
shaangill025 Dec 21, 2021
d38c6a6
flake8 check fix
shaangill025 Dec 21, 2021
9472075
test update
shaangill025 Dec 21, 2021
a31ec07
fix
shaangill025 Dec 22, 2021
1e92e22
Merge branch 'main' into upgrade_cmd
ianco Dec 22, 2021
02794af
requested updates for 0.7.3 release
shaangill025 Dec 22, 2021
a4dffe2
Merge branch 'upgrade_cmd' of https://github.com/shaangill025/aries-c…
shaangill025 Dec 22, 2021
21fe153
minor update after testing
shaangill025 Dec 22, 2021
f1cdc92
packaging version parse
shaangill025 Dec 22, 2021
9289355
cleanup
shaangill025 Dec 23, 2021
896a138
minor fix
shaangill025 Dec 23, 2021
7d845f9
Merge branch 'main' of https://github.com/hyperledger/aries-cloudagen…
shaangill025 Dec 30, 2021
adfacde
updates
shaangill025 Dec 31, 2021
db572c5
cond around print stmt
shaangill025 Jan 3, 2022
9a24059
Merge branch 'main' into upgrade_cmd
shaangill025 Jan 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aries_cloudagent/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def available_commands():
{"name": "help", "summary": "Print available commands"},
{"name": "provision", "summary": "Provision an agent"},
{"name": "start", "summary": "Start a new agent process"},
{"name": "upgrade", "summary": "Start agent upgrade process"},
]


Expand Down
11 changes: 11 additions & 0 deletions aries_cloudagent/commands/default_version_upgrade_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
v0.7.2:
resave_records:
base_record_path:
- "aries_cloudagent.connections.models.conn_record.ConnRecord"
update_existing_records: false
v0.7.1:
update_existing_records: false
v0.7.0:
update_existing_records: false
v0.6.0:
update_existing_records: false
2 changes: 1 addition & 1 deletion aries_cloudagent/commands/tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class TestInit(AsyncTestCase):
def test_available(self):
avail = test_module.available_commands()
assert len(avail) == 3
assert len(avail) == 4

def test_run(self):
with async_mock.patch.object(
Expand Down
345 changes: 345 additions & 0 deletions aries_cloudagent/commands/tests/test_upgrade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,345 @@
import asyncio

from asynctest import mock as async_mock, TestCase as AsyncTestCase

from ...core.in_memory import InMemoryProfile
from ...config.error import ArgsParseError
from ...connections.models.conn_record import ConnRecord
from ...storage.base import BaseStorage
from ...storage.record import StorageRecord
from ...version import __version__

from .. import upgrade as test_module
from ..upgrade import UpgradeError


class TestUpgrade(AsyncTestCase):
async def setUp(self):
self.session = InMemoryProfile.test_session()
self.profile = self.session.profile

self.session_storage = InMemoryProfile.test_session()
self.profile_storage = self.session_storage.profile
self.storage = self.session_storage.inject(BaseStorage)
record = StorageRecord(
"acapy_version",
"v0.7.2",
)
await self.storage.add_record(record)

def test_bad_calls(self):
with self.assertRaises(SystemExit):
test_module.execute(["bad"])

async def test_upgrade_storage_from_version_included(self):
with async_mock.patch.object(
test_module,
"wallet_config",
async_mock.CoroutineMock(
return_value=(
self.profile_storage,
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()
):
await test_module.upgrade(
{
"upgrade.config_path": "./aries_cloudagent/commands/default_version_upgrade_config.yml",
"upgrade.from_version": "v0.7.2",
}
)

async def test_upgrade_storage_missing_from_version(self):
with async_mock.patch.object(
test_module,
"wallet_config",
async_mock.CoroutineMock(
return_value=(
self.profile_storage,
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()
):
await test_module.upgrade({})

async def test_upgrade_from_version(self):
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()
):
await test_module.upgrade(
{
"upgrade.from_version": "v0.7.2",
}
)

async def test_upgrade_callable(self):
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(
test_module.yaml,
"safe_load",
async_mock.MagicMock(
return_value={
"v0.7.2": {
"resave_records": {
"base_record_path": [
"aries_cloudagent.connections.models.conn_record.ConnRecord"
]
},
"update_existing_records": True,
},
}
),
):
await test_module.upgrade(
{
"upgrade.from_version": "v0.7.2",
}
)

async def test_upgrade_x_same_version(self):
version_storage_record = await self.storage.find_record(
type_filter="acapy_version", tag_query={}
)
await self.storage.update_record(version_storage_record, f"v{__version__}", {})
with async_mock.patch.object(
test_module,
"wallet_config",
async_mock.CoroutineMock(
return_value=(
self.profile_storage,
async_mock.CoroutineMock(did="public DID", verkey="verkey"),
)
),
):
with self.assertRaises(UpgradeError):
await test_module.upgrade(
{
"upgrade.config_path": "./aries_cloudagent/commands/default_version_upgrade_config.yml",
}
)

async def test_upgrade_missing_from_version(self):
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()
):
await test_module.upgrade(
{
"upgrade.config_path": "./aries_cloudagent/commands/default_version_upgrade_config.yml",
}
)

async def test_upgrade_x_callable_not_set(self):
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(
test_module.yaml,
"safe_load",
async_mock.MagicMock(
return_value={
"v0.7.2": {
"resave_records": {
"base_record_path": [
"aries_cloudagent.connections.models.conn_record.ConnRecord"
]
},
"update_existing_records": True,
},
"v0.6.0": {"update_existing_records": True},
}
),
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(
{
"upgrade.from_version": "v0.6.0",
}
)
assert "No update_existing_records function specified" in str(ctx.exception)

async def test_upgrade_x_class_not_found(self):
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(
test_module.yaml,
"safe_load",
async_mock.MagicMock(
return_value={
"v0.7.2": {
"resave_records": {
"base_record_path": [
"aries_cloudagent.connections.models.conn_record.Invalid"
],
}
},
}
),
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(
{
"upgrade.from_version": "v0.7.2",
}
)
assert "Unknown Record type" in str(ctx.exception)

async def test_execute(self):
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(
asyncio, "get_event_loop", async_mock.MagicMock()
) as mock_get_event_loop:
mock_get_event_loop.return_value = async_mock.MagicMock(
run_until_complete=async_mock.MagicMock(),
)
test_module.execute(
[
"--upgrade-config",
"./aries_cloudagent/config/tests/test-acapy-upgrade-config.yaml",
"--from-version",
"v0.7.2",
]
)

async def test_upgrade_x_invalid_record_type(self):
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(
test_module.yaml,
"safe_load",
async_mock.MagicMock(
return_value={
"v0.7.2": {
"resave_records": {
"base_exch_record_path": [
"aries_cloudagent.connections.models.connection_target.ConnectionTarget"
],
}
}
}
),
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(
{
"upgrade.from_version": "v0.7.2",
}
)
assert "Only BaseRecord can be resaved" in str(ctx.exception)

async def test_upgrade_x_invalid_config(self):
with async_mock.patch.object(
test_module.yaml,
"safe_load",
async_mock.MagicMock(return_value={}),
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade({})
assert "No version configs found in" in str(ctx.exception)

async def test_upgrade_x_from_version_not_in_config(self):
with async_mock.patch.object(
test_module,
"wallet_config",
async_mock.CoroutineMock(
return_value=(
self.profile,
async_mock.CoroutineMock(did="public DID", verkey="verkey"),
)
),
):
with self.assertRaises(UpgradeError) as ctx:
await test_module.upgrade(
{
"upgrade.from_version": "v1.2.3",
}
)
assert "No upgrade configuration found for" in str(ctx.exception)

def test_main(self):
with async_mock.patch.object(
test_module, "__name__", "__main__"
) as mock_name, async_mock.patch.object(
test_module, "execute", async_mock.MagicMock()
) as mock_execute:
test_module.main()
mock_execute.assert_called_once
Loading