Ejemplo n.º 1
0
    def configure(self, settings_path=None):
        """Read the settings file and parse the configuration.

        :param str settings_path: path to settings file to read. If None, looks in the project
            root for a file named 'robottelo.properties'.

        :raises: ImproperlyConfigured if any issue is found during the parsing
            or validation of the configuration.
        """

        if not settings_path:
            # Expect the settings file to be on the robottelo project root.
            settings_path = os.path.join(get_project_root(),
                                         SETTINGS_FILE_NAME)

        if not os.path.isfile(settings_path):
            raise ImproperlyConfigured(
                f'Not able to find settings file at {settings_path}')

        self.reader = INIReader(settings_path)
        attrs = map(lambda attr_name: (attr_name, getattr(self, attr_name)),
                    dir(self))
        feature_settings = filter(
            lambda tpl: isinstance(tpl[1], FeatureSettings), attrs)
        for name, settings in feature_settings:
            settings.read(self.reader)
            # Only has section will extend the error
            if self.reader.has_section(name):
                self._validation_errors.extend(settings.validate())
        if self._validation_errors:
            raise ImproperlyConfigured(
                'Failed to validate the configuration, check the message(s):\n'
                '{}'.format('\n'.join(self._validation_errors)))
Ejemplo n.º 2
0
 def test_ini_reader_cast(self, mock_open):
     ini_reader = INIReader(None)
     self.assertEqual(
         ini_reader.get('awesomeness', 'enabled', cast=bool), True
     )
     self.assertEqual(
         ini_reader.get('awesomeness', 'level', cast=int), 100
     )
Ejemplo n.º 3
0
 def __server_get_hostname(self, key="hostname"):
     try:
         return self._get_from_configs(f"server.{key}")
     except AttributeError:
         default = self._get_from_configs("server.hostname")
         reader = INIReader(
             os.path.join(get_project_root(), SETTINGS_FILE_NAME))
         return reader.get('server', key, default)
Ejemplo n.º 4
0
    def __server_get_hostname(self, key="hostname"):
        try:
            return self._get_from_configs(f"server.{key}")
        except AttributeError:
            default = self._get_from_configs("server.hostname")
            from robottelo.config import robottelo_root_dir

            reader = INIReader(
                os.path.join(robottelo_root_dir, SETTINGS_FILE_NAME))
            return reader.get('server', key, default)
Ejemplo n.º 5
0
class VirtwhoSettings:
    """Virtwho's settings representation."""
    def __init__(self):
        self._validation_errors = []
        self.hypervisor = None
        self.esx = EsxSettings()
        self.xen = XenSettings()
        self.hyperv = HypervSettings()
        self.rhevm = RhevmSettings()
        self.libvirt = LibvirtSettings()
        self.kubevirt = KubevirtSettings()
        self.sku = SkuSettings()

    def configure(self, settings_path=None):
        """Read the settings file and parse the configuration.

        :param str settings_path: path to settings file to read. If None, looks in the project
            root for a file named 'robottelo.properties'.

        :raises: ImproperlyConfigured if any issue is found during the parsing
            or validation of the configuration.
        """

        if not settings_path:
            # Expect the settings file to be on the robottelo project root.
            settings_path = os.path.join(robottelo_root_dir,
                                         SETTINGS_FILE_NAME)

        if not os.path.isfile(settings_path):
            raise ImproperlyConfigured(
                f'Not able to find settings file at {settings_path}')

        self.reader = INIReader(settings_path)
        attrs = map(lambda attr_name: (attr_name, getattr(self, attr_name)),
                    dir(self))
        feature_settings = filter(
            lambda tpl: isinstance(tpl[1], FeatureSettings), attrs)
        for name, settings in feature_settings:
            settings.read(self.reader)
            # Only has section will extend the error
            if self.reader.has_section(name):
                self._validation_errors.extend(settings.validate())
        if self._validation_errors:
            raise ImproperlyConfigured(
                'Failed to validate the configuration, check the message(s):\n'
                '{}'.format('\n'.join(self._validation_errors)))
Ejemplo n.º 6
0
 def test_ini_reader_get_default(self, mock_open):
     ini_reader = INIReader(None)
     assert ini_reader.get('a', 'b', default='c') == 'c'
Ejemplo n.º 7
0
 def test_ini_reader_cast(self, mock_open):
     ini_reader = INIReader(None)
     assert ini_reader.get('awesomeness', 'enabled', cast=bool) is True
     assert ini_reader.get('awesomeness', 'level', cast=int) == 100
Ejemplo n.º 8
0
 def test_ini_reader(self, mock_open):
     ini_reader = INIReader(None)
     assert ini_reader.get('teste', 'foo') == 'bar'
     assert ini_reader.get('teste', 'bar') == 'foo'
     assert ini_reader.has_section('another')
     assert not ini_reader.has_section('schblaums')
Ejemplo n.º 9
0
 def test_ini_reader_get_default(self, mock_open):
     ini_reader = INIReader(None)
     self.assertEqual(ini_reader.get('a', 'b', default='c'), 'c')
Ejemplo n.º 10
0
 def test_ini_reader(self, mock_open):
     ini_reader = INIReader(None)
     self.assertEqual(ini_reader.get('teste', 'foo'), 'bar')
     self.assertEqual(ini_reader.get('teste', 'bar'), 'foo')
     self.assertTrue(ini_reader.has_section('another'))
     self.assertFalse(ini_reader.has_section('schblaums'))
Ejemplo n.º 11
0
 def test_ini_reader_get_default(self, mock_open):
     ini_reader = INIReader(None)
     self.assertEqual(ini_reader.get('a', 'b', default='c'), 'c')
Ejemplo n.º 12
0
 def test_ini_reader_cast(self, mock_open):
     ini_reader = INIReader(None)
     self.assertEqual(ini_reader.get('awesomeness', 'enabled', cast=bool),
                      True)
     self.assertEqual(ini_reader.get('awesomeness', 'level', cast=int), 100)
Ejemplo n.º 13
0
 def test_ini_reader(self, mock_open):
     ini_reader = INIReader(None)
     self.assertEqual(ini_reader.get('teste', 'foo'), 'bar')
     self.assertEqual(ini_reader.get('teste', 'bar'), 'foo')
     self.assertTrue(ini_reader.has_section('another'))
     self.assertFalse(ini_reader.has_section('schblaums'))