Skip to content

Commit

Permalink
fix: issue certificate after write private key
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <[email protected]>
  • Loading branch information
OjusWiZard committed Oct 28, 2024
1 parent 5c76a26 commit 11e525f
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions autonomy/cli/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions autonomy/cli/helpers/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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."""

Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions autonomy/deploy/generators/localhost/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
TM_STATE_DIR,
)
from autonomy.deploy.generators.localhost.utils import (
_run_aea_cmd,
check_tendermint_version,
setup_agent,
)
Expand Down Expand Up @@ -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"""
Expand Down
8 changes: 3 additions & 5 deletions autonomy/deploy/generators/localhost/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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)
Expand All @@ -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)
17 changes: 7 additions & 10 deletions docs/api/cli/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/cli/helpers/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/deploy/generators/localhost/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion tests/test_autonomy/test_chain/test_addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_docs/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def test_validate_doc_commands() -> None:

if cmd in skips:
continue
print(cmd)
assert validator.validate(cmd, str(file_)), cmd


Expand Down

0 comments on commit 11e525f

Please sign in to comment.