from cinder import exception
from cinder.keymgr import key
from cinder.keymgr import key_mgr
-from cinder import utils
+from cinder.volume import utils
class MockKeyManager(key_mgr.KeyManager):
mock_reload.assert_called_once_with(fake_data)
mock_open.assert_called_once_with(fake_file)
- def test_generate_password(self):
- password = utils.generate_password()
- self.assertTrue([c for c in password if c in '0123456789'])
- self.assertTrue([c for c in password
- if c in 'abcdefghijklmnopqrstuvwxyz'])
- self.assertTrue([c for c in password
- if c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'])
-
def test_read_file_as_root(self):
def fake_execute(*args, **kwargs):
if args[1] == 'bad':
execute=fake_utils_execute)
self.assertEqual(['cgexec', '-g',
'blkio:' + CONF.volume_copy_blkio_cgroup_name], cmd)
+
+
+class VolumeUtilsTestCase(test.TestCase):
+ def test_generate_password(self):
+ password = volume_utils.generate_password()
+ self.assertTrue([c for c in password if c in '0123456789'])
+ self.assertTrue([c for c in password
+ if c in 'abcdefghijklmnopqrstuvwxyz'])
+ self.assertTrue([c for c in password
+ if c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'])
import sys
import tempfile
-from Crypto.Random import random
from oslo.config import cfg
import six
from xml.dom import minidom
return os.path.abspath(cinder.__file__).split('cinder/__init__.py')[0]
-# Default symbols to use for passwords. Avoids visually confusing characters.
-# ~6 bits per symbol
-DEFAULT_PASSWORD_SYMBOLS = ('23456789', # Removed: 0,1
- 'ABCDEFGHJKLMNPQRSTUVWXYZ', # Removed: I, O
- 'abcdefghijkmnopqrstuvwxyz') # Removed: l
-
-
-# ~5 bits per symbol
-EASIER_PASSWORD_SYMBOLS = ('23456789', # Removed: 0, 1
- 'ABCDEFGHJKLMNPQRSTUVWXYZ') # Removed: I, O
-
-
def last_completed_audit_period(unit=None):
"""This method gives you the most recently *completed* audit period.
return (begin, end)
-def generate_password(length=20, symbolgroups=DEFAULT_PASSWORD_SYMBOLS):
- """Generate a random password from the supplied symbol groups.
-
- At least one symbol from each group will be included. Unpredictable
- results if length is less than the number of symbol groups.
-
- Believed to be reasonably secure (with a reasonable password length!)
-
- """
- # NOTE(jerdfelt): Some password policies require at least one character
- # from each group of symbols, so start off with one random character
- # from each symbol group
- password = [random.choice(s) for s in symbolgroups]
- # If length < len(symbolgroups), the leading characters will only
- # be from the first length groups. Try our best to not be predictable
- # by shuffling and then truncating.
- random.shuffle(password)
- password = password[:length]
- length -= len(password)
-
- # then fill with random characters from all symbol groups
- symbols = ''.join(symbolgroups)
- password.extend([random.choice(symbols) for _i in xrange(length)])
-
- # finally shuffle to ensure first x characters aren't from a
- # predictable group
- random.shuffle(password)
-
- return ''.join(password)
-
-
-def generate_username(length=20, symbolgroups=DEFAULT_PASSWORD_SYMBOLS):
- # Use the same implementation as the password generation.
- return generate_password(length, symbolgroups)
-
-
class LazyPluggable(object):
"""A pluggable backend loaded lazily based on some value."""
from cinder.openstack.common.gettextutils import _
from cinder.openstack.common import log as logging
from cinder.openstack.common import units
-from cinder import utils
from cinder.volume import driver
from cinder.volume.drivers.hds.hnas_backend import HnasBackend
+from cinder.volume import utils
HDS_HNAS_ISCSI_VERSION = '1.0.0'
from cinder.openstack.common import log as logging
from cinder.openstack.common import loopingcall
from cinder.openstack.common import strutils
-from cinder import utils
from cinder.volume.drivers.ibm.storwize_svc import ssh as storwize_ssh
+from cinder.volume import utils
from cinder.volume import volume_types
LOG = logging.getLogger(__name__)
from cinder.openstack.common.gettextutils import _
from cinder.openstack.common import log as logging
from cinder.openstack.common import units
-from cinder import utils
from cinder.volume.driver import ISCSIDriver
+from cinder.volume import utils
from cinder.volume import volume_types
from oslo.config import cfg
from cinder.openstack.common.gettextutils import _
from cinder.openstack.common import log as logging
from cinder.openstack.common import processutils as putils
-from cinder import utils
+from cinder.volume import utils
LOG = logging.getLogger(__name__)
import math
+from Crypto.Random import random
from oslo.config import cfg
from cinder.brick.local_dev import lvm as brick_lvm
return brick_lvm.LVM.get_all_volume_groups(
utils.get_root_helper(),
vg_name)
+
+# Default symbols to use for passwords. Avoids visually confusing characters.
+# ~6 bits per symbol
+DEFAULT_PASSWORD_SYMBOLS = ('23456789', # Removed: 0,1
+ 'ABCDEFGHJKLMNPQRSTUVWXYZ', # Removed: I, O
+ 'abcdefghijkmnopqrstuvwxyz') # Removed: l
+
+
+def generate_password(length=20, symbolgroups=DEFAULT_PASSWORD_SYMBOLS):
+ """Generate a random password from the supplied symbol groups.
+
+ At least one symbol from each group will be included. Unpredictable
+ results if length is less than the number of symbol groups.
+
+ Believed to be reasonably secure (with a reasonable password length!)
+
+ """
+ # NOTE(jerdfelt): Some password policies require at least one character
+ # from each group of symbols, so start off with one random character
+ # from each symbol group
+ password = [random.choice(s) for s in symbolgroups]
+ # If length < len(symbolgroups), the leading characters will only
+ # be from the first length groups. Try our best to not be predictable
+ # by shuffling and then truncating.
+ random.shuffle(password)
+ password = password[:length]
+ length -= len(password)
+
+ # then fill with random characters from all symbol groups
+ symbols = ''.join(symbolgroups)
+ password.extend([random.choice(symbols) for _i in xrange(length)])
+
+ # finally shuffle to ensure first x characters aren't from a
+ # predictable group
+ random.shuffle(password)
+
+ return ''.join(password)
+
+
+def generate_username(length=20, symbolgroups=DEFAULT_PASSWORD_SYMBOLS):
+ # Use the same implementation as the password generation.
+ return generate_password(length, symbolgroups)