
We should clear the environment before connecting to an LXC container to avoid inheriting host variables that may break container services like the following failure in rabbitmqctl: TASK [Get status of rabbitmq] ************************************************************************************************************************************************************************************* fatal: [container1]: FAILED! => {"changed": true, "cmd": ["rabbitmqctl", "status"], "delta": "0:00:00.705116", "end": "2017-06-06 20:03:13.771796", "failed": true, "rc": 69, "start": "2017-06-06 20:03:13.066680", "stderr": "Error: unable to connect to node 'rabbit@vagrant-openSUSE-Leap': nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: ['rabbit@vagrant-openSUSE-Leap']\n\nrabbit@vagrant-openSUSE-Leap:\n * unable to connect to epmd (port 4369) on vagrant-openSUSE-Leap: address (cannot connect to host/port)\n\n\ncurrent node details:\n- node name: 'rabbitmq-cli-82@localhost'\n- home dir: /var/lib/rabbitmq\n- cookie hash: NqWRA5RzO5daz4Jb5LJsXg==", "stderr_lines": ["Error: unable to connect to node 'rabbit@vagrant-openSUSE-Leap': nodedown", "", "DIAGNOSTICS", "===========", "", "attempted to contact: ['rabbit@vagrant-openSUSE-Leap']", "", "rabbit@vagrant-openSUSE-Leap:", " * unable to connect to epmd (port 4369) on vagrant-openSUSE-Leap: address (cannot connect to host/port)", "", "", "current node details:", "- node name: 'rabbitmq-cli-82@localhost'", "- home dir: /var/lib/rabbitmq", "- cookie hash: NqWRA5RzO5daz4Jb5LJsXg=="], "stdout": "Status of node 'rabbit@vagrant-openSUSE-Leap' ...", "stdout_lines": ["Status of node 'rabbit@vagrant-openSUSE-Leap' ..."]} to retry, use: --limit @/vagrant/tests/test-rabbitmq-server-functional.retry The reason for this failure is that the HOSTNAME variable is being inherited by the host (vagrant-openSUSE-Leap) and the rabbitmqctl command uses this variable to guess the host it should try to connect to. This is similar to what the upstream lxc connection module is doing. This is an attempt to fix problems introduced in https://review.openstack.org/#/c/471472/ and subsequently reverted in https://review.openstack.org/#/c/471713/ The reason for these failures was that 'lxc-attach' executed commands which assumed that basic variables like HOME are set properly. However, --clear-env didn't preserve these variables so various operations started to fail. In order to fix that, it's best if we start a real login shell using 'su' in order to mimic an expected user environment when executing commands within the container. Change-Id: I684a11f4380f91b1cb0585f38817859dfaa68f80
Description
Languages
Python
100%