Beispiel #1
0
 def test_refresh_archive_not_implemented(self, mock_log):
     mock_response = mock.Mock(headers={'content-type': 'application/gzip'})
     self.conn.get.return_value = mock_response
     BaseResource(connector=self.conn,
                  path='/Foo',
                  redfish_version='1.0.2',
                  reader=resource_base.JsonArchiveReader('Test.2.0.json'))
     mock_log.error.assert_called_once()
Beispiel #2
0
    def test_refresh_archive_badzip_error(self, mock_io):
        mock_response = mock.Mock(headers={'content-type': 'application/zip'})
        mock_io.side_effect = zipfile.BadZipfile('Something wrong')
        self.conn.get.return_value = mock_response

        self.assertRaises(
            exceptions.SushyError,
            BaseResource,
            connector=self.conn,
            path='/Foo',
            redfish_version='1.0.2',
            reader=resource_base.JsonArchiveReader('Test.2.0.json'))
Beispiel #3
0
    def test_refresh_archive(self):
        mock_response = mock.Mock(headers={'content-type': 'application/zip'})
        with open('sushy/tests/unit/json_samples/TestRegistry.zip', 'rb') as f:
            mock_response.content = f.read()
        self.conn.get.return_value = mock_response

        resource = BaseResource(
            connector=self.conn,
            path='/Foo',
            redfish_version='1.0.2',
            reader=resource_base.JsonArchiveReader('Test.2.0.json'))

        self.assertIsNotNone(resource._json)
        self.assertEqual('Test.2.0.0', resource._json['Id'])
Beispiel #4
0
    def get_message_registry(self, language, public_connector):
        """Load message registry file depending on its source

        Will try to find `MessageRegistry` based on `odata.type` property and
        provided language. If desired language is not found, will pick a
        registry that has 'default' language.

        :param language: RFC 5646 language code for registry files
        :param public_connector: connector to use when downloading registry
            from the Internet
        """

        # NOTE (etingof): as per RFC5646, languages are case-insensitive
        language = language.lower()

        locations = [
            l for l in self.location if l.language.lower() == language
        ]

        locations += [
            l for l in self.location if l.language.lower() == 'default'
        ]

        for location in locations:
            if location.uri:
                args = self._conn,
                kwargs = {
                    'path': location.uri,
                    'reader': None,
                    'redfish_version': self.redfish_version
                }

            elif location.archive_uri:
                args = self._conn,
                kwargs = {
                    'path': location.archive_uri,
                    'reader': base.JsonArchiveReader(location.archive_file),
                    'redfish_version': self.redfish_version
                }

            elif location.publication_uri:
                args = public_connector,
                kwargs = {
                    'path': location.publication_uri,
                    'reader': base.JsonPublicFileReader(),
                    'redfish_version': self.redfish_version
                }

            else:
                LOG.warning('Incomplete location for language %(language)s',
                            {'language': language})
                continue

            try:
                registry = RegistryType(*args, **kwargs)

            except Exception as exc:
                LOG.warning(
                    'Cannot load message registry type from location '
                    '%(location)s: %(error)s', {
                        'location': kwargs['path'],
                        'error': exc
                    })
                continue

            if registry._odata_type.endswith('MessageRegistry'):
                try:
                    return message_registry.MessageRegistry(*args, **kwargs)

                except Exception as exc:
                    LOG.warning(
                        'Cannot load message registry from location '
                        '%(location)s: %(error)s', {
                            'location': kwargs['path'],
                            'error': exc
                        })
                    continue

            LOG.debug('Ignoring unsupported flavor of registry %(registry)s',
                      {'registry': registry._odata_type})
            return

        LOG.warning('No message registry found for %(language)s or '
                    'default', {'language': language})