mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 16:36:06 +00:00
refactor(vrtManager): new VM UUIDs come from uuid.uuid4()
randomUUID() built a version 4 UUID from 16 random bytes by hand; the clone and create jobs now take str(uuid4()) from the standard library, and the function and its format test go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
f97708a7b7
commit
d2383be914
4 changed files with 5 additions and 21 deletions
|
|
@ -4,7 +4,6 @@ import unittest
|
|||
from vrtManager.util import (
|
||||
get_xml_path,
|
||||
randomPasswd,
|
||||
randomUUID,
|
||||
validate_macaddr,
|
||||
vol_dev_type,
|
||||
vol_driver_type,
|
||||
|
|
@ -13,14 +12,6 @@ from vrtManager.util import (
|
|||
|
||||
|
||||
class TestVrtManagerUtil(unittest.TestCase):
|
||||
def test_random_uuid_format(self):
|
||||
uuid_str = randomUUID()
|
||||
# UUIDv4 format check
|
||||
pattern = r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
|
||||
self.assertRegex(uuid_str, pattern)
|
||||
# Ensure successive UUIDs are distinct
|
||||
self.assertNotEqual(uuid_str, randomUUID())
|
||||
|
||||
def test_validate_macaddr(self):
|
||||
self.assertIsNone(validate_macaddr(None))
|
||||
self.assertIsNone(validate_macaddr("52:54:10:aa:bb:cc"))
|
||||
|
|
|
|||
|
|
@ -63,14 +63,6 @@ class HostBusy(ConnectionFailed):
|
|||
(HOST_REQUESTS) still wait for its answers."""
|
||||
|
||||
|
||||
def randomUUID():
|
||||
"""Generate a random UUID."""
|
||||
u = [secrets.randbelow(256) for _ in range(16)]
|
||||
u[6] = u[6] & 15 | 4 << 4
|
||||
u[8] = u[8] & 63 | 2 << 6
|
||||
return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2, "%02x" * 6]) % tuple(u)
|
||||
|
||||
|
||||
def randomPasswd(length=12, alphabet=string.ascii_letters + string.digits):
|
||||
"""Generate a random password"""
|
||||
return "".join([secrets.choice(alphabet) for _ in range(length)])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue