Bug 1939 fixed: : added a random suffix to the end of the Juju app name, in order to allow multiple Juju charms per VDU
I followed the second option of the bug's description. Now, Juju
applications have a random suffix with size=5 (the random suffix
size used by K8s), in order to avoid collisions between applications'
names;
Also fixed unit-test on test_n2vc_juju_conn.py
Change-Id: I5d3eb8282889e58361f7c21214b11071a7530d26
Signed-off-by: Pedro Escaleira <escaleira@av.it.pt>
diff --git a/n2vc/utils.py b/n2vc/utils.py
index a661e05..286f0fc 100644
--- a/n2vc/utils.py
+++ b/n2vc/utils.py
@@ -16,6 +16,8 @@
import re
import binascii
import yaml
+import string
+import secrets
from enum import Enum
from juju.machine import Machine
from juju.application import Application
@@ -163,3 +165,15 @@
application_name = parts[1]
machine_id = parts[2]
return model_name, application_name, machine_id
+
+
+def generate_random_alfanum_string(size: int) -> str:
+ """
+ Generate random alfa-numeric string with a size given by argument
+ :param size:
+ :return: random generated string
+ """
+
+ return "".join(
+ secrets.choice(string.ascii_letters + string.digits) for i in range(size)
+ )