Functional: only copy logs on exception
This patch adds a copy_logs as the handler with unittest's addOnException, by doing this, we can get logs for all failed cases instead of copy them before teardown. If without any failed case, don't copy logs for saving time. Partially implements: blueprint swarm-functional-testing Change-Id: I47725d0d16735f650adf325adcf4194eb70c384d
This commit is contained in:
parent
534e44c546
commit
d38eee5b3a
|
@ -47,9 +47,11 @@ if [[ "$COE" == "kubernetes" ]]; then
|
|||
remote_exec $SSH_USER "sudo journalctl -u kube-controller-manager --no-pager" kube-controller-manager.log
|
||||
remote_exec $SSH_USER "sudo journalctl -u docker --no-pager" docker.log
|
||||
remote_exec $SSH_USER "sudo journalctl -u flanneld --no-pager" flanneld.log
|
||||
remote_exec $SSH_USER "sudo ip a" ipa.log
|
||||
remote_exec $SSH_USER "sudo netstat -an" netstat.log
|
||||
elif [[ "$COE" == "swarm" ]]; then
|
||||
SSH_USER=fedora
|
||||
remote_exec $SSH_USER "sudo systemctl list-units" systemctl_list_units.log
|
||||
remote_exec $SSH_USER "sudo systemctl --full list-units" systemctl_list_units.log
|
||||
remote_exec $SSH_USER "sudo journalctl -u cloud-config --no-pager" cloud-config.log
|
||||
remote_exec $SSH_USER "sudo journalctl -u cloud-final --no-pager" cloud-final.log
|
||||
remote_exec $SSH_USER "sudo journalctl -u cloud-init-local --no-pager" cloud-init-local.log
|
||||
|
@ -59,6 +61,8 @@ elif [[ "$COE" == "swarm" ]]; then
|
|||
remote_exec $SSH_USER "sudo journalctl -u swarm-agent --no-pager" swarm-agent.log
|
||||
remote_exec $SSH_USER "sudo journalctl -u docker --no-pager" docker.log
|
||||
remote_exec $SSH_USER "sudo journalctl -u flanneld --no-pager" flanneld.log
|
||||
remote_exec $SSH_USER "sudo ip a" ipa.log
|
||||
remote_exec $SSH_USER "sudo netstat -an" netstat.log
|
||||
else
|
||||
echo "ERROR: Unknown COE '${COE}'"
|
||||
EXIT_CODE=1
|
||||
|
|
|
@ -153,18 +153,21 @@ class BaseMagnumClient(base.TestCase):
|
|||
def _delete_bay(cls, bay_uuid):
|
||||
cls.cs.bays.delete(bay_uuid)
|
||||
|
||||
@classmethod
|
||||
def _copy_logs(cls):
|
||||
if not cls.copy_logs:
|
||||
def _copy_logs(self, exec_info):
|
||||
if not self.copy_logs:
|
||||
return
|
||||
fn = exec_info[2].tb_frame.f_locals['fn']
|
||||
func_name = fn.im_self._get_test_method().__name__
|
||||
|
||||
cls.bay = cls._show_bay(cls.bay.uuid)
|
||||
for node_addr in cls.bay.node_addresses:
|
||||
bay = self._show_bay(self.bay.uuid)
|
||||
for node_addr in bay.node_addresses:
|
||||
subprocess.call(["magnum/tests/contrib/copy_instance_logs.sh",
|
||||
node_addr, cls.baymodel.coe, "worker"])
|
||||
for node_addr in getattr(cls.bay, 'master_addresses', []):
|
||||
node_addr, self.baymodel.coe,
|
||||
"worker-" + func_name])
|
||||
for node_addr in getattr(bay, 'master_addresses', []):
|
||||
subprocess.call(["magnum/tests/contrib/copy_instance_logs.sh",
|
||||
node_addr, cls.baymodel.coe, "master"])
|
||||
node_addr, self.baymodel.coe,
|
||||
"master-" + func_name])
|
||||
|
||||
|
||||
class BayTest(BaseMagnumClient):
|
||||
|
@ -229,12 +232,12 @@ class BayTest(BaseMagnumClient):
|
|||
class BayAPITLSTest(BaseMagnumClient):
|
||||
"""Base class of TLS enabled test case."""
|
||||
|
||||
def setUp(self):
|
||||
super(BayAPITLSTest, self).setUp()
|
||||
self.addOnException(self._copy_logs)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
try:
|
||||
cls._copy_logs()
|
||||
except Exception as e:
|
||||
print("WARNING: Failed to copy logs. Error: " + repr(e))
|
||||
|
||||
if cls.ca_dir:
|
||||
rmtree_without_raise(cls.ca_dir)
|
||||
|
|
Loading…
Reference in New Issue