@@ -86,7 +86,8 @@ def device_list_change(
86
86
if len (frontends ) > 1 :
87
87
# unique
88
88
device = tuple (frontends .values ())[0 ].device
89
- target_name = confirm_device_attachment (device , frontends )
89
+ target_name = asyncio .ensure_future (
90
+ confirm_device_attachment (device , frontends )).result ()
90
91
for front in frontends :
91
92
if front .name == target_name :
92
93
target = front
@@ -140,17 +141,22 @@ def compare_device_cache(vm, devices_cache, current_devices):
140
141
return added , attached , detached , removed
141
142
142
143
143
- def confirm_device_attachment (device , frontends ) -> str :
144
+ async def confirm_device_attachment (device , frontends ) -> str :
144
145
try :
146
+ front_names = [f .name for f in frontends .keys ()]
145
147
# pylint: disable=consider-using-with
146
- proc = subprocess .Popen (
147
- ["attach-confirm" , device .backend_domain .name ,
148
- device .port_id , device .description ,
149
- * [f .name for f in frontends .keys ()]],
150
- stdout = subprocess .PIPE , stderr = subprocess .PIPE
148
+ # vm names are safe to just join by spaces
149
+ proc = await asyncio .create_subprocess_shell (
150
+ " " .join (["attach-confirm" , device .backend_domain .name ,
151
+ device .port_id , "'" + device .description + "'" ,
152
+ * front_names ]),
153
+ stdout = asyncio .subprocess .PIPE
151
154
)
152
- (target_name , _ ) = proc .communicate ()
153
- return target_name .decode ()
155
+ (target_name , _ ) = await proc .communicate ()
156
+ target_name = target_name .decode ()
157
+ if target_name in front_names :
158
+ return target_name
159
+ return ""
154
160
except Exception as exc :
155
161
print ("attach-confirm" , exc , file = sys .stderr )
156
162
return ""
0 commit comments