Bug 1938 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: I53195113de8a3c4f04792742001e3d2a356b4dfd
Signed-off-by: Pedro Escaleira <escaleira@av.it.pt>
diff --git a/n2vc/utils.py b/n2vc/utils.py
index 0dbd71e..5ac0e2c 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
@@ -147,3 +149,15 @@
yaml_text = obj_to_yaml(obj)
# parse to dict
return yaml.load(yaml_text, Loader=yaml.Loader)
+
+
+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)
+ )