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 = {}
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 = {}
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) ]))
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 = {}
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()
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)
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 = {}
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 = {}
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)
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()
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)
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)
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")])
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) ]))
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)
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)]))
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')])
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))
def test_get_default(self): lockutils.set_defaults(lock_path='/the/path') self.assertEqual('/the/path', lockutils.get_lock_path(self.conf))