A python client implementing the Ironic API.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

3688 řádky
117KB

  1. #
  2. # Copyright 2015 Red Hat, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. #
  16. import copy
  17. import mock
  18. from osc_lib.tests import utils as oscutils
  19. from ironicclient.common import utils as commonutils
  20. from ironicclient import exc
  21. from ironicclient.osc.v1 import baremetal_node
  22. from ironicclient.tests.unit.osc.v1 import fakes as baremetal_fakes
  23. from ironicclient.v1 import utils as v1_utils
  24. class TestBaremetal(baremetal_fakes.TestBaremetal):
  25. def setUp(self):
  26. super(TestBaremetal, self).setUp()
  27. # Get a shortcut to the baremetal manager mock
  28. self.baremetal_mock = self.app.client_manager.baremetal
  29. self.baremetal_mock.reset_mock()
  30. class TestAdopt(TestBaremetal):
  31. def setUp(self):
  32. super(TestAdopt, self).setUp()
  33. # Get the command object to test
  34. self.cmd = baremetal_node.AdoptBaremetalNode(self.app, None)
  35. def test_adopt(self):
  36. arglist = ['node_uuid']
  37. verifylist = [
  38. ('node', 'node_uuid'),
  39. ('provision_state', 'adopt'),
  40. ]
  41. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  42. self.cmd.take_action(parsed_args)
  43. self.baremetal_mock.node.set_provision_state.assert_called_once_with(
  44. 'node_uuid', 'adopt',
  45. cleansteps=None, configdrive=None, rescue_password=None)
  46. def test_adopt_no_wait(self):
  47. arglist = ['node_uuid']
  48. verifylist = [
  49. ('node', 'node_uuid'),
  50. ('provision_state', 'adopt')
  51. ]
  52. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  53. self.cmd.take_action(parsed_args)
  54. self.baremetal_mock.node.wait_for_provision_state.assert_not_called()
  55. def test_adopt_baremetal_provision_state_active_and_wait(self):
  56. arglist = ['node_uuid',
  57. '--wait', '15']
  58. verifylist = [
  59. ('node', 'node_uuid'),
  60. ('provision_state', 'adopt'),
  61. ('wait_timeout', 15)
  62. ]
  63. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  64. self.cmd.take_action(parsed_args)
  65. test_node = self.baremetal_mock.node
  66. test_node.wait_for_provision_state.assert_called_once_with(
  67. 'node_uuid', expected_state='active',
  68. poll_interval=2, timeout=15)
  69. def test_adopt_baremetal_provision_state_default_wait(self):
  70. arglist = ['node_uuid',
  71. '--wait']
  72. verifylist = [
  73. ('node', 'node_uuid'),
  74. ('provision_state', 'adopt'),
  75. ('wait_timeout', 0)
  76. ]
  77. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  78. self.cmd.take_action(parsed_args)
  79. test_node = self.baremetal_mock.node
  80. test_node.wait_for_provision_state.assert_called_once_with(
  81. 'node_uuid', expected_state='active',
  82. poll_interval=2, timeout=0)
  83. class TestBootdeviceSet(TestBaremetal):
  84. def setUp(self):
  85. super(TestBootdeviceSet, self).setUp()
  86. # Get the command object to test
  87. self.cmd = baremetal_node.BootdeviceSetBaremetalNode(self.app, None)
  88. def test_bootdevice_set(self):
  89. arglist = ['node_uuid', 'bios']
  90. verifylist = [('node', 'node_uuid'),
  91. ('device', 'bios')]
  92. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  93. self.cmd.take_action(parsed_args)
  94. self.baremetal_mock.node.set_boot_device.assert_called_once_with(
  95. 'node_uuid', 'bios', False)
  96. def test_bootdevice_set_persistent(self):
  97. arglist = ['node_uuid', 'bios', '--persistent']
  98. verifylist = [('node', 'node_uuid'),
  99. ('device', 'bios'),
  100. ('persistent', True)]
  101. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  102. self.cmd.take_action(parsed_args)
  103. self.baremetal_mock.node.set_boot_device.assert_called_once_with(
  104. 'node_uuid', 'bios', True)
  105. def test_bootdevice_set_invalid_device(self):
  106. arglist = ['node_uuid', 'foo']
  107. verifylist = [('node', 'node_uuid'),
  108. ('device', 'foo')]
  109. self.assertRaises(oscutils.ParserException,
  110. self.check_parser,
  111. self.cmd, arglist, verifylist)
  112. def test_bootdevice_set_device_only(self):
  113. arglist = ['bios']
  114. verifylist = [('device', 'bios')]
  115. self.assertRaises(oscutils.ParserException,
  116. self.check_parser,
  117. self.cmd, arglist, verifylist)
  118. class TestBootdeviceShow(TestBaremetal):
  119. def setUp(self):
  120. super(TestBootdeviceShow, self).setUp()
  121. # Get the command object to test
  122. self.cmd = baremetal_node.BootdeviceShowBaremetalNode(self.app, None)
  123. self.baremetal_mock.node.get_boot_device.return_value = {
  124. "boot_device": "pxe", "persistent": False}
  125. self.baremetal_mock.node.get_supported_boot_devices.return_value = {
  126. "supported_boot_devices": v1_utils.BOOT_DEVICES}
  127. def test_bootdevice_show(self):
  128. arglist = ['node_uuid']
  129. verifylist = [('node', 'node_uuid')]
  130. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  131. self.cmd.take_action(parsed_args)
  132. self.baremetal_mock.node.get_boot_device.assert_called_once_with(
  133. 'node_uuid')
  134. def test_bootdevice_supported_show(self):
  135. arglist = ['node_uuid', '--supported']
  136. verifylist = [('node', 'node_uuid'), ('supported', True)]
  137. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  138. self.cmd.take_action(parsed_args)
  139. mock = self.baremetal_mock.node.get_supported_boot_devices
  140. mock.assert_called_once_with('node_uuid')
  141. class TestConsoleDisable(TestBaremetal):
  142. def setUp(self):
  143. super(TestConsoleDisable, self).setUp()
  144. # Get the command object to test
  145. self.cmd = baremetal_node.ConsoleDisableBaremetalNode(self.app, None)
  146. def test_console_disable(self):
  147. arglist = ['node_uuid']
  148. verifylist = [('node', 'node_uuid')]
  149. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  150. self.cmd.take_action(parsed_args)
  151. self.baremetal_mock.node.set_console_mode.assert_called_once_with(
  152. 'node_uuid', False)
  153. class TestConsoleEnable(TestBaremetal):
  154. def setUp(self):
  155. super(TestConsoleEnable, self).setUp()
  156. # Get the command object to test
  157. self.cmd = baremetal_node.ConsoleEnableBaremetalNode(self.app, None)
  158. def test_console_enable(self):
  159. arglist = ['node_uuid']
  160. verifylist = [('node', 'node_uuid')]
  161. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  162. self.cmd.take_action(parsed_args)
  163. self.baremetal_mock.node.set_console_mode.assert_called_once_with(
  164. 'node_uuid', True)
  165. class TestConsoleShow(TestBaremetal):
  166. def setUp(self):
  167. super(TestConsoleShow, self).setUp()
  168. # Get the command object to test
  169. self.cmd = baremetal_node.ConsoleShowBaremetalNode(self.app, None)
  170. self.baremetal_mock.node.get_console.return_value = {
  171. "console_enabled": False, "console_info": None}
  172. def test_console_show(self):
  173. arglist = ['node_uuid']
  174. verifylist = [('node', 'node_uuid')]
  175. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  176. self.cmd.take_action(parsed_args)
  177. self.baremetal_mock.node.get_console.assert_called_once_with(
  178. 'node_uuid')
  179. class TestBaremetalCreate(TestBaremetal):
  180. def setUp(self):
  181. super(TestBaremetalCreate, self).setUp()
  182. self.baremetal_mock.node.create.return_value = (
  183. baremetal_fakes.FakeBaremetalResource(
  184. None,
  185. copy.deepcopy(baremetal_fakes.BAREMETAL),
  186. loaded=True,
  187. ))
  188. # Get the command object to test
  189. self.cmd = baremetal_node.CreateBaremetalNode(self.app, None)
  190. self.arglist = ['--driver', 'fake_driver']
  191. self.verifylist = [('driver', 'fake_driver')]
  192. self.collist = ('chassis_uuid',
  193. 'instance_uuid',
  194. 'maintenance',
  195. 'name',
  196. 'power_state',
  197. 'provision_state',
  198. 'uuid'
  199. )
  200. self.datalist = (
  201. baremetal_fakes.baremetal_chassis_uuid_empty,
  202. baremetal_fakes.baremetal_instance_uuid,
  203. baremetal_fakes.baremetal_maintenance,
  204. baremetal_fakes.baremetal_name,
  205. baremetal_fakes.baremetal_power_state,
  206. baremetal_fakes.baremetal_provision_state,
  207. baremetal_fakes.baremetal_uuid,
  208. )
  209. self.actual_kwargs = {
  210. 'driver': 'fake_driver'
  211. }
  212. def check_with_options(self, addl_arglist, addl_verifylist, addl_kwargs):
  213. arglist = copy.copy(self.arglist) + addl_arglist
  214. verifylist = copy.copy(self.verifylist) + addl_verifylist
  215. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  216. # DisplayCommandBase.take_action() returns two tuples
  217. columns, data = self.cmd.take_action(parsed_args)
  218. collist = copy.copy(self.collist)
  219. self.assertEqual(collist, columns)
  220. datalist = copy.copy(self.datalist)
  221. self.assertEqual(datalist, tuple(data))
  222. kwargs = copy.copy(self.actual_kwargs)
  223. kwargs.update(addl_kwargs)
  224. self.baremetal_mock.node.create.assert_called_once_with(**kwargs)
  225. def test_baremetal_create_no_options(self):
  226. arglist = []
  227. verifylist = []
  228. self.assertRaises(oscutils.ParserException,
  229. self.check_parser,
  230. self.cmd, arglist, verifylist)
  231. def test_baremetal_create_with_driver(self):
  232. arglist = copy.copy(self.arglist)
  233. verifylist = copy.copy(self.verifylist)
  234. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  235. # DisplayCommandBase.take_action() returns two tuples
  236. columns, data = self.cmd.take_action(parsed_args)
  237. collist = copy.copy(self.collist)
  238. self.assertEqual(collist, columns)
  239. self.assertNotIn('ports', columns)
  240. self.assertNotIn('states', columns)
  241. datalist = copy.copy(self.datalist)
  242. self.assertEqual(datalist, tuple(data))
  243. kwargs = copy.copy(self.actual_kwargs)
  244. self.baremetal_mock.node.create.assert_called_once_with(**kwargs)
  245. def test_baremetal_create_with_chassis(self):
  246. self.check_with_options(['--chassis-uuid', 'chassis_uuid'],
  247. [('chassis_uuid', 'chassis_uuid')],
  248. {'chassis_uuid': 'chassis_uuid'})
  249. def test_baremetal_create_with_driver_info(self):
  250. self.check_with_options(['--driver-info', 'arg1=val1',
  251. '--driver-info', 'arg2=val2'],
  252. [('driver_info',
  253. ['arg1=val1',
  254. 'arg2=val2'])],
  255. {'driver_info': {
  256. 'arg1': 'val1',
  257. 'arg2': 'val2'}})
  258. def test_baremetal_create_with_properties(self):
  259. self.check_with_options(['--property', 'arg1=val1',
  260. '--property', 'arg2=val2'],
  261. [('properties',
  262. ['arg1=val1',
  263. 'arg2=val2'])],
  264. {'properties': {
  265. 'arg1': 'val1',
  266. 'arg2': 'val2'}})
  267. def test_baremetal_create_with_extra(self):
  268. self.check_with_options(['--extra', 'arg1=val1',
  269. '--extra', 'arg2=val2'],
  270. [('extra',
  271. ['arg1=val1',
  272. 'arg2=val2'])],
  273. {'extra': {
  274. 'arg1': 'val1',
  275. 'arg2': 'val2'}})
  276. def test_baremetal_create_with_uuid(self):
  277. self.check_with_options(['--uuid', 'uuid'],
  278. [('uuid', 'uuid')],
  279. {'uuid': 'uuid'})
  280. def test_baremetal_create_with_name(self):
  281. self.check_with_options(['--name', 'name'],
  282. [('name', 'name')],
  283. {'name': 'name'})
  284. def test_baremetal_create_with_bios_interface(self):
  285. self.check_with_options(['--bios-interface', 'bios'],
  286. [('bios_interface', 'bios')],
  287. {'bios_interface': 'bios'})
  288. def test_baremetal_create_with_boot_interface(self):
  289. self.check_with_options(['--boot-interface', 'boot'],
  290. [('boot_interface', 'boot')],
  291. {'boot_interface': 'boot'})
  292. def test_baremetal_create_with_console_interface(self):
  293. self.check_with_options(['--console-interface', 'console'],
  294. [('console_interface', 'console')],
  295. {'console_interface': 'console'})
  296. def test_baremetal_create_with_deploy_interface(self):
  297. self.check_with_options(['--deploy-interface', 'deploy'],
  298. [('deploy_interface', 'deploy')],
  299. {'deploy_interface': 'deploy'})
  300. def test_baremetal_create_with_inspect_interface(self):
  301. self.check_with_options(['--inspect-interface', 'inspect'],
  302. [('inspect_interface', 'inspect')],
  303. {'inspect_interface': 'inspect'})
  304. def test_baremetal_create_with_management_interface(self):
  305. self.check_with_options(['--management-interface', 'management'],
  306. [('management_interface', 'management')],
  307. {'management_interface': 'management'})
  308. def test_baremetal_create_with_network_interface(self):
  309. self.check_with_options(['--network-interface', 'neutron'],
  310. [('network_interface', 'neutron')],
  311. {'network_interface': 'neutron'})
  312. def test_baremetal_create_with_power_interface(self):
  313. self.check_with_options(['--power-interface', 'power'],
  314. [('power_interface', 'power')],
  315. {'power_interface': 'power'})
  316. def test_baremetal_create_with_raid_interface(self):
  317. self.check_with_options(['--raid-interface', 'raid'],
  318. [('raid_interface', 'raid')],
  319. {'raid_interface': 'raid'})
  320. def test_baremetal_create_with_rescue_interface(self):
  321. self.check_with_options(['--rescue-interface', 'rescue'],
  322. [('rescue_interface', 'rescue')],
  323. {'rescue_interface': 'rescue'})
  324. def test_baremetal_create_with_storage_interface(self):
  325. self.check_with_options(['--storage-interface', 'storage'],
  326. [('storage_interface', 'storage')],
  327. {'storage_interface': 'storage'})
  328. def test_baremetal_create_with_vendor_interface(self):
  329. self.check_with_options(['--vendor-interface', 'vendor'],
  330. [('vendor_interface', 'vendor')],
  331. {'vendor_interface': 'vendor'})
  332. def test_baremetal_create_with_resource_class(self):
  333. self.check_with_options(['--resource-class', 'foo'],
  334. [('resource_class', 'foo')],
  335. {'resource_class': 'foo'})
  336. def test_baremetal_create_with_conductor_group(self):
  337. self.check_with_options(['--conductor-group', 'conductor_group'],
  338. [('conductor_group', 'conductor_group')],
  339. {'conductor_group': 'conductor_group'})
  340. def test_baremetal_create_with_automated_clean(self):
  341. self.check_with_options(['--automated-clean'],
  342. [('automated_clean', True)],
  343. {'automated_clean': True})
  344. def test_baremetal_create_with_owner(self):
  345. self.check_with_options(['--owner', 'owner 1'],
  346. [('owner', 'owner 1')],
  347. {'owner': 'owner 1'})
  348. def test_baremetal_create_with_description(self):
  349. self.check_with_options(['--description', 'there is no spoon'],
  350. [('description', 'there is no spoon')],
  351. {'description': 'there is no spoon'})
  352. class TestBaremetalDelete(TestBaremetal):
  353. def setUp(self):
  354. super(TestBaremetalDelete, self).setUp()
  355. self.baremetal_mock.node.get.return_value = (
  356. baremetal_fakes.FakeBaremetalResource(
  357. None,
  358. copy.deepcopy(baremetal_fakes.BAREMETAL),
  359. loaded=True,
  360. ))
  361. # Get the command object to test
  362. self.cmd = baremetal_node.DeleteBaremetalNode(self.app, None)
  363. def test_baremetal_delete(self):
  364. arglist = ['xxx-xxxxxx-xxxx']
  365. verifylist = []
  366. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  367. self.cmd.take_action(parsed_args)
  368. # Set expected values
  369. args = 'xxx-xxxxxx-xxxx'
  370. self.baremetal_mock.node.delete.assert_called_with(
  371. args
  372. )
  373. def test_baremetal_delete_multiple(self):
  374. arglist = ['xxx-xxxxxx-xxxx', 'fakename']
  375. verifylist = []
  376. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  377. self.cmd.take_action(parsed_args)
  378. # Set expected values
  379. args = ['xxx-xxxxxx-xxxx', 'fakename']
  380. self.baremetal_mock.node.delete.assert_has_calls(
  381. [mock.call(x) for x in args]
  382. )
  383. self.assertEqual(2, self.baremetal_mock.node.delete.call_count)
  384. def test_baremetal_delete_multiple_with_failure(self):
  385. arglist = ['xxx-xxxxxx-xxxx', 'badname']
  386. verifylist = []
  387. self.baremetal_mock.node.delete.side_effect = ['', exc.ClientException]
  388. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  389. self.assertRaises(exc.ClientException,
  390. self.cmd.take_action,
  391. parsed_args)
  392. # Set expected values
  393. args = ['xxx-xxxxxx-xxxx', 'badname']
  394. self.baremetal_mock.node.delete.assert_has_calls(
  395. [mock.call(x) for x in args]
  396. )
  397. self.assertEqual(2, self.baremetal_mock.node.delete.call_count)
  398. class TestBaremetalList(TestBaremetal):
  399. def setUp(self):
  400. super(TestBaremetalList, self).setUp()
  401. self.baremetal_mock.node.list.return_value = [
  402. baremetal_fakes.FakeBaremetalResource(
  403. None,
  404. copy.deepcopy(baremetal_fakes.BAREMETAL),
  405. loaded=True,
  406. ),
  407. ]
  408. # Get the command object to test
  409. self.cmd = baremetal_node.ListBaremetalNode(self.app, None)
  410. def test_baremetal_list_no_options(self):
  411. arglist = []
  412. verifylist = []
  413. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  414. # DisplayCommandBase.take_action() returns two tuples
  415. columns, data = self.cmd.take_action(parsed_args)
  416. # Set expected values
  417. kwargs = {
  418. 'marker': None,
  419. 'limit': None,
  420. }
  421. self.baremetal_mock.node.list.assert_called_with(
  422. **kwargs
  423. )
  424. collist = (
  425. "UUID",
  426. "Name",
  427. "Instance UUID",
  428. "Power State",
  429. "Provisioning State",
  430. "Maintenance"
  431. )
  432. self.assertEqual(collist, columns)
  433. datalist = ((
  434. baremetal_fakes.baremetal_uuid,
  435. baremetal_fakes.baremetal_name,
  436. baremetal_fakes.baremetal_instance_uuid,
  437. baremetal_fakes.baremetal_power_state,
  438. baremetal_fakes.baremetal_provision_state,
  439. baremetal_fakes.baremetal_maintenance,
  440. ), )
  441. self.assertEqual(datalist, tuple(data))
  442. def test_baremetal_list_long(self):
  443. arglist = [
  444. '--long',
  445. ]
  446. verifylist = [
  447. ('long', True),
  448. ]
  449. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  450. # DisplayCommandBase.take_action() returns two tuples
  451. columns, data = self.cmd.take_action(parsed_args)
  452. # Set expected values
  453. kwargs = {
  454. 'detail': True,
  455. 'marker': None,
  456. 'limit': None,
  457. }
  458. self.baremetal_mock.node.list.assert_called_with(
  459. **kwargs
  460. )
  461. # NOTE(dtantsur): please keep this list sorted for sanity reasons
  462. collist = [
  463. 'Allocation UUID',
  464. 'Automated Clean',
  465. 'BIOS Interface',
  466. 'Boot Interface',
  467. 'Chassis UUID',
  468. 'Clean Step',
  469. 'Conductor',
  470. 'Conductor Group',
  471. 'Console Enabled',
  472. 'Console Interface',
  473. 'Created At',
  474. 'Current RAID configuration',
  475. 'Deploy Interface',
  476. 'Deploy Step',
  477. 'Description',
  478. 'Driver',
  479. 'Driver Info',
  480. 'Driver Internal Info',
  481. 'Extra',
  482. 'Fault',
  483. 'Inspect Interface',
  484. 'Inspection Finished At',
  485. 'Inspection Started At',
  486. 'Instance Info',
  487. 'Instance UUID',
  488. 'Last Error',
  489. 'Maintenance',
  490. 'Maintenance Reason',
  491. 'Management Interface',
  492. 'Name',
  493. 'Network Interface',
  494. 'Owner',
  495. 'Power Interface',
  496. 'Power State',
  497. 'Properties',
  498. 'Protected',
  499. 'Protected Reason',
  500. 'Provision Updated At',
  501. 'Provisioning State',
  502. 'RAID Interface',
  503. 'Rescue Interface',
  504. 'Reservation',
  505. 'Resource Class',
  506. 'Retired',
  507. 'Retired Reason',
  508. 'Storage Interface',
  509. 'Target Power State',
  510. 'Target Provision State',
  511. 'Target RAID configuration',
  512. 'Traits',
  513. 'UUID',
  514. 'Updated At',
  515. 'Vendor Interface'
  516. ]
  517. # Enforce sorting
  518. collist.sort()
  519. self.assertEqual(tuple(collist), columns)
  520. fake_values = {
  521. 'Instance UUID': baremetal_fakes.baremetal_instance_uuid,
  522. 'Maintenance': baremetal_fakes.baremetal_maintenance,
  523. 'Name': baremetal_fakes.baremetal_name,
  524. 'Power State': baremetal_fakes.baremetal_power_state,
  525. 'Provisioning State': baremetal_fakes.baremetal_provision_state,
  526. 'UUID': baremetal_fakes.baremetal_uuid,
  527. }
  528. values = tuple(fake_values.get(name, '') for name in collist)
  529. self.assertEqual((values,), tuple(data))
  530. def _test_baremetal_list_maintenance(self, maint_option, maint_value):
  531. arglist = [
  532. maint_option,
  533. ]
  534. verifylist = [
  535. ('maintenance', maint_value),
  536. ]
  537. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  538. # DisplayCommandBase.take_action() returns two tuples
  539. self.cmd.take_action(parsed_args)
  540. # Set expected values
  541. kwargs = {
  542. 'marker': None,
  543. 'limit': None,
  544. 'maintenance': maint_value,
  545. }
  546. self.baremetal_mock.node.list.assert_called_with(
  547. **kwargs
  548. )
  549. def test_baremetal_list_maintenance(self):
  550. self._test_baremetal_list_maintenance('--maintenance', True)
  551. def test_baremetal_list_no_maintenance(self):
  552. self._test_baremetal_list_maintenance('--no-maintenance', False)
  553. def test_baremetal_list_none_maintenance(self):
  554. arglist = [
  555. ]
  556. verifylist = [
  557. ]
  558. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  559. # DisplayCommandBase.take_action() returns two tuples
  560. self.cmd.take_action(parsed_args)
  561. # Set expected values
  562. kwargs = {
  563. 'marker': None,
  564. 'limit': None,
  565. }
  566. self.baremetal_mock.node.list.assert_called_with(
  567. **kwargs
  568. )
  569. def test_baremetal_list_both_maintenances(self):
  570. arglist = [
  571. '--maintenance',
  572. '--no-maintenance',
  573. ]
  574. verifylist = []
  575. self.assertRaises(oscutils.ParserException,
  576. self.check_parser,
  577. self.cmd, arglist, verifylist)
  578. def test_baremetal_list_fault(self):
  579. arglist = [
  580. '--maintenance',
  581. '--fault', 'power failure',
  582. ]
  583. verifylist = [
  584. ('maintenance', True),
  585. ('fault', 'power failure'),
  586. ]
  587. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  588. # DisplayCommandBase.take_action() returns two tuples
  589. self.cmd.take_action(parsed_args)
  590. # Set expected values
  591. kwargs = {
  592. 'marker': None,
  593. 'limit': None,
  594. 'maintenance': True,
  595. 'fault': 'power failure'
  596. }
  597. self.baremetal_mock.node.list.assert_called_with(
  598. **kwargs
  599. )
  600. def test_baremetal_list_associated(self):
  601. arglist = [
  602. '--associated',
  603. ]
  604. verifylist = [
  605. ('associated', True),
  606. ]
  607. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  608. # DisplayCommandBase.take_action() returns two tuples
  609. self.cmd.take_action(parsed_args)
  610. # Set expected values
  611. kwargs = {
  612. 'marker': None,
  613. 'limit': None,
  614. 'associated': True,
  615. }
  616. self.baremetal_mock.node.list.assert_called_with(
  617. **kwargs
  618. )
  619. def test_baremetal_list_unassociated(self):
  620. arglist = [
  621. '--unassociated',
  622. ]
  623. verifylist = [
  624. ('associated', False),
  625. ]
  626. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  627. self.cmd.take_action(parsed_args)
  628. # Set expected values
  629. kwargs = {
  630. 'marker': None,
  631. 'limit': None,
  632. 'associated': False,
  633. }
  634. self.baremetal_mock.node.list.assert_called_with(
  635. **kwargs
  636. )
  637. def test_baremetal_list_both_associated_unassociated_not_allowed(self):
  638. arglist = [
  639. '--associated', '--unassociated',
  640. ]
  641. verifylist = []
  642. self.assertRaises(oscutils.ParserException,
  643. self.check_parser,
  644. self.cmd, arglist, verifylist)
  645. def test_baremetal_list_provision_state(self):
  646. arglist = [
  647. '--provision-state', 'active',
  648. ]
  649. verifylist = [
  650. ('provision_state', 'active'),
  651. ]
  652. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  653. # DisplayCommandBase.take_action() returns two tuples
  654. self.cmd.take_action(parsed_args)
  655. # Set expected values
  656. kwargs = {
  657. 'marker': None,
  658. 'limit': None,
  659. 'provision_state': 'active'
  660. }
  661. self.baremetal_mock.node.list.assert_called_with(
  662. **kwargs
  663. )
  664. def test_baremetal_list_driver(self):
  665. arglist = [
  666. '--driver', 'ipmi',
  667. ]
  668. verifylist = [
  669. ('driver', 'ipmi'),
  670. ]
  671. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  672. # DisplayCommandBase.take_action() returns two tuples
  673. self.cmd.take_action(parsed_args)
  674. # Set expected values
  675. kwargs = {
  676. 'marker': None,
  677. 'limit': None,
  678. 'driver': 'ipmi'
  679. }
  680. self.baremetal_mock.node.list.assert_called_with(
  681. **kwargs
  682. )
  683. def test_baremetal_list_resource_class(self):
  684. arglist = [
  685. '--resource-class', 'foo',
  686. ]
  687. verifylist = [
  688. ('resource_class', 'foo'),
  689. ]
  690. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  691. # DisplayCommandBase.take_action() returns two tuples
  692. self.cmd.take_action(parsed_args)
  693. # Set expected values
  694. kwargs = {
  695. 'marker': None,
  696. 'limit': None,
  697. 'resource_class': 'foo'
  698. }
  699. self.baremetal_mock.node.list.assert_called_with(
  700. **kwargs
  701. )
  702. def test_baremetal_list_chassis(self):
  703. chassis_uuid = 'aaaaaaaa-1111-bbbb-2222-cccccccccccc'
  704. arglist = [
  705. '--chassis', chassis_uuid,
  706. ]
  707. verifylist = [
  708. ('chassis', chassis_uuid),
  709. ]
  710. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  711. # DisplayCommandBase.take_action() returns two tuples
  712. self.cmd.take_action(parsed_args)
  713. # Set expected values
  714. kwargs = {
  715. 'marker': None,
  716. 'limit': None,
  717. 'chassis': chassis_uuid
  718. }
  719. self.baremetal_mock.node.list.assert_called_with(
  720. **kwargs
  721. )
  722. def test_baremetal_list_conductor_group(self):
  723. conductor_group = 'in-the-closet-to-the-left'
  724. arglist = [
  725. '--conductor-group', conductor_group,
  726. ]
  727. verifylist = [
  728. ('conductor_group', conductor_group),
  729. ]
  730. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  731. # DisplayCommandBase.take_action() returns two tuples
  732. self.cmd.take_action(parsed_args)
  733. # Set expected values
  734. kwargs = {
  735. 'marker': None,
  736. 'limit': None,
  737. 'conductor_group': conductor_group
  738. }
  739. self.baremetal_mock.node.list.assert_called_with(
  740. **kwargs
  741. )
  742. def test_baremetal_list_empty_conductor_group(self):
  743. conductor_group = ''
  744. arglist = [
  745. '--conductor-group', conductor_group,
  746. ]
  747. verifylist = [
  748. ('conductor_group', conductor_group),
  749. ]
  750. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  751. # DisplayCommandBase.take_action() returns two tuples
  752. self.cmd.take_action(parsed_args)
  753. # Set expected values
  754. kwargs = {
  755. 'marker': None,
  756. 'limit': None,
  757. 'conductor_group': conductor_group
  758. }
  759. self.baremetal_mock.node.list.assert_called_with(
  760. **kwargs
  761. )
  762. def test_baremetal_list_by_conductor(self):
  763. conductor = 'fake-conductor'
  764. arglist = [
  765. '--conductor', conductor,
  766. ]
  767. verifylist = [
  768. ('conductor', conductor),
  769. ]
  770. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  771. # DisplayCommandBase.take_action() returns two tuples
  772. self.cmd.take_action(parsed_args)
  773. # Set expected values
  774. kwargs = {
  775. 'marker': None,
  776. 'limit': None,
  777. 'conductor': conductor
  778. }
  779. self.baremetal_mock.node.list.assert_called_with(
  780. **kwargs
  781. )
  782. def test_baremetal_list_by_owner(self):
  783. owner = 'owner 1'
  784. arglist = [
  785. '--owner', owner,
  786. ]
  787. verifylist = [
  788. ('owner', owner),
  789. ]
  790. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  791. # DisplayCommandBase.take_action() returns two tuples
  792. self.cmd.take_action(parsed_args)
  793. kwargs = {
  794. 'marker': None,
  795. 'limit': None,
  796. 'owner': owner,
  797. }
  798. self.baremetal_mock.node.list.assert_called_with(
  799. **kwargs
  800. )
  801. def test_baremetal_list_has_description(self):
  802. description = 'there is no spoon'
  803. arglist = [
  804. '--description-contains', description,
  805. ]
  806. verifylist = [
  807. ('description_contains', description),
  808. ]
  809. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  810. # DisplayCommandBase.take_action() returns two tuples
  811. self.cmd.take_action(parsed_args)
  812. # Set expected values
  813. kwargs = {
  814. 'marker': None,
  815. 'limit': None,
  816. 'description_contains': description
  817. }
  818. self.baremetal_mock.node.list.assert_called_with(
  819. **kwargs
  820. )
  821. def test_baremetal_list_fields(self):
  822. arglist = [
  823. '--fields', 'uuid', 'name',
  824. ]
  825. verifylist = [
  826. ('fields', [['uuid', 'name']]),
  827. ]
  828. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  829. # DisplayCommandBase.take_action() returns two tuples
  830. self.cmd.take_action(parsed_args)
  831. # Set expected values
  832. kwargs = {
  833. 'marker': None,
  834. 'limit': None,
  835. 'detail': False,
  836. 'fields': ('uuid', 'name'),
  837. }
  838. self.baremetal_mock.node.list.assert_called_with(
  839. **kwargs
  840. )
  841. def test_baremetal_list_fields_multiple(self):
  842. arglist = [
  843. '--fields', 'uuid', 'name',
  844. '--fields', 'extra',
  845. ]
  846. verifylist = [
  847. ('fields', [['uuid', 'name'], ['extra']])
  848. ]
  849. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  850. self.cmd.take_action(parsed_args)
  851. # Set expected values
  852. kwargs = {
  853. 'marker': None,
  854. 'limit': None,
  855. 'detail': False,
  856. 'fields': ('uuid', 'name', 'extra')
  857. }
  858. self.baremetal_mock.node.list.assert_called_with(
  859. **kwargs
  860. )
  861. def test_baremetal_list_invalid_fields(self):
  862. arglist = [
  863. '--fields', 'uuid', 'invalid'
  864. ]
  865. verifylist = [
  866. ('fields', [['uuid', 'invalid']])
  867. ]
  868. self.assertRaises(oscutils.ParserException,
  869. self.check_parser,
  870. self.cmd, arglist, verifylist)
  871. class TestBaremetalMaintenanceSet(TestBaremetal):
  872. def setUp(self):
  873. super(TestBaremetalMaintenanceSet, self).setUp()
  874. # Get the command object to test
  875. self.cmd = baremetal_node.MaintenanceSetBaremetalNode(self.app, None)
  876. def test_baremetal_maintenance_on(self):
  877. arglist = ['node_uuid',
  878. '--reason', 'maintenance reason']
  879. verifylist = [
  880. ('node', 'node_uuid'),
  881. ('reason', 'maintenance reason'),
  882. ]
  883. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  884. self.cmd.take_action(parsed_args)
  885. self.baremetal_mock.node.set_maintenance.assert_called_once_with(
  886. 'node_uuid',
  887. True,
  888. maint_reason='maintenance reason'
  889. )
  890. def test_baremetal_maintenance_on_no_reason(self):
  891. arglist = ['node_uuid']
  892. verifylist = [
  893. ('node', 'node_uuid'),
  894. ]
  895. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  896. self.cmd.take_action(parsed_args)
  897. self.baremetal_mock.node.set_maintenance.assert_called_once_with(
  898. 'node_uuid',
  899. True,
  900. maint_reason=None
  901. )
  902. class TestBaremetalMaintenanceUnset(TestBaremetal):
  903. def setUp(self):
  904. super(TestBaremetalMaintenanceUnset, self).setUp()
  905. # Get the command object to test
  906. self.cmd = baremetal_node.MaintenanceUnsetBaremetalNode(self.app, None)
  907. def test_baremetal_maintenance_off(self):
  908. arglist = ['node_uuid']
  909. verifylist = [('node', 'node_uuid')]
  910. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  911. self.cmd.take_action(parsed_args)
  912. self.baremetal_mock.node.set_maintenance.assert_called_once_with(
  913. 'node_uuid',
  914. False)
  915. class TestPassthruCall(TestBaremetal):
  916. def setUp(self):
  917. super(TestPassthruCall, self).setUp()
  918. # Get the command object to test
  919. self.cmd = baremetal_node.PassthruCallBaremetalNode(self.app, None)
  920. def test_passthru_call(self):
  921. arglist = ['node_uuid', 'heartbeat']
  922. verifylist = [('node', 'node_uuid'),
  923. ('method', 'heartbeat')]
  924. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  925. self.cmd.take_action(parsed_args)
  926. self.baremetal_mock.node.vendor_passthru.assert_called_once_with(
  927. 'node_uuid', 'heartbeat', http_method='POST', args={})
  928. def test_passthru_call_http_method(self):
  929. arglist = ['node_uuid', 'heartbeat', '--http-method', 'PUT']
  930. verifylist = [('node', 'node_uuid'),
  931. ('method', 'heartbeat'),
  932. ('http_method', 'PUT')]
  933. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  934. self.cmd.take_action(parsed_args)
  935. self.baremetal_mock.node.vendor_passthru.assert_called_once_with(
  936. 'node_uuid', 'heartbeat', http_method='PUT', args={})
  937. def test_passthru_call_args(self):
  938. arglist = ['node_uuid', 'heartbeat',
  939. '--arg', 'key1=value1', '--arg', 'key2=value2']
  940. verifylist = [('node', 'node_uuid'),
  941. ('method', 'heartbeat'),
  942. ('arg', ['key1=value1', 'key2=value2'])]
  943. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  944. self.cmd.take_action(parsed_args)
  945. expected_dict = {'key1': 'value1', 'key2': 'value2'}
  946. self.baremetal_mock.node.vendor_passthru.assert_called_once_with(
  947. 'node_uuid', 'heartbeat', http_method='POST', args=expected_dict)
  948. class TestPassthruList(TestBaremetal):
  949. def setUp(self):
  950. super(TestPassthruList, self).setUp()
  951. # Get the command object to test
  952. self.cmd = baremetal_node.PassthruListBaremetalNode(self.app, None)
  953. self.baremetal_mock.node.get_vendor_passthru_methods.return_value = {
  954. "send_raw": {"require_exclusive_lock": True, "attach": False,
  955. "http_methods": ["POST"], "description": "",
  956. "async": True},
  957. "bmc_reset": {"require_exclusive_lock": True, "attach": False,
  958. "http_methods": ["POST"], "description": "",
  959. "async": True}}
  960. def test_passthru_list(self):
  961. arglist = ['node_uuid']
  962. verifylist = [('node', 'node_uuid')]
  963. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  964. self.cmd.take_action(parsed_args)
  965. mock = self.baremetal_mock.node.get_vendor_passthru_methods
  966. mock.assert_called_once_with('node_uuid')
  967. class TestPower(TestBaremetal):
  968. def setUp(self):
  969. super(TestPower, self).setUp()
  970. # Get the command object to test
  971. self.cmd = baremetal_node.PowerBaremetalNode(self.app, None)
  972. def test_baremetal_power(self):
  973. arglist = ['node_uuid']
  974. verifylist = [('node', 'node_uuid')]
  975. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  976. self.assertRaisesRegex(AttributeError,
  977. ".*no attribute 'POWER_STATE'",
  978. self.cmd.take_action, parsed_args)
  979. class TestPowerOff(TestBaremetal):
  980. def setUp(self):
  981. super(TestPowerOff, self).setUp()
  982. # Get the command object to test
  983. self.cmd = baremetal_node.PowerOffBaremetalNode(self.app, None)
  984. def test_baremetal_power_off(self):
  985. arglist = ['node_uuid']
  986. verifylist = [('node', 'node_uuid'),
  987. ('soft', False),
  988. ('power_timeout', None)]
  989. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  990. self.cmd.take_action(parsed_args)
  991. self.baremetal_mock.node.set_power_state.assert_called_once_with(
  992. 'node_uuid', 'off', False, timeout=None)
  993. def test_baremetal_power_off_timeout(self):
  994. arglist = ['node_uuid', '--power-timeout', '2']
  995. verifylist = [('node', 'node_uuid'),
  996. ('soft', False),
  997. ('power_timeout', 2)]
  998. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  999. self.cmd.take_action(parsed_args)
  1000. self.baremetal_mock.node.set_power_state.assert_called_once_with(
  1001. 'node_uuid', 'off', False, timeout=2)
  1002. def test_baremetal_soft_power_off(self):
  1003. arglist = ['node_uuid', '--soft']
  1004. verifylist = [('node', 'node_uuid'),
  1005. ('soft', True),
  1006. ('power_timeout', None)]
  1007. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1008. self.cmd.take_action(parsed_args)
  1009. self.baremetal_mock.node.set_power_state.assert_called_once_with(
  1010. 'node_uuid', 'off', True, timeout=None)
  1011. def test_baremetal_soft_power_off_timeout(self):
  1012. arglist = ['node_uuid', '--soft', '--power-timeout', '2']
  1013. verifylist = [('node', 'node_uuid'),
  1014. ('soft', True),
  1015. ('power_timeout', 2)]
  1016. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1017. self.cmd.take_action(parsed_args)
  1018. self.baremetal_mock.node.set_power_state.assert_called_once_with(
  1019. 'node_uuid', 'off', True, timeout=2)
  1020. def test_baremetal_power_off_no_args(self):
  1021. arglist = []
  1022. verifylist = []
  1023. self.assertRaises(oscutils.ParserException,
  1024. self.check_parser,
  1025. self.cmd, arglist, verifylist)
  1026. class TestPowerOn(TestBaremetal):
  1027. def setUp(self):
  1028. super(TestPowerOn, self).setUp()
  1029. # Get the command object to test
  1030. self.cmd = baremetal_node.PowerOnBaremetalNode(self.app, None)
  1031. def test_baremetal_power_on(self):
  1032. arglist = ['node_uuid']
  1033. verifylist = [('node', 'node_uuid'),
  1034. ('power_timeout', None)]
  1035. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1036. self.cmd.take_action(parsed_args)
  1037. self.baremetal_mock.node.set_power_state.assert_called_once_with(
  1038. 'node_uuid', 'on', False, timeout=None)
  1039. def test_baremetal_power_on_timeout(self):
  1040. arglist = ['node_uuid', '--power-timeout', '2']
  1041. verifylist = [('node', 'node_uuid'),
  1042. ('power_timeout', 2)]
  1043. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1044. self.cmd.take_action(parsed_args)
  1045. self.baremetal_mock.node.set_power_state.assert_called_once_with(
  1046. 'node_uuid', 'on', False, timeout=2)
  1047. def test_baremetal_power_on_no_args(self):
  1048. arglist = []
  1049. verifylist = []
  1050. self.assertRaises(oscutils.ParserException,
  1051. self.check_parser,
  1052. self.cmd, arglist, verifylist)
  1053. class TestDeployBaremetalProvisionState(TestBaremetal):
  1054. def setUp(self):
  1055. super(TestDeployBaremetalProvisionState, self).setUp()
  1056. # Get the command object to test
  1057. self.cmd = baremetal_node.DeployBaremetalNode(self.app, None)
  1058. def test_deploy_baremetal_provision_state_active_and_configdrive(self):
  1059. arglist = ['node_uuid',
  1060. '--config-drive', 'path/to/drive']
  1061. verifylist = [
  1062. ('node', 'node_uuid'),
  1063. ('provision_state', 'active'),
  1064. ('config_drive', 'path/to/drive'),
  1065. ]
  1066. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1067. self.cmd.take_action(parsed_args)
  1068. self.baremetal_mock.node.set_provision_state.assert_called_once_with(
  1069. 'node_uuid', 'active',
  1070. cleansteps=None, configdrive='path/to/drive', rescue_password=None)
  1071. def test_deploy_baremetal_provision_state_active_and_configdrive_dict(
  1072. self):
  1073. arglist = ['node_uuid',
  1074. '--config-drive', '{"meta_data": {}}']
  1075. verifylist = [
  1076. ('node', 'node_uuid'),
  1077. ('provision_state', 'active'),
  1078. ('config_drive', '{"meta_data": {}}'),
  1079. ]
  1080. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1081. self.cmd.take_action(parsed_args)
  1082. self.baremetal_mock.node.set_provision_state.assert_called_once_with(
  1083. 'node_uuid', 'active',
  1084. cleansteps=None, configdrive={'meta_data': {}},
  1085. rescue_password=None)
  1086. def test_deploy_no_wait(self):
  1087. arglist = ['node_uuid']
  1088. verifylist = [
  1089. ('node', 'node_uuid'),
  1090. ('provision_state', 'active')
  1091. ]
  1092. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1093. self.cmd.take_action(parsed_args)
  1094. self.baremetal_mock.node.wait_for_provision_state.assert_not_called()
  1095. def test_deploy_baremetal_provision_state_active_and_wait(self):
  1096. arglist = ['node_uuid',
  1097. '--wait', '15']
  1098. verifylist = [
  1099. ('node', 'node_uuid'),
  1100. ('provision_state', 'active'),
  1101. ('wait_timeout', 15)
  1102. ]
  1103. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1104. self.cmd.take_action(parsed_args)
  1105. test_node = self.baremetal_mock.node
  1106. test_node.wait_for_provision_state.assert_called_once_with(
  1107. 'node_uuid', expected_state='active',
  1108. poll_interval=10, timeout=15)
  1109. def test_deploy_baremetal_provision_state_default_wait(self):
  1110. arglist = ['node_uuid',
  1111. '--wait']
  1112. verifylist = [
  1113. ('node', 'node_uuid'),
  1114. ('provision_state', 'active'),
  1115. ('wait_timeout', 0)
  1116. ]
  1117. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1118. self.cmd.take_action(parsed_args)
  1119. test_node = self.baremetal_mock.node
  1120. test_node.wait_for_provision_state.assert_called_once_with(
  1121. 'node_uuid', expected_state='active',
  1122. poll_interval=10, timeout=0)
  1123. def test_deploy_baremetal_provision_state_mismatch(self):
  1124. arglist = ['node_uuid',
  1125. '--provision-state', 'abort']
  1126. verifylist = [
  1127. ('node', 'node_uuid'),
  1128. ('provision_state', 'active'),
  1129. ]
  1130. self.assertRaises(oscutils.ParserException,
  1131. self.check_parser,
  1132. self.cmd, arglist, verifylist)
  1133. class TestManageBaremetalProvisionState(TestBaremetal):
  1134. def setUp(self):
  1135. super(TestManageBaremetalProvisionState, self).setUp()
  1136. # Get the command object to test
  1137. self.cmd = baremetal_node.ManageBaremetalNode(self.app, None)
  1138. def test_manage_no_wait(self):
  1139. arglist = ['node_uuid']
  1140. verifylist = [
  1141. ('node', 'node_uuid'),
  1142. ('provision_state', 'manage')
  1143. ]
  1144. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1145. self.cmd.take_action(parsed_args)
  1146. self.baremetal_mock.node.wait_for_provision_state.assert_not_called()
  1147. def test_manage_baremetal_provision_state_manageable_and_wait(self):
  1148. arglist = ['node_uuid',
  1149. '--wait', '15']
  1150. verifylist = [
  1151. ('node', 'node_uuid'),
  1152. ('provision_state', 'manage'),
  1153. ('wait_timeout', 15)
  1154. ]
  1155. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1156. self.cmd.take_action(parsed_args)
  1157. test_node = self.baremetal_mock.node
  1158. test_node.wait_for_provision_state.assert_called_once_with(
  1159. 'node_uuid', expected_state='manageable',
  1160. poll_interval=2, timeout=15)
  1161. def test_manage_baremetal_provision_state_default_wait(self):
  1162. arglist = ['node_uuid',
  1163. '--wait']
  1164. verifylist = [
  1165. ('node', 'node_uuid'),
  1166. ('provision_state', 'manage'),
  1167. ('wait_timeout', 0)
  1168. ]
  1169. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1170. self.cmd.take_action(parsed_args)
  1171. test_node = self.baremetal_mock.node
  1172. test_node.wait_for_provision_state.assert_called_once_with(
  1173. 'node_uuid', expected_state='manageable',
  1174. poll_interval=2, timeout=0)
  1175. class TestCleanBaremetalProvisionState(TestBaremetal):
  1176. def setUp(self):
  1177. super(TestCleanBaremetalProvisionState, self).setUp()
  1178. # Get the command object to test
  1179. self.cmd = baremetal_node.CleanBaremetalNode(self.app, None)
  1180. def test_clean_no_wait(self):
  1181. arglist = ['node_uuid', '--clean-steps', '-']
  1182. verifylist = [
  1183. ('node', 'node_uuid'),
  1184. ('provision_state', 'clean'),
  1185. ('clean_steps', '-')
  1186. ]
  1187. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1188. self.cmd.take_action(parsed_args)
  1189. self.baremetal_mock.node.wait_for_provision_state.assert_not_called()
  1190. def test_clean_baremetal_provision_state_manageable_and_wait(self):
  1191. arglist = ['node_uuid',
  1192. '--wait', '15',
  1193. '--clean-steps', '-']
  1194. verifylist = [
  1195. ('node', 'node_uuid'),
  1196. ('provision_state', 'clean'),
  1197. ('wait_timeout', 15),
  1198. ('clean_steps', '-')
  1199. ]
  1200. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1201. self.cmd.take_action(parsed_args)
  1202. test_node = self.baremetal_mock.node
  1203. test_node.wait_for_provision_state.assert_called_once_with(
  1204. 'node_uuid', expected_state='manageable',
  1205. poll_interval=10, timeout=15)
  1206. def test_clean_baremetal_provision_state_default_wait(self):
  1207. arglist = ['node_uuid',
  1208. '--wait',
  1209. '--clean-steps', '-']
  1210. verifylist = [
  1211. ('node', 'node_uuid'),
  1212. ('provision_state', 'clean'),
  1213. ('wait_timeout', 0),
  1214. ('clean_steps', '-')
  1215. ]
  1216. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1217. self.cmd.take_action(parsed_args)
  1218. test_node = self.baremetal_mock.node
  1219. test_node.wait_for_provision_state.assert_called_once_with(
  1220. 'node_uuid', expected_state='manageable',
  1221. poll_interval=10, timeout=0)
  1222. class TestRescueBaremetalProvisionState(TestBaremetal):
  1223. def setUp(self):
  1224. super(TestRescueBaremetalProvisionState, self).setUp()
  1225. # Get the command object to test
  1226. self.cmd = baremetal_node.RescueBaremetalNode(self.app, None)
  1227. def test_rescue_baremetal_no_wait(self):
  1228. arglist = ['node_uuid',
  1229. '--rescue-password', 'supersecret']
  1230. verifylist = [
  1231. ('node', 'node_uuid'),
  1232. ('provision_state', 'rescue'),
  1233. ('rescue_password', 'supersecret'),
  1234. ]
  1235. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1236. self.cmd.take_action(parsed_args)
  1237. self.baremetal_mock.node.set_provision_state.assert_called_once_with(
  1238. 'node_uuid', 'rescue', cleansteps=None, configdrive=None,
  1239. rescue_password='supersecret')
  1240. def test_rescue_baremetal_provision_state_rescue_and_wait(self):
  1241. arglist = ['node_uuid',
  1242. '--wait', '15',
  1243. '--rescue-password', 'supersecret']
  1244. verifylist = [
  1245. ('node', 'node_uuid'),
  1246. ('provision_state', 'rescue'),
  1247. ('rescue_password', 'supersecret'),
  1248. ('wait_timeout', 15)
  1249. ]
  1250. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1251. self.cmd.take_action(parsed_args)
  1252. test_node = self.baremetal_mock.node
  1253. test_node.wait_for_provision_state.assert_called_once_with(
  1254. 'node_uuid', expected_state='rescue',
  1255. poll_interval=10, timeout=15)
  1256. def test_rescue_baremetal_provision_state_default_wait(self):
  1257. arglist = ['node_uuid',
  1258. '--wait',
  1259. '--rescue-password', 'supersecret']
  1260. verifylist = [
  1261. ('node', 'node_uuid'),
  1262. ('provision_state', 'rescue'),
  1263. ('rescue_password', 'supersecret'),
  1264. ('wait_timeout', 0)
  1265. ]
  1266. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1267. self.cmd.take_action(parsed_args)
  1268. test_node = self.baremetal_mock.node
  1269. test_node.wait_for_provision_state.assert_called_once_with(
  1270. 'node_uuid', expected_state='rescue',
  1271. poll_interval=10, timeout=0)
  1272. def test_rescue_baremetal_no_rescue_password(self):
  1273. arglist = ['node_uuid']
  1274. verifylist = [('node', 'node_uuid'),
  1275. ('provision_state', 'rescue')]
  1276. self.assertRaises(oscutils.ParserException,
  1277. self.check_parser,
  1278. self.cmd, arglist, verifylist)
  1279. class TestInspectBaremetalProvisionState(TestBaremetal):
  1280. def setUp(self):
  1281. super(TestInspectBaremetalProvisionState, self).setUp()
  1282. # Get the command object to test
  1283. self.cmd = baremetal_node.InspectBaremetalNode(self.app, None)
  1284. def test_inspect_no_wait(self):
  1285. arglist = ['node_uuid']
  1286. verifylist = [
  1287. ('node', 'node_uuid'),
  1288. ('provision_state', 'inspect')
  1289. ]
  1290. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1291. self.cmd.take_action(parsed_args)
  1292. self.baremetal_mock.node.wait_for_provision_state.assert_not_called()
  1293. def test_inspect_baremetal_provision_state_managable_and_wait(self):
  1294. arglist = ['node_uuid',
  1295. '--wait', '15']
  1296. verifylist = [
  1297. ('node', 'node_uuid'),
  1298. ('provision_state', 'inspect'),
  1299. ('wait_timeout', 15)
  1300. ]
  1301. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1302. self.cmd.take_action(parsed_args)
  1303. test_node = self.baremetal_mock.node
  1304. test_node.wait_for_provision_state.assert_called_once_with(
  1305. 'node_uuid', expected_state='manageable',
  1306. poll_interval=2, timeout=15)
  1307. def test_inspect_baremetal_provision_state_default_wait(self):
  1308. arglist = ['node_uuid',
  1309. '--wait']
  1310. verifylist = [
  1311. ('node', 'node_uuid'),
  1312. ('provision_state', 'inspect'),
  1313. ('wait_timeout', 0)
  1314. ]
  1315. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1316. self.cmd.take_action(parsed_args)
  1317. test_node = self.baremetal_mock.node
  1318. test_node.wait_for_provision_state.assert_called_once_with(
  1319. 'node_uuid', expected_state='manageable',
  1320. poll_interval=2, timeout=0)
  1321. class TestProvideBaremetalProvisionState(TestBaremetal):
  1322. def setUp(self):
  1323. super(TestProvideBaremetalProvisionState, self).setUp()
  1324. # Get the command object to test
  1325. self.cmd = baremetal_node.ProvideBaremetalNode(self.app, None)
  1326. def test_provide_no_wait(self):
  1327. arglist = ['node_uuid']
  1328. verifylist = [
  1329. ('node', 'node_uuid'),
  1330. ('provision_state', 'provide')
  1331. ]
  1332. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1333. self.cmd.take_action(parsed_args)
  1334. self.baremetal_mock.node.wait_for_provision_state.assert_not_called()
  1335. def test_provide_baremetal_provision_state_available_and_wait(self):
  1336. arglist = ['node_uuid',
  1337. '--wait', '15']
  1338. verifylist = [
  1339. ('node', 'node_uuid'),
  1340. ('provision_state', 'provide'),
  1341. ('wait_timeout', 15)
  1342. ]
  1343. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1344. self.cmd.take_action(parsed_args)
  1345. test_node = self.baremetal_mock.node
  1346. test_node.wait_for_provision_state.assert_called_once_with(
  1347. 'node_uuid', expected_state='available',
  1348. poll_interval=10, timeout=15)
  1349. def test_provide_baremetal_provision_state_default_wait(self):
  1350. arglist = ['node_uuid',
  1351. '--wait']
  1352. verifylist = [
  1353. ('node', 'node_uuid'),
  1354. ('provision_state', 'provide'),
  1355. ('wait_timeout', 0)
  1356. ]
  1357. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1358. self.cmd.take_action(parsed_args)
  1359. test_node = self.baremetal_mock.node
  1360. test_node.wait_for_provision_state.assert_called_once_with(
  1361. 'node_uuid', expected_state='available',
  1362. poll_interval=10, timeout=0)
  1363. class TestRebuildBaremetalProvisionState(TestBaremetal):
  1364. def setUp(self):
  1365. super(TestRebuildBaremetalProvisionState, self).setUp()
  1366. # Get the command object to test
  1367. self.cmd = baremetal_node.RebuildBaremetalNode(self.app, None)
  1368. def test_rebuild_baremetal_provision_state_active_and_configdrive(self):
  1369. arglist = ['node_uuid',
  1370. '--config-drive', 'path/to/drive']
  1371. verifylist = [
  1372. ('node', 'node_uuid'),
  1373. ('provision_state', 'rebuild'),
  1374. ('config_drive', 'path/to/drive'),
  1375. ]
  1376. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1377. self.cmd.take_action(parsed_args)
  1378. self.baremetal_mock.node.set_provision_state.assert_called_once_with(
  1379. 'node_uuid', 'rebuild',
  1380. cleansteps=None, configdrive='path/to/drive',
  1381. rescue_password=None)
  1382. def test_rebuild_no_wait(self):
  1383. arglist = ['node_uuid']
  1384. verifylist = [
  1385. ('node', 'node_uuid'),
  1386. ('provision_state', 'rebuild')
  1387. ]
  1388. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1389. self.cmd.take_action(parsed_args)
  1390. self.baremetal_mock.node.set_provision_state.assert_called_once_with(
  1391. 'node_uuid', 'rebuild',
  1392. cleansteps=None, configdrive=None,
  1393. rescue_password=None)
  1394. self.baremetal_mock.node.wait_for_provision_state.assert_not_called()
  1395. def test_rebuild_baremetal_provision_state_active_and_wait(self):
  1396. arglist = ['node_uuid',
  1397. '--wait', '15']
  1398. verifylist = [
  1399. ('node', 'node_uuid'),
  1400. ('provision_state', 'rebuild'),
  1401. ('wait_timeout', 15)
  1402. ]
  1403. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1404. self.cmd.take_action(parsed_args)
  1405. test_node = self.baremetal_mock.node
  1406. test_node.wait_for_provision_state.assert_called_once_with(
  1407. 'node_uuid', expected_state='active',
  1408. poll_interval=10, timeout=15)
  1409. def test_rebuild_baremetal_provision_state_default_wait(self):
  1410. arglist = ['node_uuid',
  1411. '--wait']
  1412. verifylist = [
  1413. ('node', 'node_uuid'),
  1414. ('provision_state', 'rebuild'),
  1415. ('wait_timeout', 0)
  1416. ]
  1417. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1418. self.cmd.take_action(parsed_args)
  1419. test_node = self.baremetal_mock.node
  1420. test_node.wait_for_provision_state.assert_called_once_with(
  1421. 'node_uuid', expected_state='active',
  1422. poll_interval=10, timeout=0)
  1423. class TestUndeployBaremetalProvisionState(TestBaremetal):
  1424. def setUp(self):
  1425. super(TestUndeployBaremetalProvisionState, self).setUp()
  1426. # Get the command object to test
  1427. self.cmd = baremetal_node.UndeployBaremetalNode(self.app, None)
  1428. def test_undeploy_no_wait(self):
  1429. arglist = ['node_uuid']
  1430. verifylist = [
  1431. ('node', 'node_uuid'),
  1432. ('provision_state', 'deleted')
  1433. ]
  1434. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1435. self.cmd.take_action(parsed_args)
  1436. self.baremetal_mock.node.wait_for_provision_state.assert_not_called()
  1437. def test_undeploy_baremetal_provision_state_available_and_wait(self):
  1438. arglist = ['node_uuid',
  1439. '--wait', '15']
  1440. verifylist = [
  1441. ('node', 'node_uuid'),
  1442. ('provision_state', 'deleted'),
  1443. ('wait_timeout', 15)
  1444. ]
  1445. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1446. self.cmd.take_action(parsed_args)
  1447. test_node = self.baremetal_mock.node
  1448. test_node.wait_for_provision_state.assert_called_once_with(
  1449. 'node_uuid', expected_state='available',
  1450. poll_interval=10, timeout=15)
  1451. def test_undeploy_baremetal_provision_state_default_wait(self):
  1452. arglist = ['node_uuid',
  1453. '--wait']
  1454. verifylist = [
  1455. ('node', 'node_uuid'),
  1456. ('provision_state', 'deleted'),
  1457. ('wait_timeout', 0)
  1458. ]
  1459. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1460. self.cmd.take_action(parsed_args)
  1461. test_node = self.baremetal_mock.node
  1462. test_node.wait_for_provision_state.assert_called_once_with(
  1463. 'node_uuid', expected_state='available',
  1464. poll_interval=10, timeout=0)
  1465. class TestUnrescueBaremetalProvisionState(TestBaremetal):
  1466. def setUp(self):
  1467. super(TestUnrescueBaremetalProvisionState, self).setUp()
  1468. # Get the command object to test
  1469. self.cmd = baremetal_node.UnrescueBaremetalNode(self.app, None)
  1470. def test_unrescue_no_wait(self):
  1471. arglist = ['node_uuid']
  1472. verifylist = [
  1473. ('node', 'node_uuid'),
  1474. ('provision_state', 'unrescue'),
  1475. ]
  1476. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1477. self.cmd.take_action(parsed_args)
  1478. self.baremetal_mock.node.set_provision_state.assert_called_once_with(
  1479. 'node_uuid', 'unrescue', cleansteps=None, configdrive=None,
  1480. rescue_password=None)
  1481. def test_unrescue_baremetal_provision_state_active_and_wait(self):
  1482. arglist = ['node_uuid',
  1483. '--wait', '15']
  1484. verifylist = [
  1485. ('node', 'node_uuid'),
  1486. ('provision_state', 'unrescue'),
  1487. ('wait_timeout', 15)
  1488. ]
  1489. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1490. self.cmd.take_action(parsed_args)
  1491. test_node = self.baremetal_mock.node
  1492. test_node.wait_for_provision_state.assert_called_once_with(
  1493. 'node_uuid', expected_state='active',
  1494. poll_interval=10, timeout=15)
  1495. def test_unrescue_baremetal_provision_state_default_wait(self):
  1496. arglist = ['node_uuid',
  1497. '--wait']
  1498. verifylist = [
  1499. ('node', 'node_uuid'),
  1500. ('provision_state', 'unrescue'),
  1501. ('wait_timeout', 0)
  1502. ]
  1503. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1504. self.cmd.take_action(parsed_args)
  1505. test_node = self.baremetal_mock.node
  1506. test_node.wait_for_provision_state.assert_called_once_with(
  1507. 'node_uuid', expected_state='active',
  1508. poll_interval=10, timeout=0)
  1509. class TestBaremetalReboot(TestBaremetal):
  1510. def setUp(self):
  1511. super(TestBaremetalReboot, self).setUp()
  1512. # Get the command object to test
  1513. self.cmd = baremetal_node.RebootBaremetalNode(self.app, None)
  1514. def test_baremetal_reboot_no_options(self):
  1515. arglist = []
  1516. verifylist = []
  1517. self.assertRaises(oscutils.ParserException,
  1518. self.check_parser,
  1519. self.cmd, arglist, verifylist)
  1520. def test_baremetal_reboot_uuid_only(self):
  1521. arglist = ['node_uuid']
  1522. verifylist = [('node', 'node_uuid'),
  1523. ('soft', False),
  1524. ('power_timeout', None)]
  1525. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1526. self.cmd.take_action(parsed_args)
  1527. self.baremetal_mock.node.set_power_state.assert_called_once_with(
  1528. 'node_uuid', 'reboot', False, timeout=None)
  1529. def test_baremetal_reboot_timeout(self):
  1530. arglist = ['node_uuid', '--power-timeout', '2']
  1531. verifylist = [('node', 'node_uuid'),
  1532. ('soft', False),
  1533. ('power_timeout', 2)]
  1534. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1535. self.cmd.take_action(parsed_args)
  1536. self.baremetal_mock.node.set_power_state.assert_called_once_with(
  1537. 'node_uuid', 'reboot', False, timeout=2)
  1538. def test_baremetal_soft_reboot(self):
  1539. arglist = ['node_uuid', '--soft']
  1540. verifylist = [('node', 'node_uuid'),
  1541. ('soft', True),
  1542. ('power_timeout', None)]
  1543. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1544. self.cmd.take_action(parsed_args)
  1545. self.baremetal_mock.node.set_power_state.assert_called_once_with(
  1546. 'node_uuid', 'reboot', True, timeout=None)
  1547. def test_baremetal_soft_reboot_timeout(self):
  1548. arglist = ['node_uuid', '--soft', '--power-timeout', '2']
  1549. verifylist = [('node', 'node_uuid'),
  1550. ('soft', True),
  1551. ('power_timeout', 2)]
  1552. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1553. self.cmd.take_action(parsed_args)
  1554. self.baremetal_mock.node.set_power_state.assert_called_once_with(
  1555. 'node_uuid', 'reboot', True, timeout=2)
  1556. class TestBaremetalSet(TestBaremetal):
  1557. def setUp(self):
  1558. super(TestBaremetalSet, self).setUp()
  1559. self.baremetal_mock.node.update.return_value = (
  1560. baremetal_fakes.FakeBaremetalResource(
  1561. None,
  1562. copy.deepcopy(baremetal_fakes.BAREMETAL),
  1563. loaded=True,
  1564. ))
  1565. # Get the command object to test
  1566. self.cmd = baremetal_node.SetBaremetalNode(self.app, None)
  1567. def test_baremetal_set_no_options(self):
  1568. arglist = []
  1569. verifylist = []
  1570. self.assertRaises(oscutils.ParserException,
  1571. self.check_parser,
  1572. self.cmd, arglist, verifylist)
  1573. def test_baremetal_set_no_property(self):
  1574. arglist = ['node_uuid']
  1575. verifylist = [
  1576. ('node', 'node_uuid'),
  1577. ]
  1578. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1579. self.cmd.take_action(parsed_args)
  1580. self.assertFalse(self.baremetal_mock.node.update.called)
  1581. def test_baremetal_set_one_property(self):
  1582. arglist = ['node_uuid', '--property', 'path/to/property=value']
  1583. verifylist = [
  1584. ('node', 'node_uuid'),
  1585. ('property', ['path/to/property=value']),
  1586. ]
  1587. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1588. self.cmd.take_action(parsed_args)
  1589. self.baremetal_mock.node.update.assert_called_once_with(
  1590. 'node_uuid',
  1591. [{'path': '/properties/path/to/property',
  1592. 'value': 'value',
  1593. 'op': 'add'}],
  1594. reset_interfaces=None)
  1595. def test_baremetal_set_multiple_properties(self):
  1596. arglist = [
  1597. 'node_uuid',
  1598. '--property', 'path/to/property=value',
  1599. '--property', 'other/path=value2'
  1600. ]
  1601. verifylist = [
  1602. ('node', 'node_uuid'),
  1603. ('property',
  1604. [
  1605. 'path/to/property=value',
  1606. 'other/path=value2',
  1607. ]),
  1608. ]
  1609. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1610. self.cmd.take_action(parsed_args)
  1611. self.baremetal_mock.node.update.assert_called_once_with(
  1612. 'node_uuid',
  1613. [{'path': '/properties/path/to/property',
  1614. 'value': 'value',
  1615. 'op': 'add'},
  1616. {'path': '/properties/other/path',
  1617. 'value': 'value2',
  1618. 'op': 'add'}],
  1619. reset_interfaces=None,
  1620. )
  1621. def test_baremetal_set_instance_uuid(self):
  1622. arglist = [
  1623. 'node_uuid',
  1624. '--instance-uuid', 'xxxxx',
  1625. ]
  1626. verifylist = [
  1627. ('node', 'node_uuid'),
  1628. ('instance_uuid', 'xxxxx')
  1629. ]
  1630. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1631. self.cmd.take_action(parsed_args)
  1632. self.baremetal_mock.node.update.assert_called_once_with(
  1633. 'node_uuid',
  1634. [{'path': '/instance_uuid', 'value': 'xxxxx', 'op': 'add'}],
  1635. reset_interfaces=None,
  1636. )
  1637. def test_baremetal_set_name(self):
  1638. arglist = [
  1639. 'node_uuid',
  1640. '--name', 'xxxxx',
  1641. ]
  1642. verifylist = [
  1643. ('node', 'node_uuid'),
  1644. ('name', 'xxxxx')
  1645. ]
  1646. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1647. self.cmd.take_action(parsed_args)
  1648. self.baremetal_mock.node.update.assert_called_once_with(
  1649. 'node_uuid',
  1650. [{'path': '/name', 'value': 'xxxxx', 'op': 'add'}],
  1651. reset_interfaces=None,
  1652. )
  1653. def test_baremetal_set_chassis(self):
  1654. chassis = '4f4135ea-7e58-4e3d-bcc4-b87ca16e980b'
  1655. arglist = [
  1656. 'node_uuid',
  1657. '--chassis-uuid', chassis,
  1658. ]
  1659. verifylist = [
  1660. ('node', 'node_uuid'),
  1661. ('chassis_uuid', chassis)
  1662. ]
  1663. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1664. self.cmd.take_action(parsed_args)
  1665. self.baremetal_mock.node.update.assert_called_once_with(
  1666. 'node_uuid',
  1667. [{'path': '/chassis_uuid', 'value': chassis, 'op': 'add'}],
  1668. reset_interfaces=None,
  1669. )
  1670. def test_baremetal_set_driver(self):
  1671. arglist = [
  1672. 'node_uuid',
  1673. '--driver', 'xxxxx',
  1674. ]
  1675. verifylist = [
  1676. ('node', 'node_uuid'),
  1677. ('driver', 'xxxxx')
  1678. ]
  1679. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1680. self.cmd.take_action(parsed_args)
  1681. self.baremetal_mock.node.update.assert_called_once_with(
  1682. 'node_uuid',
  1683. [{'path': '/driver', 'value': 'xxxxx', 'op': 'add'}],
  1684. reset_interfaces=None,
  1685. )
  1686. def test_baremetal_set_driver_reset_interfaces(self):
  1687. arglist = [
  1688. 'node_uuid',
  1689. '--driver', 'xxxxx',
  1690. '--reset-interfaces',
  1691. ]
  1692. verifylist = [
  1693. ('node', 'node_uuid'),
  1694. ('driver', 'xxxxx'),
  1695. ('reset_interfaces', True),
  1696. ]
  1697. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1698. self.cmd.take_action(parsed_args)
  1699. self.baremetal_mock.node.update.assert_called_once_with(
  1700. 'node_uuid',
  1701. [{'path': '/driver', 'value': 'xxxxx', 'op': 'add'}],
  1702. reset_interfaces=True,
  1703. )
  1704. def test_reset_interfaces_without_driver(self):
  1705. arglist = [
  1706. 'node_uuid',
  1707. '--reset-interfaces',
  1708. ]
  1709. verifylist = [
  1710. ('node', 'node_uuid'),
  1711. ('reset_interfaces', True),
  1712. ]
  1713. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1714. self.assertRaises(exc.CommandError,
  1715. self.cmd.take_action, parsed_args)
  1716. self.assertFalse(self.baremetal_mock.node.update.called)
  1717. def _test_baremetal_set_hardware_interface(self, interface):
  1718. arglist = [
  1719. 'node_uuid',
  1720. '--%s-interface' % interface, 'xxxxx',
  1721. ]
  1722. verifylist = [
  1723. ('node', 'node_uuid'),
  1724. ('%s_interface' % interface, 'xxxxx')
  1725. ]
  1726. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1727. self.cmd.take_action(parsed_args)
  1728. self.baremetal_mock.node.update.assert_called_once_with(
  1729. 'node_uuid',
  1730. [{'path': '/%s_interface' % interface,
  1731. 'value': 'xxxxx', 'op': 'add'}],
  1732. reset_interfaces=None,
  1733. )
  1734. def test_baremetal_set_bios_interface(self):
  1735. self._test_baremetal_set_hardware_interface('bios')
  1736. def test_baremetal_set_boot_interface(self):
  1737. self._test_baremetal_set_hardware_interface('boot')
  1738. def test_baremetal_set_console_interface(self):
  1739. self._test_baremetal_set_hardware_interface('console')
  1740. def test_baremetal_set_deploy_interface(self):
  1741. self._test_baremetal_set_hardware_interface('deploy')
  1742. def test_baremetal_set_inspect_interface(self):
  1743. self._test_baremetal_set_hardware_interface('inspect')
  1744. def test_baremetal_set_management_interface(self):
  1745. self._test_baremetal_set_hardware_interface('management')
  1746. def test_baremetal_set_network_interface(self):
  1747. self._test_baremetal_set_hardware_interface('network')
  1748. def test_baremetal_set_power_interface(self):
  1749. self._test_baremetal_set_hardware_interface('power')
  1750. def test_baremetal_set_raid_interface(self):
  1751. self._test_baremetal_set_hardware_interface('raid')
  1752. def test_baremetal_set_rescue_interface(self):
  1753. self._test_baremetal_set_hardware_interface('rescue')
  1754. def test_baremetal_set_storage_interface(self):
  1755. self._test_baremetal_set_hardware_interface('storage')
  1756. def test_baremetal_set_vendor_interface(self):
  1757. self._test_baremetal_set_hardware_interface('vendor')
  1758. def _test_baremetal_reset_hardware_interface(self, interface):
  1759. arglist = [
  1760. 'node_uuid',
  1761. '--reset-%s-interface' % interface,
  1762. ]
  1763. verifylist = [
  1764. ('node', 'node_uuid'),
  1765. ('reset_%s_interface' % interface, True)
  1766. ]
  1767. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1768. self.cmd.take_action(parsed_args)
  1769. self.baremetal_mock.node.update.assert_called_once_with(
  1770. 'node_uuid',
  1771. [{'path': '/%s_interface' % interface, 'op': 'remove'}],
  1772. reset_interfaces=None,
  1773. )
  1774. def test_baremetal_reset_bios_interface(self):
  1775. self._test_baremetal_reset_hardware_interface('bios')
  1776. def test_baremetal_reset_boot_interface(self):
  1777. self._test_baremetal_reset_hardware_interface('boot')
  1778. def test_baremetal_reset_console_interface(self):
  1779. self._test_baremetal_reset_hardware_interface('console')
  1780. def test_baremetal_reset_deploy_interface(self):
  1781. self._test_baremetal_reset_hardware_interface('deploy')
  1782. def test_baremetal_reset_inspect_interface(self):
  1783. self._test_baremetal_reset_hardware_interface('inspect')
  1784. def test_baremetal_reset_management_interface(self):
  1785. self._test_baremetal_reset_hardware_interface('management')
  1786. def test_baremetal_reset_network_interface(self):
  1787. self._test_baremetal_reset_hardware_interface('network')
  1788. def test_baremetal_reset_power_interface(self):
  1789. self._test_baremetal_reset_hardware_interface('power')
  1790. def test_baremetal_reset_raid_interface(self):
  1791. self._test_baremetal_reset_hardware_interface('raid')
  1792. def test_baremetal_reset_rescue_interface(self):
  1793. self._test_baremetal_reset_hardware_interface('rescue')
  1794. def test_baremetal_reset_storage_interface(self):
  1795. self._test_baremetal_reset_hardware_interface('storage')
  1796. def test_baremetal_reset_vendor_interface(self):
  1797. self._test_baremetal_reset_hardware_interface('vendor')
  1798. def test_baremetal_set_resource_class(self):
  1799. arglist = [
  1800. 'node_uuid',
  1801. '--resource-class', 'foo',
  1802. ]
  1803. verifylist = [
  1804. ('node', 'node_uuid'),
  1805. ('resource_class', 'foo')
  1806. ]
  1807. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1808. self.cmd.take_action(parsed_args)
  1809. self.baremetal_mock.node.update.assert_called_once_with(
  1810. 'node_uuid',
  1811. [{'path': '/resource_class', 'value': 'foo', 'op': 'add'}],
  1812. reset_interfaces=None,
  1813. )
  1814. def test_baremetal_set_conductor_group(self):
  1815. arglist = [
  1816. 'node_uuid',
  1817. '--conductor-group', 'foo',
  1818. ]
  1819. verifylist = [
  1820. ('node', 'node_uuid'),
  1821. ('conductor_group', 'foo')
  1822. ]
  1823. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1824. self.cmd.take_action(parsed_args)
  1825. self.baremetal_mock.node.update.assert_called_once_with(
  1826. 'node_uuid',
  1827. [{'path': '/conductor_group', 'value': 'foo', 'op': 'add'}],
  1828. reset_interfaces=None,
  1829. )
  1830. def test_baremetal_set_automated_clean(self):
  1831. arglist = [
  1832. 'node_uuid',
  1833. '--automated-clean'
  1834. ]
  1835. verifylist = [
  1836. ('node', 'node_uuid'),
  1837. ('automated_clean', True)
  1838. ]
  1839. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1840. self.cmd.take_action(parsed_args)
  1841. self.baremetal_mock.node.update.assert_called_once_with(
  1842. 'node_uuid',
  1843. [{'path': '/automated_clean', 'value': 'True', 'op': 'add'}],
  1844. reset_interfaces=None,
  1845. )
  1846. def test_baremetal_set_protected(self):
  1847. arglist = [
  1848. 'node_uuid',
  1849. '--protected'
  1850. ]
  1851. verifylist = [
  1852. ('node', 'node_uuid'),
  1853. ('protected', True)
  1854. ]
  1855. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1856. self.cmd.take_action(parsed_args)
  1857. self.baremetal_mock.node.update.assert_called_once_with(
  1858. 'node_uuid',
  1859. [{'path': '/protected', 'value': 'True', 'op': 'add'}],
  1860. reset_interfaces=None,
  1861. )
  1862. def test_baremetal_set_protected_with_reason(self):
  1863. arglist = [
  1864. 'node_uuid',
  1865. '--protected',
  1866. '--protected-reason', 'reason!'
  1867. ]
  1868. verifylist = [
  1869. ('node', 'node_uuid'),
  1870. ('protected', True),
  1871. ('protected_reason', 'reason!')
  1872. ]
  1873. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1874. self.cmd.take_action(parsed_args)
  1875. self.baremetal_mock.node.update.assert_called_once_with(
  1876. 'node_uuid',
  1877. [{'path': '/protected', 'value': 'True', 'op': 'add'},
  1878. {'path': '/protected_reason', 'value': 'reason!', 'op': 'add'}],
  1879. reset_interfaces=None,
  1880. )
  1881. def test_baremetal_set_retired(self):
  1882. arglist = [
  1883. 'node_uuid',
  1884. '--retired'
  1885. ]
  1886. verifylist = [
  1887. ('node', 'node_uuid'),
  1888. ('retired', True)
  1889. ]
  1890. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1891. self.cmd.take_action(parsed_args)
  1892. self.baremetal_mock.node.update.assert_called_once_with(
  1893. 'node_uuid',
  1894. [{'path': '/retired', 'value': 'True', 'op': 'add'}],
  1895. reset_interfaces=None,
  1896. )
  1897. def test_baremetal_set_retired_with_reason(self):
  1898. arglist = [
  1899. 'node_uuid',
  1900. '--retired',
  1901. '--retired-reason', 'out of warranty!'
  1902. ]
  1903. verifylist = [
  1904. ('node', 'node_uuid'),
  1905. ('retired', True),
  1906. ('retired_reason', 'out of warranty!')
  1907. ]
  1908. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1909. self.cmd.take_action(parsed_args)
  1910. self.baremetal_mock.node.update.assert_called_once_with(
  1911. 'node_uuid',
  1912. [{'path': '/retired', 'value': 'True', 'op': 'add'},
  1913. {'path': '/retired_reason', 'value': 'out of warranty!',
  1914. 'op': 'add'}],
  1915. reset_interfaces=None,
  1916. )
  1917. def test_baremetal_set_extra(self):
  1918. arglist = [
  1919. 'node_uuid',
  1920. '--extra', 'foo=bar',
  1921. ]
  1922. verifylist = [
  1923. ('node', 'node_uuid'),
  1924. ('extra', ['foo=bar'])
  1925. ]
  1926. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1927. self.cmd.take_action(parsed_args)
  1928. self.baremetal_mock.node.update.assert_called_once_with(
  1929. 'node_uuid',
  1930. [{'path': '/extra/foo', 'value': 'bar', 'op': 'add'}],
  1931. reset_interfaces=None,
  1932. )
  1933. def test_baremetal_set_driver_info(self):
  1934. arglist = [
  1935. 'node_uuid',
  1936. '--driver-info', 'foo=bar',
  1937. ]
  1938. verifylist = [
  1939. ('node', 'node_uuid'),
  1940. ('driver_info', ['foo=bar'])
  1941. ]
  1942. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1943. self.cmd.take_action(parsed_args)
  1944. self.baremetal_mock.node.update.assert_called_once_with(
  1945. 'node_uuid',
  1946. [{'path': '/driver_info/foo', 'value': 'bar', 'op': 'add'}],
  1947. reset_interfaces=None,
  1948. )
  1949. def test_baremetal_set_instance_info(self):
  1950. arglist = [
  1951. 'node_uuid',
  1952. '--instance-info', 'foo=bar',
  1953. ]
  1954. verifylist = [
  1955. ('node', 'node_uuid'),
  1956. ('instance_info', ['foo=bar'])
  1957. ]
  1958. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1959. self.cmd.take_action(parsed_args)
  1960. self.baremetal_mock.node.update.assert_called_once_with(
  1961. 'node_uuid',
  1962. [{'path': '/instance_info/foo', 'value': 'bar', 'op': 'add'}],
  1963. reset_interfaces=None,
  1964. )
  1965. @mock.patch.object(commonutils, 'get_from_stdin', autospec=True)
  1966. @mock.patch.object(commonutils, 'handle_json_or_file_arg', autospec=True)
  1967. def test_baremetal_set_target_raid_config(self, mock_handle, mock_stdin):
  1968. self.cmd.log = mock.Mock(autospec=True)
  1969. target_raid_config_string = '{"raid": "config"}'
  1970. expected_target_raid_config = {'raid': 'config'}
  1971. mock_handle.return_value = expected_target_raid_config.copy()
  1972. arglist = ['node_uuid',
  1973. '--target-raid-config', target_raid_config_string]
  1974. verifylist = [('node', 'node_uuid'),
  1975. ('target_raid_config', target_raid_config_string)]
  1976. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1977. self.cmd.take_action(parsed_args)
  1978. self.cmd.log.warning.assert_not_called()
  1979. self.assertFalse(mock_stdin.called)
  1980. mock_handle.assert_called_once_with(target_raid_config_string)
  1981. self.baremetal_mock.node.set_target_raid_config.\
  1982. assert_called_once_with('node_uuid', expected_target_raid_config)
  1983. self.assertFalse(self.baremetal_mock.node.update.called)
  1984. @mock.patch.object(commonutils, 'get_from_stdin', autospec=True)
  1985. @mock.patch.object(commonutils, 'handle_json_or_file_arg', autospec=True)
  1986. def test_baremetal_set_target_raid_config_and_name(
  1987. self, mock_handle, mock_stdin):
  1988. self.cmd.log = mock.Mock(autospec=True)
  1989. target_raid_config_string = '{"raid": "config"}'
  1990. expected_target_raid_config = {'raid': 'config'}
  1991. mock_handle.return_value = expected_target_raid_config.copy()
  1992. arglist = ['node_uuid',
  1993. '--name', 'xxxxx',
  1994. '--target-raid-config', target_raid_config_string]
  1995. verifylist = [('node', 'node_uuid'),
  1996. ('name', 'xxxxx'),
  1997. ('target_raid_config', target_raid_config_string)]
  1998. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  1999. self.cmd.take_action(parsed_args)
  2000. self.cmd.log.warning.assert_not_called()
  2001. self.assertFalse(mock_stdin.called)
  2002. mock_handle.assert_called_once_with(target_raid_config_string)
  2003. self.baremetal_mock.node.set_target_raid_config.\
  2004. assert_called_once_with('node_uuid', expected_target_raid_config)
  2005. self.baremetal_mock.node.update.assert_called_once_with(
  2006. 'node_uuid',
  2007. [{'path': '/name', 'value': 'xxxxx', 'op': 'add'}],
  2008. reset_interfaces=None)
  2009. @mock.patch.object(commonutils, 'get_from_stdin', autospec=True)
  2010. @mock.patch.object(commonutils, 'handle_json_or_file_arg', autospec=True)
  2011. def test_baremetal_set_target_raid_config_stdin(self, mock_handle,
  2012. mock_stdin):
  2013. self.cmd.log = mock.Mock(autospec=True)
  2014. target_value = '-'
  2015. target_raid_config_string = '{"raid": "config"}'
  2016. expected_target_raid_config = {'raid': 'config'}
  2017. mock_stdin.return_value = target_raid_config_string
  2018. mock_handle.return_value = expected_target_raid_config.copy()
  2019. arglist = ['node_uuid',
  2020. '--target-raid-config', target_value]
  2021. verifylist = [('node', 'node_uuid'),
  2022. ('target_raid_config', target_value)]
  2023. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2024. self.cmd.take_action(parsed_args)
  2025. self.cmd.log.warning.assert_not_called()
  2026. mock_stdin.assert_called_once_with('target_raid_config')
  2027. mock_handle.assert_called_once_with(target_raid_config_string)
  2028. self.baremetal_mock.node.set_target_raid_config.\
  2029. assert_called_once_with('node_uuid', expected_target_raid_config)
  2030. self.assertFalse(self.baremetal_mock.node.update.called)
  2031. @mock.patch.object(commonutils, 'get_from_stdin', autospec=True)
  2032. @mock.patch.object(commonutils, 'handle_json_or_file_arg', autospec=True)
  2033. def test_baremetal_set_target_raid_config_stdin_exception(
  2034. self, mock_handle, mock_stdin):
  2035. self.cmd.log = mock.Mock(autospec=True)
  2036. target_value = '-'
  2037. mock_stdin.side_effect = exc.InvalidAttribute('bad')
  2038. arglist = ['node_uuid',
  2039. '--target-raid-config', target_value]
  2040. verifylist = [('node', 'node_uuid'),
  2041. ('target_raid_config', target_value)]
  2042. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2043. self.assertRaises(exc.InvalidAttribute,
  2044. self.cmd.take_action, parsed_args)
  2045. self.cmd.log.warning.assert_not_called()
  2046. mock_stdin.assert_called_once_with('target_raid_config')
  2047. self.assertFalse(mock_handle.called)
  2048. self.assertFalse(
  2049. self.baremetal_mock.node.set_target_raid_config.called)
  2050. self.assertFalse(self.baremetal_mock.node.update.called)
  2051. def test_baremetal_set_owner(self):
  2052. arglist = [
  2053. 'node_uuid',
  2054. '--owner', 'owner 1',
  2055. ]
  2056. verifylist = [
  2057. ('node', 'node_uuid'),
  2058. ('owner', 'owner 1')
  2059. ]
  2060. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2061. self.cmd.take_action(parsed_args)
  2062. self.baremetal_mock.node.update.assert_called_once_with(
  2063. 'node_uuid',
  2064. [{'path': '/owner',
  2065. 'value': 'owner 1',
  2066. 'op': 'add'}],
  2067. reset_interfaces=None,
  2068. )
  2069. def test_baremetal_set_description(self):
  2070. arglist = [
  2071. 'node_uuid',
  2072. '--description', 'there is no spoon',
  2073. ]
  2074. verifylist = [
  2075. ('node', 'node_uuid'),
  2076. ('description', 'there is no spoon')
  2077. ]
  2078. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2079. self.cmd.take_action(parsed_args)
  2080. self.baremetal_mock.node.update.assert_called_once_with(
  2081. 'node_uuid',
  2082. [{'path': '/description',
  2083. 'value': 'there is no spoon',
  2084. 'op': 'add'}],
  2085. reset_interfaces=None,
  2086. )
  2087. class TestBaremetalShow(TestBaremetal):
  2088. def setUp(self):
  2089. super(TestBaremetalShow, self).setUp()
  2090. self.baremetal_mock.node.get.return_value = (
  2091. baremetal_fakes.FakeBaremetalResource(
  2092. None,
  2093. copy.deepcopy(baremetal_fakes.BAREMETAL),
  2094. loaded=True,
  2095. ))
  2096. self.baremetal_mock.node.get_by_instance_uuid.return_value = (
  2097. baremetal_fakes.FakeBaremetalResource(
  2098. None,
  2099. copy.deepcopy(baremetal_fakes.BAREMETAL),
  2100. loaded=True,
  2101. ))
  2102. # Get the command object to test
  2103. self.cmd = baremetal_node.ShowBaremetalNode(self.app, None)
  2104. def test_baremetal_show(self):
  2105. arglist = ['xxx-xxxxxx-xxxx']
  2106. verifylist = []
  2107. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2108. # DisplayCommandBase.take_action() returns two tuples
  2109. columns, data = self.cmd.take_action(parsed_args)
  2110. # Set expected values
  2111. args = ['xxx-xxxxxx-xxxx']
  2112. self.baremetal_mock.node.get.assert_called_with(
  2113. *args, fields=None
  2114. )
  2115. collist = ('chassis_uuid',
  2116. 'instance_uuid',
  2117. 'maintenance',
  2118. 'name',
  2119. 'power_state',
  2120. 'provision_state',
  2121. 'uuid'
  2122. )
  2123. self.assertEqual(collist, columns)
  2124. self.assertNotIn('ports', columns)
  2125. self.assertNotIn('states', columns)
  2126. datalist = (
  2127. baremetal_fakes.baremetal_chassis_uuid_empty,
  2128. baremetal_fakes.baremetal_instance_uuid,
  2129. baremetal_fakes.baremetal_maintenance,
  2130. baremetal_fakes.baremetal_name,
  2131. baremetal_fakes.baremetal_power_state,
  2132. baremetal_fakes.baremetal_provision_state,
  2133. baremetal_fakes.baremetal_uuid
  2134. )
  2135. self.assertEqual(datalist, tuple(data))
  2136. def test_baremetal_show_no_node(self):
  2137. arglist = []
  2138. verifylist = []
  2139. self.assertRaises(oscutils.ParserException,
  2140. self.check_parser,
  2141. self.cmd, arglist, verifylist)
  2142. def test_baremetal_show_with_instance_uuid(self):
  2143. arglist = [
  2144. 'xxx-xxxxxx-xxxx',
  2145. '--instance',
  2146. ]
  2147. verifylist = [
  2148. ('instance_uuid', True)
  2149. ]
  2150. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2151. # DisplayCommandBase.take_action() returns two tuples
  2152. self.cmd.take_action(parsed_args)
  2153. # Set expected values
  2154. args = ['xxx-xxxxxx-xxxx']
  2155. self.baremetal_mock.node.get_by_instance_uuid.assert_called_with(
  2156. *args, fields=None
  2157. )
  2158. def test_baremetal_show_fields(self):
  2159. arglist = [
  2160. 'xxxxx',
  2161. '--fields', 'uuid', 'name',
  2162. ]
  2163. verifylist = [
  2164. ('node', 'xxxxx'),
  2165. ('fields', [['uuid', 'name']]),
  2166. ]
  2167. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2168. # DisplayCommandBase.take_action() returns two tuples
  2169. columns, data = self.cmd.take_action(parsed_args)
  2170. self.assertNotIn('chassis_uuid', columns)
  2171. # Set expected values
  2172. args = ['xxxxx']
  2173. fields = ['uuid', 'name']
  2174. self.baremetal_mock.node.get.assert_called_with(
  2175. *args, fields=fields
  2176. )
  2177. def test_baremetal_show_fields_multiple(self):
  2178. arglist = [
  2179. 'xxxxx',
  2180. '--fields', 'uuid', 'name',
  2181. '--fields', 'extra',
  2182. ]
  2183. verifylist = [
  2184. ('node', 'xxxxx'),
  2185. ('fields', [['uuid', 'name'], ['extra']])
  2186. ]
  2187. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2188. columns, data = self.cmd.take_action(parsed_args)
  2189. self.assertNotIn('chassis_uuid', columns)
  2190. # Set expected values
  2191. args = ['xxxxx']
  2192. fields = ['uuid', 'name', 'extra']
  2193. self.baremetal_mock.node.get.assert_called_with(
  2194. *args, fields=fields
  2195. )
  2196. def test_baremetal_show_invalid_fields(self):
  2197. arglist = [
  2198. 'xxxxx',
  2199. '--fields', 'uuid', 'invalid'
  2200. ]
  2201. verifylist = [
  2202. ('node', 'xxxxx'),
  2203. ('fields', [['uuid', 'invalid']])
  2204. ]
  2205. self.assertRaises(oscutils.ParserException,
  2206. self.check_parser,
  2207. self.cmd, arglist, verifylist)
  2208. class TestBaremetalUnset(TestBaremetal):
  2209. def setUp(self):
  2210. super(TestBaremetalUnset, self).setUp()
  2211. self.baremetal_mock.node.update.return_value = (
  2212. baremetal_fakes.FakeBaremetalResource(
  2213. None,
  2214. copy.deepcopy(baremetal_fakes.BAREMETAL),
  2215. loaded=True,
  2216. ))
  2217. # Get the command object to test
  2218. self.cmd = baremetal_node.UnsetBaremetalNode(self.app, None)
  2219. def test_baremetal_unset_no_options(self):
  2220. arglist = []
  2221. verifylist = []
  2222. self.assertRaises(oscutils.ParserException,
  2223. self.check_parser,
  2224. self.cmd, arglist, verifylist)
  2225. def test_baremetal_unset_no_property(self):
  2226. arglist = ['node_uuid']
  2227. verifylist = [('node', 'node_uuid')]
  2228. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2229. self.cmd.take_action(parsed_args)
  2230. self.assertFalse(self.baremetal_mock.node.update.called)
  2231. def test_baremetal_unset_one_property(self):
  2232. arglist = ['node_uuid', '--property', 'path/to/property']
  2233. verifylist = [('node', 'node_uuid'),
  2234. ('property', ['path/to/property'])]
  2235. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2236. self.cmd.take_action(parsed_args)
  2237. self.baremetal_mock.node.update.assert_called_once_with(
  2238. 'node_uuid',
  2239. [{'path': '/properties/path/to/property', 'op': 'remove'}])
  2240. def test_baremetal_unset_multiple_properties(self):
  2241. arglist = ['node_uuid',
  2242. '--property', 'path/to/property',
  2243. '--property', 'other/path']
  2244. verifylist = [('node', 'node_uuid'),
  2245. ('property',
  2246. ['path/to/property',
  2247. 'other/path'])]
  2248. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2249. self.cmd.take_action(parsed_args)
  2250. self.baremetal_mock.node.update.assert_called_once_with(
  2251. 'node_uuid',
  2252. [{'path': '/properties/path/to/property', 'op': 'remove'},
  2253. {'path': '/properties/other/path', 'op': 'remove'}]
  2254. )
  2255. def test_baremetal_unset_instance_uuid(self):
  2256. arglist = [
  2257. 'node_uuid',
  2258. '--instance-uuid',
  2259. ]
  2260. verifylist = [
  2261. ('node', 'node_uuid'),
  2262. ('instance_uuid', True)
  2263. ]
  2264. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2265. self.cmd.take_action(parsed_args)
  2266. self.baremetal_mock.node.update.assert_called_once_with(
  2267. 'node_uuid',
  2268. [{'path': '/instance_uuid', 'op': 'remove'}]
  2269. )
  2270. def test_baremetal_unset_name(self):
  2271. arglist = [
  2272. 'node_uuid',
  2273. '--name',
  2274. ]
  2275. verifylist = [
  2276. ('node', 'node_uuid'),
  2277. ('name', True)
  2278. ]
  2279. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2280. self.cmd.take_action(parsed_args)
  2281. self.baremetal_mock.node.update.assert_called_once_with(
  2282. 'node_uuid',
  2283. [{'path': '/name', 'op': 'remove'}]
  2284. )
  2285. def test_baremetal_unset_resource_class(self):
  2286. arglist = [
  2287. 'node_uuid',
  2288. '--resource-class',
  2289. ]
  2290. verifylist = [
  2291. ('node', 'node_uuid'),
  2292. ('resource_class', True)
  2293. ]
  2294. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2295. self.cmd.take_action(parsed_args)
  2296. self.baremetal_mock.node.update.assert_called_once_with(
  2297. 'node_uuid',
  2298. [{'path': '/resource_class', 'op': 'remove'}]
  2299. )
  2300. def test_baremetal_unset_conductor_group(self):
  2301. arglist = [
  2302. 'node_uuid',
  2303. '--conductor-group',
  2304. ]
  2305. verifylist = [
  2306. ('node', 'node_uuid'),
  2307. ('conductor_group', True)
  2308. ]
  2309. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2310. self.cmd.take_action(parsed_args)
  2311. self.baremetal_mock.node.update.assert_called_once_with(
  2312. 'node_uuid',
  2313. [{'path': '/conductor_group', 'op': 'remove'}]
  2314. )
  2315. def test_baremetal_unset_automated_clean(self):
  2316. arglist = [
  2317. 'node_uuid',
  2318. '--automated-clean',
  2319. ]
  2320. verifylist = [
  2321. ('node', 'node_uuid'),
  2322. ('automated_clean', True)
  2323. ]
  2324. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2325. self.cmd.take_action(parsed_args)
  2326. self.baremetal_mock.node.update.assert_called_once_with(
  2327. 'node_uuid',
  2328. [{'path': '/automated_clean', 'op': 'remove'}]
  2329. )
  2330. def test_baremetal_unset_protected(self):
  2331. arglist = [
  2332. 'node_uuid',
  2333. '--protected',
  2334. ]
  2335. verifylist = [
  2336. ('node', 'node_uuid'),
  2337. ('protected', True)
  2338. ]
  2339. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2340. self.cmd.take_action(parsed_args)
  2341. self.baremetal_mock.node.update.assert_called_once_with(
  2342. 'node_uuid',
  2343. [{'path': '/protected', 'op': 'remove'}]
  2344. )
  2345. def test_baremetal_unset_protected_reason(self):
  2346. arglist = [
  2347. 'node_uuid',
  2348. '--protected-reason',
  2349. ]
  2350. verifylist = [
  2351. ('node', 'node_uuid'),
  2352. ('protected_reason', True)
  2353. ]
  2354. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2355. self.cmd.take_action(parsed_args)
  2356. self.baremetal_mock.node.update.assert_called_once_with(
  2357. 'node_uuid',
  2358. [{'path': '/protected_reason', 'op': 'remove'}]
  2359. )
  2360. def test_baremetal_unset_retired(self):
  2361. arglist = [
  2362. 'node_uuid',
  2363. '--retired',
  2364. ]
  2365. verifylist = [
  2366. ('node', 'node_uuid'),
  2367. ('retired', True)
  2368. ]
  2369. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2370. self.cmd.take_action(parsed_args)
  2371. self.baremetal_mock.node.update.assert_called_once_with(
  2372. 'node_uuid',
  2373. [{'path': '/retired', 'op': 'remove'}]
  2374. )
  2375. def test_baremetal_unset_retired_reason(self):
  2376. arglist = [
  2377. 'node_uuid',
  2378. '--retired-reason',
  2379. ]
  2380. verifylist = [
  2381. ('node', 'node_uuid'),
  2382. ('retired_reason', True)
  2383. ]
  2384. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2385. self.cmd.take_action(parsed_args)
  2386. self.baremetal_mock.node.update.assert_called_once_with(
  2387. 'node_uuid',
  2388. [{'path': '/retired_reason', 'op': 'remove'}]
  2389. )
  2390. def test_baremetal_unset_extra(self):
  2391. arglist = [
  2392. 'node_uuid',
  2393. '--extra', 'foo',
  2394. ]
  2395. verifylist = [
  2396. ('node', 'node_uuid'),
  2397. ('extra', ['foo'])
  2398. ]
  2399. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2400. self.cmd.take_action(parsed_args)
  2401. self.baremetal_mock.node.update.assert_called_once_with(
  2402. 'node_uuid',
  2403. [{'path': '/extra/foo', 'op': 'remove'}]
  2404. )
  2405. def test_baremetal_unset_driver_info(self):
  2406. arglist = [
  2407. 'node_uuid',
  2408. '--driver-info', 'foo',
  2409. ]
  2410. verifylist = [
  2411. ('node', 'node_uuid'),
  2412. ('driver_info', ['foo'])
  2413. ]
  2414. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2415. self.cmd.take_action(parsed_args)
  2416. self.baremetal_mock.node.update.assert_called_once_with(
  2417. 'node_uuid',
  2418. [{'path': '/driver_info/foo', 'op': 'remove'}]
  2419. )
  2420. def test_baremetal_unset_instance_info(self):
  2421. arglist = [
  2422. 'node_uuid',
  2423. '--instance-info', 'foo',
  2424. ]
  2425. verifylist = [
  2426. ('node', 'node_uuid'),
  2427. ('instance_info', ['foo'])
  2428. ]
  2429. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2430. self.cmd.take_action(parsed_args)
  2431. self.baremetal_mock.node.update.assert_called_once_with(
  2432. 'node_uuid',
  2433. [{'path': '/instance_info/foo', 'op': 'remove'}]
  2434. )
  2435. def test_baremetal_unset_target_raid_config(self):
  2436. self.cmd.log = mock.Mock(autospec=True)
  2437. arglist = [
  2438. 'node_uuid',
  2439. '--target-raid-config',
  2440. ]
  2441. verifylist = [
  2442. ('node', 'node_uuid'),
  2443. ('target_raid_config', True)
  2444. ]
  2445. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2446. self.cmd.take_action(parsed_args)
  2447. self.cmd.log.warning.assert_not_called()
  2448. self.assertFalse(self.baremetal_mock.node.update.called)
  2449. self.baremetal_mock.node.set_target_raid_config.\
  2450. assert_called_once_with('node_uuid', {})
  2451. def test_baremetal_unset_target_raid_config_and_name(self):
  2452. self.cmd.log = mock.Mock(autospec=True)
  2453. arglist = [
  2454. 'node_uuid',
  2455. '--name',
  2456. '--target-raid-config',
  2457. ]
  2458. verifylist = [
  2459. ('node', 'node_uuid'),
  2460. ('name', True),
  2461. ('target_raid_config', True)
  2462. ]
  2463. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2464. self.cmd.take_action(parsed_args)
  2465. self.cmd.log.warning.assert_not_called()
  2466. self.baremetal_mock.node.set_target_raid_config.\
  2467. assert_called_once_with('node_uuid', {})
  2468. self.baremetal_mock.node.update.assert_called_once_with(
  2469. 'node_uuid',
  2470. [{'path': '/name', 'op': 'remove'}]
  2471. )
  2472. def test_baremetal_unset_chassis_uuid(self):
  2473. arglist = [
  2474. 'node_uuid',
  2475. '--chassis-uuid',
  2476. ]
  2477. verifylist = [
  2478. ('node', 'node_uuid'),
  2479. ('chassis_uuid', True)
  2480. ]
  2481. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2482. self.cmd.take_action(parsed_args)
  2483. self.baremetal_mock.node.update.assert_called_once_with(
  2484. 'node_uuid',
  2485. [{'path': '/chassis_uuid', 'op': 'remove'}]
  2486. )
  2487. def _test_baremetal_unset_hw_interface(self, interface):
  2488. arglist = [
  2489. 'node_uuid',
  2490. '--%s-interface' % interface,
  2491. ]
  2492. verifylist = [
  2493. ('node', 'node_uuid'),
  2494. ('%s_interface' % interface, True)
  2495. ]
  2496. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2497. self.cmd.take_action(parsed_args)
  2498. self.baremetal_mock.node.update.assert_called_once_with(
  2499. 'node_uuid',
  2500. [{'path': '/%s_interface' % interface, 'op': 'remove'}]
  2501. )
  2502. def test_baremetal_unset_bios_interface(self):
  2503. self._test_baremetal_unset_hw_interface('bios')
  2504. def test_baremetal_unset_boot_interface(self):
  2505. self._test_baremetal_unset_hw_interface('boot')
  2506. def test_baremetal_unset_console_interface(self):
  2507. self._test_baremetal_unset_hw_interface('console')
  2508. def test_baremetal_unset_deploy_interface(self):
  2509. self._test_baremetal_unset_hw_interface('deploy')
  2510. def test_baremetal_unset_inspect_interface(self):
  2511. self._test_baremetal_unset_hw_interface('inspect')
  2512. def test_baremetal_unset_management_interface(self):
  2513. self._test_baremetal_unset_hw_interface('management')
  2514. def test_baremetal_unset_network_interface(self):
  2515. self._test_baremetal_unset_hw_interface('network')
  2516. def test_baremetal_unset_power_interface(self):
  2517. self._test_baremetal_unset_hw_interface('power')
  2518. def test_baremetal_unset_raid_interface(self):
  2519. self._test_baremetal_unset_hw_interface('raid')
  2520. def test_baremetal_unset_rescue_interface(self):
  2521. self._test_baremetal_unset_hw_interface('rescue')
  2522. def test_baremetal_unset_storage_interface(self):
  2523. self._test_baremetal_unset_hw_interface('storage')
  2524. def test_baremetal_unset_vendor_interface(self):
  2525. self._test_baremetal_unset_hw_interface('vendor')
  2526. def test_baremetal_unset_owner(self):
  2527. arglist = [
  2528. 'node_uuid',
  2529. '--owner',
  2530. ]
  2531. verifylist = [
  2532. ('node', 'node_uuid'),
  2533. ('owner', True)
  2534. ]
  2535. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2536. self.cmd.take_action(parsed_args)
  2537. self.baremetal_mock.node.update.assert_called_once_with(
  2538. 'node_uuid',
  2539. [{'path': '/owner', 'op': 'remove'}]
  2540. )
  2541. def test_baremetal_unset_description(self):
  2542. arglist = [
  2543. 'node_uuid',
  2544. '--description',
  2545. ]
  2546. verifylist = [
  2547. ('node', 'node_uuid'),
  2548. ('description', True)
  2549. ]
  2550. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2551. self.cmd.take_action(parsed_args)
  2552. self.baremetal_mock.node.update.assert_called_once_with(
  2553. 'node_uuid',
  2554. [{'path': '/description', 'op': 'remove'}]
  2555. )
  2556. class TestValidate(TestBaremetal):
  2557. def setUp(self):
  2558. super(TestValidate, self).setUp()
  2559. # Get the command object to test
  2560. self.cmd = baremetal_node.ValidateBaremetalNode(self.app, None)
  2561. self.baremetal_mock.node.validate.return_value = (
  2562. baremetal_fakes.FakeBaremetalResource(
  2563. None,
  2564. {'management': {'result': True},
  2565. 'console': {'reason': "Missing 'ipmi_terminal_port'",
  2566. 'result': False},
  2567. 'network': {'result': True},
  2568. 'power': {'result': True},
  2569. 'deploy': {'result': True},
  2570. 'inspect': {'reason': "not supported", 'result': None},
  2571. 'boot': {'result': True},
  2572. 'raid': {'result': True}},
  2573. loaded=True,
  2574. ))
  2575. def test_baremetal_validate_no_arg(self):
  2576. arglist = []
  2577. verifylist = []
  2578. self.assertRaises(oscutils.ParserException,
  2579. self.check_parser,
  2580. self.cmd, arglist, verifylist)
  2581. def test_baremetal_validate(self):
  2582. arglist = ['node_uuid']
  2583. verifylist = [('node', 'node_uuid')]
  2584. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2585. self.cmd.take_action(parsed_args)
  2586. self.baremetal_mock.node.validate.assert_called_once_with('node_uuid')
  2587. class TestVifList(TestBaremetal):
  2588. def setUp(self):
  2589. super(TestVifList, self).setUp()
  2590. self.baremetal_mock.node.vif_list.return_value = [
  2591. baremetal_fakes.FakeBaremetalResource(
  2592. None,
  2593. copy.deepcopy(baremetal_fakes.VIFS),
  2594. loaded=True,
  2595. ),
  2596. ]
  2597. # Get the command object to test
  2598. self.cmd = baremetal_node.VifListBaremetalNode(self.app, None)
  2599. def test_baremetal_vif_list(self):
  2600. arglist = ['node_uuid']
  2601. verifylist = [('node', 'node_uuid')]
  2602. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2603. self.cmd.take_action(parsed_args)
  2604. self.baremetal_mock.node.vif_list.assert_called_once_with('node_uuid')
  2605. class TestVifAttach(TestBaremetal):
  2606. def setUp(self):
  2607. super(TestVifAttach, self).setUp()
  2608. # Get the command object to test
  2609. self.cmd = baremetal_node.VifAttachBaremetalNode(self.app, None)
  2610. def test_baremetal_vif_attach(self):
  2611. arglist = ['node_uuid', 'aaa-aaa']
  2612. verifylist = [('node', 'node_uuid'),
  2613. ('vif_id', 'aaa-aaa')]
  2614. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2615. self.cmd.take_action(parsed_args)
  2616. self.baremetal_mock.node.vif_attach.assert_called_once_with(
  2617. 'node_uuid', 'aaa-aaa')
  2618. def test_baremetal_vif_attach_custom_fields(self):
  2619. arglist = ['node_uuid', 'aaa-aaa', '--vif-info', 'foo=bar']
  2620. verifylist = [('node', 'node_uuid'),
  2621. ('vif_id', 'aaa-aaa'),
  2622. ('vif_info', ['foo=bar'])]
  2623. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2624. self.cmd.take_action(parsed_args)
  2625. self.baremetal_mock.node.vif_attach.assert_called_once_with(
  2626. 'node_uuid', 'aaa-aaa', foo='bar')
  2627. class TestVifDetach(TestBaremetal):
  2628. def setUp(self):
  2629. super(TestVifDetach, self).setUp()
  2630. # Get the command object to test
  2631. self.cmd = baremetal_node.VifDetachBaremetalNode(self.app, None)
  2632. def test_baremetal_vif_detach(self):
  2633. arglist = ['node_uuid', 'aaa-aaa']
  2634. verifylist = [('node', 'node_uuid'),
  2635. ('vif_id', 'aaa-aaa')]
  2636. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2637. self.cmd.take_action(parsed_args)
  2638. self.baremetal_mock.node.vif_detach.assert_called_once_with(
  2639. 'node_uuid', 'aaa-aaa')
  2640. class TestBaremetalInject(TestBaremetal):
  2641. def setUp(self):
  2642. super(TestBaremetalInject, self).setUp()
  2643. # Get the command object to test
  2644. self.cmd = baremetal_node.InjectNmiBaremetalNode(self.app, None)
  2645. def test_baremetal_inject_no_options(self):
  2646. arglist = []
  2647. verifylist = []
  2648. self.assertRaises(oscutils.ParserException,
  2649. self.check_parser,
  2650. self.cmd, arglist, verifylist)
  2651. def test_baremetal_inject_nmi_uuid(self):
  2652. arglist = ['node_uuid']
  2653. verifylist = [('node', 'node_uuid')]
  2654. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2655. self.cmd.take_action(parsed_args)
  2656. self.baremetal_mock.node.inject_nmi.assert_called_once_with(
  2657. 'node_uuid')
  2658. class TestListTraits(TestBaremetal):
  2659. def setUp(self):
  2660. super(TestListTraits, self).setUp()
  2661. self.baremetal_mock.node.get_traits.return_value = (
  2662. baremetal_fakes.TRAITS)
  2663. # Get the command object to test
  2664. self.cmd = baremetal_node.ListTraitsBaremetalNode(self.app, None)
  2665. def test_baremetal_list_traits(self):
  2666. arglist = ['node_uuid']
  2667. verifylist = [('node', 'node_uuid')]
  2668. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2669. columns, data = self.cmd.take_action(parsed_args)
  2670. self.baremetal_mock.node.get_traits.assert_called_once_with(
  2671. 'node_uuid')
  2672. self.assertEqual(('Traits',), columns)
  2673. self.assertEqual([[trait] for trait in baremetal_fakes.TRAITS], data)
  2674. class TestAddTrait(TestBaremetal):
  2675. def setUp(self):
  2676. super(TestAddTrait, self).setUp()
  2677. # Get the command object to test
  2678. self.cmd = baremetal_node.AddTraitBaremetalNode(self.app, None)
  2679. def test_baremetal_add_trait(self):
  2680. arglist = ['node_uuid', 'CUSTOM_FOO']
  2681. verifylist = [('node', 'node_uuid'), ('traits', ['CUSTOM_FOO'])]
  2682. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2683. self.cmd.take_action(parsed_args)
  2684. self.baremetal_mock.node.add_trait.assert_called_once_with(
  2685. 'node_uuid', 'CUSTOM_FOO')
  2686. def test_baremetal_add_traits_multiple(self):
  2687. arglist = ['node_uuid', 'CUSTOM_FOO', 'CUSTOM_BAR']
  2688. verifylist = [('node', 'node_uuid'),
  2689. ('traits', ['CUSTOM_FOO', 'CUSTOM_BAR'])]
  2690. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2691. self.cmd.take_action(parsed_args)
  2692. expected_calls = [
  2693. mock.call('node_uuid', 'CUSTOM_FOO'),
  2694. mock.call('node_uuid', 'CUSTOM_BAR'),
  2695. ]
  2696. self.assertEqual(expected_calls,
  2697. self.baremetal_mock.node.add_trait.call_args_list)
  2698. def test_baremetal_add_traits_multiple_with_failure(self):
  2699. arglist = ['node_uuid', 'CUSTOM_FOO', 'CUSTOM_BAR']
  2700. verifylist = [('node', 'node_uuid'),
  2701. ('traits', ['CUSTOM_FOO', 'CUSTOM_BAR'])]
  2702. self.baremetal_mock.node.add_trait.side_effect = [
  2703. '', exc.ClientException]
  2704. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2705. self.assertRaises(exc.ClientException,
  2706. self.cmd.take_action,
  2707. parsed_args)
  2708. expected_calls = [
  2709. mock.call('node_uuid', 'CUSTOM_FOO'),
  2710. mock.call('node_uuid', 'CUSTOM_BAR'),
  2711. ]
  2712. self.assertEqual(expected_calls,
  2713. self.baremetal_mock.node.add_trait.call_args_list)
  2714. def test_baremetal_add_traits_no_traits(self):
  2715. arglist = ['node_uuid']
  2716. verifylist = [('node', 'node_uuid')]
  2717. self.assertRaises(oscutils.ParserException,
  2718. self.check_parser,
  2719. self.cmd,
  2720. arglist,
  2721. verifylist)
  2722. class TestRemoveTrait(TestBaremetal):
  2723. def setUp(self):
  2724. super(TestRemoveTrait, self).setUp()
  2725. # Get the command object to test
  2726. self.cmd = baremetal_node.RemoveTraitBaremetalNode(self.app, None)
  2727. def test_baremetal_remove_trait(self):
  2728. arglist = ['node_uuid', 'CUSTOM_FOO']
  2729. verifylist = [('node', 'node_uuid'), ('traits', ['CUSTOM_FOO'])]
  2730. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2731. self.cmd.take_action(parsed_args)
  2732. self.baremetal_mock.node.remove_trait.assert_called_once_with(
  2733. 'node_uuid', 'CUSTOM_FOO')
  2734. def test_baremetal_remove_trait_multiple(self):
  2735. arglist = ['node_uuid', 'CUSTOM_FOO', 'CUSTOM_BAR']
  2736. verifylist = [('node', 'node_uuid'),
  2737. ('traits', ['CUSTOM_FOO', 'CUSTOM_BAR'])]
  2738. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2739. self.cmd.take_action(parsed_args)
  2740. expected_calls = [
  2741. mock.call('node_uuid', 'CUSTOM_FOO'),
  2742. mock.call('node_uuid', 'CUSTOM_BAR'),
  2743. ]
  2744. self.assertEqual(expected_calls,
  2745. self.baremetal_mock.node.remove_trait.call_args_list)
  2746. def test_baremetal_remove_trait_multiple_with_failure(self):
  2747. arglist = ['node_uuid', 'CUSTOM_FOO', 'CUSTOM_BAR']
  2748. verifylist = [('node', 'node_uuid'),
  2749. ('traits', ['CUSTOM_FOO', 'CUSTOM_BAR'])]
  2750. self.baremetal_mock.node.remove_trait.side_effect = [
  2751. '', exc.ClientException]
  2752. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2753. self.assertRaises(exc.ClientException,
  2754. self.cmd.take_action,
  2755. parsed_args)
  2756. expected_calls = [
  2757. mock.call('node_uuid', 'CUSTOM_FOO'),
  2758. mock.call('node_uuid', 'CUSTOM_BAR'),
  2759. ]
  2760. self.assertEqual(expected_calls,
  2761. self.baremetal_mock.node.remove_trait.call_args_list)
  2762. def test_baremetal_remove_trait_all(self):
  2763. arglist = ['node_uuid', '--all']
  2764. verifylist = [('node', 'node_uuid'), ('remove_all', True)]
  2765. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2766. self.cmd.take_action(parsed_args)
  2767. self.baremetal_mock.node.remove_all_traits.assert_called_once_with(
  2768. 'node_uuid')
  2769. def test_baremetal_remove_trait_traits_and_all(self):
  2770. arglist = ['node_uuid', 'CUSTOM_FOO', '--all']
  2771. verifylist = [('node', 'node_uuid'),
  2772. ('traits', ['CUSTOM_FOO']),
  2773. ('remove_all', True)]
  2774. self.assertRaises(oscutils.ParserException,
  2775. self.check_parser,
  2776. self.cmd,
  2777. arglist,
  2778. verifylist)
  2779. self.baremetal_mock.node.remove_all_traits.assert_not_called()
  2780. self.baremetal_mock.node.remove_trait.assert_not_called()
  2781. def test_baremetal_remove_traits_no_traits_no_all(self):
  2782. arglist = ['node_uuid']
  2783. verifylist = [('node', 'node_uuid')]
  2784. self.assertRaises(oscutils.ParserException,
  2785. self.check_parser,
  2786. self.cmd,
  2787. arglist,
  2788. verifylist)
  2789. self.baremetal_mock.node.remove_all_traits.assert_not_called()
  2790. self.baremetal_mock.node.remove_trait.assert_not_called()
  2791. class TestListBIOSSetting(TestBaremetal):
  2792. def setUp(self):
  2793. super(TestListBIOSSetting, self).setUp()
  2794. self.baremetal_mock.node.list_bios_settings.return_value = (
  2795. baremetal_fakes.BIOS_SETTINGS)
  2796. # Get the command object to test
  2797. self.cmd = baremetal_node.ListBIOSSettingBaremetalNode(self.app, None)
  2798. def test_baremetal_list_bios_setting(self):
  2799. arglist = ['node_uuid']
  2800. verifylist = [('node', 'node_uuid')]
  2801. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2802. data = self.cmd.take_action(parsed_args)
  2803. self.baremetal_mock.node.list_bios_settings.assert_called_once_with(
  2804. 'node_uuid')
  2805. expected_data = (('BIOS setting name', 'BIOS setting value'),
  2806. [[s['name'], s['value']]
  2807. for s in baremetal_fakes.BIOS_SETTINGS])
  2808. self.assertEqual(expected_data, data)
  2809. class TestBIOSSettingShow(TestBaremetal):
  2810. def setUp(self):
  2811. super(TestBIOSSettingShow, self).setUp()
  2812. self.baremetal_mock.node.get_bios_setting.return_value = (
  2813. baremetal_fakes.BIOS_SETTINGS[0])
  2814. # Get the command object to test
  2815. self.cmd = baremetal_node.BIOSSettingShowBaremetalNode(self.app, None)
  2816. def test_baremetal_bios_setting_show(self):
  2817. arglist = ['node_uuid', 'bios_name_1']
  2818. verifylist = [('node', 'node_uuid'), ('setting_name', 'bios_name_1')]
  2819. parsed_args = self.check_parser(self.cmd, arglist, verifylist)
  2820. columns, data = self.cmd.take_action(parsed_args)
  2821. self.baremetal_mock.node.get_bios_setting.assert_called_once_with(
  2822. 'node_uuid', 'bios_name_1')
  2823. expected_data = ('bios_name_1', 'bios_value_1')
  2824. self.assertEqual(expected_data, tuple(data))