def sync(cls): """Checks all of the plugins on file systems, and makes sure that they have consistent information in API service. """ for metadata in utils.glob_and_parse_yaml(METADATA_MASK): cls.update_or_create(metadata, force=True)
def test_glob_and_parse_yaml(self, parse_mock, iglob_mock): path = "/tmp/path/mask*" content = [] for data in utils.glob_and_parse_yaml(path): content.append(data) iglob_mock.assert_called_once_with(path) self.assertEqual(parse_mock.call_args_list, [mock.call("file1"), mock.call("file2")]) self.assertEqual(content, ["content_file1", "content_file2"])
def test_glob_and_parse_yaml(self, parse_mock, iglob_mock): path = '/tmp/path/mask*' content = [] for data in utils.glob_and_parse_yaml(path): content.append(data) iglob_mock.assert_called_once_with(path) self.assertEqual( parse_mock.call_args_list, [mock.call('file1'), mock.call('file2')]) self.assertEqual(content, ['content_file1', 'content_file2'])
def register(cls, name, version, force=False): """Tries to find plugin on file system, creates it in API service if it exists. :param str name: plugin name :param str version: plugin version :param str force: if True updates meta information about the plugin even it does not support updates """ metadata = None for m in utils.glob_and_parse_yaml(METADATA_MASK): if m.get('version') == version and \ m.get('name') == name: metadata = m break if not metadata: raise error.BadDataException( 'Plugin {0} with version {1} does ' 'not exist, install it and try again'.format( name, version)) return cls.update_or_create(metadata, force=force)
def register(cls, name, version, force=False): """Tries to find plugin on file system, creates it in API service if it exists. :param str name: plugin name :param str version: plugin version :param bool force: if True updates meta information about the plugin even it does not support updates """ metadata = None for m in utils.glob_and_parse_yaml(METADATA_MASK): if m.get('version') == version and \ m.get('name') == name: metadata = m break if not metadata: raise error.BadDataException( 'Plugin {0} with version {1} does ' 'not exist, install it and try again'.format( name, version)) return cls.update_or_create(metadata, force=force)