def test_setup_memory_default(self): dimm_device = memory.Memory() dimm_device.setup_attrs(**dimm_device_attrs) cmp_device = memory.Memory() cmp_device.xml = XML.strip() self.assertEqual(dimm_device, cmp_device)
def create_mem_xml(): """ Create memory device xml. """ mem_xml = memory.Memory() mem_model = params.get("mem_model", "dimm") mem_xml.mem_model = mem_model if tg_size: tg_xml = memory.Memory.Target() tg_xml.size = int(tg_size) tg_xml.size_unit = tg_sizeunit # There is support for non-numa node if numa_cells: tg_xml.node = int(tg_node) mem_xml.target = tg_xml if pg_size: src_xml = memory.Memory.Source() src_xml.pagesize = int(pg_size) src_xml.pagesize_unit = pg_unit src_xml.nodemask = node_mask mem_xml.source = src_xml if mem_addr: mem_xml.address = mem_xml.new_mem_address(**{"attrs": mem_addr}) logging.debug("Memory device xml: %s", mem_xml) return mem_xml.copy()
def create_mem_hotplug_xml(mem_size, mem_unit, numa_node='', mem_model='dimm'): """ Forms and return memory device xml for hotplugging :param mem_size: memory to be hotplugged :param mem_unit: unit for memory size :param numa_node: numa node to which memory is hotplugged :param mem_model: memory model to be hotplugged :return: xml with memory device """ mem_xml = memory.Memory() mem_xml.mem_model = mem_model target_xml = memory.Memory.Target() target_xml.size = mem_size target_xml.size_unit = mem_unit if numa_node: target_xml.node = int(numa_node) mem_xml.target = target_xml logging.debug(mem_xml) mem_xml_file = os.path.join(data_dir.get_tmp_dir(), 'memory_hotplug.xml') try: fp = open(mem_xml_file, 'w') except Exception, info: raise exceptions.TestError(info)
def create_mem_xml(tg_size, pg_size=None, mem_addr=None, tg_sizeunit="KiB", pg_unit="KiB", tg_node=0, node_mask=0, mem_model="dimm", lb_size=None, lb_sizeunit="Kib", mem_access=None): """ Create memory device xml. Parameters: :param tg_size: Target hotplug memory size :param pg_size: Source page size in case of hugepages backed. :param mem_addr: Memory address to be mapped in guest. :param tg_sizeunit: Target size unit, Default=KiB. :param pg_unit: Source page size unit, Default=KiB. :param tg_node: Target node to hotplug. :param node_mask: Source node for hotplug. :param mem_model: Memory Model, Default="dimm". :param lb_size: Label size in Target :param lb_sizeunit: Label size unit, Default=KiB :param mem_access: Value of attrib 'access' of memory :return: Returns a copy of Memory Hotplug xml instance. """ mem_xml = memory.Memory() mem_xml.mem_model = mem_model if tg_size: tg_xml = memory.Memory.Target() tg_xml.size = int(tg_size) tg_xml.size_unit = tg_sizeunit if tg_node != "": tg_xml.node = int(tg_node) if lb_size: lb_xml = memory.Memory.Target.Label() lb_xml.size = int(lb_size) lb_xml.size_unit = lb_sizeunit tg_xml.label = lb_xml mem_xml.target = tg_xml if pg_size: src_xml = memory.Memory.Source() src_xml.pagesize = int(pg_size) src_xml.pagesize_unit = pg_unit src_xml.nodemask = node_mask mem_xml.source = src_xml if mem_addr: mem_xml.address = mem_xml.new_mem_address(**{"attrs": mem_addr}) if mem_access: mem_xml.mem_access = mem_access logging.debug("Memory device xml: %s", mem_xml) return mem_xml.copy()
def setup_test_pmem_alignsize(guest_xml, params): """ Setup steps for pmem and alignsize test :param guest_xml: guest xml :param params: dict, test parameters :return: the updated guest xml """ vm_attrs = eval(params.get('vm_attrs', '{}')) mem_device_attrs = eval(params.get('mem_device_attrs', '{}')) if vm_attrs: guest_xml.setup_attrs(**vm_attrs) if mem_device_attrs: mem_device = memory.Memory() mem_device.setup_attrs(**mem_device_attrs) guest_xml.add_device(mem_device) guest_xml.sync() return guest_xml
def create_mem_xml(tg_size, pg_size=None, mem_addr=None, tg_sizeunit="KiB", pg_unit="KiB", tg_node=0, node_mask=0, mem_model="dimm", mem_discard=None, alias=None, lb_size=None, lb_sizeunit="Kib", mem_access=None, uuid=None): """ Create memory device xml. This function is deprecated now. The recommended usage is below: Define a parameter in cfg like mem_device_attrs = {'mem_model': 'dimm', 'target': {'size': 512, 'size_unit': 'KiB', 'node': 1}} Set up the device in python like mem_device_attrs = eval(params.get('mem_device_attrs', '{}')) mem_device = Memory() mem_device.setup_attrs(**mem_device_attrs) Parameters: :param tg_size: Target hotplug memory size :param pg_size: Source page size in case of hugepages backed. :param mem_addr: Memory address to be mapped in guest. :param tg_sizeunit: Target size unit, Default=KiB. :param pg_unit: Source page size unit, Default=KiB. :param tg_node: Target node to hotplug. :param node_mask: Source node for hotplug. :param mem_model: Memory Model, Default="dimm". :param mem_discard: discard, Default="no". :param lb_size: Label size in Target :param lb_sizeunit: Label size unit, Default=KiB :param mem_access: Value of attrib 'access' of memory :param uuid: Value of attrib 'uuid' of memory :return: Returns a copy of Memory Hotplug xml instance. """ LOG.warning("This function is deprecated now. See more details in docstring") mem_xml = memory.Memory() mem_xml.mem_model = mem_model if tg_size: tg_xml = memory.Memory.Target() tg_xml.size = int(tg_size) tg_xml.size_unit = tg_sizeunit if tg_node != "": tg_xml.node = int(tg_node) if lb_size: lb_xml = memory.Memory.Target.Label() lb_xml.size = int(lb_size) lb_xml.size_unit = lb_sizeunit tg_xml.label = lb_xml mem_xml.target = tg_xml if pg_size: src_xml = memory.Memory.Source() src_xml.pagesize = int(pg_size) src_xml.pagesize_unit = pg_unit src_xml.nodemask = node_mask mem_xml.source = src_xml if mem_discard: mem_xml.mem_discard = mem_discard if mem_addr: mem_xml.address = mem_xml.new_mem_address( **{"attrs": mem_addr}) if mem_access: mem_xml.mem_access = mem_access if alias: mem_xml.alias = dict(name=alias) if uuid: mem_xml.uuid = uuid LOG.debug("Memory device xml: %s", mem_xml) return mem_xml.copy()
def test_fetch_attrs_memory_default(self): dimm_device = memory.Memory() dimm_device.xml = XML.strip() self.assertEqual(dimm_device_attrs, dimm_device.fetch_attrs())