def setUpClass(cls): super(ExtractCorruptArchiveTest, cls).setUpClass() cls.default_obj_name = cls.behaviors.VALID_OBJECT_NAME cls.data_dir = EngineConfig().data_directory cls.no_compression = None cls.storage_url = cls.client.storage_url cls.archive_paths = {} cls.obj_names = [] cls.obj_names_with_slashes = [] cls.obj_names_without_slashes = [] cls.num_archive_files = 20 for num in range(cls.num_archive_files): if num < 10: cls.obj_names_with_slashes.append( "{0}_test{1}/{0}_obj_{1}".format(BASE_NAME, num)) else: cls.obj_names_without_slashes.append("{0}_obj_{1}".format( BASE_NAME, num)) cls.obj_names = \ cls.obj_names_with_slashes + cls.obj_names_without_slashes tar_archive = cls.client.create_archive(cls.obj_names, None) cls.archive_paths["tar"] = tar_archive gz_archive = cls.client.create_archive(cls.obj_names, "gz") cls.archive_paths["tar.gz"] = gz_archive bz2_archive = cls.client.create_archive(cls.obj_names, "bz2") cls.archive_paths["tar.bz2"] = bz2_archive
def generate_rsa_ssh_keys(cls, keyfile_name=None, keyfile_path=None, key_size=1024, pass_phrase=""): """ Generates rsa keys """ engine_config = EngineConfig() _log = cclogging.getLogger(__name__) _log.debug( "Creating RSA keys with name: {0} inside folder: {1}".format( keyfile_name, keyfile_path)) # Build the key file names and path if keyfile_name is None: keyfile_name = "test_ssh_key_{0}".format( str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S"))) if keyfile_path is None: keyfile_path = engine_config.temp_directory pub_keyfile_path = os.path.join(keyfile_path, "{0}.pub".format(keyfile_name)) private_key_file_path = os.path.join(keyfile_path, keyfile_name) # If the key files already exist, remove them if os.path.isfile(private_key_file_path): os.remove(private_key_file_path) if os.path.isfile(pub_keyfile_path): os.remove(pub_keyfile_path) try: # Generate the keys private_key = RSA.generate(key_size) public_key = private_key.publickey() except ValueError as msg: _log.error("Key Generate exception: \n {0}".format(msg)) return SSHKeyResponse(error=msg) try: # Create the key files and write the keys onto them with open(pub_keyfile_path, "w") as public_key_file: public_key_file.write( public_key.exportKey(passphrase=pass_phrase)) if not os.path.isfile(pub_keyfile_path): return SSHKeyResponse(error="No public key file created") with open(private_key_file_path, "w") as private_key_file: private_key_file.write( private_key.exportKey(passphrase=pass_phrase)) if not os.path.isfile(private_key_file_path): return SSHKeyResponse(error="No private key file created") else: os.chmod(private_key_file_path, 0700) return SSHKeyResponse(public_key=pub_keyfile_path, private_key=private_key_file_path) except IOError as (errno, strerror): _log.error("I/O error({0}): {1}".format(errno, strerror)) return SSHKeyResponse(error=strerror)
def __init__(self, storage_url, auth_token, base_container_name=None, base_object_name=None): super(ObjectStorageAPIClient, self).__init__() self.engine_config = EngineConfig() self.storage_url = storage_url self.auth_token = auth_token self.base_container_name = base_container_name or '' self.base_object_name = base_object_name or '' self.default_headers['X-Auth-Token'] = self.auth_token
def __init__(self, product_name, test_config_file_name, engine_config_path=None): self.product_name = product_name self.test_config_file_name = test_config_file_name self.engine_config_path = engine_config_path or \ EngineConfigManager.ENGINE_CONFIG_PATH self.engine_config_interface = EngineConfig(self.engine_config_path)
def get_engine_config(): """ Get the engine config. :return: Instantiated EngineConfig object :rtype: EngineConfig """ return EngineConfig( os.environ.get("CAFE_ENGINE_CONFIG_FILE_PATH") or EngineConfigManager.ENGINE_CONFIG_PATH)
def _transfer_private_key_to_vm(cls, ssh_client, private_key, remote_file_path): pkey_file_path = os.path.join(EngineConfig().temp_directory, 'pkey') with open(pkey_file_path, "w") as private_key_file: private_key_file.write(private_key) ssh_client.transfer_file_to(pkey_file_path, remote_file_path) error = ssh_client.execute_command( 'chmod 600 {}'.format(remote_file_path)).stderr msg = ('Error changing access permission to private key file in ' 'gateway server') assert not error, msg
def __init__(self, storage_url, auth_token, base_container_name=None, base_object_name=None): super(ObjectStorageAPIClient, self).__init__() self.engine_config = EngineConfig() self.temp_dir = expanduser(self.engine_config.temp_directory) self.swift_endpoint = storage_url.split('/v1/')[0] self.storage_url = storage_url self.auth_token = auth_token self.base_container_name = base_container_name or '' self.base_object_name = base_object_name or '' self.default_headers['X-Auth-Token'] = self.auth_token self._swift_features = None
def set_test_repo_package_path(): eng_conf = EngineConfig(EngineConfigManager.ENGINE_CONFIG_PATH) test_repo_package = eng_conf.default_test_repo os.environ["CAFE_TEST_REPO_PACKAGE"] = test_repo_package module_info = None try: module_info = imp.find_module(test_repo_package) except ImportError as exception: print "Cannot find test repo '{0}'".format(test_repo_package) raise exception test_repo_path = module_info[1] os.environ["CAFE_TEST_REPO_PATH"] = test_repo_path return test_repo_path
def __init__(self, product_name, test_config_file_name, engine_config_path=None): self.product_name = product_name self.test_config_file_name = test_config_file_name self.engine_config_path = engine_config_path or \ EngineConfigManager.ENGINE_CONFIG_PATH os.environ['CAFE_ENGINE_CONFIG_FILE_PATH'] = \ self.engine_config_path self.engine_config_interface = EngineConfig(self.engine_config_path) #Property value vars self._test_repo_path = None self._test_repo_package = None self._test_data_directory = None self._test_root_log_dir = None self._test_log_dir = None self._test_logging_verbosity = None self._test_config_file_path = None self._test_master_log_file_name = None
def __init__(self, product_name, test_config_file_name, engine_config_path=None, test_repo_package_name=None): self.product_name = product_name self.test_config_file_name = test_config_file_name self._overrides_allowed = True if os.environ.get( "CAFE_ALLOW_MANAGED_ENV_VAR_OVERRIDES") is not None else False # Anything passed into the text env manager should take # precedence over environment variables, since the passed-in # parameters are used by runners, and thus are usually set at # runtime. override = self._override(self.MANAGED_VARS.test_repo_package) self._test_repo_package_name = test_repo_package_name or override override = self._override(self.MANAGED_VARS.engine_config_path) self.engine_config_path = (engine_config_path or override or EngineConfigManager.ENGINE_CONFIG_PATH) self.engine_config_interface = EngineConfig(self.engine_config_path)
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 logging import os import sys from cafe.engine.config import EngineConfig engine_config = EngineConfig() def get_object_namespace(obj): '''Attempts to return a dotted string name representation of the general form 'package.module.class.obj' for an object that has an __mro__ attribute Designed to let you to name loggers inside objects in such a way that the engine logger organizes them as child loggers to the modules they originate from. So that logging doesn't cause exceptions, if the namespace cannot be extracted from the object's mro attribute, the actual name returned is set to a probably-unique string, the id() of the object passed, and is then further improved by a series of functions until one of them fails.
import os import importlib import pkgutil from cafe.configurator.managers import EngineConfigManager from cafe.engine.config import EngineConfig ENGINE_CONFIG = EngineConfig( os.environ.get("CAFE_ENGINE_CONFIG_FILE_PATH") or EngineConfigManager.ENGINE_CONFIG_PATH) def print_configs(): config_dir = os.path.abspath( os.path.expanduser(ENGINE_CONFIG.config_directory)) for path, dirs, files in os.walk(config_dir): for file_ in files: if file_.endswith(".config"): print( os.path.join(path, file_)[len(config_dir) + len(os.sep):]) def print_imports(string): import_paths = string.strip().rsplit(".", 1) if len(import_paths) == 1: for _, module_name, _ in pkgutil.iter_modules(): if module_name.startswith(import_paths[0]): print(module_name) else: try: base = importlib.import_module(import_paths[0])
def get_engine_config_interface(): return EngineConfig(EngineConfigManager.ENGINE_CONFIG_PATH)
# 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 Crypto.PublicKey import RSA import os from cafe.engine.config import EngineConfig from cafe.engine.sshv2.common import BaseSSHClass from cafe.engine.sshv2.models import SSHKeyResponse ENGINE_CONFIG = EngineConfig() class SSHBehavior(BaseSSHClass): @classmethod def generate_rsa_ssh_keys(cls, key_size=None, pass_phrase=None): """Generates a public and private rsa ssh key Returns an SSHKeyResponse objects which has both the public and private key as attributes :param int key_size: RSA modulus length (must be a multiple of 256) and >= 1024 :param str pass_phrase: The pass phrase to derive the encryption key from """