SatelliteQE / broker

The infrastructure middleman

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BUG: `sftp_write` fails if the destination file does not exist in the container

ogajduse opened this issue · comments

Problem statement

sftp_write method that we are using in robottelo behaves differently based on the broker provider - Container or AAP.

https://github.com/SatelliteQE/robottelo/blob/eca242110a5c9b4040d62d04a7094d00cebf5aa7/robottelo/hosts.py#L686-L697

Traceback

../../lib64/python3.8/site-packages/docker/api/client.py:268: in _raise_for_status
    response.raise_for_status()
../../lib64/python3.8/site-packages/requests/models.py:1021: in raise_for_status
    raise HTTPError(http_error_msg, response=self)
E   requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http+docker://ssh/v1.41/containers/9e2407883fed4af87a97ab80579150153a3ef2a7fbdcd0558618ac6b3bb3762e/archive?path=%2Fetc%2Frhsm%2Ffacts%2Flocations.facts

The above exception was the direct cause of the following exception:
tests/foreman/ui/test_dashboard.py:257: in test_positive_user_access_with_host_filter
    repos_collection.setup_virtual_machine(
robottelo/host_helpers/repository_mixins.py:725: in setup_virtual_machine
    vm.contenthost_setup(
robottelo/hosts.py:1007: in contenthost_setup
    self.set_facts({'locations.facts': {'foreman_location': str(location_title)}})
robottelo/host_helpers/contenthost_mixins.py:145: in set_facts
    self.put(tf.name, f'/etc/rhsm/facts/{filename}')
robottelo/hosts.py:697: in put
    self.session.sftp_write(source=local_path, destination=remote_path)
../../lib64/python3.8/site-packages/broker/session.py:234: in sftp_write
    self._cont_inst._cont_inst.put_archive(str(destination), tar.read_bytes())
../../lib64/python3.8/site-packages/docker/models/containers.py:334: in put_archive
    return self.client.api.put_archive(self.id, path, data)
../../lib64/python3.8/site-packages/docker/utils/decorators.py:19: in wrapped
    return f(self, resource_id, *args, **kwargs)
../../lib64/python3.8/site-packages/docker/api/container.py:976: in put_archive
    self._raise_for_status(res)
../../lib64/python3.8/site-packages/docker/api/client.py:270: in _raise_for_status
    raise create_api_error_from_http_exception(e) from e
../../lib64/python3.8/site-packages/docker/errors.py:39: in create_api_error_from_http_exception
    raise cls(e, response=response, explanation=explanation) from e
E   docker.errors.NotFound: 404 Client Error for http+docker://ssh/v1.41/containers/9e2407883fed4af87a97ab80579150153a3ef2a7fbdcd0558618ac6b3bb3762e/archive?path=%2Fetc%2Frhsm%2Ffacts%2Flocations.facts: Not Found ("Could not find the file /etc/rhsm/facts/locations.facts in container 9e2407883fed4af87a97ab80579150153a3ef2a7fbdcd0558618ac6b3bb3762e")****

If the file does not exist on the host, the above exception is raised.

Proposed solution

Broker should be smart and should create the file in the container if it does not exist - like in the VM (AnsibleTower provider).

Notes

@peterdragun and I played around with it a bit and we found out that if the destination file exists, it is overridden by the source file.