Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
11 deletions
+22
-11
circle/dashboard/virtvalidator.py
+22
-11
No files found.
circle/dashboard/virtvalidator.py
View file @
d5c535da
from
django.core.exceptions
import
ValidationError
from
lxml
import
etree
as
ET
import
logging
rng_file
=
"/usr/share/libvirt/schemas/domain.rng"
header
=
"""<domain type='kvm'>
<name>validator</name>
<memory unit='KiB'>1024</memory>
<os>
<type>hvm</type>
</os>"""
footer
=
"""</domain>"""
# Mandatory xml elements dor parsing
header
=
"<domain type='kvm'><name>validator</name>
\
<memory unit='KiB'>1024</memory>
\
<os><type>hvm</type></os>"
footer
=
"</domain>"
logger
=
logging
.
getLogger
()
def
domain_validator
(
value
):
xml
=
header
+
value
+
footer
relaxng
=
ET
.
RelaxNG
(
file
=
rng_file
)
if
not
relaxng
.
validate
(
ET
.
fromstring
(
xml
)):
raise
ValidationError
(
"
%
s is not valid libvirt Domain xml."
%
value
)
try
:
parsed_xml
=
ET
.
fromstring
(
xml
)
except
Exception
as
e
:
raise
ValidationError
(
e
.
message
)
try
:
relaxng
=
ET
.
RelaxNG
(
file
=
rng_file
)
except
:
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