Beispiel #1
0
 def validate(self):
     m = check_manager.Manager(self._file,
                               loader=check_pkg_loader.ZipLoader)
     errors = m.validate(
         validators=[check_validators.manifest.ManifestValidator],
         only_errors=True)
     if errors:
         fmt = check_manager.PlainTextFormatter().format
         return 'Invalid Murano package\n{}\n'.format(fmt(errors))
Beispiel #2
0
def run(args, pkg_path=None, quiet_load=False):
    m = manager.Manager(pkg_path or args.path, quiet_load=quiet_load)
    m.load_plugins()
    if args.select:
        select = args.select.split(',')
    else:
        select = None
    if args.ignore:
        ignore = args.ignore.split(',')
    else:
        ignore = None
    errors = m.validate(select=select, ignore=ignore)
    fmt = manager.PlainTextFormatter()
    return fmt.format(errors)
Beispiel #3
0
    def test_load_plugins(self, m_stevedore, m_pkg_loader):
        fake_validator = mock.Mock()
        fake_plugin = mock.Mock()
        fake_plugin.obj.validators.return_value = [fake_validator]
        m_stevedore.ExtensionManager.return_value = [fake_plugin]
        fake_manager = manager.Manager('fake')
        m_pkg_loader.load_package.assert_called_once_with('fake', quiet=False)
        fake_manager.load_plugins()
        m_stevedore.ExtensionManager.assert_called()
        self.assertEqual(validators.VALIDATORS + [fake_validator],
                         fake_manager.validators)

        m_stevedore.ExtensionManager.reset_mock()
        fake_manager.load_plugins()
        m_stevedore.ExtensionManager.assert_not_called()
Beispiel #4
0
    def test_validate(self, m_error, m_pkg_loader):
        fake_error = error.CheckError('W007', 'Fake')
        m_error.W007.return_value = fake_error
        fake_E000_error = error.CheckError('E000', 'Fake')
        m_error.E000.return_value = fake_E000_error

        def error_generator():
            yield fake_error

        def broken_checker():
            a = 0
            if 1 / a:
                yield fake_error

        def broken_method_checker(self):
            a = 0
            if 1 / a:
                yield fake_error

        mgr = manager.Manager('fake')
        m_pkg_loader.load_package.assert_called_once_with('fake', quiet=False)
        MockValidator = mock.Mock()
        m_validator = MockValidator.return_value

        def prepare_errors():
            return iter((fake_error, error_generator(), broken_checker(),
                         broken_method_checker(m_validator)))

        m_validator.run.return_value = prepare_errors()
        errors = mgr.validate(validators=[MockValidator])
        self._assert_errors(
            [fake_E000_error, fake_E000_error, fake_error, fake_error], errors)

        m_validator.run.return_value = prepare_errors()
        errors = mgr.validate(validators=[MockValidator], only_errors=True)
        self._assert_errors([fake_E000_error, fake_E000_error], errors)

        m_validator.run.return_value = prepare_errors()
        errors = mgr.validate(validators=[MockValidator], select=['W007'])
        self._assert_errors([fake_error, fake_error], errors)

        m_validator.run.return_value = prepare_errors()
        errors = mgr.validate(validators=[MockValidator], ignore=['E000'])
        self._assert_errors([fake_error, fake_error], errors)
Beispiel #5
0
 def test_foo(self):
     m = manager.Manager(self.pkg, loader=DictLoader)
     errors = m.validate()
     fmt = DictFormatter()
     self.assertEqual(self.expected, fmt.format(errors))