09413022b1
Introduces base classes and utilities for setting up the system in specific configurations that are suitable for testing different different system and host configurations. The base classes are used by a new set of Puppet plugin unit tests to improve the test coverage of the puppet plugins. Additional unit tests will be required to test specific features of each plugin that is domain specific or based on a specific deployment configuration. Also includes a required change for Python 3 compatibility to permit py35 tox tests to pass. Change-Id: Id4aa51ce1a8b66987d6f74a8994f989800243b61 Story: 2005939 Task: 35947 Signed-off-by: Matt Peters <matt.peters@windriver.com>
41 lines
1011 B
Python
41 lines
1011 B
Python
# Copyright (c) 2019 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
import fixtures
|
|
import keyring
|
|
|
|
|
|
class TestKeyring(keyring.backend.KeyringBackend):
|
|
"""A faked keyring for testing."""
|
|
def __init__(self):
|
|
self.passwords = {}
|
|
|
|
def supported(self):
|
|
return 0
|
|
|
|
def get_password(self, service, username):
|
|
try:
|
|
return self.passwords[(service, username)]
|
|
except KeyError:
|
|
return None
|
|
|
|
def set_password(self, service, username, password):
|
|
self.passwords[(service, username)] = password
|
|
return 0
|
|
|
|
def delete_password(self, service, username):
|
|
try:
|
|
del self.passwords[(service, username)]
|
|
except KeyError:
|
|
raise keyring.errors.PasswordDeleteError("not set")
|
|
|
|
|
|
class KeyringBackend(fixtures.Fixture):
|
|
"""Fixture to create and set keyring backend."""
|
|
|
|
def setUp(self):
|
|
super(KeyringBackend, self).setUp()
|
|
keyring.set_keyring(TestKeyring())
|