Пример #1
0
 def __init__(self, path=None):
     lockutils.get_lock_path(CONF)
     self.path = path or os.path.join(
         os.path.expanduser("~"), ".tempest", "workspace.yaml")
     if not os.path.isdir(os.path.dirname(self.path)):
         os.makedirs(self.path.rsplit(os.path.sep, 1)[0])
     self.workspaces = {}
Пример #2
0
 def __init__(self, path=None):
     lockutils.get_lock_path(CONF)
     self.path = path or os.path.join(os.path.expanduser("~"), ".tempest",
                                      "workspace.yaml")
     if not os.path.isdir(os.path.dirname(self.path)):
         os.makedirs(self.path.rsplit(os.path.sep, 1)[0])
     self.workspaces = {}
Пример #3
0
def _get_preprov_provider_params():
    _common_params = _get_common_provider_params()
    reseller_admin_role = CONF.object_storage.reseller_admin_role
    return dict(_common_params, **dict([
        ('accounts_lock_dir', lockutils.get_lock_path(CONF)),
        ('test_accounts_file', CONF.auth.test_accounts_file),
        ('object_storage_operator_role', CONF.object_storage.operator_role),
        ('object_storage_reseller_admin_role', reseller_admin_role)
    ]))
Пример #4
0
 def __init__(self, identity_version=None, name=None):
     super(Accounts, self).__init__(identity_version=identity_version, name=name)
     if CONF.auth.test_accounts_file and os.path.isfile(CONF.auth.test_accounts_file):
         accounts = read_accounts_yaml(CONF.auth.test_accounts_file)
         self.use_default_creds = False
     else:
         accounts = {}
         self.use_default_creds = True
     self.hash_dict = self.get_hash_dict(accounts)
     self.accounts_dir = os.path.join(lockutils.get_lock_path(CONF), "test_accounts")
     self._creds = {}
Пример #5
0
 def test_remove_hash_not_last_account(self, lock_mock):
     hash_list = self._get_hash_list(self.test_accounts)
     # Pretend the pseudo-lock is there
     self.useFixture(mockpatch.Patch("os.path.isfile", return_value=True))
     # Pretend the lock dir is empty
     self.useFixture(mockpatch.Patch("os.listdir", return_value=[hash_list[1], hash_list[4]]))
     test_account_class = accounts.Accounts("v2", "test_name")
     remove_mock = self.useFixture(mockpatch.Patch("os.remove"))
     rmdir_mock = self.useFixture(mockpatch.Patch("os.rmdir"))
     test_account_class.remove_hash(hash_list[2])
     hash_path = os.path.join(lockutils.get_lock_path(accounts.CONF), "test_accounts", hash_list[2])
     remove_mock.mock.assert_called_once_with(hash_path)
     rmdir_mock.mock.assert_not_called()
Пример #6
0
 def test_get_free_hash_no_previous_accounts(self, lock_mock):
     # Emulate no pre-existing lock
     self.useFixture(mockpatch.Patch("os.path.isdir", return_value=False))
     hash_list = self._get_hash_list(self.test_accounts)
     mkdir_mock = self.useFixture(mockpatch.Patch("os.mkdir"))
     self.useFixture(mockpatch.Patch("os.path.isfile", return_value=False))
     test_account_class = accounts.Accounts("v2", "test_name")
     with mock.patch("six.moves.builtins.open", mock.mock_open(), create=True) as open_mock:
         test_account_class._get_free_hash(hash_list)
         lock_path = os.path.join(lockutils.get_lock_path(accounts.CONF), "test_accounts", hash_list[0])
         open_mock.assert_called_once_with(lock_path, "w")
     mkdir_path = os.path.join(accounts.CONF.oslo_concurrency.lock_path, "test_accounts")
     mkdir_mock.mock.assert_called_once_with(mkdir_path)
Пример #7
0
 def __init__(self, identity_version=None, name=None):
     super(Accounts, self).__init__(identity_version=identity_version,
                                    name=name)
     if (CONF.auth.test_accounts_file and
             os.path.isfile(CONF.auth.test_accounts_file)):
         accounts = read_accounts_yaml(CONF.auth.test_accounts_file)
         self.use_default_creds = False
     else:
         accounts = {}
         self.use_default_creds = True
     self.hash_dict = self.get_hash_dict(accounts)
     self.accounts_dir = os.path.join(lockutils.get_lock_path(CONF),
                                      'test_accounts')
     self.isolated_creds = {}
Пример #8
0
 def __init__(self, identity_version, name=None, credentials_domain=None):
     super(PreProvisionedCredentialProvider, self).__init__(
         identity_version=identity_version, name=name,
         credentials_domain=credentials_domain)
     if (CONF.auth.test_accounts_file and
             os.path.isfile(CONF.auth.test_accounts_file)):
         accounts = read_accounts_yaml(CONF.auth.test_accounts_file)
         self.use_default_creds = False
     else:
         accounts = {}
         self.use_default_creds = True
     self.hash_dict = self.get_hash_dict(accounts)
     self.accounts_dir = os.path.join(lockutils.get_lock_path(CONF),
                                      'test_accounts')
     self._creds = {}
Пример #9
0
 def test_get_free_hash_no_previous_accounts(self, lock_mock):
     # Emulate no pre-existing lock
     self.useFixture(mockpatch.Patch('os.path.isdir', return_value=False))
     hash_list = self._get_hash_list(self.test_accounts)
     mkdir_mock = self.useFixture(mockpatch.Patch('os.mkdir'))
     self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))
     test_account_class = accounts.Accounts('v2', 'test_name')
     with mock.patch('__builtin__.open', mock.mock_open(),
                     create=True) as open_mock:
         test_account_class._get_free_hash(hash_list)
         lock_path = os.path.join(lockutils.get_lock_path(accounts.CONF),
                                  'test_accounts', hash_list[0])
         open_mock.assert_called_once_with(lock_path, 'w')
     mkdir_path = os.path.join(accounts.CONF.oslo_concurrency.lock_path,
                               'test_accounts')
     mkdir_mock.mock.assert_called_once_with(mkdir_path)
Пример #10
0
 def test_remove_hash_not_last_account(self, lock_mock):
     hash_list = self._get_hash_list(self.test_accounts)
     # Pretend the pseudo-lock is there
     self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
     # Pretend the lock dir is empty
     self.useFixture(mockpatch.Patch('os.listdir', return_value=[
         hash_list[1], hash_list[4]]))
     test_account_class = accounts.Accounts('v2', 'test_name')
     remove_mock = self.useFixture(mockpatch.Patch('os.remove'))
     rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))
     test_account_class.remove_hash(hash_list[2])
     hash_path = os.path.join(lockutils.get_lock_path(accounts.CONF),
                              'test_accounts',
                              hash_list[2])
     remove_mock.mock.assert_called_once_with(hash_path)
     rmdir_mock.mock.assert_not_called()
Пример #11
0
 def test_remove_hash_last_account(self, lock_mock):
     hash_list = self._get_hash_list(self.test_accounts)
     # Pretend the pseudo-lock is there
     self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
     # Pretend the lock dir is empty
     self.useFixture(mockpatch.Patch('os.listdir', return_value=[]))
     test_account_class = accounts.Accounts('v2', 'test_name')
     remove_mock = self.useFixture(mockpatch.Patch('os.remove'))
     rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))
     test_account_class.remove_hash(hash_list[2])
     hash_path = os.path.join(lockutils.get_lock_path(accounts.CONF),
                              'test_accounts',
                              hash_list[2])
     lock_path = os.path.join(accounts.CONF.oslo_concurrency.lock_path,
                              'test_accounts')
     remove_mock.mock.assert_called_once_with(hash_path)
     rmdir_mock.mock.assert_called_once_with(lock_path)
 def test_remove_hash_not_last_account(self, lock_mock):
     hash_list = self._get_hash_list(self.test_accounts)
     # Pretend the pseudo-lock is there
     self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
     # Pretend the lock dir is empty
     self.useFixture(mockpatch.Patch('os.listdir', return_value=[
         hash_list[1], hash_list[4]]))
     test_account_class = preprov_creds.PreProvisionedCredentialProvider(
         **self.fixed_params)
     remove_mock = self.useFixture(mockpatch.Patch('os.remove'))
     rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))
     test_account_class.remove_hash(hash_list[2])
     hash_path = os.path.join(lockutils.get_lock_path(preprov_creds.CONF),
                              'test_accounts',
                              hash_list[2])
     remove_mock.mock.assert_called_once_with(hash_path)
     rmdir_mock.mock.assert_not_called()
 def test_get_free_hash_no_previous_accounts(self, lock_mock):
     # Emulate no pre-existing lock
     self.useFixture(mockpatch.Patch('os.path.isdir', return_value=False))
     hash_list = self._get_hash_list(self.test_accounts)
     mkdir_mock = self.useFixture(mockpatch.Patch('os.mkdir'))
     self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))
     test_account_class = preprov_creds.PreProvisionedCredentialProvider(
         **self.fixed_params)
     with mock.patch('six.moves.builtins.open', mock.mock_open(),
                     create=True) as open_mock:
         test_account_class._get_free_hash(hash_list)
         lock_path = os.path.join(lockutils.get_lock_path(
             preprov_creds.CONF), 'test_accounts', hash_list[0])
         open_mock.assert_called_once_with(lock_path, 'w')
     mkdir_path = os.path.join(
         preprov_creds.CONF.oslo_concurrency.lock_path, 'test_accounts')
     mkdir_mock.mock.assert_called_once_with(mkdir_path)
Пример #14
0
 def test_remove_hash_last_account(self, lock_mock):
     hash_list = self._get_hash_list(self.test_accounts)
     # Pretend the pseudo-lock is there
     self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))
     # Pretend the lock dir is empty
     self.useFixture(mockpatch.Patch('os.listdir', return_value=[]))
     test_account_class = preprov_creds.PreProvisionedCredentialProvider(
         'v2', 'test_name')
     remove_mock = self.useFixture(mockpatch.Patch('os.remove'))
     rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))
     test_account_class.remove_hash(hash_list[2])
     hash_path = os.path.join(lockutils.get_lock_path(preprov_creds.CONF),
                              'test_accounts', hash_list[2])
     lock_path = os.path.join(preprov_creds.CONF.oslo_concurrency.lock_path,
                              'test_accounts')
     remove_mock.mock.assert_called_once_with(hash_path)
     rmdir_mock.mock.assert_called_once_with(lock_path)
Пример #15
0
 def test_get_free_hash_no_previous_accounts(self, lock_mock):
     # Emulate no pre-existing lock
     self.useFixture(mockpatch.Patch('os.path.isdir', return_value=False))
     hash_list = self._get_hash_list(self.test_accounts)
     mkdir_mock = self.useFixture(mockpatch.Patch('os.mkdir'))
     self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))
     test_account_class = accounts.Accounts('v2', 'test_name')
     with mock.patch('__builtin__.open', mock.mock_open(),
                     create=True) as open_mock:
         test_account_class._get_free_hash(hash_list)
         lock_path = os.path.join(lockutils.get_lock_path(accounts.CONF),
                                  'test_accounts',
                                  hash_list[0])
         open_mock.assert_called_once_with(lock_path, 'w')
     mkdir_path = os.path.join(accounts.CONF.oslo_concurrency.lock_path,
                               'test_accounts')
     mkdir_mock.mock.assert_called_once_with(mkdir_path)
Пример #16
0
    def test_get_free_hash_some_in_use_accounts(self, lock_mock):
        # Emulate no pre-existing lock
        self.useFixture(mockpatch.Patch("os.path.isdir", return_value=True))
        hash_list = self._get_hash_list(self.test_accounts)
        test_account_class = accounts.Accounts("v2", "test_name")

        def _fake_is_file(path):
            # Fake isfile() to return that the path exists unless a specific
            # hash is in the path
            if hash_list[3] in path:
                return False
            return True

        self.stubs.Set(os.path, "isfile", _fake_is_file)
        with mock.patch("six.moves.builtins.open", mock.mock_open(), create=True) as open_mock:
            test_account_class._get_free_hash(hash_list)
            lock_path = os.path.join(lockutils.get_lock_path(accounts.CONF), "test_accounts", hash_list[3])
            open_mock.assert_has_calls([mock.call(lock_path, "w")])
Пример #17
0
def get_preprov_provider_params(identity_version):
    """Pre-provisioned provider parameters setup from config

    This helper returns a dict of parameter that can be used to initialise
    a `PreProvisionedCredentialProvider` according to tempest configuration.
    Parameters that are not configuration specific (name) are not returned.

    :param identity_version: 'v2' or 'v3'
    :return: A dict with the parameters
    """
    _common_params = _get_common_provider_params(identity_version)
    reseller_admin_role = CONF.object_storage.reseller_admin_role
    return dict(_common_params, **dict([
        ('accounts_lock_dir', lockutils.get_lock_path(CONF)),
        ('test_accounts_file', CONF.auth.test_accounts_file),
        ('object_storage_operator_role', CONF.object_storage.operator_role),
        ('object_storage_reseller_admin_role', reseller_admin_role)
    ]))
Пример #18
0
 def test_get_free_hash_no_previous_accounts(self, lock_mock):
     # Emulate no pre-existing lock
     self.useFixture(mockpatch.Patch('os.path.isdir', return_value=False))
     hash_list = self._get_hash_list(self.test_accounts)
     mkdir_mock = self.useFixture(mockpatch.Patch('os.mkdir'))
     self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))
     test_account_class = preprov_creds.PreProvisionedCredentialProvider(
         **self.fixed_params)
     with mock.patch('six.moves.builtins.open',
                     mock.mock_open(),
                     create=True) as open_mock:
         test_account_class._get_free_hash(hash_list)
         lock_path = os.path.join(
             lockutils.get_lock_path(preprov_creds.CONF), 'test_accounts',
             hash_list[0])
         open_mock.assert_called_once_with(lock_path, 'w')
     mkdir_path = os.path.join(
         preprov_creds.CONF.oslo_concurrency.lock_path, 'test_accounts')
     mkdir_mock.mock.assert_called_once_with(mkdir_path)
Пример #19
0
def get_preprov_provider_params(identity_version):
    """Pre-provisioned provider parameters setup from config

    This helper returns a dict of parameter that can be used to initialise
    a `PreProvisionedCredentialProvider` according to tempest configuration.
    Parameters that are not configuration specific (name) are not returned.

    :param identity_version: 'v2' or 'v3'
    :return: A dict with the parameters
    """
    _common_params = _get_common_provider_params(identity_version)
    reseller_admin_role = CONF.object_storage.reseller_admin_role
    return dict(
        _common_params,
        **dict([('accounts_lock_dir', lockutils.get_lock_path(CONF)),
                ('test_accounts_file', CONF.auth.test_accounts_file),
                ('object_storage_operator_role',
                 CONF.object_storage.operator_role),
                ('object_storage_reseller_admin_role', reseller_admin_role)]))
Пример #20
0
    def test_get_free_hash_some_in_use_accounts(self, lock_mock):
        # Emulate no pre-existing lock
        self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))
        hash_list = self._get_hash_list(self.test_accounts)
        test_account_class = accounts.Accounts('v2', 'test_name')

        def _fake_is_file(path):
            # Fake isfile() to return that the path exists unless a specific
            # hash is in the path
            if hash_list[3] in path:
                return False
            return True

        self.stubs.Set(os.path, 'isfile', _fake_is_file)
        with mock.patch('__builtin__.open', mock.mock_open(),
                        create=True) as open_mock:
            test_account_class._get_free_hash(hash_list)
            lock_path = os.path.join(lockutils.get_lock_path(accounts.CONF),
                                     'test_accounts', hash_list[3])
            open_mock.assert_has_calls([mock.call(lock_path, 'w')])
    def test_get_free_hash_some_in_use_accounts(self, lock_mock):
        # Emulate no pre-existing lock
        self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))
        hash_list = self._get_hash_list(self.test_accounts)
        test_account_class = preprov_creds.PreProvisionedCredentialProvider(
            **self.fixed_params)

        def _fake_is_file(path):
            # Fake isfile() to return that the path exists unless a specific
            # hash is in the path
            if hash_list[3] in path:
                return False
            return True

        self.stubs.Set(os.path, 'isfile', _fake_is_file)
        with mock.patch('six.moves.builtins.open', mock.mock_open(),
                        create=True) as open_mock:
            test_account_class._get_free_hash(hash_list)
            lock_path = os.path.join(
                lockutils.get_lock_path(preprov_creds.CONF),
                'test_accounts', hash_list[3])
            open_mock.assert_has_calls([mock.call(lock_path, 'w')])
Пример #22
0
    def test_get_free_hash_some_in_use_accounts(self, lock_mock):
        # Emulate no pre-existing lock
        self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))
        hash_list = self._get_hash_list(self.test_accounts)
        test_account_class = preprov_creds.PreProvisionedCredentialProvider(
            **self.fixed_params)

        def _fake_is_file(path):
            # Fake isfile() to return that the path exists unless a specific
            # hash is in the path
            if hash_list[3] in path:
                return False
            return True

        self.stubs.Set(os.path, 'isfile', _fake_is_file)
        with mock.patch('six.moves.builtins.open',
                        mock.mock_open(),
                        create=True) as open_mock:
            test_account_class._get_free_hash(hash_list)
            lock_path = os.path.join(
                lockutils.get_lock_path(preprov_creds.CONF), 'test_accounts',
                hash_list[3])
            open_mock.assert_has_calls([mock.call(lock_path, 'w')])
Пример #23
0
 def test_get_override(self):
     lockutils._register_opts(self.conf)
     self.conf.set_override('lock_path', '/alternate/path',
                            group='oslo_concurrency')
     self.assertEqual('/alternate/path', lockutils.get_lock_path(self.conf))
Пример #24
0
 def test_get_default(self):
     lockutils.set_defaults(lock_path='/the/path')
     self.assertEqual('/the/path', lockutils.get_lock_path(self.conf))
Пример #25
0
 def test_get_default(self):
     lockutils.set_defaults(lock_path='/the/path')
     self.assertEqual('/the/path', lockutils.get_lock_path(self.conf))
Пример #26
0
 def test_get_override(self):
     lockutils._register_opts(self.conf)
     self.conf.set_override('lock_path',
                            '/alternate/path',
                            group='oslo_concurrency')
     self.assertEqual('/alternate/path', lockutils.get_lock_path(self.conf))