Skip to content

Commit

Permalink
Prefix driver and network with payment_ where appropriate (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmazurek authored Sep 22, 2021
1 parent fadebbc commit 5012c8d
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 94 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ It's possible to set various elements of `yagna` configuration through environme
- `YAGNA_API_URL`, base URL to `yagna` REST API, e.g. `http://localhost:7500`
- `YAGNA_APPKEY`, `yagna` app key to be used, e.g. `a70facb9501d4528a77f25574ab0f12b`
- `YAGNA_MARKET_URL`, URL to `yagna` market API, e.g. `http://localhost:7500/market-api/v1`
- `YAGNA_NETWORK`, Ethereum network name for `yagna` to use, e.g. `rinkeby`
- `YAGNA_PAYMENT_NETWORK`, Ethereum network name for `yagna` to use, e.g. `rinkeby`
- `YAGNA_PAYMENT_DRIVER`, payment driver name for `yagna` to use, e.g. `zksync`
- `YAGNA_PAYMENT_URL`, URL to `yagna` payment API, e.g. `http://localhost:7500/payment-api/v1`
- `YAGNA_SUBNET`, name of the `yagna` sub network to be used, e.g. `devnet-beta.2`
Expand Down
14 changes: 7 additions & 7 deletions examples/blender/blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)


async def main(subnet_tag, driver=None, network=None, show_usage=False):
async def main(subnet_tag, payment_driver=None, payment_network=None, show_usage=False):
package = await vm.repo(
image_hash="9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae",
min_mem_gib=0.5,
Expand Down Expand Up @@ -115,15 +115,15 @@ async def worker(ctx: WorkContext, tasks):
async with Golem(
budget=10.0,
subnet_tag=subnet_tag,
driver=driver,
network=network,
payment_driver=payment_driver,
payment_network=payment_network,
) as golem:

print(
f"yapapi version: {TEXT_COLOR_YELLOW}{yapapi_version}{TEXT_COLOR_DEFAULT}\n"
f"Using subnet: {TEXT_COLOR_YELLOW}{subnet_tag}{TEXT_COLOR_DEFAULT}, "
f"payment driver: {TEXT_COLOR_YELLOW}{golem.driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.network}{TEXT_COLOR_DEFAULT}\n"
f"payment driver: {TEXT_COLOR_YELLOW}{golem.payment_driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.payment_network}{TEXT_COLOR_DEFAULT}\n"
)

num_tasks = 0
Expand Down Expand Up @@ -172,8 +172,8 @@ async def worker(ctx: WorkContext, tasks):
task = loop.create_task(
main(
subnet_tag=args.subnet_tag,
driver=args.driver,
network=args.network,
payment_driver=args.payment_driver,
payment_network=args.payment_network,
show_usage=args.show_usage,
)
)
Expand Down
10 changes: 5 additions & 5 deletions examples/erigon/erigon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@dataclass
class ErigonPayload(Payload):
network: str = prop(PROP_ERIGON_ETHEREUM_NETWORK)
payment_network: str = prop(PROP_ERIGON_ETHEREUM_NETWORK)

runtime: str = constraint(inf.INF_RUNTIME_NAME, default=TURBOGETH_RUNTIME_NAME)
min_mem_gib: float = constraint(inf.INF_MEM, operator=">=", default=16)
Expand All @@ -36,7 +36,7 @@ def __repr__(self):

@staticmethod
async def get_payload():
return ErigonPayload(network="rinkeby")
return ErigonPayload(payment_network="rinkeby")

async def start(self):
deploy_idx = self.ctx.deploy()
Expand All @@ -62,13 +62,13 @@ async def shutdown(self):
yield self.ctx.commit()


async def main(subnet_tag, driver=None, network=None):
async def main(subnet_tag, payment_driver=None, payment_network=None):

async with Golem(
budget=10.0,
subnet_tag=subnet_tag,
driver=driver,
network=network,
payment_driver=payment_driver,
payment_network=payment_network,
) as golem:
cluster = await golem.run_service(
ErigonService,
Expand Down
16 changes: 8 additions & 8 deletions examples/http-proxy/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,23 @@ async def handle_request(self, query_string: str):

async def main(
subnet_tag,
driver=None,
network=None,
payment_driver=None,
payment_network=None,
num_instances=1,
port=8080,
):
async with Golem(
budget=1.0,
subnet_tag=subnet_tag,
driver=driver,
network=network,
payment_driver=payment_driver,
payment_network=payment_network,
) as golem:

print(
f"yapapi version: {TEXT_COLOR_YELLOW}{yapapi_version}{TEXT_COLOR_DEFAULT}\n"
f"Using subnet: {TEXT_COLOR_YELLOW}{subnet_tag}{TEXT_COLOR_DEFAULT}, "
f"payment driver: {TEXT_COLOR_YELLOW}{golem.driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.network}{TEXT_COLOR_DEFAULT}\n"
f"payment driver: {TEXT_COLOR_YELLOW}{golem.payment_driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.payment_network}{TEXT_COLOR_DEFAULT}\n"
)

commissioning_time = datetime.now()
Expand Down Expand Up @@ -228,8 +228,8 @@ def still_starting():
run_golem_example(
main(
subnet_tag=args.subnet_tag,
driver=args.driver,
network=args.network,
payment_driver=args.payment_driver,
payment_network=args.payment_network,
num_instances=args.num_instances,
port=args.port,
),
Expand Down
19 changes: 12 additions & 7 deletions examples/simple-service-poc/simple_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,25 @@ async def shutdown(self):


async def main(
subnet_tag, running_time, driver=None, network=None, num_instances=1, show_usage=False
subnet_tag,
running_time,
payment_driver=None,
payment_network=None,
num_instances=1,
show_usage=False,
):
async with Golem(
budget=1.0,
subnet_tag=subnet_tag,
driver=driver,
network=network,
payment_driver=payment_driver,
payment_network=payment_network,
) as golem:

print(
f"yapapi version: {TEXT_COLOR_YELLOW}{yapapi_version}{TEXT_COLOR_DEFAULT}\n"
f"Using subnet: {TEXT_COLOR_YELLOW}{subnet_tag}{TEXT_COLOR_DEFAULT}, "
f"payment driver: {TEXT_COLOR_YELLOW}{golem.driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.network}{TEXT_COLOR_DEFAULT}\n"
f"payment driver: {TEXT_COLOR_YELLOW}{golem.payment_driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.payment_network}{TEXT_COLOR_DEFAULT}\n"
)

commissioning_time = datetime.now()
Expand Down Expand Up @@ -243,8 +248,8 @@ def still_starting():
main(
subnet_tag=args.subnet_tag,
running_time=args.running_time,
driver=args.driver,
network=args.network,
payment_driver=args.payment_driver,
payment_network=args.payment_network,
num_instances=args.num_instances,
show_usage=args.show_usage,
)
Expand Down
16 changes: 10 additions & 6 deletions examples/ssh/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ async def run(self):
await asyncio.Future()


async def main(subnet_tag, driver=None, network=None):
async def main(subnet_tag, payment_driver=None, payment_network=None):
# By passing `event_consumer=log_summary()` we enable summary logging.
# See the documentation of the `yapapi.log` module on how to set
# the level of detail and format of the logged information.
async with Golem(
budget=1.0,
subnet_tag=subnet_tag,
driver=driver,
network=network,
payment_driver=payment_driver,
payment_network=payment_network,
) as golem:

print(
f"yapapi version: {TEXT_COLOR_YELLOW}{yapapi_version}{TEXT_COLOR_DEFAULT}\n"
f"Using subnet: {TEXT_COLOR_YELLOW}{golem.subnet_tag}{TEXT_COLOR_DEFAULT}, "
f"payment driver: {TEXT_COLOR_YELLOW}{golem.driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.network}{TEXT_COLOR_DEFAULT}\n"
f"payment driver: {TEXT_COLOR_YELLOW}{golem.payment_driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.payment_network}{TEXT_COLOR_DEFAULT}\n"
)

network = await golem.create_network("192.168.0.1/24")
Expand Down Expand Up @@ -108,6 +108,10 @@ def still_running():
args = parser.parse_args()

run_golem_example(
main(subnet_tag=args.subnet_tag, driver=args.driver, network=args.network),
main(
subnet_tag=args.subnet_tag,
payment_driver=args.payment_driver,
payment_network=args.payment_network,
),
log_file=args.log_file,
)
8 changes: 6 additions & 2 deletions examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ def build_parser(description: str) -> argparse.ArgumentParser:
default_log_path = Path(tempfile.gettempdir()) / f"yapapi_{current_time_str}.log"

parser = argparse.ArgumentParser(description=description)
parser.add_argument("--driver", help="Payment driver name, for example `zksync`")
parser.add_argument("--network", help="Network name, for example `rinkeby`")
parser.add_argument(
"--payment-driver", "--driver", help="Payment driver name, for example `zksync`"
)
parser.add_argument(
"--payment-network", "--network", help="Payment network name, for example `rinkeby`"
)
parser.add_argument("--subnet-tag", help="Subnet name, for example `devnet-beta.2`")
parser.add_argument(
"--log-file",
Expand Down
8 changes: 4 additions & 4 deletions examples/yacat/yacat.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ async def main(args):
async with Golem(
budget=10.0,
subnet_tag=args.subnet_tag,
driver=args.driver,
network=args.network,
payment_driver=args.payment_driver,
payment_network=args.payment_network,
) as golem:

print(
f"Using subnet: {TEXT_COLOR_YELLOW}{args.subnet_tag}{TEXT_COLOR_DEFAULT}, "
f"payment driver: {TEXT_COLOR_YELLOW}{golem.driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.network}{TEXT_COLOR_DEFAULT}\n"
f"payment driver: {TEXT_COLOR_YELLOW}{golem.payment_driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.payment_network}{TEXT_COLOR_DEFAULT}\n"
)

start_time = datetime.now()
Expand Down
16 changes: 10 additions & 6 deletions tests/drone/drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)


async def main(subnet_tag, driver=None, network=None):
async def main(subnet_tag, payment_driver=None, payment_network=None):
package = await vm.repo(
image_hash="a23ce2c0c29ea9711e4a293a2805700e2f0cb6450fddf9506812eb1b",
min_mem_gib=0.5,
Expand Down Expand Up @@ -60,15 +60,15 @@ async def worker(ctx: WorkContext, tasks):
async with Golem(
budget=10.0,
subnet_tag=subnet_tag,
driver=driver,
network=network,
payment_driver=payment_driver,
payment_network=payment_network,
) as golem:

print(
f"yapapi version: {TEXT_COLOR_YELLOW}{yapapi_version}{TEXT_COLOR_DEFAULT}\n"
f"Using subnet: {TEXT_COLOR_YELLOW}{subnet_tag}{TEXT_COLOR_DEFAULT}, "
f"payment driver: {TEXT_COLOR_YELLOW}{golem.driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.network}{TEXT_COLOR_DEFAULT}\n"
f"payment driver: {TEXT_COLOR_YELLOW}{golem.payment_driver}{TEXT_COLOR_DEFAULT}, "
f"and network: {TEXT_COLOR_YELLOW}{golem.payment_network}{TEXT_COLOR_DEFAULT}\n"
)

num_tasks = 0
Expand Down Expand Up @@ -114,7 +114,11 @@ async def worker(ctx: WorkContext, tasks):

loop = asyncio.get_event_loop()
task = loop.create_task(
main(subnet_tag=args.subnet_tag, driver=args.driver, network=args.network)
main(
subnet_tag=args.subnet_tag,
payment_driver=args.payment_driver,
payment_network=args.payment_network,
)
)

try:
Expand Down
4 changes: 2 additions & 2 deletions tests/goth_tests/test_agreement_termination/requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ async def worker(ctx: WorkContext, tasks):
async with Golem(
budget=10.0,
subnet_tag="goth",
driver="zksync",
network="rinkeby",
payment_driver="zksync",
payment_network="rinkeby",
) as golem:

tasks = [Task(data=n) for n in range(6)]
Expand Down
12 changes: 7 additions & 5 deletions tests/test_payment_platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ async def test_no_matching_account_raises(monkeypatch):
)

with pytest.raises(NoPaymentAccountError) as exc_info:
async with Golem(budget=10.0, driver="matching-driver", network="matching-network"):
async with Golem(
budget=10.0, payment_driver="matching-driver", payment_network="matching-network"
):
pass

exc = exc_info.value
Expand Down Expand Up @@ -131,8 +133,8 @@ async def mock_release_allocation(*args, **kwargs):
with pytest.raises(_StopExecutor):
async with Golem(
budget=10.0,
driver="matching-driver",
network="matching-network",
payment_driver="matching-driver",
payment_network="matching-network",
):
pass

Expand All @@ -150,8 +152,8 @@ async def test_driver_network_case_insensitive(monkeypatch, _mock_create_allocat
with pytest.raises(_StopExecutor):
async with Golem(
budget=10.0,
driver="dRiVeR",
network="NeTwOrK",
payment_driver="dRiVeR",
payment_network="NeTwOrK",
):
pass

Expand Down
Loading

0 comments on commit 5012c8d

Please sign in to comment.