facebookarchive / nailgun

Nailgun is a client, protocol, and server for running Java programs from the command line without incurring the JVM startup overhead.
https://github.com/facebook/nailgun
Other
731 stars 138 forks source link

Mirroring policy breaks repositories #201

Closed lhellebr closed 2 years ago

lhellebr commented 2 years ago

Mirroring policy has been added to the API recently in this PR: https://github.com/Katello/katello/pull/9834/files It causes some failures in Nailgun, e.g.:

$ pytest tests/foreman/cli/test_computeresource_rhev.py::test_positive_provision_rhev_image_based_and_disassociate
[...]
tests/foreman/cli/test_computeresource_rhev.py::test_positive_provision_rhev_image_based_and_disassociate[destroy_vm_on_host_delete] ERROR [100%]

======================================================== ERRORS =========================================================
________ ERROR at setup of test_positive_provision_rhev_image_based_and_disassociate[destroy_vm_on_host_delete] _________

module_org = nailgun.entities.Organization(compute_resource=[], description=None, domain=[], hostgroup=[], label='apnHArWN', medium... default_content_view=nailgun.entities.ContentView(id=12), library=nailgun.entities.LifecycleEnvironment(id=22), id=23)
module_location = nailgun.entities.Location(compute_resource=[], description=None, domain=[], hostgroup=[], medium=[], name='achGpl', or....ProvisioningTemplate(id=25), nailgun.entities.ProvisioningTemplate(id=64)], smart_proxy=[], subnet=[], user=[], id=24)

    @pytest.fixture(scope='module')
    def provisioning(module_org, module_location):
        provisioning.org_name = module_org.name
        provisioning.loc_name = module_location.name
>       provisioning.config_env = configure_provisioning(
            compute=True, org=module_org, loc=module_location, os=None
        )

tests/foreman/cli/test_computeresource_rhev.py:69: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
robottelo/api/utils.py:261: in configure_provisioning
    repo = entities.Repository(
../../broker/venv/lib/python3.8/site-packages/nailgun/entity_mixins.py:948: in create
    return self.read(attrs=self.create_json(create_missing))
../../broker/venv/lib/python3.8/site-packages/nailgun/entities.py:6201: in read
    return super().read(entity, attrs, ignore, params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = nailgun.entities.Repository(product=nailgun.entities.Product(description=None, gpg_key=None, label='fnYDeXa', name='fn.../RHEL-7/latest-RHEL-7.9/compose/Server/x86_64/os/', download_policy='immediate', content_type='yum', name='TaafCOScQE')
entity = nailgun.entities.Repository(ansible_collection_auth_url=None, ansible_collection_auth_token=None, ansible_collection_r...apnHArWN/Library/custom/fnYDeXa/TaafCOScQE/', gpg_key=None, ignorable_content=None, label='TaafCOScQE', last_sync=None)
attrs = {'ansible_collection_auth_token': None, 'ansible_collection_auth_url': None, 'ansible_collection_requirements': None, 'arch': 'noarch', ...}
ignore = {'organization', 'upstream_password'}, params = None

    def read(self, entity=None, attrs=None, ignore=None, params=None):
        """Get information about the current entity.

        1. Create a new entity of type ``type(self)``.
        2. Call :meth:`read_json` and capture the response.
        3. Populate the entity with the response.
        4. Return the entity.

        Step one is skipped if the ``entity`` argument is specified. Step two
        is skipped if the ``attrs`` argument is specified. Step three is
        modified by the ``ignore`` argument.

        All of an entity's one-to-one and one-to-many relationships are
        populated with objects of the correct type. For example, if
        ``SomeEntity.other_entity`` is a one-to-one relationship, this should
        return ``True``::

            isinstance(
                SomeEntity(id=N).read().other_entity,
                nailgun.entity_mixins.Entity
            )

        Additionally, both of these commands should succeed::

            SomeEntity(id=N).read().other_entity.id
            SomeEntity(id=N).read().other_entity.read().other_attr

        In the example above, ``other_entity.id`` is the **only** attribute
        with a meaningful value. Calling ``other_entity.read`` populates the
        remaining entity attributes.

        :param nailgun.entity_mixins.Entity entity: The object to be populated
            and returned. An object of type ``type(self)`` by default.
        :param attrs: A dict. Data used to populate the object's attributes.
            The response from
            :meth:`nailgun.entity_mixins.EntityReadMixin.read_json` by default.
        :param ignore: A set of attributes which should not be read from the
            server. This is mainly useful for attributes like a password which
            are not returned.
        :return: An instance of type ``type(self)``.
        :rtype: nailgun.entity_mixins.Entity

        """
        if entity is None:
            try:
                entity = type(self)(self._server_config)
            except TypeError:
                # in the event that an entity's init is overwritten
                # with a positional server_config
                entity = type(self)()
        if attrs is None:
            attrs = self.read_json(params=params)
        if ignore is None:
            ignore = set()

        for field_name, field in entity.get_fields().items():
            if field_name in self.ignore_fields and field.entity.__name__ in self.ignore_entities:
                continue
            if field_name in ignore:
                continue
            if isinstance(field, OneToOneField):
                entity_id = _get_entity_id(field_name, attrs)
                if entity_id is None:
                    referenced_entity = None
                else:
                    referenced_entity = field.entity(
                        self._server_config,
                        id=entity_id,
                    )
                setattr(entity, field_name, referenced_entity)
            elif isinstance(field, OneToManyField):
                referenced_entities = [
                    field.entity(self._server_config, id=entity_id)
                    for entity_id in _get_entity_ids(field_name, attrs)
                ]
                setattr(entity, field_name, referenced_entities)
            else:
>               setattr(entity, field_name, attrs[field_name])
E               KeyError: 'mirror_on_sync'

../../broker/venv/lib/python3.8/site-packages/nailgun/entity_mixins.py:811: KeyError
[...]
lhellebr commented 2 years ago

I don't have permissions to set myself as Assignee

lhellebr commented 2 years ago

Eh, wrong Nailgun project. This should be in the other Nailgun: https://github.com/SatelliteQE/nailgun/issues/808