- Added package data configuration for the 'gpu_rent' package in pyproject.toml. - Updated README.md to include usage instructions for Windows and Unix launchers. - Enhanced CLI documentation in cli.md to reflect new commands and their functionalities. - Revised setup.md to clarify installation steps and environment setup. - Improved error handling and command descriptions in the CLI implementation. - Added new functions for model version handling and flavor resolution in the codebase. - Updated state management to include additional properties for better tracking.
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from gpu_rent.cloud import ensure_floating_ip, server_floating_ip, server_status
|
|
from gpu_rent.lock import SessionLock
|
|
from gpu_rent.paths import lock_path
|
|
|
|
|
|
class Obj:
|
|
def __init__(self, **kwargs):
|
|
self.__dict__.update(kwargs)
|
|
|
|
|
|
def test_server_floating_ip():
|
|
server = Obj(
|
|
status="ACTIVE",
|
|
addresses={"gpu-rent": [{"addr": "192.168.77.10", "OS-EXT-IPS:type": "fixed"}, {"addr": "203.0.113.9", "OS-EXT-IPS:type": "floating"}]},
|
|
)
|
|
assert server_status(server) == "ACTIVE"
|
|
assert server_floating_ip(server) == "203.0.113.9"
|
|
|
|
|
|
def test_lock_roundtrip():
|
|
with SessionLock():
|
|
assert lock_path().is_file()
|
|
assert not lock_path().is_file()
|
|
|
|
|
|
def test_ensure_floating_ip_reuses_existing():
|
|
class Net:
|
|
def ports(self, device_id=None):
|
|
return [Obj(id="p1")]
|
|
|
|
def update_ip(self, existing_id, port_id=None):
|
|
assert existing_id == "old-fip"
|
|
assert port_id == "p1"
|
|
return Obj(floating_ip_address="9.9.9.9")
|
|
|
|
def create_ip(self, floating_network_id=None):
|
|
raise AssertionError("must reuse FIP")
|
|
|
|
conn = Obj(network=Net())
|
|
server = Obj(id="s1", addresses={})
|
|
ip, fip_id = ensure_floating_ip(conn, server, "old-fip", "9.9.9.9", lambda m: None)
|
|
assert ip == "9.9.9.9"
|
|
assert fip_id == "old-fip"
|