Esempio n. 1
0
    def test_process_unit(self):
        step = publish.PublishErrataStepIncremental()
        self.publisher.add_child(step)
        unit_key = {'id': 'foo'}
        metadata = {'filename': 'bar.txt', '_test': 'hidden'}
        test_unit = Unit('foo_type', unit_key, metadata.copy(), '')

        step.process_main(test_unit)

        modified_metadata = metadata.copy()
        modified_metadata.pop('_test')
        modified_metadata[server_constants.PULP_USER_METADATA_FIELDNAME] = {}
        unit_file = os.path.join(self.working_dir, 'foo.json')
        self.assertTrue(os.path.exists(unit_file))
        with open(unit_file) as file_handle:
            loaded = json.load(file_handle)
            compare_dict(loaded, {'unit_key': unit_key, 'unit_metadata': modified_metadata})
Esempio n. 2
0
    def test_process_unit(self):
        step = publish.PublishErrataStepIncremental()
        self.publisher.add_child(step)
        unit_key = {'id': 'foo'}
        metadata = {'filename': 'bar.txt', '_test': 'hidden'}
        original_metadata = metadata.copy()
        test_unit = Unit('foo_type', unit_key, metadata, '')

        step.process_unit(test_unit)

        original_metadata.pop('_test')
        unit_file = os.path.join(self.working_dir, 'foo.json')
        self.assertTrue(os.path.exists(unit_file))
        with open(unit_file) as file_handle:
            loaded = json.load(file_handle)
            compare_dict(loaded, {
                'unit_key': unit_key, 'unit_metadata': original_metadata
            })
Esempio n. 3
0
    def test_process_unit(self):
        step = publish.PublishRpmAndDrpmStepIncremental()
        self.publisher.add_child(step)
        unit_key = {'name': 'foo', 'version': '1', 'release': '2', 'arch': 'flux'}
        metadata = {'filename': 'bar.txt', 'repodata': 'baz', '_test': 'hidden'}
        original_metadata = metadata.copy()
        storage_path = os.path.join(self.working_dir, 'foo')
        touch(storage_path)
        test_unit = Unit('foo_type', unit_key, metadata, storage_path)

        step.process_unit(test_unit)
        original_metadata.pop('repodata')
        original_metadata.pop('_test')
        unit_file = os.path.join(self.working_dir, 'foo-1-2.flux.json')
        self.assertTrue(os.path.exists(unit_file))
        with open(unit_file) as file_handle:
            loaded = json.load(file_handle)
            compare_dict(loaded, {
                'unit_key': unit_key, 'unit_metadata': original_metadata
            })
Esempio n. 4
0
def read_json_config(file_path):
    """
    Read a set of configuration values from a file to a dictionary
    If the file does not exist on disk it will return an empty dictionary

    @param file_path: the inside of /etc/pulp to find the file.
    @return: dictionary containing the configuration values contained in the file
    @rtype: dict
    """

    config_filename = '/etc/pulp/' + file_path.lstrip('/')
    config = {}
    if os.path.exists(config_filename):
        # Let the exception bubble up so it ends up in pulp.log
        f = open(config_filename, 'r')
        try:
            config = json.load(f)
        finally:
            f.close()
    return config
Esempio n. 5
0
def read_json_config(file_path):
    """
    Read a set of configuration values from a file to a dictionary
    If the file does not exist on disk it will return an empty dictionary

    @param file_path: the inside of /etc/pulp to find the file.
    @return: dictionary containing the configuration values contained in the file
    @rtype: dict
    """

    config_filename = '/etc/pulp/' + file_path.lstrip('/')
    config = {}
    if os.path.exists(config_filename):
        # Let the exception bubble up so it ends up in pulp.log
        f = open(config_filename, 'r')
        try:
            config = json.load(f)
        finally:
            f.close()
    return config
Esempio n. 6
0
    def test_process_unit(self):
        step = publish.PublishRpmAndDrpmStepIncremental()
        self.publisher.add_child(step)
        unit_key = {'name': 'foo', 'version': '1', 'release': '2', 'arch': 'flux'}
        metadata = {'filename': 'bar.txt', 'repodata': 'baz', '_test': 'hidden'}
        storage_path = os.path.join(self.working_dir, 'foo')
        touch(storage_path)
        test_unit = Unit('foo_type', unit_key, metadata.copy(), storage_path)

        step.process_main(test_unit)
        modified_metadata = metadata.copy()
        modified_metadata.pop('repodata')
        modified_metadata.pop('_test')
        modified_metadata[server_constants.PULP_USER_METADATA_FIELDNAME] = {}
        unit_file = os.path.join(self.working_dir, 'foo-1-2.flux.json')
        self.assertTrue(os.path.exists(unit_file))
        with open(unit_file) as file_handle:
            loaded = json.load(file_handle)
            compare_dict(loaded, {
                'unit_key': unit_key, 'unit_metadata': modified_metadata
            })