From ec36b22748134f2133783d4743fe454ee4a1aabc Mon Sep 17 00:00:00 2001 From: caoyuan Date: Sun, 4 Mar 2018 22:14:10 +0800 Subject: [PATCH] Replace uuid.uuid4() with uuidutils.generate_uuid() Since oslo.utils provide the ability to generate the uuid string, and some others use oslo.utils[0] too. For consistency, this ps replaces uuid.uuid4() with uuidutils.generate_uuid(). [0]: https://github.com/openstack/qinling/blob/master/qinling/api/controllers/v1/types.py#L16 Change-Id: Iba01711dfadb36e2090926c2c7452ff62362b57b --- .../tests/unit/api/controllers/v1/test_function_worker.py | 4 ++-- qinling/utils/etcd_util.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/qinling/tests/unit/api/controllers/v1/test_function_worker.py b/qinling/tests/unit/api/controllers/v1/test_function_worker.py index 31f1397d..5f97b6bf 100644 --- a/qinling/tests/unit/api/controllers/v1/test_function_worker.py +++ b/qinling/tests/unit/api/controllers/v1/test_function_worker.py @@ -11,10 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import uuid import mock +from oslo_utils import uuidutils from qinling.tests.unit.api import base TEST_CASE_NAME = 'TestFunctionWorkerController' @@ -23,7 +23,7 @@ TEST_CASE_NAME = 'TestFunctionWorkerController' class TestFunctionWorkerController(base.APITest): @mock.patch('qinling.utils.etcd_util.get_workers') def test_get_all_workers(self, mock_get_workers): - function_id = str(uuid.uuid4()) + function_id = uuidutils.generate_uuid() mock_get_workers.return_value = ['test_worker0', 'test_worker1'] resp = self.app.get('/v1/functions/%s/workers' % function_id) diff --git a/qinling/utils/etcd_util.py b/qinling/utils/etcd_util.py index 4cacef45..c178fb5c 100644 --- a/qinling/utils/etcd_util.py +++ b/qinling/utils/etcd_util.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import uuid - import etcd3gw from oslo_config import cfg +from oslo_utils import uuidutils CONF = cfg.CONF CLIENT = None @@ -39,7 +38,7 @@ def get_worker_lock(): def create_worker(function_id, worker): client = get_client() client.create( - '%s/worker_%s' % (function_id, str(uuid.uuid4())), + '%s/worker_%s' % (function_id, uuidutils.generate_uuid()), worker )