Skip to content

Commit

Permalink
Merge pull request #799 from galitf/fix_doc_build
Browse files Browse the repository at this point in the history
  • Loading branch information
ovirt-infra authored May 15, 2019
2 parents 74757f0 + 452eac6 commit 9803eea
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
1 change: 1 addition & 0 deletions automation/check-patch.packages
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ansible
bats
dnf
dnf-command(builddep)
gcc
git
grubby
libffi-devel
Expand Down
37 changes: 34 additions & 3 deletions lago/providers/libvirt/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

import logging

import os
from lxml import etree as ET

import lago.providers.libvirt.utils as utils
Expand Down Expand Up @@ -405,9 +405,40 @@ def get_cpus_by_arch(cls, arch):
:exc:`~LagoException`: If no such ARCH is found
"""

with open('/usr/share/libvirt/cpu_map.xml', 'r') as cpu_map:
cpu_xml = ET.parse(cpu_map)
cpu_map_xml = "/usr/share/libvirt/cpu_map.xml"
cpu_map_dir = "/usr/share/libvirt/cpu_map/"
cpu_map_index_xml = cpu_map_dir + "index.xml"
if not os.path.exists(cpu_map_xml):
cpu_xml = ET.ElementTree(
ET.fromstring(create_xml_map(cpu_map_index_xml, cpu_map_dir))
)
else:
with open(cpu_map_xml, 'r') as cpu_map:
cpu_xml = ET.parse(cpu_map)
try:
return cpu_xml.xpath('/cpus/arch[@name="{0}"]'.format(arch))[0]
except IndexError:
raise LagoException('No such arch: {0}'.format(arch))


def create_xml_map(cpu_map_index_xml, cpu_map_dir):
xml_list = []
if os.path.exists(cpu_map_index_xml):
with open(cpu_map_index_xml) as fp:
line = fp.readline()
while line:
if "include" in line:
tree = ET.fromstring(line)
for child in tree.getiterator():
if child.tag == "include":
filename = child.attrib["filename"]
with open(
cpu_map_dir + filename, 'r'
) as content_file:
for content_line in content_file:
if "cpus" not in content_line:
xml_list.append(content_line)
else:
xml_list.append(line)
line = fp.readline()
return ''.join(xml_list)
5 changes: 5 additions & 0 deletions tests/unit/lago/providers/libvirt/fixtures/cpu_map/index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<cpus>
<arch name="x86">
<include filename="x86_Penryn.xml"/>
</arch>
</cpus>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<cpus>
<model name='Penryn'>
<signature family='6' model='23'/>
<vendor name='Intel'/>
<feature name='apic'/>
</model>
</cpus>
22 changes: 21 additions & 1 deletion tests/unit/lago/providers/libvirt/test_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import lxml.etree as ET
import pytest
from xmlunittest import XmlTestCase

import os
from lago.providers.libvirt import cpu
from lago.utils import LagoInitException

Expand Down Expand Up @@ -247,3 +247,23 @@ def test_init_custom_and_model_not_allowed(self):
}
with pytest.raises(LagoInitException):
cpu.CPU(spec=spec, host_cpu=self.get_host_cpu())

def test_create_xml_string(self):
_xml = """
<cpus>
<arch name="x86">
<model name='Penryn'>
<signature family='6' model='23'/>
<vendor name='Intel'/>
<feature name='apic'/>
</model>
</arch>
</cpus>
"""
test_dir = os.path.dirname(__file__)
cpu_map_dir = test_dir + "/fixtures/cpu_map/"
cpu_map_index_xml = cpu_map_dir + "index.xml"
cpu_xml = ET.fromstring(
cpu.create_xml_map(cpu_map_index_xml, cpu_map_dir)
)
self.assertXmlEquivalentOutputs(ET.tostring(cpu_xml), _xml)

0 comments on commit 9803eea

Please sign in to comment.