X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=nfvbench%2Fconfig_plugin.py;h=0596fcfde6937f0e3d9cc5173bd18ac3fefa14c7;hb=95f2491ed89ac99b0d8bd006b4a13cbeb1eb96ce;hp=78c2ebb69c4d77ed3fdef80d8e3c786012c5a1af;hpb=6c4e55c53c65b7e63c17c85367b4813443c5d942;p=nfvbench.git diff --git a/nfvbench/config_plugin.py b/nfvbench/config_plugin.py index 78c2ebb..0596fcf 100644 --- a/nfvbench/config_plugin.py +++ b/nfvbench/config_plugin.py @@ -13,44 +13,47 @@ # License for the specific language governing permissions and limitations # under the License. # +"""Configuration Plugin. +This module is used to override the configuration with platform specific constraints and extensions +""" import abc -import specs +from . import specs -class ConfigPluginBase(object): - """Base class for config plugins. Need to implement public interfaces.""" - __metaclass__ = abc.ABCMeta +class ConfigPluginBase(object, metaclass=abc.ABCMeta): + """Base class for config plugins.""" class InitializationFailure(Exception): - pass + """Used in case of any init failure.""" def __init__(self, config): + """Save configuration.""" if not config: raise ConfigPluginBase.InitializationFailure( 'Initialization parameters need to be assigned.') - self.config = config @abc.abstractmethod def get_config(self): - """Returns updated default configuration file.""" + """Return updated default configuration file.""" def set_config(self, config): - """This method is called when the config has changed after this instance was initialized. + """Set a new configuration. - This is needed in teh frequent case where the main config is changed in a copy and to + This method is called when the config has changed after this instance was initialized. + This is needed in the frequent case where the main config is changed in a copy and to prevent this instance to keep pointing to the old copy of the config """ self.config = config @abc.abstractmethod def get_openstack_spec(self): - """Returns OpenStack specs for host.""" + """Return OpenStack specs for host.""" @abc.abstractmethod - def get_run_spec(self, openstack_spec): - """Returns RunSpec for given platform.""" + def get_run_spec(self, config, openstack_spec): + """Return RunSpec for given platform.""" @abc.abstractmethod def validate_config(self, cfg, openstack_spec): @@ -58,19 +61,22 @@ class ConfigPluginBase(object): @abc.abstractmethod def prepare_results_config(self, cfg): - """This function is called before running configuration is copied. + """Insert any plugin specific information to the results. + + This function is called before running configuration is copied. Example usage is to remove sensitive information like switch credentials. """ @abc.abstractmethod def get_version(self): - """Returns platform version.""" + """Return platform version.""" class ConfigPlugin(ConfigPluginBase): """No-op config plugin class. Does not change anything.""" def __init__(self, config): + """Invoke the base class constructor.""" ConfigPluginBase.__init__(self, config) def get_config(self): @@ -78,18 +84,20 @@ class ConfigPlugin(ConfigPluginBase): return self.config def get_openstack_spec(self): - """Returns OpenStack specs for host.""" + """Return OpenStack specs for host.""" return specs.OpenStackSpec() - def get_run_spec(self, openstack_spec): - """Returns RunSpec for given platform.""" - return specs.RunSpec(self.config.no_vswitch_access, openstack_spec) + def get_run_spec(self, config, openstack_spec): + """Return RunSpec for given platform.""" + return specs.RunSpec(config.no_vswitch_access, openstack_spec) def validate_config(self, config, openstack_spec): - pass + """Nothing to validate by default.""" def prepare_results_config(self, cfg): + """Nothing to add the results by default.""" return cfg def get_version(self): + """Return an empty version.""" return {}