]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Remote: Add is_container property 1712/head
authorZack Cerza <zack@redhat.com>
Mon, 17 Jan 2022 19:19:53 +0000 (12:19 -0700)
committerZack Cerza <zack@redhat.com>
Tue, 15 Feb 2022 23:06:11 +0000 (16:06 -0700)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/orchestra/remote.py
teuthology/orchestra/test/test_remote.py

index 634ce76004e315ef42b863b8f981e38559588b9b..80c8962078c109ed7d6f2549674ef7e5e9a68f6c 100644 (file)
@@ -679,6 +679,15 @@ class Remote(RemoteShell):
             self._is_vm = teuthology.lock.query.is_vm(self.name)
         return self._is_vm
 
+    @property
+    def is_container(self):
+        if not hasattr(self, '_is_container'):
+            self._is_container = not bool(self.run(
+                args="test -f /run/.containerenv -o -f /.dockerenv",
+                check_status=False,
+            ).returncode)
+        return self._is_container
+
     @property
     def init_system(self):
         """
index 9a94bfc43c51ba734a0e7bb6610e1e1784511865..5fa5797eca0592af69aead987d176060b109ae49 100644 (file)
@@ -183,3 +183,23 @@ class TestRemote(object):
         assert remote.Remote._format_size(1024**5).strip() == '1TB'
         assert remote.Remote._format_size(1021112).strip() == '997KB'
         assert remote.Remote._format_size(1021112**2).strip() == '971GB'
+
+    def test_is_container(self):
+        m_transport = MagicMock()
+        m_transport.getpeername.return_value = ('name', 22)
+        self.m_ssh.get_transport.return_value = m_transport
+        m_run = MagicMock()
+        args = []
+        proc = RemoteProcess(
+            client=self.m_ssh,
+            args=args,
+        )
+        proc.returncode = 0
+        m_run.return_value = proc
+        rem = remote.Remote(name='jdoe@xyzzy.example.com', ssh=self.m_ssh)
+        rem._runner = m_run
+        assert rem.is_container
+        proc.returncode = 1
+        rem2 = remote.Remote(name='jdoe@xyzzy.example.com', ssh=self.m_ssh)
+        rem2._runner = m_run
+        assert not rem2.is_container