Пример #1
0
    def get_storage_config_file(self):
        """
        Returns the configuration file for the storage.
        :return: 
        """
        if self.alternative_config_dir:
            file = os.path.join(self.alternative_config_dir,
                                self.STORAGE_CONFIG_FILE)
            if os.path.isfile(file):
                return file

            file = os.path.join(self.alternative_config_dir,
                                self.STORAGE_JSON_CONFIG_FILE)
            if os.path.isfile(file):
                return file

        file = os.path.join(self.default_config_dir, self.STORAGE_CONFIG_FILE)
        if os.path.isfile(file):
            return file

        file = os.path.join(self.default_config_dir,
                            self.STORAGE_JSON_CONFIG_FILE)
        if os.path.isfile(file):
            return file

        raise ControllerConfigurationException(
            'Storage configuration file not found')
Пример #2
0
    def __init__(self, config_file):
        self.name = os.path.splitext(os.path.basename(config_file))[0]

        # TODO: use here the functions in provider.py to load the providers from the configuration
        try:
            with open(config_file) as f:
                config = configparser.ConfigParser()
                config.read_dict(json.load(f))
        except ValueError as ex:
            logger.warning(
                'Got an exception trying to decode configuration file as json: '
                + str(ex))
            try:
                config = configparser.ConfigParser()
                config.read(config_file)
            except Exception as ex:
                raise ControllerConfigurationException(
                    'Invalid configuration provided: {0}'.format(str(ex)))

        # TODO: libcloud_extra_params should not go here because it is something dependant from the implemetnation of
        sections = [
            s for s in list(config.keys()) if s != 'DEFAULT'
            and s != 'provider' and s != 'libcloud_extra_params'
        ]

        self.service_types = sections
Пример #3
0
    def new_session(self,
                    cloud_provider_name: str,
                    cloud_service_name: str,
                    properties={}) -> BenchmarkingSession:

        # service type is not provided via argument. Try to load from env variable
        # Even if not provided, it is fine if the provider has only one service type
        if not cloud_service_name and SERVICE_TYPE_STRING_ENV_VAR_NAME in os.environ:
            cloud_service_name = os.environ[SERVICE_TYPE_STRING_ENV_VAR_NAME]

        if not cloud_provider_name:
            # provider configuration is not provided via argument. Try to load from environment
            if PROVIDER_STRING_ENV_VAR_NAME in os.environ:
                provider_config = os.environ[PROVIDER_STRING_ENV_VAR_NAME]
                p = load_provider_from_config_string(provider_config,
                                                     cloud_service_name)

            else:
                raise ControllerConfigurationException(
                    'Provider must be specified either '
                    'via argument (--provider) or via environment '
                    'variable ({0})'.format(PROVIDER_STRING_ENV_VAR_NAME))
        else:
            c = self.configuration.get_provider_config_file(
                cloud_provider_name)
            p = load_service_provider_from_config_file(c, cloud_service_name)

        s = BenchmarkingSession(p)
        s.add_all_props(properties)
        self.session_storage.add(s)
        return s
Пример #4
0
    def get_benchmark_by_name(self, name):

        if self.alternative_config_dir:
            for n in glob.glob(
                    os.path.join(self.alternative_config_dir,
                                 self.BENCHMARKS_DIR, name + '.conf')):
                return BenchmarkToolConfiguration(n)

        for n in glob.glob(
                os.path.join(self.default_config_dir, self.BENCHMARKS_DIR,
                             name + '.conf')):
            return BenchmarkToolConfiguration(n)

        raise ControllerConfigurationException(
            'Benchmark with name {0} does not exist'.format(name))
Пример #5
0
def load_service_provider_from_config_file(config_file,
                                           service_type=None
                                           ) -> ServiceProvider:
    if not os.path.isfile(config_file):
        raise ControllerConfigurationException(
            'Config file {0} does not exist'.format(config_file))

    try:
        with open(config_file) as f:
            config = configparser.ConfigParser()
            config.read_dict(json.load(f))
    except ValueError as ex:
        config = configparser.ConfigParser()
        config.read(config_file)

    return load_provider_from_config(config, service_type)
def load_benchmark_from_config_file(config_file, tool, workload):
    if not os.path.isfile(config_file):
        raise ControllerConfigurationException(
            'Config file {0} does not exist'.format(config_file))

    config = BenchsuiteConfigParser()
    config.read(config_file)

    provider_class = config['DEFAULT']['class']

    module_name, class_name = provider_class.rsplit('.', 1)

    __import__(module_name)
    module = sys.modules[module_name]
    clazz = getattr(module, class_name)

    return clazz.load_from_config_file(config, tool, workload)
Пример #7
0
    def get_benchmark_config_file(self, name):

        if os.path.isfile(name):
            return name

        if self.alternative_config_dir:
            file = os.path.join(self.alternative_config_dir,
                                self.BENCHMARKS_DIR, name + ".conf")

            if os.path.isfile(file):
                return file

        file = os.path.join(self.default_config_dir, self.BENCHMARKS_DIR,
                            name + ".conf")

        if os.path.isfile(file):
            return file

        raise ControllerConfigurationException(
            'Impossible to find benchmark configuration for {0}'.format(name))
Пример #8
0
    def get_provider_config_file(self, name):

        if os.path.isfile(name):
            return name

        if self.alternative_config_dir:
            for f in os.listdir(
                    os.path.join(self.alternative_config_dir,
                                 self.CLOUD_PROVIDERS_DIR)):
                if os.path.splitext(f)[0] == name:
                    return os.path.join(self.alternative_config_dir,
                                        self.CLOUD_PROVIDERS_DIR, f)

        for f in os.listdir(
                os.path.join(self.default_config_dir,
                             self.CLOUD_PROVIDERS_DIR)):
            if os.path.splitext(f)[0] == name:
                return os.path.join(self.default_config_dir,
                                    self.CLOUD_PROVIDERS_DIR, f)

        raise ControllerConfigurationException(
            'Impossible to find prodiver configuration for {0}'.format(name))
Пример #9
0
def load_provider_from_config(config, service_type=None):
    provider_class = config['provider']['class']

    module_name, class_name = provider_class.rsplit('.', 1)

    __import__(module_name)
    module = sys.modules[module_name]
    clazz = getattr(module, class_name)

    if not service_type:
        # if there is only one section (other then "provider") in the configuration, use that as service provider,
        # otherwise rise an excepction
        sections = [
            s for s in list(config.keys())
            if s != 'DEFAULT' and s != 'provider'
        ]
        if len(sections) > 1:
            raise ControllerConfigurationException(
                'Service Type not specified and multiple sections found in the configuration'
            )
        else:
            service_type = sections[0]

    return clazz.load_from_config_file(config, service_type)