Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d5c535da
authored
Jul 23, 2014
by
Guba Sándor
Committed by
Őry Máté
Jul 28, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add exception handling
parent
842b98c9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
10 deletions
+21
-10
circle/dashboard/virtvalidator.py
+21
-10
No files found.
circle/dashboard/virtvalidator.py
View file @
d5c535da
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
lxml
import
etree
as
ET
from
lxml
import
etree
as
ET
import
logging
rng_file
=
"/usr/share/libvirt/schemas/domain.rng"
rng_file
=
"/usr/share/libvirt/schemas/domain.rng"
header
=
"""<domain type='kvm'>
# Mandatory xml elements dor parsing
<name>validator</name>
header
=
"<domain type='kvm'><name>validator</name>
\
<memory unit='KiB'>1024</memory>
<memory unit='KiB'>1024</memory>
\
<os>
<os><type>hvm</type></os>"
<type>hvm</type>
footer
=
"</domain>"
</os>"""
footer
=
"""</domain>"""
logger
=
logging
.
getLogger
()
def
domain_validator
(
value
):
def
domain_validator
(
value
):
xml
=
header
+
value
+
footer
xml
=
header
+
value
+
footer
try
:
parsed_xml
=
ET
.
fromstring
(
xml
)
except
Exception
as
e
:
raise
ValidationError
(
e
.
message
)
try
:
relaxng
=
ET
.
RelaxNG
(
file
=
rng_file
)
relaxng
=
ET
.
RelaxNG
(
file
=
rng_file
)
if
not
relaxng
.
validate
(
ET
.
fromstring
(
xml
)):
except
:
raise
ValidationError
(
"
%
s is not valid libvirt Domain xml."
%
value
)
logger
.
critical
(
"
%
s RelaxNG libvirt domain schema file "
"is missing for validation."
,
rng_file
)
else
:
try
:
relaxng
.
assertValid
(
parsed_xml
)
except
Exception
as
e
:
raise
ValidationError
(
e
.
message
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment