Skip to content

Commit 95ffde2

Browse files
committed
fix: ports in the aggregate can be None, if None then we continue
1 parent 2b3b8f7 commit 95ffde2

File tree

6 files changed

+15
-16
lines changed

6 files changed

+15
-16
lines changed

src/aleph_client/commands/instance/__init__.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import shutil
77
from decimal import Decimal
88
from pathlib import Path
9-
from typing import Annotated, Any, Optional, Union
9+
from typing import Annotated, Any, Optional
1010

1111
import aiohttp
1212
import typer
@@ -30,8 +30,6 @@
3030
)
3131
from aleph.sdk.query.responses import PriceResponse
3232
from aleph.sdk.types import (
33-
CrnExecutionV1,
34-
CrnExecutionV2,
3533
InstanceAllocationsInfo,
3634
InstanceWithScheduler,
3735
PortFlags,
@@ -470,7 +468,6 @@ async def create(
470468
echo(f"Failed to fetch credit info, error: {e}")
471469
raise typer.Exit(code=1) from e
472470

473-
stream_reward_address = None
474471
crn, crn_info, gpu_id = None, None, None
475472
if is_stream or confidential or gpu or is_credit:
476473
if crn_url:
@@ -610,7 +607,7 @@ async def create(
610607

611608
payment = Payment(
612609
chain=payment_chain,
613-
receiver=stream_reward_address if stream_reward_address else None,
610+
receiver=crn_info.stream_reward_address if crn_info and crn_info.stream_reward_address else None,
614611
type=payment_type,
615612
)
616613

@@ -636,7 +633,7 @@ async def create(
636633
try:
637634
content = make_instance_content(**content_dict)
638635
price: PriceResponse = await client.get_estimated_price(content)
639-
required_tokens = Decimal(price.required_tokens)
636+
required_tokens = price.required_tokens if price.cost is None else Decimal(price.cost)
640637
except Exception as e:
641638
echo(f"Failed to estimate instance cost, error: {e}")
642639
raise typer.Exit(code=1) from e
@@ -839,7 +836,6 @@ async def delete(
839836
existing_message: InstanceMessage = await client.get_message(
840837
item_hash=ItemHash(item_hash), message_type=InstanceMessage
841838
)
842-
843839
except MessageNotFoundError:
844840
echo("Instance does not exist")
845841
raise typer.Exit(code=1) from None
@@ -872,11 +868,6 @@ async def delete(
872868
if isinstance(instance_info, InstanceWithScheduler):
873869
echo(f"Instance {item_hash} was auto-scheduled, VM will be erased automatically.")
874870
elif instance_info is not None and hasattr(instance_info, "crn_url") and instance_info.crn_url:
875-
execution: Optional[Union[CrnExecutionV1, CrnExecutionV2]] = await client.crn.get_vm(
876-
instance_info.crn_url, item_hash=ItemHash(item_hash)
877-
)
878-
if not execution:
879-
echo("VM is not running or CRN not accessible, Skipping ...")
880871
try:
881872
async with VmClient(account, instance_info.crn_url) as manager:
882873
status, _ = await manager.erase_instance(vm_id=item_hash)

src/aleph_client/commands/instance/display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ async def _prepare_instance_column(self):
283283
# Price information
284284
async with AlephHttpClient() as client:
285285
price: PriceResponse = await client.get_program_price(self.message.item_hash)
286-
required_tokens = Decimal(price.required_tokens)
286+
required_tokens = price.required_tokens if price.cost is None else Decimal(price.cost)
287287

288288
if self.is_hold:
289289
aleph_price = Text(f"{displayable_amount(required_tokens, decimals=3)} (fixed)", style="magenta3")

src/aleph_client/commands/program.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ async def upload(
242242
try:
243243
content = make_program_content(**content_dict)
244244
price: PriceResponse = await client.get_estimated_price(content)
245-
required_tokens = Decimal(price.required_tokens)
245+
required_tokens = price.required_tokens if price.cost is None else Decimal(price.cost)
246246
except Exception as e:
247247
typer.echo(f"Failed to estimate program cost, error: {e}")
248248
raise typer.Exit(code=1) from e
@@ -575,7 +575,7 @@ async def list_programs(
575575
if message.sender != message.content.address:
576576
payer = Text.assemble("\nPayer: ", Text(str(message.content.address), style="orange1"))
577577
price: PriceResponse = await client.get_program_price(message.item_hash)
578-
required_tokens = Decimal(price.required_tokens)
578+
required_tokens = price.required_tokens if price.cost is None else Decimal(price.cost)
579579
if price.payment_type == PaymentType.hold.value:
580580
aleph_price = Text(
581581
f"{displayable_amount(required_tokens, decimals=3)} (fixed)".ljust(13), style="violet"

tests/unit/test_display.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ async def test_instance_display_columns():
147147
with patch("aleph_client.commands.instance.display.download", AsyncMock(return_value=None)):
148148
mock_price = MagicMock()
149149
mock_price.required_tokens = "0.001"
150+
mock_price.cost = "0.001"
150151
mock_client = AsyncMock()
151152
mock_client.get_program_price = AsyncMock(return_value=mock_price)
152153

@@ -321,6 +322,7 @@ async def test_instance_table_builder():
321322
mock_client = AsyncMock()
322323
mock_price = MagicMock()
323324
mock_price.required_tokens = "0.001"
325+
mock_price.cost = "0.001"
324326
mock_client.get_program_price = AsyncMock(return_value=mock_price)
325327

326328
mock_client_class.return_value.__aenter__ = AsyncMock(return_value=mock_client)
@@ -430,6 +432,7 @@ async def test_show_instances():
430432
mock_client = AsyncMock()
431433
mock_price = MagicMock()
432434
mock_price.required_tokens = "0.001"
435+
mock_price.cost = "0.001"
433436
mock_client.get_program_price = AsyncMock(return_value=mock_price)
434437

435438
mock_client_class.return_value.__aenter__ = AsyncMock(return_value=mock_client)

tests/unit/test_instance.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def create_mock_client(
292292
get_estimated_price=AsyncMock(
293293
return_value=MagicMock(
294294
required_tokens=required_tokens,
295+
cost=required_tokens,
295296
payment_type=payment_type,
296297
)
297298
),
@@ -317,8 +318,10 @@ def create_mock_auth_client(
317318
):
318319

319320
def response_get_program_price(ptype):
321+
required_tokens = 0.00001527777777777777 if ptype == "superfluid" else 1000
320322
return MagicMock(
321-
required_tokens=0.00001527777777777777 if ptype == "superfluid" else 1000,
323+
required_tokens=required_tokens,
324+
cost=required_tokens,
322325
payment_type=ptype,
323326
)
324327

tests/unit/test_program.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ def create_mock_auth_client(mock_account, swap_persistent=False):
100100
get_estimated_price=AsyncMock(
101101
return_value=MagicMock(
102102
required_tokens=1000,
103+
cost=1000,
103104
payment_type="hold",
104105
)
105106
),
106107
get_program_price=AsyncMock(
107108
return_value=MagicMock(
108109
required_tokens=1000,
110+
cost=1000,
109111
payment_type="hold",
110112
)
111113
),

0 commit comments

Comments
 (0)