Use uuid.uuid4 to generate model name
Take the last 12 characters from a uuid for generating the model name. uuid.uuid4 takes into account the host and the current timestamp and should be sufficient for our needs.
This commit is contained in:
@@ -7,8 +7,10 @@ import unit_tests.utils as ut_utils
|
||||
class TestCharmLifecycleFuncTestRunner(ut_utils.BaseTestCase):
|
||||
|
||||
def test_generate_model_name(self):
|
||||
mname = lc_func_test_runner.generate_model_name()
|
||||
self.assertTrue(mname.startswith('zaza-'))
|
||||
self.patch_object(lc_func_test_runner.uuid, "uuid4")
|
||||
self.uuid4.return_value = "longer-than-12characters"
|
||||
self.assertEqual(lc_func_test_runner.generate_model_name(),
|
||||
"zaza-12characters")
|
||||
|
||||
def test_parser(self):
|
||||
# Test defaults
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
import zaza.charm_lifecycle.configure as configure
|
||||
import zaza.charm_lifecycle.destroy as destroy
|
||||
@@ -14,8 +14,7 @@ import zaza.charm_lifecycle.test as test
|
||||
|
||||
|
||||
def generate_model_name():
|
||||
timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
|
||||
return 'zaza-{}'.format(timestamp)
|
||||
return 'zaza-{}'.format(str(uuid.uuid4())[-12:])
|
||||
|
||||
|
||||
def func_test_runner(keep_model=False, smoke=False):
|
||||
|
||||
Reference in New Issue
Block a user