X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=nfvbench%2Fconfig_plugin.py;h=0596fcfde6937f0e3d9cc5173bd18ac3fefa14c7;hb=95f2491ed89ac99b0d8bd006b4a13cbeb1eb96ce;hp=ed6b3c683e5f6ae2e03f89b4b12d4b43d479576d;hpb=04a7de082bd221eae3c7004f4e0b99dfa4f8be91;p=nfvbench.git diff --git a/nfvbench/config_plugin.py b/nfvbench/config_plugin.py index ed6b3c6..0596fcf 100644 --- a/nfvbench/config_plugin.py +++ b/nfvbench/config_plugin.py @@ -13,56 +13,70 @@ # 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): + """Set a new configuration. + + 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): + def validate_config(self, cfg, openstack_spec): """Validate config file.""" @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): @@ -70,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): - pass + def validate_config(self, config, openstack_spec): + """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 {}