Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4535 from golemfactory/enable-local-granary
Browse files Browse the repository at this point in the history
enable local `golem-granary` with the use of `--use-granary` parameter
  • Loading branch information
shadeofblue authored Jul 24, 2019
2 parents c2953fe + 1da4102 commit 44120ad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
15 changes: 12 additions & 3 deletions scripts/node_integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ def pytest_addoption(parser: _pytest.config.argparsing.Parser) -> None:
help="Disables reuse of provider's and requestor's node keys. "
"All node_integration_tests run with new, fresh keys."
)
parser.addoption(
"--use-granary", action="store_true",
help="Enable the `golem-granary`. "
"Unless you also provide the `--granary-hostname`, it will "
"use a local `golem-granary` executable."
)
parser.addoption(
"--granary-hostname", action="store",
help="The ssh hostname for the granary server to use."
help="The ssh hostname for the granary server to use. "
"Implicitly enables the granary. "
"If not provided and --use-granary is specified, "
"will use a local `golem-granary`."
)
parser.addoption(
"--dump-output-on-fail", action="store_true",
Expand All @@ -54,8 +63,8 @@ def pytest_collection_modifyitems(config: _pytest.config.Config,
if config.getoption("--disable-key-reuse"):
NodeKeyReuseConfig.disable()
hostname = config.getoption("--granary-hostname")
if hostname:
NodeKeyReuseConfig.set_granary(hostname)
if hostname or config.getoption('--use-granary'):
NodeKeyReuseConfig.enable_granary(hostname)
if config.getoption('--dump-output-on-crash'):
DumpOutput.enable_on_crash()
if config.getoption('--dump-output-on-fail'):
Expand Down
11 changes: 7 additions & 4 deletions scripts/node_integration_tests/key_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class NodeKeyReuseConfig:
enabled: bool = True

# Provider specific variables
use_granary: bool = False
granary_hostname: Optional[str] = None
local_reuse_dir: Optional[Path] = None

Expand All @@ -51,8 +52,9 @@ def get(cls):
_log("NodeKeyReuseConfig.get() called.")
if not cls.instance:
cls.instance = cls()
if cls.granary_hostname:
print("key_reuse - granary selected:", cls.granary_hostname)
if cls.use_granary:
print("key_reuse - granary selected:",
cls.granary_hostname or 'local golem-granary')
cls.provider = NodeKeyReuseGranary(cls.granary_hostname)
else:
print("key_reuse - local folder selected:", cls.local_reuse_dir)
Expand Down Expand Up @@ -95,8 +97,9 @@ def reset(cls):
cls.instance = None

@classmethod
def set_granary(cls, hostname):
_log("NodeKeyReuseConfig.set_granary() called. host=", hostname)
def enable_granary(cls, hostname: Optional[str] = None):
_log("NodeKeyReuseConfig.enable_granary() called. host=", hostname)
cls.use_granary = True
cls.granary_hostname = hostname


Expand Down
21 changes: 16 additions & 5 deletions tests/factories/granary.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

_logging = False


def _log(*args):
# Private log function since pytest.tearDown() does not print logger
if _logging:
print(*args)


GRANARY_EXECUTABLE_NAME = 'golem-granary'


class Account:
def __init__(self, raw_key: bytes, ts: str):
self.key = ECCx(raw_key)
Expand All @@ -27,12 +29,17 @@ def __init__(self, raw_key: bytes, ts: str):


class Granary:
def __init__(self, hostname: str):
def __init__(self, hostname: Optional[str] = None):
self.hostname = hostname

def _cmd(self, *args):
cmd = ['ssh', self.hostname] if self.hostname else []
cmd.extend([GRANARY_EXECUTABLE_NAME, *args])
return cmd

def request_account(self) -> Optional[Account]:
_log("Granary called, account requested")
cmd = ['ssh', self.hostname, 'golem-granary', 'get_used_account']
cmd = self._cmd('get_used_account')

completed = subprocess.run(
cmd,
Expand Down Expand Up @@ -62,8 +69,12 @@ def return_account(self, account: Account):
ts = account.transaction_store or '{}'
ts = shlex.quote(ts)

cmd = ['ssh', self.hostname, 'golem-granary', 'return_used_account',
'-p', key_pub_addr, '-P', encode_hex(account.raw_key), '-t', ts]
cmd = self._cmd(
'return_used_account',
'-p', key_pub_addr,
'-P', encode_hex(account.raw_key),
'-t', ts
)

_log(cmd)
completed = subprocess.run(
Expand Down

0 comments on commit 44120ad

Please sign in to comment.