diff --git a/scripts/node_integration_tests/conftest.py b/scripts/node_integration_tests/conftest.py index 5771b27322..7e43659241 100644 --- a/scripts/node_integration_tests/conftest.py +++ b/scripts/node_integration_tests/conftest.py @@ -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", @@ -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'): diff --git a/scripts/node_integration_tests/key_reuse.py b/scripts/node_integration_tests/key_reuse.py index fd58841bb8..062d939950 100644 --- a/scripts/node_integration_tests/key_reuse.py +++ b/scripts/node_integration_tests/key_reuse.py @@ -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 @@ -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) @@ -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 diff --git a/tests/factories/granary.py b/tests/factories/granary.py index de4d7be566..d770bf942a 100644 --- a/tests/factories/granary.py +++ b/tests/factories/granary.py @@ -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) @@ -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, @@ -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(