From 11e525f0c099783dd67314128afb073bc61252bc Mon Sep 17 00:00:00 2001 From: OjusWiZard Date: Mon, 28 Oct 2024 18:04:57 +0530 Subject: [PATCH] fix: issue certificate after write private key Signed-off-by: OjusWiZard --- autonomy/cli/deploy.py | 4 ++-- autonomy/cli/helpers/deployment.py | 7 ++++--- autonomy/deploy/generators/localhost/base.py | 2 ++ autonomy/deploy/generators/localhost/utils.py | 8 +++----- docs/api/cli/deploy.md | 17 +++++++---------- docs/api/cli/helpers/deployment.md | 2 +- docs/api/deploy/generators/localhost/utils.md | 2 +- .../test_autonomy/test_chain/test_addresses.py | 4 +++- .../test_cli/test_deploy/test_run_deployment.py | 8 +++----- tests/test_docs/test_commands.py | 1 + 10 files changed, 27 insertions(+), 28 deletions(-) diff --git a/autonomy/cli/deploy.py b/autonomy/cli/deploy.py index b24846da39..8cd84bd237 100644 --- a/autonomy/cli/deploy.py +++ b/autonomy/cli/deploy.py @@ -22,7 +22,7 @@ import os import shutil from pathlib import Path -from typing import Optional, cast +from typing import List, Optional, cast import click from aea import AEA_DIR @@ -241,7 +241,7 @@ def build_deployment_command( # pylint: disable=too-many-arguments, too-many-lo output_dir: Optional[Path], dev_mode: bool, registry: str, - mkdir: list[str], + mkdir: List[str], number_of_agents: Optional[int] = None, number_of_services: int = 1, password: Optional[str] = None, diff --git a/autonomy/cli/helpers/deployment.py b/autonomy/cli/helpers/deployment.py index c013c46c96..896abe5efd 100644 --- a/autonomy/cli/helpers/deployment.py +++ b/autonomy/cli/helpers/deployment.py @@ -65,7 +65,7 @@ from autonomy.deploy.image import build_image -def _build_dirs(build_dir: Path, mkdir: list[str] = []) -> None: +def _build_dirs(build_dir: Path, mkdir: List[str]) -> None: """Build necessary directories.""" mkdirs = [(new_dir_name,) for new_dir_name in mkdir] @@ -257,7 +257,7 @@ def build_deployment( # pylint: disable=too-many-arguments, too-many-locals resources: Optional[Resources] = None, service_hash_id: Optional[str] = None, service_offset: int = 0, - mkdir: Optional[str] = None, + mkdir: Optional[List[str]] = None, ) -> None: """Build deployment.""" @@ -271,7 +271,8 @@ def build_deployment( # pylint: disable=too-many-arguments, too-many-locals click.echo(f"Building deployment @ {build_dir}") build_dir.mkdir() - _build_dirs(build_dir, mkdir) + if mkdir is not None: + _build_dirs(build_dir, mkdir) if service_hash_id is None: service_hash_id = build_hash_id() diff --git a/autonomy/deploy/generators/localhost/base.py b/autonomy/deploy/generators/localhost/base.py index 1a1f7e88a8..047030e283 100644 --- a/autonomy/deploy/generators/localhost/base.py +++ b/autonomy/deploy/generators/localhost/base.py @@ -47,6 +47,7 @@ TM_STATE_DIR, ) from autonomy.deploy.generators.localhost.utils import ( + _run_aea_cmd, check_tendermint_version, setup_agent, ) @@ -114,6 +115,7 @@ def _populate_keys(self) -> None: ledger = kp.get(LEDGER, DEFAULT_LEDGER) keys_file = self.build_dir / PRIVATE_KEY_PATH_SCHEMA.format(ledger) keys_file.write_text(key, encoding=DEFAULT_ENCODING) + _run_aea_cmd(["issue-certificates"], cwd=self.build_dir) def _populate_keys_multiledger(self) -> None: """Populate the keys directory with multiple set of keys""" diff --git a/autonomy/deploy/generators/localhost/utils.py b/autonomy/deploy/generators/localhost/utils.py index a0bddc56cc..b3c1047eec 100644 --- a/autonomy/deploy/generators/localhost/utils.py +++ b/autonomy/deploy/generators/localhost/utils.py @@ -25,7 +25,7 @@ import subprocess # nosec import sys from pathlib import Path -from typing import Any, List, Optional +from typing import Any, Dict, List, Optional from aea.configurations.constants import DEFAULT_AEA_CONFIG_FILE, VENDOR @@ -74,7 +74,7 @@ def _run_aea_cmd( cwd: Optional[Path] = None, stdout: int = subprocess.PIPE, stderr: int = subprocess.PIPE, - ignore_error: str | None = None, + ignore_error: Optional[str] = None, **kwargs: Any, ) -> None: """Run an aea command in a subprocess.""" @@ -121,7 +121,7 @@ def _prepare_agent_env(working_dir: Path) -> None: ) -def setup_agent(working_dir: Path, agent_config: dict[str, Any]) -> None: +def setup_agent(working_dir: Path, agent_config: Dict[str, Any]) -> None: """Setup locally deployed agent.""" _prepare_agent_env(working_dir) shutil.copy(DEFAULT_AEA_CONFIG_FILE, working_dir) @@ -139,5 +139,3 @@ def setup_agent(working_dir: Path, agent_config: dict[str, Any]) -> None: cwd=working_dir, ignore_error="already present", ) - - _run_aea_cmd(["issue-certificates"], cwd=working_dir) diff --git a/docs/api/cli/deploy.md b/docs/api/cli/deploy.md index cc7c3a5838..4adbc1453c 100644 --- a/docs/api/cli/deploy.md +++ b/docs/api/cli/deploy.md @@ -149,9 +149,9 @@ Deploy an agent service. @click.option( "--mkdir", type=str, - help= - "Comma-separated list of directory names to create in the build directory.", - default=None, + help="Directory names to create in the build directory.", + default=[], + multiple=True, ) @registry_flag() @password_option(confirmation_prompt=True) @@ -164,6 +164,7 @@ def build_deployment_command( output_dir: Optional[Path], dev_mode: bool, registry: str, + mkdir: List[str], number_of_agents: Optional[int] = None, number_of_services: int = 1, password: Optional[str] = None, @@ -179,8 +180,7 @@ def build_deployment_command( agent_cpu_limit: Optional[float] = None, agent_memory_limit: Optional[int] = None, agent_cpu_request: Optional[float] = None, - agent_memory_request: Optional[int] = None, - mkdir: Optional[str] = None) -> None + agent_memory_request: Optional[int] = None) -> None ``` Build deployment setup for n agents. @@ -227,11 +227,8 @@ Build deployment setup for n agents. help="Use docker as a backend. (default)", default=True, ) -def run(build_dir: Path, - no_recreate: bool, - remove_orphans: bool, - detach: bool = False, - deployment_type: str = "localhost") -> None +def run(build_dir: Path, no_recreate: bool, remove_orphans: bool, detach: bool, + deployment_type: str) -> None ``` Run deployment. diff --git a/docs/api/cli/helpers/deployment.md b/docs/api/cli/helpers/deployment.md index 4360fa11ef..466c8e0a71 100644 --- a/docs/api/cli/helpers/deployment.md +++ b/docs/api/cli/helpers/deployment.md @@ -62,7 +62,7 @@ def build_deployment(keys_file: Path, resources: Optional[Resources] = None, service_hash_id: Optional[str] = None, service_offset: int = 0, - mkdir: Optional[str] = None) -> None + mkdir: Optional[List[str]] = None) -> None ``` Build deployment. diff --git a/docs/api/deploy/generators/localhost/utils.md b/docs/api/deploy/generators/localhost/utils.md index b45558406a..eff3468ea5 100644 --- a/docs/api/deploy/generators/localhost/utils.md +++ b/docs/api/deploy/generators/localhost/utils.md @@ -19,7 +19,7 @@ Check tendermint version. #### setup`_`agent ```python -def setup_agent(working_dir: Path, agent_config: dict[str, Any]) -> None +def setup_agent(working_dir: Path, agent_config: Dict[str, Any]) -> None ``` Setup locally deployed agent. diff --git a/tests/test_autonomy/test_chain/test_addresses.py b/tests/test_autonomy/test_chain/test_addresses.py index 2a9e168df9..9e939ebdbe 100644 --- a/tests/test_autonomy/test_chain/test_addresses.py +++ b/tests/test_autonomy/test_chain/test_addresses.py @@ -29,7 +29,9 @@ from autonomy.chain.constants import CHAIN_PROFILES -ADDRESS_FILE_URL = "https://raw.githubusercontent.com/valory-xyz/autonolas-registries/main/docs/configuration.json" +# this file is fetched from an old commit, because the latest file version has removed some chains +# TODO: use the latest file +ADDRESS_FILE_URL = "https://github.com/valory-xyz/autonolas-registries/raw/a6a35cf7bbdbac64eeab9375c0b32848b266a166/docs/configuration.json" class TestAddresses: diff --git a/tests/test_autonomy/test_cli/test_deploy/test_run_deployment.py b/tests/test_autonomy/test_cli/test_deploy/test_run_deployment.py index e9722f0d62..1679db0738 100644 --- a/tests/test_autonomy/test_cli/test_deploy/test_run_deployment.py +++ b/tests/test_autonomy/test_cli/test_deploy/test_run_deployment.py @@ -102,11 +102,9 @@ def test_run_local(self) -> None: json.dump({}, fp) with open(build_path / AGENT_VARS_CONFIG_FILE, "w") as fp: json.dump({}, fp) - with ( - mock.patch("autonomy.cli.helpers.deployment.subprocess.run"), - mock.patch("autonomy.cli.helpers.deployment.subprocess.Popen"), - mock.patch("autonomy.cli.helpers.deployment.check_tendermint_version"), - ): + with mock.patch("autonomy.cli.helpers.deployment.subprocess.run"), mock.patch( + "autonomy.cli.helpers.deployment.subprocess.Popen" + ), mock.patch("autonomy.cli.helpers.deployment.check_tendermint_version"): result = self.run_cli(("--localhost", "--build-dir", build_path.as_posix())) assert result.exit_code == 0, result.output assert "Running build @" in result.output diff --git a/tests/test_docs/test_commands.py b/tests/test_docs/test_commands.py index cef4d4a03e..196c9c6e3c 100644 --- a/tests/test_docs/test_commands.py +++ b/tests/test_docs/test_commands.py @@ -168,6 +168,7 @@ def test_validate_doc_commands() -> None: if cmd in skips: continue + print(cmd) assert validator.validate(cmd, str(file_)), cmd