示例#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_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)