예제 #1
0
    def test_03__get_volume_bindings(self, mock_isdir, mock_gethome):
        """Test03 SingularityEngine()._get_volume_bindings()."""
        res_exp = ['-B', '/dir1:/dir1',
                   '-B', '/home/user:/home/user',
                   '-B', '/tmp:/tmp',
                   '-B', '/var/tmp:/var/tmp']
        mock_gethome.return_value = "/home/user"
        mock_isdir.side_effect = [True, True]
        sing = SingularityEngine(self.local, self.xmode)
        sing.opt = dict()
        sing.opt["vol"] = ["/dir1", "/home/user"]
        status = sing._get_volume_bindings()
        self.assertEqual(status, res_exp)
        self.assertTrue(mock_gethome.called)
        self.assertTrue(mock_isdir.call_count, 2)

        res_exp = ['-B', '/home/user:/home/user',
                   '-B', '/tmp:/tmp',
                   '-B', '/var/tmp:/var/tmp']
        mock_gethome.return_value = "/home/user"
        mock_isdir.side_effect = [True, True, True]
        sing = SingularityEngine(self.local, self.xmode)
        sing.opt = dict()
        sing.opt["vol"] = ["/home/user", "/tmp", "/var/tmp"]
        status = sing._get_volume_bindings()
        self.assertEqual(status, res_exp)
        self.assertTrue(mock_gethome.called)
        self.assertTrue(mock_isdir.call_count, 3)
예제 #2
0
 def test_04__singularity_env_get(self):
     """Test04 SingularityEngine()._singularity_env_get()."""
     res_exp = {"SINGULARITYENV_AA": "aa", "SINGULARITYENV_BB": "bb"}
     sing = SingularityEngine(self.local, self.xmode)
     sing.opt = dict()
     sing.opt["env"] = [("AA", "aa"), ("BB", "bb")]
     status = sing._singularity_env_get()
     self.assertEqual(status, res_exp)
예제 #3
0
    def test_08_run(self, mock_isdir, mock_fbind, mock_uuid, mock_call,
                    mock_rinit, mock_rinvopt, mock_mkcontdir,
                    mock_selsing, mock_runroot, mock_renvset, mock_getvolbind,
                    mock_renvclean, mock_rbann):
        """Test08 SingularityEngine().run()."""
        mock_isdir.return_value = True
        mock_fbind.return_value.container_orig_dir.return_value = "/d1"
        mock_fbind.return_value.restore.return_value = None
        mock_rinit.return_value = False
        sing = SingularityEngine(self.local, self.xmode)
        status = sing.run("CONTAINERID")
        self.assertEqual(status, 2)

        mock_isdir.return_value = True
        mock_fbind.return_value.container_orig_dir.return_value = "/d1"
        mock_fbind.return_value.restore.return_value = None
        mock_rinit.return_value = "/cont/"
        mock_rinvopt.return_value = None
        mock_mkcontdir.return_value = None
        mock_selsing.return_value = None
        mock_runroot.return_value = None
        mock_renvset.return_value = None
        self.local.bindir = "/cont/bin"
        mock_getvolbind.return_value = ['-B', '/home/user:/home/user',
                                        '-B', '/tmp:/tmp',
                                        '-B', '/var/tmp:/var/tmp']
        mock_uuid.return_value = "EXECUTION_ID"
        mock_renvclean.return_value = None
        mock_rbann.return_value = None
        mock_call.return_value = 0
        sing = SingularityEngine(self.local, self.xmode)
        sing.executable = "/bin/sing"
        status = sing.run("CONTAINERID")
        self.assertEqual(status, 0)
예제 #4
0
 def test_06__run_invalid_options(self, mock_msg):
     """Test06 SingularityEngine()._run_invalid_options()."""
     mock_msg.level = 0
     sing = SingularityEngine(self.local, self.xmode)
     sing.opt['netcoop'] = False
     sing.opt['portsmap'] = True
     sing._run_invalid_options()
     self.assertTrue(mock_msg.called)
예제 #5
0
 def get_engine(self):
     """get execution engine instance"""
     xmode = self.get_mode()
     if xmode.startswith("P"):
         self.exec_engine = \
             PRootEngine(self.localrepo, self)
     elif xmode.startswith("F"):
         self.exec_engine = \
             FakechrootEngine(self.localrepo, self)
     elif xmode.startswith("R"):
         self.exec_engine = \
             RuncEngine(self.localrepo, self)
     elif xmode.startswith("S"):
         self.exec_engine = \
             SingularityEngine(self.localrepo, self)
     return self.exec_engine
예제 #6
0
    def test_02_select_singularity(self, mock_findexe, mock_find,
                                   mock_arch, mock_exists):
        """Test02 SingularityEngine().select_singularity()."""
        Config.conf['use_singularity_executable'] = ""
        mock_findexe.return_value = "/bin/runc-arm"
        mock_exists.return_value = True
        sing = SingularityEngine(self.local, self.xmode)
        sing.select_singularity()
        self.assertTrue(mock_findexe.called)

        Config.conf['use_singularity_executable'] = "UDOCKER"
        mock_arch.return_value = "amd64"
        mock_find.return_value = "singularity-x86_64"
        mock_exists.return_value = True
        sing = SingularityEngine(self.local, self.xmode)
        sing.select_singularity()
        self.assertTrue(mock_arch.called)
        self.assertTrue(mock_find.called)

        Config.conf['use_singularity_executable'] = "UDOCKER"
        mock_arch.return_value = "i386"
        mock_find.return_value = "singularity-x86"
        mock_exists.return_value = True
        sing = SingularityEngine(self.local, self.xmode)
        sing.select_singularity()
        self.assertTrue(mock_arch.called)
        self.assertTrue(mock_find.called)
예제 #7
0
 def test_01_init(self):
     """Test01 SingularityEngine() constructor."""
     sing = SingularityEngine(self.local, self.xmode)
     self.assertEqual(sing.executable, None)
     self.assertEqual(sing.execution_id, None)
예제 #8
0
    def test_07__run_as_root(self, mock_msg, mock_uname,
                             mock_nixauth, mock_hasopt):
        """Test07 SingularityEngine()._run_as_root()."""
        mock_msg.level = 0
        mock_uname.return_value = "u1"
        sing = SingularityEngine(self.local, self.xmode)
        sing.opt = dict()
        status = sing._run_as_root()
        self.assertFalse(status)
        self.assertTrue(mock_uname.called)

        mock_msg.level = 0
        mock_uname.return_value = "u1"
        sing = SingularityEngine(self.local, self.xmode)
        sing.opt = dict()
        sing.opt["user"] = "******"
        status = sing._run_as_root()
        self.assertFalse(status)
        self.assertTrue(mock_uname.called)

        mock_msg.level = 0
        mock_uname.return_value = "u1"
        sing = SingularityEngine(self.local, self.xmode)
        sing.opt = dict()
        sing.opt["user"] = "******"
        sing.opt["uid"] = "1000"
        status = sing._run_as_root()
        self.assertFalse(status)
        self.assertTrue(mock_uname.called)

        mock_msg.level = 0
        mock_uname.return_value = "u1"
        mock_hasopt.return_value = True
        mock_nixauth.return_value.user_in_subuid.return_value = True
        mock_nixauth.return_value.user_in_subgid.return_value = True
        sing = SingularityEngine(self.local, self.xmode)
        sing.opt = dict()
        sing.opt["user"] = "******"
        sing.opt["uid"] = "0"
        status = sing._run_as_root()
        self.assertTrue(status)
        self.assertTrue(mock_hasopt.called)
        self.assertTrue(mock_nixauth.return_value.user_in_subuid.called)
        self.assertTrue(mock_nixauth.return_value.user_in_subgid.called)
예제 #9
0
 def test_05__make_container_dirs(self, mock_mkdir):
     """Test05 SingularityEngine()._make_container_directories()."""
     mock_mkdir.side_effect = [None, None, None, None, None, None]
     sing = SingularityEngine(self.local, self.xmode)
     sing._make_container_directories()
     self.assertTrue(mock_mkdir.call_count, 6)