From c9227f7920eadaaf28d481246a246d07386765e5 Mon Sep 17 00:00:00 2001 From: Jose Idar Date: Mon, 26 Aug 2013 18:39:16 -0500 Subject: [PATCH] Refactor to support changes made in engine config overhaul * Updated all files to reflect changes in engine configuration overhaul. * Cleaned up post-install processes and improved post-install reporting of where configs are being copied to. * Moved ConfigSectionInterface class to opencafe Change-Id: If0ddf88563c3ff7cf9971221e19b5f4666db295f --- MANIFEST.in | 1 + cloudcafe/__init__.py | 4 +- cloudcafe/common/models/configuration.py | 33 +---- metatests/conftest.py | 10 +- metatests/unittest.json.config | 2 +- pip-requires | 2 +- setup.py | 170 ++++++++++++----------- unittest.engine.config | 2 + unittest.json.config | 2 - 9 files changed, 97 insertions(+), 129 deletions(-) create mode 100644 MANIFEST.in create mode 100644 unittest.engine.config delete mode 100644 unittest.json.config diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..000f6d47 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include LICENSE README* \ No newline at end of file diff --git a/cloudcafe/__init__.py b/cloudcafe/__init__.py index 8bc91168..85a43303 100644 --- a/cloudcafe/__init__.py +++ b/cloudcafe/__init__.py @@ -15,8 +15,6 @@ limitations under the License. """ __title__ = 'cloudcafe' -__version__ = '0.0.1' -#__build__ = 0x010100 __author__ = 'Rackspace Cloud QE' -__license__ = 'Internal Only' +__license__ = 'Apache License Version 2.0' __copyright__ = 'Copyright 2013 Rackspace Inc.' diff --git a/cloudcafe/common/models/configuration.py b/cloudcafe/common/models/configuration.py index 8f4fcc1d..e16467ef 100644 --- a/cloudcafe/common/models/configuration.py +++ b/cloudcafe/common/models/configuration.py @@ -14,36 +14,5 @@ See the License for the specific language governing permissions and limitations under the License. """ -import os from cafe.engine.models.data_interfaces import\ - BaseConfigSectionInterface, ConfigEnvironmentVariableError - -_TEST_CONFIG_FILE_ENV_VAR = 'CONFIG_FILE' - - -class ConfigSectionInterface(BaseConfigSectionInterface): - def __init__(self, config_file_path=None, section_name=None): - section_name = (section_name or - getattr(self, 'SECTION_NAME', None) or - getattr(self, 'CONFIG_SECTION_NAME', None)) - - config_file_path = config_file_path or self.default_config_file - - super(ConfigSectionInterface, self).__init__(config_file_path, - section_name) - - @property - def default_config_file(self): - test_config_file_path = None - try: - test_config_file_path = os.environ[_TEST_CONFIG_FILE_ENV_VAR] - except KeyError: - msg = "'{0}' environment variable was not set.".format( - _TEST_CONFIG_FILE_ENV_VAR) - raise ConfigEnvironmentVariableError(msg) - except Exception as exception: - print ("Unexpected exception when attempting to access '{1}'" - " environment variable.".format(_TEST_CONFIG_FILE_ENV_VAR)) - raise exception - - return test_config_file_path + ConfigSectionInterface diff --git a/metatests/conftest.py b/metatests/conftest.py index 9ed18c5c..36e579e9 100644 --- a/metatests/conftest.py +++ b/metatests/conftest.py @@ -1,13 +1,9 @@ # Configure path for py.test import os -os.environ["CCTNG_CONFIG_FILE"] = os.path.join( +os.environ["OPENCAFE_ENGINE_CONFIG_FILE"] = os.path.join( os.path.dirname(__file__), - "unittest.json.config" + "unittest.engine.config" ) -os.environ["MOCK"] = 'True' -os.environ["OSTNG_CONFIG_FILE"] = os.path.join( - os.path.dirname(__file__), - "unittest.json.config" -) +os.environ["MOCK"] = 'True' diff --git a/metatests/unittest.json.config b/metatests/unittest.json.config index f21c2088..039ac700 100644 --- a/metatests/unittest.json.config +++ b/metatests/unittest.json.config @@ -1,2 +1,2 @@ -[CCTNG_ENGINE] +[OPENCAFE_ENGINE] use_verbose_logging=false diff --git a/pip-requires b/pip-requires index 14f9a278..90539acb 100644 --- a/pip-requires +++ b/pip-requires @@ -1,4 +1,4 @@ httpretty mock unittest2 -IPy +IPy \ No newline at end of file diff --git a/setup.py b/setup.py index 772faf4d..8d79a40f 100644 --- a/setup.py +++ b/setup.py @@ -16,44 +16,116 @@ limitations under the License. import os import sys -import cloudcafe -import platform import shutil +import textwrap -# These imports are only possible on Linux/OSX -if platform.system().lower() != 'windows': - import pwd - import grp try: from setuptools import setup, find_packages + from setuptools.command.install import install as _install except ImportError: from distutils.core import setup, find_packages + from distutils.command.install import install as _install if sys.argv[-1] == 'publish': os.system('python setup.py sdist upload') sys.exit() -requires = open('pip-requires').readlines() +def print_cafe_mug(): + print('\n'.join(["\t\t _ _ _", + "\t\t ( ` )_ ", + "\t\t ( ) `) _", + "\t\t(____(__.___`)__)", + "\t\t", + "\t\t ( (", + "\t\t ) )", + "\t\t ......... ", + "\t\t | |___ ", + "\t\t | |_ |", + "\t\t | :-) |_| |", + "\t\t | |___|", + "\t\t |_______|", + "\t\t=== CloudCAFE ==="])) + print("========================================================") + print("CloudCAFE Framework installed") + print("========================================================") + + +def install_default_configs(): + from cafe.configurator.managers import ( + EngineDirectoryManager, PlatformManager) + + opencafe_root_dir = EngineDirectoryManager.OPENCAFE_ROOT_DIR + + twrap = textwrap.TextWrapper( + initial_indent='* ', subsequent_indent=' ', break_long_words=False) + print twrap.fill( + 'Installing reference configuration files in ...'.format( + opencafe_root_dir)) + + twrap = textwrap.TextWrapper( + initial_indent=' ', subsequent_indent=' ', break_long_words=False) + + _printed = [] + for root, subFolders, files in os.walk('configs'): + for file_ in files: + source = os.path.join(root, file_) + destination_dir = os.path.join(opencafe_root_dir, root) + destination_file = os.path.join(destination_dir, file_) + + try: + #Create the expected directory structure if it doesn't already + #exist. + os.makedirs(destination_dir) + print twrap.fill('Creating path: {0}'.format(destination_dir)) + except OSError: + #File exsits. This is ok and expected. + pass + + shutil.copyfile(source, destination_file) + if destination_dir not in _printed: + print twrap.fill('{0}'.format(destination_dir)) + _printed.append(destination_dir) + + if not PlatformManager.USING_WINDOWS: + uid = PlatformManager.get_user_uid() + gid = PlatformManager.get_user_gid() + os.chown(destination_file, uid, gid) + + +#Post-install engine configuration +def _post_install(dir): + install_default_configs() + print_cafe_mug() + + +class install(_install): + def run(self): + _install.run(self) + self.execute( + _post_install, (self.install_lib,), + msg="Running post install tasks...") + + +requires = open('pip-requires').readlines() setup( name='cloudcafe', - version=cloudcafe.__version__, - description='CloudCAFE is an implementation of the Open CAFE Framework specifically designed to test deployed versions of OpenStack', + version='0.0.1', + description=( + 'CloudCAFE is an implementation of the Open CAFE Framework ' + 'specifically designed to test deployed versions of OpenStack'), long_description='{0}\n\n{1}'.format( open('README.md').read(), open('HISTORY.rst').read()), author='Rackspace Cloud QE', author_email='cloud-cafe@lists.rackspace.com', url='http://rackspace.com', - packages=find_packages(exclude=[]), - package_data={'': ['LICENSE', 'NOTICE']}, - package_dir={'cloudcafe': 'cloudcafe'}, + packages=find_packages(), include_package_data=True, install_requires=requires, license=open('LICENSE').read(), zip_safe=False, - #https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=( 'Development Status :: 1 - Planning', 'Intended Audience :: Developers', @@ -62,73 +134,5 @@ setup( 'Operating System :: POSIX :: Linux', 'Programming Language :: Python', 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - #'Programming Language :: Python :: 3', - #'Programming Language :: Python :: 3.0', - #'Programming Language :: Python :: 3.1', - #'Programming Language :: Python :: 3.2', - #'Programming Language :: Python :: 3.3', - ) -) -# real_prefix should only be set under a virtualenv -using_virtualenv = hasattr(sys, 'real_prefix') - -''' @todo: need to clean this up or do it with puppet/chef ''' -# Default Config Options -root_dir = "{0}/.cloudcafe".format(os.path.expanduser("~")) -config_dir = "{0}/configs".format(root_dir) - -# Build Default directories -if(os.path.exists("{0}/engine.config".format(config_dir)) == False): - raise Exception("Core CAFE Engine configuration not found") -else: - # Copy over the default configurations - if(os.path.exists("~install")): - os.remove("~install") - # Report - print('\n'.join(["\t\t _ _ _", - "\t\t ( ` )_ ", - "\t\t ( ) `) _", - "\t\t(____(__.___`)__)", - "\t\t", - "\t\t ( (", - "\t\t ) )", - "\t\t ......... ", - "\t\t | |___ ", - "\t\t | |_ |", - "\t\t | :-) |_| |", - "\t\t | |___|", - "\t\t |_______|", - "\t\t=== CloudCAFE ==="])) - print("========================================================") - print("CloudCAFE Framework installed") - print("========================================================") - else: - # State file - temp = open("~install", "w") - temp.close() - - # Get uid and gid of the current user to set permissions (Linux/OSX only) - if platform.system().lower() != 'windows': - if using_virtualenv: - working_user = os.getenv("USER") - else: - working_user = os.getenv("SUDO_USER") - - uid = pwd.getpwnam(working_user).pw_uid - gid = pwd.getpwnam(working_user).pw_gid - - config_dirs = os.listdir("configs") - for dir in config_dirs: - if not os.path.exists("{0}/{1}".format(config_dir, dir)): - print("Installing configurations for: {0}".format("{0}/{1}".format(config_dir, dir))) - os.makedirs("{0}/{1}".format(config_dir, dir)) - # Fix the directory permissions - if platform.system().lower() != 'windows': - os.chown("{0}/{1}".format(config_dir, dir), uid, gid) - for file in os.listdir("configs/{0}".format(dir)): - print("Installing {0}/{1}/{2}".format(config_dir, dir, file)) - shutil.copy2("configs/{0}/{1}".format(dir, file), "{0}/{1}/{2}".format(config_dir, dir, file)) - # Fix the directory permissions - if platform.system().lower() != 'windows': - os.chown("{0}/{1}/{2}".format(config_dir, dir, file), uid, gid) + 'Programming Language :: Python :: 2.7',), + cmdclass={'install': install}) diff --git a/unittest.engine.config b/unittest.engine.config new file mode 100644 index 00000000..0d9d5990 --- /dev/null +++ b/unittest.engine.config @@ -0,0 +1,2 @@ +[OPENCAFE_ENGINE] +logging_verbosity = STANDARD \ No newline at end of file diff --git a/unittest.json.config b/unittest.json.config deleted file mode 100644 index 8966247f..00000000 --- a/unittest.json.config +++ /dev/null @@ -1,2 +0,0 @@ -[CCTNG_ENGINE] -use_verbose_logging = false