qvm_run.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation; either version 2.1 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. import io
  21. import os
  22. import unittest.mock
  23. import subprocess
  24. import sys
  25. import qubesadmin.tests
  26. import qubesadmin.tools.qvm_run
  27. class TC_00_qvm_run(qubesadmin.tests.QubesTestCase):
  28. def setUp(self):
  29. if sys.stdout is not sys.__stdout__ or \
  30. sys.stderr is not sys.__stderr__:
  31. self.skipTest('qvm-run change behavior on redirected stdout/stderr')
  32. super(TC_00_qvm_run, self).setUp()
  33. def default_filter_esc(self):
  34. return os.isatty(sys.stdout.fileno())
  35. def test_000_run_single(self):
  36. self.app.expected_calls[
  37. ('dom0', 'admin.vm.List', None, None)] = \
  38. b'0\x00test-vm class=AppVM state=Running\n'
  39. self.app.expected_calls[
  40. ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  41. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  42. # self.app.expected_calls[
  43. # ('test-vm', 'admin.vm.List', None, None)] = \
  44. # b'0\x00test-vm class=AppVM state=Running\n'
  45. ret = qubesadmin.tools.qvm_run.main(
  46. ['--no-gui', 'test-vm', 'command'],
  47. app=self.app)
  48. self.assertEqual(ret, 0)
  49. self.assertEqual(self.app.service_calls, [
  50. ('test-vm', 'qubes.VMShell', {
  51. 'localcmd': None,
  52. 'stdout': subprocess.DEVNULL,
  53. 'stderr': subprocess.DEVNULL,
  54. 'user': None,
  55. }),
  56. ('test-vm', 'qubes.VMShell', b'command; exit\n')
  57. ])
  58. self.assertAllCalled()
  59. def test_001_run_multiple(self):
  60. self.app.expected_calls[
  61. ('dom0', 'admin.vm.List', None, None)] = \
  62. b'0\x00test-vm class=AppVM state=Running\n' \
  63. b'test-vm2 class=AppVM state=Running\n' \
  64. b'test-vm3 class=AppVM state=Halted\n'
  65. self.app.expected_calls[
  66. ('test-vm', 'admin.vm.List', None, None)] = \
  67. b'0\x00test-vm class=AppVM state=Running\n'
  68. self.app.expected_calls[
  69. ('test-vm2', 'admin.vm.List', None, None)] = \
  70. b'0\x00test-vm2 class=AppVM state=Running\n'
  71. self.app.expected_calls[
  72. ('test-vm3', 'admin.vm.List', None, None)] = \
  73. b'0\x00test-vm3 class=AppVM state=Halted\n'
  74. self.app.expected_calls[
  75. ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  76. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  77. self.app.expected_calls[
  78. ('test-vm2', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  79. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  80. ret = qubesadmin.tools.qvm_run.main(
  81. ['--no-gui', '--all', 'command'],
  82. app=self.app)
  83. self.assertEqual(ret, 0)
  84. self.assertEqual(self.app.service_calls, [
  85. ('test-vm', 'qubes.VMShell', {
  86. 'localcmd': None,
  87. 'stdout': subprocess.DEVNULL,
  88. 'stderr': subprocess.DEVNULL,
  89. 'user': None,
  90. }),
  91. ('test-vm', 'qubes.VMShell', b'command; exit\n'),
  92. ('test-vm2', 'qubes.VMShell', {
  93. 'localcmd': None,
  94. 'stdout': subprocess.DEVNULL,
  95. 'stderr': subprocess.DEVNULL,
  96. 'user': None,
  97. }),
  98. ('test-vm2', 'qubes.VMShell', b'command; exit\n')
  99. ])
  100. self.assertAllCalled()
  101. @unittest.expectedFailure
  102. def test_002_passio(self):
  103. self.app.expected_calls[
  104. ('dom0', 'admin.vm.List', None, None)] = \
  105. b'0\x00test-vm class=AppVM state=Running\n'
  106. self.app.expected_calls[
  107. ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  108. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  109. # self.app.expected_calls[
  110. # ('test-vm', 'admin.vm.List', None, None)] = \
  111. # b'0\x00test-vm class=AppVM state=Running\n'
  112. echo = subprocess.Popen(['echo', 'some-data'], stdout=subprocess.PIPE)
  113. with unittest.mock.patch('sys.stdin', echo.stdout):
  114. ret = qubesadmin.tools.qvm_run.main(
  115. ['--no-gui', '--pass-io', 'test-vm', 'command'],
  116. app=self.app)
  117. self.assertEqual(ret, 0)
  118. self.assertEqual(self.app.service_calls, [
  119. ('test-vm', 'qubes.VMShell', {
  120. 'filter_esc': self.default_filter_esc(),
  121. 'localcmd': None,
  122. 'stdout': None,
  123. 'stderr': None,
  124. 'user': None,
  125. }),
  126. ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n')
  127. ])
  128. self.assertAllCalled()
  129. @unittest.expectedFailure
  130. def test_002_color_output(self):
  131. self.app.expected_calls[
  132. ('dom0', 'admin.vm.List', None, None)] = \
  133. b'0\x00test-vm class=AppVM state=Running\n'
  134. self.app.expected_calls[
  135. ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  136. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  137. # self.app.expected_calls[
  138. # ('test-vm', 'admin.vm.List', None, None)] = \
  139. # b'0\x00test-vm class=AppVM state=Running\n'
  140. stdout = io.StringIO()
  141. echo = subprocess.Popen(['echo', 'some-data'], stdout=subprocess.PIPE)
  142. with unittest.mock.patch('sys.stdin', echo.stdout):
  143. with unittest.mock.patch('sys.stdout', stdout):
  144. ret = qubesadmin.tools.qvm_run.main(
  145. ['--no-gui', '--filter-esc', '--pass-io', 'test-vm',
  146. 'command'],
  147. app=self.app)
  148. self.assertEqual(ret, 0)
  149. self.assertEqual(self.app.service_calls, [
  150. ('test-vm', 'qubes.VMShell', {
  151. 'filter_esc': True,
  152. 'localcmd': None,
  153. 'stdout': None,
  154. 'stderr': None,
  155. 'user': None,
  156. }),
  157. ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n')
  158. ])
  159. self.assertEqual(stdout.getvalue(), '\033[0;31m\033[0m')
  160. stdout.close()
  161. self.assertAllCalled()
  162. @unittest.expectedFailure
  163. def test_003_no_color_output(self):
  164. self.app.expected_calls[
  165. ('dom0', 'admin.vm.List', None, None)] = \
  166. b'0\x00test-vm class=AppVM state=Running\n'
  167. # self.app.expected_calls[
  168. # ('test-vm', 'admin.vm.List', None, None)] = \
  169. # b'0\x00test-vm class=AppVM state=Running\n'
  170. stdout = io.StringIO()
  171. echo = subprocess.Popen(['echo', 'some-data'], stdout=subprocess.PIPE)
  172. with unittest.mock.patch('sys.stdin', echo.stdout):
  173. with unittest.mock.patch('sys.stdout', stdout):
  174. ret = qubesadmin.tools.qvm_run.main(
  175. ['--no-gui', '--pass-io', '--no-color-output',
  176. 'test-vm', 'command'],
  177. app=self.app)
  178. self.assertEqual(ret, 0)
  179. self.assertEqual(self.app.service_calls, [
  180. ('test-vm', 'qubes.VMShell', {
  181. 'filter_esc': self.default_filter_esc(),
  182. 'localcmd': None,
  183. 'stdout': None,
  184. 'stderr': None,
  185. 'user': None,
  186. }),
  187. ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n')
  188. ])
  189. self.assertEqual(stdout.getvalue(), '')
  190. stdout.close()
  191. self.assertAllCalled()
  192. @unittest.expectedFailure
  193. def test_004_no_filter_esc(self):
  194. self.app.expected_calls[
  195. ('dom0', 'admin.vm.List', None, None)] = \
  196. b'0\x00test-vm class=AppVM state=Running\n'
  197. self.app.expected_calls[
  198. ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  199. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  200. # self.app.expected_calls[
  201. # ('test-vm', 'admin.vm.List', None, None)] = \
  202. # b'0\x00test-vm class=AppVM state=Running\n'
  203. stdout = io.StringIO()
  204. echo = subprocess.Popen(['echo', 'some-data'], stdout=subprocess.PIPE)
  205. with unittest.mock.patch('sys.stdin', echo.stdout):
  206. with unittest.mock.patch('sys.stdout', stdout):
  207. ret = qubesadmin.tools.qvm_run.main(
  208. ['--no-gui', '--pass-io', '--no-filter-esc',
  209. 'test-vm', 'command'],
  210. app=self.app)
  211. self.assertEqual(ret, 0)
  212. self.assertEqual(self.app.service_calls, [
  213. ('test-vm', 'qubes.VMShell', {
  214. 'filter_esc': False,
  215. 'localcmd': None,
  216. 'stdout': None,
  217. 'stderr': None,
  218. 'user': None,
  219. }),
  220. ('test-vm', 'qubes.VMShell', b'command; exit\nsome-data\n')
  221. ])
  222. self.assertEqual(stdout.getvalue(), '')
  223. stdout.close()
  224. self.assertAllCalled()
  225. def test_005_localcmd(self):
  226. self.app.expected_calls[
  227. ('dom0', 'admin.vm.List', None, None)] = \
  228. b'0\x00test-vm class=AppVM state=Running\n'
  229. self.app.expected_calls[
  230. ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  231. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  232. # self.app.expected_calls[
  233. # ('test-vm', 'admin.vm.List', None, None)] = \
  234. # b'0\x00test-vm class=AppVM state=Running\n'
  235. ret = qubesadmin.tools.qvm_run.main(
  236. ['--no-gui', '--pass-io', '--localcmd', 'local-command',
  237. 'test-vm', 'command'],
  238. app=self.app)
  239. self.assertEqual(ret, 0)
  240. self.assertEqual(self.app.service_calls, [
  241. ('test-vm', 'qubes.VMShell', {
  242. 'localcmd': 'local-command',
  243. 'stdout': None,
  244. 'stderr': None,
  245. 'user': None,
  246. }),
  247. ('test-vm', 'qubes.VMShell', b'command; exit\n')
  248. ])
  249. self.assertAllCalled()
  250. def test_006_run_single_with_gui(self):
  251. self.app.expected_calls[
  252. ('dom0', 'admin.vm.List', None, None)] = \
  253. b'0\x00test-vm class=AppVM state=Running\n'
  254. self.app.expected_calls[
  255. ('test-vm', 'admin.vm.property.Get', 'default_user', None)] = \
  256. b'0\x00default=yes type=str user'
  257. self.app.expected_calls[
  258. ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  259. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  260. # self.app.expected_calls[
  261. # ('test-vm', 'admin.vm.List', None, None)] = \
  262. # b'0\x00test-vm class=AppVM state=Running\n'
  263. ret = qubesadmin.tools.qvm_run.main(
  264. ['test-vm', 'command'],
  265. app=self.app)
  266. self.assertEqual(ret, 0)
  267. # make sure we have the same instance below
  268. self.assertEqual(self.app.service_calls, [
  269. ('test-vm', 'qubes.WaitForSession', {
  270. 'stdout': subprocess.DEVNULL,
  271. 'stderr': subprocess.DEVNULL,
  272. }),
  273. ('test-vm', 'qubes.WaitForSession', b'user'),
  274. ('test-vm', 'qubes.VMShell', {
  275. 'localcmd': None,
  276. 'stdout': subprocess.DEVNULL,
  277. 'stderr': subprocess.DEVNULL,
  278. 'user': None,
  279. }),
  280. ('test-vm', 'qubes.VMShell', b'command; exit\n')
  281. ])
  282. self.assertAllCalled()
  283. def test_007_run_service_with_gui(self):
  284. self.app.expected_calls[
  285. ('dom0', 'admin.vm.List', None, None)] = \
  286. b'0\x00test-vm class=AppVM state=Running\n'
  287. self.app.expected_calls[
  288. ('test-vm', 'admin.vm.property.Get', 'default_user', None)] = \
  289. b'0\x00default=yes type=str user'
  290. # self.app.expected_calls[
  291. # ('test-vm', 'admin.vm.List', None, None)] = \
  292. # b'0\x00test-vm class=AppVM state=Running\n'
  293. ret = qubesadmin.tools.qvm_run.main(
  294. ['--service', 'test-vm', 'service.name'],
  295. app=self.app)
  296. self.assertEqual(ret, 0)
  297. # make sure we have the same instance below
  298. self.assertEqual(self.app.service_calls, [
  299. ('test-vm', 'qubes.WaitForSession', {
  300. 'stdout': subprocess.DEVNULL,
  301. 'stderr': subprocess.DEVNULL,
  302. }),
  303. ('test-vm', 'qubes.WaitForSession', b'user'),
  304. ('test-vm', 'service.name', {
  305. 'localcmd': None,
  306. 'stdout': subprocess.DEVNULL,
  307. 'stderr': subprocess.DEVNULL,
  308. 'user': None,
  309. }),
  310. ('test-vm', 'service.name', b''),
  311. ])
  312. self.assertAllCalled()
  313. def test_008_dispvm_remote(self):
  314. ret = qubesadmin.tools.qvm_run.main(
  315. ['--dispvm', '--service', 'test.service'], app=self.app)
  316. self.assertEqual(ret, 0)
  317. self.assertEqual(self.app.service_calls, [
  318. ('$dispvm', 'test.service', {
  319. 'localcmd': None,
  320. 'stdout': subprocess.DEVNULL,
  321. 'stderr': subprocess.DEVNULL,
  322. 'user': None,
  323. }),
  324. ('$dispvm', 'test.service', b''),
  325. ])
  326. self.assertAllCalled()
  327. def test_009_dispvm_remote_specific(self):
  328. ret = qubesadmin.tools.qvm_run.main(
  329. ['--dispvm=test-vm', '--service', 'test.service'], app=self.app)
  330. self.assertEqual(ret, 0)
  331. self.assertEqual(self.app.service_calls, [
  332. ('$dispvm:test-vm', 'test.service', {
  333. 'localcmd': None,
  334. 'stdout': subprocess.DEVNULL,
  335. 'stderr': subprocess.DEVNULL,
  336. 'user': None,
  337. }),
  338. ('$dispvm:test-vm', 'test.service', b''),
  339. ])
  340. self.assertAllCalled()
  341. def test_010_dispvm_local(self):
  342. self.app.qubesd_connection_type = 'socket'
  343. self.app.expected_calls[
  344. ('dom0', 'admin.vm.CreateDisposable', None, None)] = \
  345. b'0\0disp123'
  346. self.app.expected_calls[('disp123', 'admin.vm.Kill', None, None)] = \
  347. b'0\0'
  348. self.app.expected_calls[
  349. ('disp123', 'admin.vm.property.Get', 'qrexec_timeout', None)] = \
  350. b'0\0default=yes type=int 30'
  351. ret = qubesadmin.tools.qvm_run.main(
  352. ['--dispvm', '--service', 'test.service'], app=self.app)
  353. self.assertEqual(ret, 0)
  354. self.assertEqual(self.app.service_calls, [
  355. ('disp123', 'test.service', {
  356. 'localcmd': None,
  357. 'stdout': subprocess.DEVNULL,
  358. 'stderr': subprocess.DEVNULL,
  359. 'user': None,
  360. 'connect_timeout': 30,
  361. }),
  362. ('disp123', 'test.service', b''),
  363. ])
  364. self.assertAllCalled()
  365. def test_011_dispvm_local_specific(self):
  366. self.app.qubesd_connection_type = 'socket'
  367. self.app.expected_calls[
  368. ('test-vm', 'admin.vm.CreateDisposable', None, None)] = \
  369. b'0\0disp123'
  370. self.app.expected_calls[('disp123', 'admin.vm.Kill', None, None)] = \
  371. b'0\0'
  372. self.app.expected_calls[
  373. ('disp123', 'admin.vm.property.Get', 'qrexec_timeout', None)] = \
  374. b'0\0default=yes type=int 30'
  375. ret = qubesadmin.tools.qvm_run.main(
  376. ['--dispvm=test-vm', '--service', 'test.service'], app=self.app)
  377. self.assertEqual(ret, 0)
  378. self.assertEqual(self.app.service_calls, [
  379. ('disp123', 'test.service', {
  380. 'localcmd': None,
  381. 'stdout': subprocess.DEVNULL,
  382. 'stderr': subprocess.DEVNULL,
  383. 'user': None,
  384. 'connect_timeout': 30,
  385. }),
  386. ('disp123', 'test.service', b''),
  387. ])
  388. self.assertAllCalled()
  389. def test_012_exclude(self):
  390. self.app.expected_calls[
  391. ('dom0', 'admin.vm.List', None, None)] = \
  392. b'0\x00test-vm class=AppVM state=Running\n' \
  393. b'test-vm2 class=AppVM state=Running\n' \
  394. b'test-vm3 class=AppVM state=Halted\n'
  395. self.app.expected_calls[
  396. ('test-vm', 'admin.vm.List', None, None)] = \
  397. b'0\x00test-vm class=AppVM state=Running\n'
  398. self.app.expected_calls[
  399. ('test-vm3', 'admin.vm.List', None, None)] = \
  400. b'0\x00test-vm3 class=AppVM state=Halted\n'
  401. self.app.expected_calls[
  402. ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  403. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  404. ret = qubesadmin.tools.qvm_run.main(
  405. ['--no-gui', '--all', '--exclude', 'test-vm2', 'command'],
  406. app=self.app)
  407. self.assertEqual(ret, 0)
  408. self.assertEqual(self.app.service_calls, [
  409. ('test-vm', 'qubes.VMShell', {
  410. 'localcmd': None,
  411. 'stdout': subprocess.DEVNULL,
  412. 'stderr': subprocess.DEVNULL,
  413. 'user': None,
  414. }),
  415. ('test-vm', 'qubes.VMShell', b'command; exit\n'),
  416. ])
  417. self.assertAllCalled()
  418. def test_013_no_autostart(self):
  419. self.app.expected_calls[
  420. ('dom0', 'admin.vm.List', None, None)] = \
  421. b'0\x00test-vm class=AppVM state=Running\n' \
  422. b'test-vm2 class=AppVM state=Running\n' \
  423. b'test-vm3 class=AppVM state=Halted\n'
  424. self.app.expected_calls[
  425. ('test-vm3', 'admin.vm.List', None, None)] = \
  426. b'0\x00test-vm3 class=AppVM state=Halted\n'
  427. ret = qubesadmin.tools.qvm_run.main(
  428. ['--no-gui', '--no-autostart', 'test-vm3', 'command'],
  429. app=self.app)
  430. self.assertEqual(ret, 0)
  431. self.assertEqual(self.app.service_calls, [])
  432. self.assertAllCalled()
  433. def test_014_dispvm_local_gui(self):
  434. self.app.qubesd_connection_type = 'socket'
  435. self.app.expected_calls[
  436. ('dom0', 'admin.vm.CreateDisposable', None, None)] = \
  437. b'0\0disp123'
  438. self.app.expected_calls[('disp123', 'admin.vm.Kill', None, None)] = \
  439. b'0\0'
  440. self.app.expected_calls[
  441. ('disp123', 'admin.vm.property.Get', 'qrexec_timeout', None)] = \
  442. b'0\0default=yes type=int 30'
  443. self.app.expected_calls[
  444. ('disp123', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  445. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  446. ret = qubesadmin.tools.qvm_run.main(
  447. ['--dispvm', '--', 'test.command'], app=self.app)
  448. self.assertEqual(ret, 0)
  449. self.assertEqual(self.app.service_calls, [
  450. ('disp123', 'qubes.VMShell+WaitForSession', {
  451. 'localcmd': None,
  452. 'stdout': subprocess.DEVNULL,
  453. 'stderr': subprocess.DEVNULL,
  454. 'user': None,
  455. 'connect_timeout': 30,
  456. }),
  457. ('disp123', 'qubes.VMShell+WaitForSession',
  458. b'test.command; exit\n'),
  459. ])
  460. self.assertAllCalled()
  461. def test_015_dispvm_local_no_gui(self):
  462. self.app.qubesd_connection_type = 'socket'
  463. self.app.expected_calls[
  464. ('dom0', 'admin.vm.CreateDisposable', None, None)] = \
  465. b'0\0disp123'
  466. self.app.expected_calls[('disp123', 'admin.vm.Kill', None, None)] = \
  467. b'0\0'
  468. self.app.expected_calls[
  469. ('disp123', 'admin.vm.property.Get', 'qrexec_timeout', None)] = \
  470. b'0\0default=yes type=int 30'
  471. self.app.expected_calls[
  472. ('disp123', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  473. b'2\x00QubesFeatureNotFoundError\x00\x00Feature \'os\' not set\x00'
  474. ret = qubesadmin.tools.qvm_run.main(
  475. ['--dispvm', '--no-gui', 'test.command'], app=self.app)
  476. self.assertEqual(ret, 0)
  477. self.assertEqual(self.app.service_calls, [
  478. ('disp123', 'qubes.VMShell', {
  479. 'localcmd': None,
  480. 'stdout': subprocess.DEVNULL,
  481. 'stderr': subprocess.DEVNULL,
  482. 'user': None,
  483. 'connect_timeout': 30,
  484. }),
  485. ('disp123', 'qubes.VMShell', b'test.command; exit\n'),
  486. ])
  487. self.assertAllCalled()
  488. def test_016_run_single_windows(self):
  489. self.app.expected_calls[
  490. ('dom0', 'admin.vm.List', None, None)] = \
  491. b'0\x00test-vm class=AppVM state=Running\n'
  492. self.app.expected_calls[
  493. ('test-vm', 'admin.vm.feature.CheckWithTemplate', 'os', None)] = \
  494. b'0\x00Windows'
  495. # self.app.expected_calls[
  496. # ('test-vm', 'admin.vm.List', None, None)] = \
  497. # b'0\x00test-vm class=AppVM state=Running\n'
  498. ret = qubesadmin.tools.qvm_run.main(
  499. ['--no-gui', 'test-vm', 'command'],
  500. app=self.app)
  501. self.assertEqual(ret, 0)
  502. self.assertEqual(self.app.service_calls, [
  503. ('test-vm', 'qubes.VMShell', {
  504. 'localcmd': None,
  505. 'stdout': subprocess.DEVNULL,
  506. 'stderr': subprocess.DEVNULL,
  507. 'user': None,
  508. }),
  509. ('test-vm', 'qubes.VMShell', b'command& exit\n')
  510. ])
  511. self.assertAllCalled()