def activate_bootloader(self, context, node, instance, network_info): """Configure Tilera boot loader for an instance Kernel and ramdisk images are downloaded by cache_tftp_images, and stored in /tftpboot/{uuid}/ This method writes the instances config file, and then creates symlinks for each MAC address in the instance. By default, the complete layout looks like this: /tftpboot/ ./{uuid}/ kernel ./fs_node_id/ """ image_info = get_tftp_image_info(instance) (root_mb, swap_mb) = get_partition_sizes(instance) tilera_nfs_path = get_tilera_nfs_path(node['id']) image_file_path = get_image_file_path(instance) deployment_key = bm_utils.random_alnum(32) db.bm_node_update(context, node['id'], {'deploy_key': deployment_key, 'image_path': image_file_path, 'pxe_config_path': tilera_nfs_path, 'root_mb': root_mb, 'swap_mb': swap_mb}) if os.path.exists(image_file_path) and \ os.path.exists(tilera_nfs_path): utils.execute('mount', '-o', 'loop', image_file_path, tilera_nfs_path, run_as_root=True)
def activate_bootloader(self, context, node, instance): """Configure Tilera boot loader for an instance Kernel and ramdisk images are downloaded by cache_tftp_images, and stored in /tftpboot/{uuid}/ This method writes the instances config file, and then creates symlinks for each MAC address in the instance. By default, the complete layout looks like this: /tftpboot/ ./{uuid}/ kernel ./fs_node_id/ """ image_info = get_tftp_image_info(instance) (root_mb, swap_mb) = get_partition_sizes(instance) tilera_nfs_path = get_tilera_nfs_path(node['id']) image_file_path = get_image_file_path(instance) deployment_key = bm_utils.random_alnum(32) db.bm_node_update(context, node['id'], {'deploy_key': deployment_key, 'image_path': image_file_path, 'pxe_config_path': tilera_nfs_path, 'root_mb': root_mb, 'swap_mb': swap_mb}) if os.path.exists(image_file_path) and \ os.path.exists(tilera_nfs_path): utils.execute('mount', '-o', 'loop', image_file_path, tilera_nfs_path, run_as_root=True)
def activate_bootloader(self, context, node, instance, network_info): """Configure PXE boot loader for an instance Kernel and ramdisk images are downloaded by cache_tftp_images, and stored in /tftpboot/{uuid}/ This method writes the instances config file, and then creates symlinks for each MAC address in the instance. By default, the complete layout looks like this: /tftpboot/ ./{uuid}/ kernel ramdisk deploy_kernel deploy_ramdisk config ./pxelinux.cfg/ {mac} -> ../{uuid}/config """ flavor = objects.Flavor.get_by_id(context, instance["instance_type_id"]) image_info = get_tftp_image_info(instance, flavor) (root_mb, swap_mb, ephemeral_mb) = get_partition_sizes(instance) pxe_config_file_path = get_pxe_config_file_path(instance) image_file_path = get_image_file_path(instance) deployment_key = bm_utils.random_alnum(32) deployment_iscsi_iqn = "iqn-%s" % instance["uuid"] db.bm_node_update( context, node["id"], { "deploy_key": deployment_key, "image_path": image_file_path, "pxe_config_path": pxe_config_file_path, "root_mb": root_mb, "swap_mb": swap_mb, "ephemeral_mb": ephemeral_mb, }, ) pxe_config = build_pxe_config( node["id"], deployment_key, deployment_iscsi_iqn, image_info["deploy_kernel"][1], image_info["deploy_ramdisk"][1], image_info["kernel"][1], image_info["ramdisk"][1], network_info, ) bm_utils.write_to_file(pxe_config_file_path, pxe_config) macs = self._collect_mac_addresses(context, node) for mac in macs: mac_path = get_pxe_mac_path(mac) bm_utils.unlink_without_raise(mac_path) bm_utils.create_link_without_raise(pxe_config_file_path, mac_path)
def test_activate_bootloader_passes_details(self): self._create_node() macs = [nic['address'] for nic in self.nic_info] macs.sort() image_info = { 'deploy_kernel': [None, 'aaaa'], 'deploy_ramdisk': [None, 'bbbb'], 'kernel': [None, 'cccc'], 'ramdisk': [None, 'dddd'], } self.instance['uuid'] = 'fake-uuid' iqn = "iqn-%s" % self.instance['uuid'] pxe_config = 'this is a fake pxe config' pxe_path = pxe.get_pxe_config_file_path(self.instance) image_path = pxe.get_image_file_path(self.instance) self.mox.StubOutWithMock(flavor_obj.Flavor, 'get_by_id') self.mox.StubOutWithMock(pxe, 'get_tftp_image_info') self.mox.StubOutWithMock(pxe, 'get_partition_sizes') self.mox.StubOutWithMock(bm_utils, 'random_alnum') self.mox.StubOutWithMock(pxe, 'build_pxe_config') self.mox.StubOutWithMock(bm_utils, 'write_to_file') self.mox.StubOutWithMock(bm_utils, 'create_link_without_raise') flavor_obj.Flavor.get_by_id( self.context, self.instance['instance_type_id']).AndReturn({}) pxe.get_tftp_image_info(self.instance, {}).AndReturn(image_info) pxe.get_partition_sizes(self.instance).AndReturn((0, 0, 0)) bm_utils.random_alnum(32).AndReturn('alnum') pxe.build_pxe_config(self.node['id'], 'alnum', iqn, 'aaaa', 'bbbb', 'cccc', 'dddd', self.test_network_info).AndReturn(pxe_config) bm_utils.write_to_file(pxe_path, pxe_config) for mac in macs: bm_utils.create_link_without_raise(pxe_path, pxe.get_pxe_mac_path(mac)) self.mox.ReplayAll() self.driver.activate_bootloader(self.context, self.node, self.instance, network_info=self.test_network_info) self.mox.VerifyAll()
def test_activate_bootloader_passes_details(self): self._create_node() macs = [nic['address'] for nic in self.nic_info] macs.sort() image_info = { 'deploy_kernel': [None, 'aaaa'], 'deploy_ramdisk': [None, 'bbbb'], 'kernel': [None, 'cccc'], 'ramdisk': [None, 'dddd'], } self.instance['uuid'] = 'fake-uuid' iqn = "iqn-%s" % self.instance['uuid'] pxe_config = 'this is a fake pxe config' pxe_path = pxe.get_pxe_config_file_path(self.instance) pxe.get_image_file_path(self.instance) self.mox.StubOutWithMock(flavor_obj.Flavor, 'get_by_id') self.mox.StubOutWithMock(pxe, 'get_tftp_image_info') self.mox.StubOutWithMock(pxe, 'get_partition_sizes') self.mox.StubOutWithMock(bm_utils, 'random_alnum') self.mox.StubOutWithMock(pxe, 'build_pxe_config') self.mox.StubOutWithMock(bm_utils, 'write_to_file') self.mox.StubOutWithMock(bm_utils, 'create_link_without_raise') flavor_obj.Flavor.get_by_id(self.context, self.instance['instance_type_id'] ).AndReturn({}) pxe.get_tftp_image_info(self.instance, {}).AndReturn(image_info) pxe.get_partition_sizes(self.instance).AndReturn((0, 0, 0)) bm_utils.random_alnum(32).AndReturn('alnum') pxe.build_pxe_config( self.node['id'], 'alnum', iqn, 'aaaa', 'bbbb', 'cccc', 'dddd', self.test_network_info).AndReturn(pxe_config) bm_utils.write_to_file(pxe_path, pxe_config) for mac in macs: bm_utils.create_link_without_raise( pxe_path, pxe.get_pxe_mac_path(mac)) self.mox.ReplayAll() self.driver.activate_bootloader(self.context, self.node, self.instance, network_info=self.test_network_info) self.mox.VerifyAll()
def activate_bootloader(self, context, node, instance, network_info): """Configure PXE boot loader for an instance Kernel and ramdisk images are downloaded by cache_tftp_images, and stored in /tftpboot/{uuid}/ This method writes the instances config file, and then creates symlinks for each MAC address in the instance. By default, the complete layout looks like this: /tftpboot/ ./{uuid}/ kernel ramdisk deploy_kernel deploy_ramdisk config ./pxelinux.cfg/ {mac} -> ../{uuid}/config """ flavor = flavor_obj.Flavor.get_by_id(context, instance['instance_type_id']) image_info = get_tftp_image_info(instance, flavor) (root_mb, swap_mb, ephemeral_mb) = get_partition_sizes(instance) pxe_config_file_path = get_pxe_config_file_path(instance) image_file_path = get_image_file_path(instance) deployment_key = bm_utils.random_alnum(32) deployment_iscsi_iqn = "iqn-%s" % instance['uuid'] db.bm_node_update( context, node['id'], { 'deploy_key': deployment_key, 'image_path': image_file_path, 'pxe_config_path': pxe_config_file_path, 'root_mb': root_mb, 'swap_mb': swap_mb, 'ephemeral_mb': ephemeral_mb }) pxe_config = build_pxe_config( node['id'], deployment_key, deployment_iscsi_iqn, image_info['deploy_kernel'][1], image_info['deploy_ramdisk'][1], image_info['kernel'][1], image_info['ramdisk'][1], network_info, ) bm_utils.write_to_file(pxe_config_file_path, pxe_config) macs = self._collect_mac_addresses(context, node) for mac in macs: mac_path = get_pxe_mac_path(mac) bm_utils.unlink_without_raise(mac_path) bm_utils.create_link_without_raise(pxe_config_file_path, mac_path)
def test_activate_bootloader(self): self._create_node() macs = [nic['address'] for nic in self.nic_info] macs.append(self.node_info['prov_mac_address']) macs.sort() image_info = { 'deploy_kernel': [None, 'aaaa'], 'deploy_ramdisk': [None, 'bbbb'], 'kernel': [None, 'cccc'], 'ramdisk': [None, 'dddd'], } self.instance['uuid'] = 'fake-uuid' iqn = "iqn-%s" % self.instance['uuid'] pxe_config = 'this is a fake pxe config' pxe_path = pxe.get_pxe_config_file_path(self.instance) image_path = pxe.get_image_file_path(self.instance) self.mox.StubOutWithMock(pxe, 'get_tftp_image_info') self.mox.StubOutWithMock(pxe, 'get_partition_sizes') self.mox.StubOutWithMock(bm_utils, 'random_alnum') self.mox.StubOutWithMock(db, 'bm_deployment_create') self.mox.StubOutWithMock(pxe, 'build_pxe_config') self.mox.StubOutWithMock(bm_utils, 'write_to_file') self.mox.StubOutWithMock(bm_utils, 'create_link_without_raise') pxe.get_tftp_image_info(self.instance).AndReturn(image_info) pxe.get_partition_sizes(self.instance).AndReturn((0, 0)) bm_utils.random_alnum(32).AndReturn('alnum') db.bm_deployment_create( self.context, 'alnum', image_path, pxe_path, 0, 0).\ AndReturn(1234) pxe.build_pxe_config( 1234, 'alnum', iqn, 'aaaa', 'bbbb', 'cccc', 'dddd').\ AndReturn(pxe_config) bm_utils.write_to_file(pxe_path, pxe_config) for mac in macs: bm_utils.create_link_without_raise( pxe_path, pxe.get_pxe_mac_path(mac)) self.mox.ReplayAll() self.driver.activate_bootloader( self.context, self.node, self.instance) self.mox.VerifyAll()
def activate_bootloader(self, context, node, instance, network_info): """Configure PXE boot loader for an instance Kernel and ramdisk images are downloaded by cache_tftp_images, and stored in /tftpboot/{uuid}/ This method writes the instances config file, and then creates symlinks for each MAC address in the instance. By default, the complete layout looks like this: /tftpboot/ ./{uuid}/ kernel ramdisk deploy_kernel deploy_ramdisk config ./pxelinux.cfg/ {mac} -> ../{uuid}/config """ instance_type = self.virtapi.flavor_get( context, instance['instance_type_id']) image_info = get_tftp_image_info(instance, instance_type) (root_mb, swap_mb, ephemeral_mb) = get_partition_sizes(instance) pxe_config_file_path = get_pxe_config_file_path(instance) image_file_path = get_image_file_path(instance) deployment_key = bm_utils.random_alnum(32) deployment_iscsi_iqn = "iqn-%s" % instance['uuid'] db.bm_node_update(context, node['id'], {'deploy_key': deployment_key, 'image_path': image_file_path, 'pxe_config_path': pxe_config_file_path, 'root_mb': root_mb, 'swap_mb': swap_mb, 'ephemeral_mb': ephemeral_mb}) pxe_config = build_pxe_config( node['id'], deployment_key, deployment_iscsi_iqn, image_info['deploy_kernel'][1], image_info['deploy_ramdisk'][1], image_info['kernel'][1], image_info['ramdisk'][1], network_info, ) bm_utils.write_to_file(pxe_config_file_path, pxe_config) macs = self._collect_mac_addresses(context, node) for mac in macs: mac_path = get_pxe_mac_path(mac) bm_utils.unlink_without_raise(mac_path) bm_utils.create_link_without_raise(pxe_config_file_path, mac_path)
def activate_bootloader(self, context, node, instance): """Configure PXE boot loader for an instance Kernel and ramdisk images are downloaded by cache_tftp_images, and stored in /tftpboot/{uuid}/ This method writes the instances config file, and then creates symlinks for each MAC address in the instance. By default, the complete layout looks like this: /tftpboot/ ./{uuid}/ kernel ramdisk deploy_kernel deploy_ramdisk config ./pxelinux.cfg/ {mac} -> ../{uuid}/config """ image_info = get_tftp_image_info(instance) (root_mb, swap_mb) = get_partition_sizes(instance) pxe_config_file_path = get_pxe_config_file_path(instance) image_file_path = get_image_file_path(instance) deployment_key = bm_utils.random_alnum(32) deployment_iscsi_iqn = "iqn-%s" % instance['uuid'] deployment_id = db.bm_deployment_create( context, deployment_key, image_file_path, pxe_config_file_path, root_mb, swap_mb ) pxe_config = build_pxe_config( deployment_id, deployment_key, deployment_iscsi_iqn, image_info['deploy_kernel'][1], image_info['deploy_ramdisk'][1], image_info['kernel'][1], image_info['ramdisk'][1], ) bm_utils.write_to_file(pxe_config_file_path, pxe_config) macs = self._collect_mac_addresses(context, node) for mac in macs: mac_path = get_pxe_mac_path(mac) bm_utils.unlink_without_raise(mac_path) bm_utils.create_link_without_raise(pxe_config_file_path, mac_path)
def test_activate_bootloader_passes_details(self): self._create_node() macs = [nic["address"] for nic in self.nic_info] macs.sort() image_info = { "deploy_kernel": [None, "aaaa"], "deploy_ramdisk": [None, "bbbb"], "kernel": [None, "cccc"], "ramdisk": [None, "dddd"], } self.instance["uuid"] = "fake-uuid" iqn = "iqn-%s" % self.instance["uuid"] pxe_config = "this is a fake pxe config" pxe_path = pxe.get_pxe_config_file_path(self.instance) image_path = pxe.get_image_file_path(self.instance) self.mox.StubOutWithMock(self.driver.virtapi, "instance_type_get") self.mox.StubOutWithMock(pxe, "get_tftp_image_info") self.mox.StubOutWithMock(pxe, "get_partition_sizes") self.mox.StubOutWithMock(bm_utils, "random_alnum") self.mox.StubOutWithMock(pxe, "build_pxe_config") self.mox.StubOutWithMock(bm_utils, "write_to_file") self.mox.StubOutWithMock(bm_utils, "create_link_without_raise") self.driver.virtapi.instance_type_get(self.context, self.instance["instance_type_id"]).AndReturn({}) pxe.get_tftp_image_info(self.instance, {}).AndReturn(image_info) pxe.get_partition_sizes(self.instance).AndReturn((0, 0)) bm_utils.random_alnum(32).AndReturn("alnum") pxe.build_pxe_config( self.node["id"], "alnum", iqn, "aaaa", "bbbb", "cccc", "dddd", self.test_network_info ).AndReturn(pxe_config) bm_utils.write_to_file(pxe_path, pxe_config) for mac in macs: bm_utils.create_link_without_raise(pxe_path, pxe.get_pxe_mac_path(mac)) self.mox.ReplayAll() self.driver.activate_bootloader(self.context, self.node, self.instance, network_info=self.test_network_info) self.mox.VerifyAll()
def activate_bootloader(self, context, node, instance): """Configure PXE boot loader for an instance Kernel and ramdisk images are downloaded by cache_tftp_images, and stored in /tftpboot/{uuid}/ This method writes the instances config file, and then creates symlinks for each MAC address in the instance. By default, the complete layout looks like this: /tftpboot/ ./{uuid}/ kernel ramdisk deploy_kernel deploy_ramdisk config ./pxelinux.cfg/ {mac} -> ../{uuid}/config """ image_info = get_tftp_image_info(instance) (root_mb, swap_mb) = get_partition_sizes(instance) pxe_config_file_path = get_pxe_config_file_path(instance) image_file_path = get_image_file_path(instance) deployment_key = bm_utils.random_alnum(32) deployment_iscsi_iqn = "iqn-%s" % instance["uuid"] deployment_id = db.bm_deployment_create( context, deployment_key, image_file_path, pxe_config_file_path, root_mb, swap_mb ) pxe_config = build_pxe_config( deployment_id, deployment_key, deployment_iscsi_iqn, image_info["deploy_kernel"][1], image_info["deploy_ramdisk"][1], image_info["kernel"][1], image_info["ramdisk"][1], ) bm_utils.write_to_file(pxe_config_file_path, pxe_config) macs = self._collect_mac_addresses(context, node) for mac in macs: mac_path = get_pxe_mac_path(mac) bm_utils.unlink_without_raise(mac_path) bm_utils.create_link_without_raise(pxe_config_file_path, mac_path)
def activate_bootloader(self, context, node, instance, network_info): """Configure Tilera boot loader for an instance Kernel and ramdisk images are downloaded by cache_tftp_images, and stored in /tftpboot/{uuid}/ This method writes the instances config file, and then creates symlinks for each MAC address in the instance. By default, the complete layout looks like this:: /tftpboot/ ./{uuid}/ kernel ./fs_node_id/ """ get_tftp_image_info(instance) (root_mb, swap_mb) = get_partition_sizes(instance) tilera_nfs_path = get_tilera_nfs_path(node["id"]) image_file_path = get_image_file_path(instance) deployment_key = bm_utils.random_alnum(32) db.bm_node_update( context, node["id"], { "deploy_key": deployment_key, "image_path": image_file_path, "pxe_config_path": tilera_nfs_path, "root_mb": root_mb, "swap_mb": swap_mb, }, ) if os.path.exists(image_file_path) and os.path.exists(tilera_nfs_path): utils.execute("mount", "-o", "loop", image_file_path, tilera_nfs_path, run_as_root=True)
def test_random_alnum(self): s = utils.random_alnum(10) self.assertEqual(len(s), 10) s = utils.random_alnum(100) self.assertEqual(len(s), 100)