def test_file_has_content_differ(self): data = b'Mary had a little lamb, its fleece as white as snow' ref = data + b'!' with mock.patch('oslo_utils.fileutils.open', mock.mock_open(read_data=data)) as mopen: self.assertFalse(utils.file_has_content('foo', ref)) mopen.assert_called_once_with('foo', 'rb')
def test_file_has_content_equal_not_binary(self): data = u'Mary had a little lamb, its fleece as white as sno\u0449' ref = data with mock.patch('ironic.common.utils.open', mock.mock_open(read_data=data)) as mopen: self.assertTrue(utils.file_has_content('foo', ref)) mopen.assert_called_once_with('foo', 'rb')
def test_file_has_content_differ(self): data = b'Mary had a little lamb, its fleece as white as snow' ref = data + b'!' with mock.patch('ironic.common.utils.open', mock.mock_open(read_data=data)) as mopen: self.assertFalse(utils.file_has_content('foo', ref)) mopen.assert_called_once_with('foo', 'rb')
def test_file_has_content_equal(self): data = b'Mary had a little lamb, its fleece as white as snow' ref = data with mock.patch('oslo_utils.fileutils.open', mock.mock_open(read_data=data)) as mopen: self.assertTrue(utils.file_has_content('foo', ref)) mopen.assert_called_once_with('foo', 'rb')
def test_file_has_content_equal_not_binary(self): data = ('Mary had a little lamb, its fleece as white as ' 'sno\u0449').encode('utf-8') ref = data with mock.patch('oslo_utils.fileutils.open', mock.mock_open(read_data=data)) as mopen: self.assertTrue(utils.file_has_content('foo', ref)) mopen.assert_called_once_with('foo', 'rb')
def create_ipxe_boot_script(): """Render the iPXE boot script into the HTTP root directory""" boot_script = utils.render_template( CONF.pxe.ipxe_boot_script, {'ipxe_for_mac_uri': PXE_CFG_DIR_NAME + '/'}) bootfile_path = os.path.join(CONF.deploy.http_root, os.path.basename(CONF.pxe.ipxe_boot_script)) # NOTE(pas-ha) to prevent unneeded writes, # only write to file if its content is different from required, # which should be rather rare if (not os.path.isfile(bootfile_path) or not utils.file_has_content(bootfile_path, boot_script)): utils.write_to_file(bootfile_path, boot_script)
def create_ipxe_boot_script(): """Render the iPXE boot script into the HTTP root directory""" boot_script = utils.render_template( CONF.pxe.ipxe_boot_script, {'ipxe_for_mac_uri': PXE_CFG_DIR_NAME + '/'}) bootfile_path = os.path.join( CONF.deploy.http_root, os.path.basename(CONF.pxe.ipxe_boot_script)) # NOTE(pas-ha) to prevent unneeded writes, # only write to file if its content is different from required, # which should be rather rare if (not os.path.isfile(bootfile_path) or not utils.file_has_content(bootfile_path, boot_script)): utils.write_to_file(bootfile_path, boot_script)
def prepare_ramdisk(self, task, ramdisk_params): """Prepares the boot of Ironic ramdisk using PXE. This method prepares the boot of the deploy kernel/ramdisk after reading relevant information from the node's driver_info and instance_info. :param task: a task from TaskManager. :param ramdisk_params: the parameters to be passed to the ramdisk. pxe driver passes these parameters as kernel command-line arguments. :returns: None :raises: MissingParameterValue, if some information is missing in node's driver_info or instance_info. :raises: InvalidParameterValue, if some information provided is invalid. :raises: IronicException, if some power or set boot boot device operation failed on the node. """ node = task.node if CONF.pxe.ipxe_enabled: # Render the iPXE boot script template and save it # to HTTP root directory boot_script = utils.render_template( CONF.pxe.ipxe_boot_script, {'ipxe_for_mac_uri': pxe_utils.PXE_CFG_DIR_NAME + '/'}) bootfile_path = os.path.join( CONF.deploy.http_root, os.path.basename(CONF.pxe.ipxe_boot_script)) # NOTE(pas-ha) to prevent unneeded writes, # only write to file if its content is different from required, # which should be rather rare if (not os.path.isfile(bootfile_path) or not utils.file_has_content(bootfile_path, boot_script)): utils.write_to_file(bootfile_path, boot_script) dhcp_opts = pxe_utils.dhcp_options_for_instance(task) provider = dhcp_factory.DHCPFactory() provider.update_dhcp(task, dhcp_opts) pxe_info = _get_deploy_image_info(node) # NODE: Try to validate and fetch instance images only # if we are in DEPLOYING state. if node.provision_state == states.DEPLOYING: pxe_info.update(_get_instance_image_info(node, task.context)) pxe_options = _build_pxe_config_options(task, pxe_info) pxe_options.update(ramdisk_params) pxe_config_template = deploy_utils.get_pxe_config_template(node) pxe_utils.create_pxe_config(task, pxe_options, pxe_config_template) deploy_utils.try_set_boot_device(task, boot_devices.PXE) if CONF.pxe.ipxe_enabled and CONF.pxe.ipxe_use_swift: pxe_info.pop('deploy_kernel', None) pxe_info.pop('deploy_ramdisk', None) if pxe_info: _cache_ramdisk_kernel(task.context, node, pxe_info)
def test_file_has_content_differ(self): data = b'Mary had a little lamb, its fleece as white as snow' ref = data + b'!' with mock.patch('ironic.common.utils.open', mock.mock_open(read_data=data)): self.assertFalse(utils.file_has_content('foo', ref))
def test_file_has_content_equal(self): data = b'Mary had a little lamb, its fleece as white as snow' ref = data with mock.patch('ironic.common.utils.open', mock.mock_open(read_data=data)): self.assertTrue(utils.file_has_content('foo', ref))