diff --git a/rdomanager_oscplugin/tests/test_util.py b/rdomanager_oscplugin/tests/test_util.py new file mode 100644 index 000000000..ca5efd1f3 --- /dev/null +++ b/rdomanager_oscplugin/tests/test_util.py @@ -0,0 +1,29 @@ +# Copyright 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, 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. +# + +from unittest import TestCase + +from rdomanager_oscplugin.v1 import util + + +class TestPasswordsUtil(TestCase): + + def test_generate_passwords(self): + + passwords = util.generate_overcloud_passwords() + passwords2 = util.generate_overcloud_passwords() + + self.assertEqual(len(passwords), 13) + self.assertNotEqual(passwords, passwords2) diff --git a/rdomanager_oscplugin/v1/util.py b/rdomanager_oscplugin/v1/util.py new file mode 100644 index 000000000..c1c0a4616 --- /dev/null +++ b/rdomanager_oscplugin/v1/util.py @@ -0,0 +1,44 @@ +# Copyright 2015 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, 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 hashlib +import six +import uuid + + +def _generate_password(): + uuid_str = six.text_type(uuid.uuid1()).encode("UTF-8") + return hashlib.sha1(uuid_str).hexdigest() + + +def generate_overcloud_passwords(): + + passwords = ( + "OVERCLOUD_ADMIN_PASSWORD", + "OVERCLOUD_ADMIN_TOKEN", + "OVERCLOUD_CEILOMETER_PASSWORD", + "OVERCLOUD_CEILOMETER_SECRET", + "OVERCLOUD_CINDER_PASSWORD", + "OVERCLOUD_DEMO_PASSWORD", + "OVERCLOUD_GLANCE_PASSWORD", + "OVERCLOUD_HEAT_PASSWORD", + "OVERCLOUD_HEAT_STACK_DOMAIN_PASSWORD", + "OVERCLOUD_NEUTRON_PASSWORD", + "OVERCLOUD_NOVA_PASSWORD", + "OVERCLOUD_SWIFT_HASH", + "OVERCLOUD_SWIFT_PASSWORD", + ) + + return dict((password, _generate_password()) for password in passwords) diff --git a/requirements.txt b/requirements.txt index 4ced6460e..91032c2de 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,7 @@ os-cloud-config python-heatclient>=0.3.0 python-ironicclient>=0.4.1 python-openstackclient>=1.0.0 +six>=1.9.0 # The ironic-discoverd OSC integration isn't yet on PyPI -e git://github.com/stackforge/ironic-discoverd.git#egg=ironic_discoverd