Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 4065565

Browse files
committed
util: Break out helper for mac address validation
1 parent d8d149e commit 4065565

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

tests/clonetest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
clonexml_dir = os.path.join(os.getcwd(), "tests/clone-xml")
4343
clone_files = []
4444

45-
for f in os.listdir(clonexml_dir):
45+
for tmpf in os.listdir(clonexml_dir):
4646
black_list = [ "managed-storage", "cross-pool", "force", "skip",
4747
"fullpool"]
48-
if f.endswith("-out.xml"):
49-
f = f[0:(len(f) - len("-out.xml"))]
50-
if f not in clone_files and f not in black_list:
51-
clone_files.append(f)
48+
if tmpf.endswith("-out.xml"):
49+
tmpf = tmpf[0:(len(tmpf) - len("-out.xml"))]
50+
if tmpf not in clone_files and tmpf not in black_list:
51+
clone_files.append(tmpf)
5252

5353
conn = tests.open_testdriver()
5454

virtinst/VirtualNetworkInterface.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
1818
# MA 02110-1301 USA.
1919

20-
import re
2120
import logging
2221
import libvirt
23-
import __builtin__
2422

2523
import _util
2624
import VirtualDevice
@@ -82,17 +80,7 @@ def set_type(self, val):
8280
def get_macaddr(self):
8381
return self._macaddr
8482
def set_macaddr(self, val):
85-
if val is None:
86-
self._macaddr = None
87-
return
88-
89-
if __builtin__.type(val) is not str:
90-
raise ValueError, _("MAC address must be a string.")
91-
92-
form = re.match("^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$", val)
93-
if form is None:
94-
raise ValueError(_("MAC address must be of the format "
95-
"AA:BB:CC:DD:EE:FF"))
83+
_util.validate_macaddr(val)
9684
self._macaddr = val
9785
macaddr = property(get_macaddr, set_macaddr)
9886

virtinst/_util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ def validate_name(name_type, val):
153153
raise ValueError, _("%s name can only contain alphanumeric, '_', '.', "
154154
"or '-' characters") % name_type
155155

156+
def validate_macaddr(val):
157+
if val is None:
158+
return
159+
160+
if type(val) is not str:
161+
raise ValueError, _("MAC address must be a string.")
162+
163+
form = re.match("^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$", val)
164+
if form is None:
165+
raise ValueError(_("MAC address must be of the format "
166+
"AA:BB:CC:DD:EE:FF"))
156167
def xml_append(orig, new):
157168
"""
158169
Little function that helps generate consistent xml

0 commit comments

Comments
 (0)