def test_device_list_not_found(self): action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID', root_device='hda') self.assertRaisesRegex(exception.RootDeviceDetectionError, "Cannot find a disk", action.run, self.context) self.assertEqual(self.ironic.node.update.call_count, 0)
def test_no_overwrite(self): self.node.properties['root_device'] = {'foo': 'bar'} action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID', root_device='smallest') action.run(self.context) self.assertEqual(self.ironic.node.update.call_count, 0)
def test_bad_inventory(self): self.inspector.get_data.return_value = {} action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID', root_device='smallest') self.assertRaisesRegexp(exception.RootDeviceDetectionError, "Malformed introspection data", action.run) self.assertEqual(self.ironic.node.update.call_count, 0)
def test_no_data(self): self.inspector.get_data.side_effect = ( ironic_inspector_client.ClientError(mock.Mock())) action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID', root_device='smallest') self.assertRaisesRegexp(exception.RootDeviceDetectionError, "No introspection data", action.run) self.assertEqual(self.ironic.node.update.call_count, 0)
def test_largest(self): action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID', root_device='largest') action.run(self.context) self.assertEqual(self.ironic.node.update.call_count, 1) root_device_args = self.ironic.node.update.call_args_list[0] expected_patch = [{'op': 'add', 'path': '/properties/root_device', 'value': {'wwn': 'wwn3'}}, {'op': 'add', 'path': '/properties/local_gb', 'value': 20}] self.assertEqual(mock.call('ABCDEFGH', expected_patch), root_device_args)
def test_smallest_with_ext(self): self.disks[2]['wwn_with_extension'] = 'wwnext' action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID', root_device='smallest') action.run(self.context) self.assertEqual(self.ironic.node.update.call_count, 1) root_device_args = self.ironic.node.update.call_args_list[0] expected_patch = [{'op': 'add', 'path': '/properties/root_device', 'value': {'wwn_with_extension': 'wwnext'}}, {'op': 'add', 'path': '/properties/local_gb', 'value': 4}] self.assertEqual(mock.call('ABCDEFGH', expected_patch), root_device_args)
def test_no_wwn_and_serial(self): self.inspector.get_data.return_value = { 'inventory': { 'disks': [{'name': '/dev/sda', 'size': 10 * units.Gi}] } } action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID', root_device='smallest') self.assertRaisesRegexp(exception.RootDeviceDetectionError, "Neither WWN nor serial number are known", action.run) self.assertEqual(self.ironic.node.update.call_count, 0)
def configure(clients, node_uuids, kernel_name='bm-deploy-kernel', ramdisk_name='bm-deploy-ramdisk', instance_boot_option=None, root_device=None, root_device_minimum_size=4, overwrite_root_device_hints=False): """Configure Node boot options. :param node_uuids: List of instance UUID(s). :type node_uuids: List :param kernel_name: Kernel to use :type kernel_name: String :param ramdisk_name: RAMDISK to use :type ramdisk_name: String :param instance_boot_option: Boot options to use :type instance_boot_option: String :param root_device: Path (name) of the root device. :type root_device: String :param root_device_minimum_size: Size of the given root device. :type root_device_minimum_size: Integer :param overwrite_root_device_hints: Whether to overwrite existing root device hints when `root_device` is used. :type overwrite_root_device_hints: Boolean """ context = clients.tripleoclient.create_mistral_context() for node_uuid in node_uuids: boot_action = baremetal.ConfigureBootAction( node_uuid=node_uuid, kernel_name=kernel_name, ramdisk_name=ramdisk_name, instance_boot_option=instance_boot_option ).run(context=context) if boot_action: raise RuntimeError(boot_action) root_device_action = baremetal.ConfigureRootDeviceAction( node_uuid=node_uuid, root_device=root_device, minimum_size=root_device_minimum_size, overwrite=overwrite_root_device_hints ) root_device_action.run(context=context) else: print('Successfully configured the nodes.')
def test_no_disks(self): self.inspector.get_data.return_value = { 'inventory': { 'disks': [{'name': '/dev/sda', 'size': 1 * units.Gi}] } } action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID', root_device='smallest') self.assertRaisesRegex(exception.RootDeviceDetectionError, "No suitable disks", action.run, self.context) self.assertEqual(self.ironic.node.update.call_count, 0)
def test_with_overwrite(self): self.node.properties['root_device'] = {'foo': 'bar'} action = baremetal.ConfigureRootDeviceAction(node_uuid='MOCK_UUID', root_device='smallest', overwrite=True) action.run(self.context) self.assertEqual(self.ironic.node.update.call_count, 1) root_device_args = self.ironic.node.update.call_args_list[0] expected_patch = [{'op': 'add', 'path': '/properties/root_device', 'value': {'wwn': 'wwn2'}}, {'op': 'add', 'path': '/properties/local_gb', 'value': 4}] self.assertEqual(mock.call('ABCDEFGH', expected_patch), root_device_args)
def baremetal_configure_root_device(self, kwargs): """Run the action configure root device, and return data. :param kwargs: options to pass into the ConfigureRootDeviceAction :type kwargs: Dictionary :returns: Object """ action = baremetal.ConfigureRootDeviceAction(**kwargs) baremetal_client = ironicclient.Client(1, session=self.sess) inspector_client = self.get_ironic_inspector_client() if not action.root_device: return else: return action.configure_root_device(baremetal_client, inspector_client)