aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpmikus <peter.mikus@protonmail.ch>2023-05-05 09:26:12 +0000
committerPeter Mikus <peter.mikus@protonmail.ch>2023-05-05 09:32:26 +0000
commit4fef5ddc97a8acec3b3cb41e67736385f93081b6 (patch)
tree22501f61abfb4c49c551e99e3866485201b848df
parentd74acc4db2987d9ac40aae10be8453c922a16731 (diff)
fix(core): Docker detection
Signed-off-by: pmikus <peter.mikus@protonmail.ch> Change-Id: I976f96410b06b4f4d7500b03b1f5dd54486bbf42
-rw-r--r--resources/libraries/python/DUTSetup.py18
-rw-r--r--resources/libraries/robot/shared/container.robot7
2 files changed, 15 insertions, 10 deletions
diff --git a/resources/libraries/python/DUTSetup.py b/resources/libraries/python/DUTSetup.py
index 300248c448..363bb7243b 100644
--- a/resources/libraries/python/DUTSetup.py
+++ b/resources/libraries/python/DUTSetup.py
@@ -713,18 +713,15 @@ class DUTSetup:
to detect.
:rtype: bool
"""
- command = u"fgrep docker /proc/1/cgroup"
- message = u"Failed to get cgroup settings."
+ command = "cat /.dockerenv"
try:
- exec_cmd_no_error(
- node, command, timeout=30, sudo=False, message=message
- )
+ exec_cmd_no_error(node, command, timeout=30)
except RuntimeError:
return False
return True
@staticmethod
- def get_docker_mergeddir(node, uuid):
+ def get_docker_mergeddir(node, uuid=None):
"""Get Docker overlay for MergedDir diff.
:param node: DUT node.
@@ -735,8 +732,15 @@ class DUTSetup:
:rtype: str
:raises RuntimeError: If getting output failed.
"""
- command = f"docker inspect " \
+ if not uuid:
+ command = 'fgrep "hostname" /proc/self/mountinfo | cut -f 4 -d" "'
+ message = "Failed to get UUID!"
+ stdout, _ = exec_cmd_no_error(node, command, message=message)
+ uuid = stdout.split(sep="/")[-2]
+ command = (
+ f"docker inspect "
f"--format='{{{{.GraphDriver.Data.MergedDir}}}}' {uuid}"
+ )
message = f"Failed to get directory of {uuid} on host {node[u'host']}"
stdout, _ = exec_cmd_no_error(node, command, sudo=True, message=message)
diff --git a/resources/libraries/robot/shared/container.robot b/resources/libraries/robot/shared/container.robot
index 931508bdc9..ed695af541 100644
--- a/resources/libraries/robot/shared/container.robot
+++ b/resources/libraries/robot/shared/container.robot
@@ -1,4 +1,4 @@
-# Copyright (c) 2021 Cisco and/or its affiliates.
+# Copyright (c) 2023 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
@@ -85,8 +85,9 @@
| | ${nf_id}= | Evaluate | (${nf_chain} - ${1}) * ${nf_nodes} + ${nf_node}
| | ${env}= | Create List | DEBIAN_FRONTEND=noninteractive
| | ${dut1_uuid_length} = | Get Length | ${DUT1_UUID}
-| | ${root}= | Run Keyword If | ${dut1_uuid_length}
-| | ... | Get Docker Mergeddir | ${nodes['DUT1']} | ${DUT1_UUID}
+| | ${in_container}= | Running in Container | ${nodes['${dut}']}
+| | ${root}= | Run Keyword If | ${in_container}
+| | ... | Get Docker Mergeddir | ${nodes['DUT1']}
| | ... | ELSE | Set Variable | ${EMPTY}
| | ${node_arch}= | Get Node Arch | ${nodes['${dut}']}
| | ${name}= | Set Variable | ${dut}_${container_group}${nf_id}${DUT1_UUID}