Skip to content

Commit 5f871df

Browse files
authored
Merge branch 'main' into vivien
2 parents 69fac49 + 84654b9 commit 5f871df

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

runpod/api/ctl_commands.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_pod(pod_id: str):
8888

8989
def create_pod(
9090
name: str,
91-
image_name: str,
91+
image_name: Optional[str] = "",
9292
gpu_type_id: Optional[str] = None,
9393
cloud_type: str = "ALL",
9494
support_public_ip: bool = True,
@@ -143,6 +143,10 @@ def create_pod(
143143
>>> pod_id = runpod.create_pod("test", "runpod/stack", instance_id="cpu3c-2-4")
144144
"""
145145
# Input Validation
146+
147+
if not image_name and not template_id:
148+
raise ValueError("Either image_name or template_id must be provided")
149+
146150
if gpu_type_id is not None:
147151
get_gpu(gpu_type_id) # Check if GPU exists, will raise ValueError if not.
148152
if cloud_type not in ["ALL", "COMMUNITY", "SECURE"]:

tests/test_api/test_ctl_commands.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ def test_create_pod_with_encrypt_volume(self):
206206
called_mutation = patch_request.call_args[1]['data']
207207
self.assertNotIn("encryptVolume", called_mutation)
208208

209+
def test_create_pod_missing_image_and_template(self):
210+
"""
211+
Tests create_pod error if neither image_name nor template_id are provided
212+
"""
213+
with patch("runpod.api.graphql.requests.post"), patch(
214+
"runpod.api.ctl_commands.get_gpu"
215+
), patch("runpod.api.ctl_commands.get_user"):
216+
with self.assertRaises(ValueError) as context:
217+
ctl_commands.create_pod(
218+
name="POD_NAME",
219+
gpu_type_id="NVIDIA A100 80GB PCIe",
220+
network_volume_id="NETWORK_VOLUME_ID",
221+
)
222+
223+
self.assertEqual(
224+
str(context.exception),
225+
"Either image_name or template_id must be provided",
226+
)
227+
228+
209229
def test_stop_pod(self):
210230
"""
211231
Test stop_pod

0 commit comments

Comments
 (0)