Commits

Moises Henriquez committed a5f6e91

Begin working on a Networking module for the backend

Comments (0)

Files changed (25)

+* python-netifaces ( http://alastairs-place.net/projects/netifaces/) (2.)
 * pyparted (1.)
 * parted
 * gparted
 Note 1.
 VL7 package can be downloaded from 
 https://bitbucket.org/m0e_lnx/vasm/downloads
+
+Note 2.
+We need a package for this.
 ------
 * vkmap (keyboard mapping settings)
   [ Mappings come from /usr/share/kbd/keymaps/i386/qwerty and /usr/share/kbd/keymaps/i386]
-* Boot manager setup (lilo and grub configure utility)
 * vnetconf equivalent (hostname)
+  + lets the user choose DHCP or STATIC IP
+  + list which networking daemon to use. (from available to the
+    system.)
+  + Select weather to use a daemon or not.  Not using a daemon would
+    mean it sets dhcp on the selected interface.
+  
     All other networking settings are handled by wicd, or some other networking daemon.
 * network manager launcher (launch the available network manager config)
 
 
 Completed:
 ----------
+*   OLD: N/a
+    DESCRIPTION:  Configure LILO and GRUB2
+    NEW: bootloaders.py, tui_bootloaders.py
+    SUPPORT MODULES: BOOTLOADERS.py
+
 *   OLD: vskel
     DESCRIPTION: Resets user home settings.
     NEW: skel.py

src/tests/__init__.py

+#!/usr/bin/env python
+
+""" Unit tests for the backend modules on vasm """

src/tests/config.py

+#!/usr/bin/env python
+
+import os
+""" Some variables for the tests """
+backendpath = os.path.dirname(os.path.abspath(__file__))

src/tests/jailedtest.sh

+#!/bin/bash
+
+#    This file is part of VASM.
+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+#    ro-chroot concept by Uelsk8s
+
+__author__="uelsk8s"
+# Modified by M0E-lnx
+
+TEST=$1
+CURDIR=$(pwd)
+TARGETDIR=/vasm
+TESTSDIR=${TARGETDIR}/tests
+#echo $CURDIR
+#cd ../../../../../
+cd ../../
+CURDIR=$(pwd)
+
+#echo $CURDIR
+mkdir -p /dev/shm/CHROOT-RW /dev/shm/CHROOT
+#cp -ar vasm /dev/shm/CHROOT-RW/ || exit 1
+mkdir /dev/shm/CHROOT-RW/vasm
+cp src/* -ar /dev/shm/CHROOT-RW/vasm || exit 1
+mount -t aufs -o br=/dev/shm/CHROOT-RW=rw:/=ro,xino=/dev/shm/aufs.xino none /dev/shm/CHROOT
+mount -t proc none /dev/shm/CHROOT/proc
+mount -o bind /dev/ /dev/shm/CHROOT/dev
+#ls -la /dev/shm/CHROOT
+chroot /dev/shm/CHROOT python ${TESTSDIR}/${TEST}
+
+umount /dev/shm/CHROOT/dev
+umount /dev/shm/CHROOT/proc
+umount /dev/shm/CHROOT
+rm -rf /dev/shm/CHROOT-RW/vasm

src/tests/test_BOOTMODE.py

+#!/usr/bin/env python
+
+#    This file is part of VASM.
+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+__author__ = "Moises Henriquez"
+__author_email__ = "moc.liamg@xnl.E0M"[::-1]
+
+
+import os
+import sys
+import shutil
+import unittest
+vasmdir = os.path.join(os.path.dirname(
+    os.path.dirname(os.path.abspath(__file__))), 'vasm')
+if not vasmdir in sys.path: sys.path.append(vasmdir)
+from backend import BOOTMODE
+
+
+
+class BootModeTest(unittest.TestCase):
+    def setUp(self):
+        self.file = "/tmp/inittab"
+        shutil.copy2("/etc/inittab", "/tmp/inittab")
+        self.model = BOOTMODE.InitTab(self.file)
+        self._original_data = []
+        with open(self.file) as file:
+            for line in file:
+                self._original_data.append(line)
+        
+    
+    def tearDown(self):
+        # remove the temp file
+        os.remove("/tmp/inittab")
+    
+    def test_methods(self):
+        """ Test to make sure the class has the right methods """
+        self.assertTrue(callable(self.model.getMode))
+        self.assertTrue(callable(self.model.setMode))
+
+    def test_getMode(self):
+        mode = self.model.getMode()
+        self.assertTrue(type(mode) == int)
+    
+    def test_setMode(self):
+        # copy the file to tmp
+        mode = 3
+        self.model.setMode(mode)
+        # make sure when we read it, it comes back the same as it went in
+        result = self.model.getMode()
+        self.assertEqual(mode, result)
+        
+        # Check that this method raises an exception if fed the wrong values
+        self.assertRaises(AssertionError, self.model.setMode, 0)
+        self.assertRaises(AssertionError, self.model.setMode, 6)
+
+if __name__ == "__main__":
+    unittest.main()

src/tests/test_DATESET.py

+
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+#    This file is part of VASM.
+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+
+import unittest
+import os
+import sys
+vasmdir = os.path.join(os.path.dirname(
+    os.path.dirname(os.path.abspath(__file__))), 'vasm')
+if not vasmdir in sys.path: sys.path.append(vasmdir)
+from backend import DATESET
+
+class ClockTest(unittest.TestCase):
+    """ Test the functionality to set the hardware clock """
+    def setUp(self):
+        self.clock = DATESET.HWClock()
+        super(ClockTest, self).setUp()
+        self.dummyvalue = "localtime"
+
+    def test_setClock(self):
+        # This will except if something goes wrong
+        self.clock.set_value(self.dummyvalue)
+        gotval = self.clock.get_value()
+        return self.assertEqual(gotval, self.dummyvalue)
+
+    def test_invalid_values(self):
+        self.assertRaises(AssertionError,
+                          self.clock.set_value, "foo")
+        self.assertRaises(AssertionError,
+                          self.clock.set_value, "")
+        
+
+class TimeZoneTest(unittest.TestCase):
+    """ Test timezone setting and getting """
+    def setUp(self):
+        self.zone = DATESET.TimeZone()
+        super(TimeZoneTest, self).setUp()
+        self.zonesbase = "/usr/share/zoneinfo/"
+        self.tz = "US/Eastern"
+
+    def test_setEmtyZone(self):
+        self.assertRaises(AssertionError,
+                          self.zone.set_zone, "")
+        return self.assertRaises(AssertionError,
+                                 self.zone.set_zone, None)
+
+    def test_setzone(self):
+        ret = self.zone.set_zone(self.tz)
+        return self.assertTrue(ret)
+
+    def test_getzone(self):
+        # set the zone.
+        self.assertTrue(self.zone.set_zone(self.tz))
+        zone = self.zone.get_zone()
+        return self.assertEqual(zone, self.tz)
+
+    def test_verify_with_filesystem(self):
+        # we must set it again
+        self.assertTrue(self.zone.set_zone(self.tz))
+        rlink = os.readlink("/etc/localtime-copied-from")
+        return self.assertEqual(rlink, os.path.join(self.zonesbase, self.tz))
+
+
+class DateTimeTest(unittest.TestCase):
+    """ Test the functionality to set and get the system time """
+
+    def setUp(self):
+        super(DateTimeTest, self).setUp()
+        self.date_time = DATESET.DateTime()
+
+        # save current time for restoring it later
+        self.now = self.date_time._date_time
+        self.date = self.now.year, self.now.month, self.now.day
+        self.time = self.now.hour, self.now.minute, self.now.second
+
+    def tearDown(self):
+        super(DateTimeTest, self).tearDown()
+        dt = self.date_time
+        dt.year, dt.month, dt.day = self.date
+        dt.hour, dt.minute, dt.second = self.time
+        self.date_time.set_date_and_time()
+
+    def testSetDate(self):
+
+        # test day and month < 10
+        self.date_time.year += 1
+        self.date_time.month = 2
+        self.date_time.day = 2
+        self.date_time.set_date()
+        current_date = DATESET.DateTime()
+        self.assertEqual(current_date.year, self.date[0] + 1)
+        self.assertEqual(self.date_time.year, current_date.year)
+        self.assertEqual(self.date_time.month, current_date.month)
+        self.assertEqual(self.date_time.day, current_date.day)
+
+        # test day and month > 10
+        self.date_time.month = 12
+        self.date_time.day = 24
+        self.date_time.set_date()
+        current_date = DATESET.DateTime()
+        self.assertEqual(current_date.year, self.date[0] + 1)
+        self.assertEqual(self.date_time.year, current_date.year)
+        self.assertEqual(self.date_time.month, current_date.month)
+        self.assertEqual(self.date_time.day, current_date.day)
+
+    def testSetTime(self):
+ 
+        self.date_time.hour += 1
+        self.date_time.minute += 1
+        self.date_time.second = 0
+        self.date_time.set_time()
+        current_time = DATESET.DateTime()
+        self.assertEqual(current_time.hour, self.time[0] + 1)
+        self.assertEqual(current_time.minute, self.time[1] + 1)
+        self.assertEqual(self.date_time.hour, current_time.hour)
+        self.assertEqual(self.date_time.minute, current_time.minute)
+        self.assertAlmostEqual(self.date_time.second, current_time.second)
+
+
+if __name__ == "__main__":
+    assert os.getuid() == 0, "You need to be root for running DateTime tests"
+    unittest.main()

src/tests/test_FSTAB.py

+#!/usr/bin/env python
+
+#    This file is part of VASM.
+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+__author__ = "Moises Henriquez"
+__author_email__ = "moc.liamg@xnl.E0M"[::-1]
+
+import unittest
+import os
+import sys
+vasmdir = os.path.join(os.path.dirname(
+    os.path.dirname(os.path.abspath(__file__))), 'vasm')
+if not vasmdir in sys.path: sys.path.append(vasmdir)
+import unittest
+from backend import FSTAB
+from shutil import copy2
+
+class FstabTest(unittest.TestCase):
+    def setUp(self):
+        # create a copy of /etc/fstab so we can play with it
+        self.datapath = '/tmp/test_fstab'
+        copy2('/etc/fstab', self.datapath)
+        self.datamodel = FSTAB.FstabModel(self.datapath)
+        self.fake_entry = FSTAB.FstabEntry()
+        self.fake_entry.device = "/dev/sdz1"
+        self.fake_entry.mountpoint = "fake_mount_point"
+        self.fake_entry.filesystem = "ext2"
+        self.fake_entry.options = "defaults 1 0"
+        return
+
+    def test_check_for_entry(self):
+        # Check if an entry exists
+        # We have not yet added fake_entry, so this should return False
+        self.assertTrue(self.datamodel.hasEntry(self.fake_entry.device) is False)
+
+    def test_add_entry(self):
+        # Check if we can add an entry
+        self.datamodel.addEntry(self.fake_entry)
+        # now check if we have the entry there
+        self.assertTrue(self.datamodel.hasEntry(self.fake_entry.device))
+
+    def test_remove_entry(self):
+        # Check if we can remove an entry
+        self.datamodel.addEntry(self.fake_entry)
+        self.assertTrue(self.datamodel.hasEntry(self.fake_entry.device))
+        self.datamodel.removeEntry(self.fake_entry.device)
+        self.assertTrue(self.datamodel.hasEntry(self.fake_entry.device) is False)
+
+    def test_invalid_entry_argument(self):
+        # Make sure it raises an exception if we give it a string
+        self.assertRaises(AssertionError,
+                          self.datamodel.addEntry, 'foo')
+
+    def test_incomplete_entry_attributes(self):
+        # make sure we raise an exception when the attributes of the entry are not complete
+        entry = FSTAB.FstabEntry() # empty entry
+        self.assertRaises(AssertionError,
+                          self.datamodel.addEntry, entry)
+        
+    def tearDown(self):
+        """ Remove the file when we're done """
+        return os.remove(self.datapath)
+
+
+if __name__ == "__main__":
+    assert os.geteuid() == 0, "You must be root to run tests on /etc/fstab """
+    unittest.main()
+

src/tests/test_LOGINMANAGERS.py

+#!/usr/bin/env python
+
+#    This file is part of VASM.
+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+__author__ = "Moises Henriquez"
+__author_email__ = "moc.liamg@xnl.E0M"[::-1]
+
+import sys
+import os
+import shutil
+import unittest
+vasmdir = os.path.join(os.path.dirname(
+    os.path.dirname(os.path.abspath(__file__))), 'vasm')
+if not vasmdir in sys.path: sys.path.append(vasmdir)
+from backend import LOGINMANAGERS as gestores
+
+
+class BootModeTest(unittest.TestCase):
+    def setUp(self):
+        self.file = "/tmp/rc.X"
+        shutil.copy2("/etc/rc.d/rc.X", "/tmp/rc.X")
+        self.model = gestores.LoginManagers(specfile=self.file)
+    
+    def tearDown(self):
+        # remove the temp file
+        os.remove(self.file)
+        
+    def test_getCurrent(self):
+        gestor = self.model.get_current()
+        self.assertTrue(type(gestor) == str)
+    
+    def test_setMode(self):
+        # copy the file to tmp
+        manager = "FOO"
+        res = self.model.set_manager("FOO")
+        read_man = self.model.get_current()
+        self.assertEqual(read_man, manager)
+    
+    def test_roundTest(self):
+        man = "BAR"
+        # set the mode
+        res = self.model.set_manager(man)
+        # read it to make sure it comes back the same
+        read = self.model.get_current()
+        self.assertEqual(read, man)
+    
+    def test_managers(self):
+        res = self.model.list_existing()
+        self.assertTrue(len(res) > 0)
+    
+    def test_descriptions(self):
+        manager = self.model.list_existing()[0].lower()
+        res = self.model._describe_manager(manager)
+        self.assertTrue(type(res), str)
+        
+        
+        
+        
+
+if __name__ == "__main__":
+    unittest.main()

src/tests/test_NETWORKING.py

+#!/usr/bin/env python
+
+#    This file is part of VASM.
+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+""" test_NETWORKING.py
+Test suite for the networking module"""
+__author__ = "Moises Henriquez"
+__author_email__ = "moc.liamg@xnl.E0M"[::-1]
+
+import os
+import sys
+vasmdir = os.path.join(os.path.dirname(
+    os.path.dirname(os.path.abspath(__file__))), 'vasm')
+if not vasmdir in sys.path: sys.path.append(vasmdir)
+import unittest
+from backend import NETWORKING
+
+class NetworkingTests(unittest.TestCase):
+    def setUp(self):
+        return
+    
+    def testModuleAttributes(self):
+        self.assertTrue(hasattr(NETWORKING, 'NetConfModel'))
+    
+    def testReadHostName(self):
+        self.assertEqual(1, 0)
+    
+    def testSetHostName(self):
+        self.assertEqual(1, 0)
+    
+    def testGetNicList(self):
+        self.assertEqual(1, 0)
+
+if __name__ == '__main__':
+    assert os.geteuid() == 0, "Only root is allowed to run these tests."""
+    unittest.main()

src/tests/test_SERVICES.py

+#!/usr/bin/env python
+
+#    This file is part of VASM.
+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+__author__ = "Moises Henriquez"
+__author_email__ = "moc.liamg@xnl.E0M"[::-1]
+
+import unittest
+import os
+import sys
+vasmdir = os.path.join(os.path.dirname(
+    os.path.dirname(os.path.abspath(__file__))), 'vasm')
+if not vasmdir in sys.path: sys.path.append(vasmdir)
+from backend import SERVICES as services
+
+class ServicesTests(unittest.TestCase):
+    def setUp(self):
+        self.datamodel = services.ServiceModel()
+        self.fake_service = self.datamodel.list_all_services()[0]
+        self.fake_runlevel = 4
+
+    def test_EnableService(self):
+        code, output = self.datamodel.enable_service(self.fake_service,
+                                                     self.fake_runlevel)
+        # subprocess will return > 0 if this fails
+        self.assertEqual(code, 0)
+        # this return True when service is enabled, False otherwise
+        # should be enabled now
+        val = self.datamodel.get_service_runlevel_status(self.fake_service,
+                                                         self.fake_runlevel)
+        self.assertTrue(val)
+
+    def test_DisableService(self):
+        code, output = self.datamodel.disable_service(self.fake_service,
+                                                      self.fake_runlevel)
+        # Subprocess will return > 0 if this fails
+        self.assertEqual(code, 0)
+        # Check the status of this service now.  Should be disabled
+        val = self.datamodel.get_service_runlevel_status(self.fake_service,
+                                                         self.fake_runlevel)
+        self.assertEqual(val, False)
+
+    def test_InvalidRunlevel_enable(self):
+        self.assertRaises(AssertionError,
+                          self.datamodel.enable_service,
+                          self.fake_service, 0)
+        self.assertRaises(AssertionError,
+                          self.datamodel.enable_service,
+            self.fake_service, 6)
+
+    def test_InvalidService_enable(self):
+        """ Try to enable an unknown service."""
+        return self.assertRaises(AssertionError,
+                          self.datamodel.enable_service,
+            "foo", 2)
+
+    def test_InvalidRunlevel_disable(self):
+        """ Try to disable services for an invalid runlevel """
+        self.assertRaises(AssertionError,
+                          self.datamodel.disable_service,
+            self.fake_service, 0)
+        self.assertRaises(AssertionError,
+                          self.datamodel.disable_service,
+            self.fake_service, 6)
+        return
+
+    def test_InvalidService_disable(self):
+        """ Try to disable an invalid service """
+        return self.assertRaises(AssertionError,
+                                 self.datamodel.disable_service,
+            "foo", 2)
+        
+
+if __name__ == '__main__':
+    assert os.geteuid() == 0, "You must be root to run tests on system services"
+    unittest.main()

src/tests/test_SKEL.py

+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import sys
+vasmdir = os.path.join(os.path.dirname(
+    os.path.dirname(os.path.abspath(__file__))), 'vasm')
+if not vasmdir in sys.path: sys.path.append(vasmdir)
+from backend import USERADMIN, SKEL
+import unittest
+
+__author__ = "Moises Henriquez"
+__author_email__ = "moc.liamg@xnl.E0M"[::-1]
+
+
+class TestSkel(unittest.TestCase):
+    def setUp(self):
+        # create a fake user account.
+        self.usermodel = USERADMIN.UserModel()
+        self._fake_user = USERADMIN.User(login='fidencio', new=True)
+        if self.usermodel.hasUser(self._fake_user.login):
+            self.usermodel.deleteUser(self._fake_user.login)
+        self._fake_user.realname = 'Fidencio Hdz'
+        self._fake_user.groups = ['sys', 'adm', 'slocate', 'netdev', 'power']
+        self._fake_user.password = 'secrepassword'
+        self.usermodel.addUser(self._fake_user)
+        
+        self.assertTrue(self.usermodel.hasUser('fidencio'))
+        self.SkelModel = SKEL.UserSkel('fidencio')
+        self.addCleanup(self._custom_cleanup)
+
+    def test_ResetInvalidSetting(self):
+        """ Make sure we raise an exception when we try to reset something that doesn't exist."""
+        return self.assertRaises(AssertionError,
+                                 self.SkelModel.reset_settings,'foo')
+
+    def test_ResetSettingsDir(self):
+        """ Test resetting a directory of settings """
+        d = None
+        for f in self.SkelModel.list_resettable_settings():
+            if os.path.isdir(os.path.join('/etc/skel', f)):
+                d = f
+                break
+        return self.assertTrue(self.SkelModel.reset_settings([d]))
+
+    def test_ResetSettingsFile(self):
+        """ Test resetting a settings file """
+        # get a file first
+        f = None
+        for s in self.SkelModel.list_resettable_settings():
+            if not os.path.isdir(os.path.join('/etc/skel', s)):
+                f = s
+                break
+        return self.assertTrue(self.SkelModel.reset_settings([f]))
+
+    def _custom_cleanup(self):
+        if self.usermodel.hasUser(self._fake_user.login):
+            self.usermodel.deleteUser(self._fake_user.login)
+
+    def tearDown(self):
+        # delete the created user
+        if self.usermodel.hasUser(self._fake_user.login):
+            self.usermodel.deleteUser(self._fake_user.login)
+        super(TestSkel, self).tearDown()
+
+
+if __name__ == '__main__':
+    assert os.geteuid != 0, "You must be root to perform SKEL tests because these are jailed tests."
+    unittest.main()

src/tests/test_USERMANAGE.py

+#!/usr/bin/env python
+
+#    This file is part of VASM.
+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import sys
+import unittest
+vasmdir = os.path.join(os.path.dirname(
+    os.path.dirname(os.path.abspath(__file__))), 'vasm')
+if not vasmdir in sys.path: sys.path.append(vasmdir)
+from backend import USERADMIN
+
+class Test(unittest.TestCase):
+    """ Subclass of jailedtests to test how we do when creating accounts """
+
+    @classmethod
+    def setUpClass(cls):
+        pass
+
+    @classmethod
+    def tearDownClass(cls):
+        pass
+
+    def tearDown(self):
+        if self.usermodel.hasUser(self.user.login):
+            self.usermodel.deleteUser(self.user.login)
+    
+    def setUp(self):
+        self.usermodel = USERADMIN.UserModel()
+        # create a dummy account
+        self.user = USERADMIN.User('fidencio', new=True)
+        self.user.fullname = 'Fidencio Hdz'
+        self.user.groups = ['sys', 'adm', 'slocate', 'power']
+        self.user.password = 'supersecretpassword'
+        self.addCleanup(self._cleanup)
+
+    def _cleanup(self):
+        if self.usermodel.hasUser(self.user.login):
+            self.usermodel.deleteUser(self.user.login)
+        return
+
+    def test_Invalid_user_object(self):
+        # Make sure we raise an exception when invalid user argument is given to addUser
+        self.assertRaises(AssertionError,
+                          self.usermodel.addUser, self.user.login)
+        return
+
+    def test_missing_login_attribute(self):
+        user = self.user
+        user.login = None
+        return self.assertRaises(USERADMIN.EmptyAttributeError,
+                                 self.usermodel.addUser, user)
+
+    def test_missing_passsword_attribute(self):
+        user = self.user
+        user.password = None
+        return self.assertRaises(USERADMIN.EmptyAttributeError,
+                                 self.usermodel.addUser, user)
+
+    def test_short_password_attribute(self):
+        user = self.user
+        user.password = 'foo'
+        return self.assertRaises(AssertionError,
+                                 self.usermodel.addUser, user)
+
+    def test_missing_groups_attribute(self):
+        user = self.user
+        user.groups = None
+        return self.assertRaises(USERADMIN.EmptyAttributeError,
+                                 self.usermodel.addUser, user)
+
+    def test_wrong_groups_attribute(self):
+        user = self.user
+        user.groups = "foo,bar"
+        return self.assertRaises(USERADMIN.EmptyAttributeError,
+                                 self.usermodel.addUser, user)
+    
+    def test_Delete_Nonexistant_User(self):
+        # Try to delete a user account that doesn't exist.  This should except.
+        return self.assertRaises(AssertionError,
+                                 self.usermodel.deleteUser, self.user)
+
+    def test_MakeUser(self):
+        # Create a new user account
+        self.usermodel.addUser(self.user)
+        self.assertTrue(self.usermodel.hasUser(self.user.login)), "User account was not successfully created."
+        # test to make sure the attributes of the created account match what we wanted.
+        return
+
+    def test_Add_Existing_user(self):
+        # Try to add a user that already exists.  This should except
+        self.test_MakeUser()
+        return self.assertRaises(AssertionError,
+                          self.usermodel.addUser, self.user)
+
+    def test_user_attributes(self):
+        # Test the user attributes, with the resulting user account
+        self.test_MakeUser()
+        euser = self.usermodel.getUser(self.user.login)
+        self.assertEqual(self.user.login, euser.login), "User login mismatch."
+        self.assertTrue(euser.uid > 1000), "User ID is in invalid range."
+        self.assertEqual(self.user.groups, euser.groups), "User groups mismatch."
+        self.assertEqual(self.user.fullname, euser.fullname), "User full name mismatch."
+    
+    def test_DeleteUser(self):
+        """ Testing user deletion capabilities ... """
+        self.test_MakeUser()
+        # make sure the user is created
+        self.assertTrue, self.usermodel.hasUser(self.user.login)
+        # delete the account
+        self.usermodel.deleteUser(self.user.login)
+        self.assertTrue(self.usermodel.hasUser(self.user.login) is False), "User account was not deleted."
+
+
+if __name__ =='__main__':
+    assert os.geteuid() == 0, "You must be root to run jailed tests."
+    unittest.main()

src/vasm/backend/NETWORKING.py

+#!/usr/bin/env python
+
+#    This file is part of VASM.
+#
+#    VASM is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    VASM is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
+
+#   Thanks to Jason Pierce (rxMokka) for the research that went into this.
+
+__author__ = "Moises Henriquez"
+__author_email__ = "moc.liamg@xnl.E0M"[::-1]
+
+""" NETWORKING.py
+Interact with network interfaces and general system networking settings. """
+from netifaces import *
+import os
+import logging
+from utils import get_popen
+import SERVICES
+
+DHCP = -1
+STATIC = -2
+logger = logging.getLogger('vasm')
+
+class MissingDaemonError(Exception):
+    def __init__(self, message):
+        self.message = message
+    
+    def __str__(self):
+        return repr(self.message)
+
+class NDaemon(object):
+    """ Class representing a networking daemon available on the system. 
+    Allows us to interact with this daemon, and perform tasks such as
+    enabling it and disabling it. 
+    Arguments:
+        bin_path    -   Path to the executable.
+        init_script -   Path to the rc.daemon file in /etc/rc.d
+        service_script - Path to the service handler for this daemon. 
+                        Usually somewhere in /etc/rc.d/init.d """
+        
+    def __init__(self, name=None, bin_path=None, init_script=None, 
+            service_script=None):
+        self.name = name
+        self.bin_path = bin_path
+        self.init_script = init_script
+        self.service_script = service_script
+    
+    def _run_command(self, cmd):
+        proc = get_popen(cmd)
+        stdout, stderr = proc.communicate()
+        code = proc.returncode
+        assert code == 0, stderr.strip()
+    
+    def enable(self):
+        """ Make the init_script executable """
+        return self._run_command(['chmod','+x', self.init_stript])
+    
+    def disable(self):
+        """ Make the init_script not executable """
+        return self._run_command(['chmod', '-x', self.init_stript])
+    
+    def disable_service(self):
+        """ disable the service for all runlevels """
+        assert self.service_script is not None, \
+            "No service script available for %s."% self.bin_path
+        svcmodel = SERVICES.ServiceModel()
+        assert svcmodel.hasService(self.service_script), \
+            "No such service %s on the system."% self.service_script
+        for x in range(3,5):
+            svcmodel.disable_service(self.service_script, x)        
+        return
+    
+    def enable_service(self):
+        """ enable service for runlevels 3-5 """
+        assert self.service_script is not None, \
+            "No service script available available for %s."% self.bin_path
+        svcmodel = SERVICES.ServiceModel()
+        assert svcmodel.hasService(self.service_script), \
+            "No such service %s on the system."% self.service_script
+        
+        for x in range(3, 5):
+            svcmodel.enable_service(self.service_script, x)
+        return
+
+class Nic(object):
+    """ Class representing a network interface. 
+    By using this class, we can access information about the network
+    
+    Arguments:
+        devname - Device name. ie, 'eth0'
+        ip_addr - IP Address for the adaptor.
+        netmask - netmask address.
+        bcast -   broadcast address.
+        macaddr - hardware MAC address
+    """
+    def __init__(self, devname=None,
+            ip_addr = None,
+            netmask = None,
+            bcast = None,
+            macaddr = None,
+            ):
+        self.devname = devname
+        self.ip_addr = ip_addr
+        self.netmask = netmask
+        self.broadcast = bcast
+        self.macaddr = macaddr
+
+class Inet(object):
+    """ Class used to represent an rc.inet entry in a vectorlinux system.
+    
+    Arguments:
+        nic     -   Interface to be used for this inet.  Must be an instance
+                    of the class Nic.
+        nmethod -   Networking Method.  Defines how the NIC is configured.
+                    Must be one of STATIC or DHCP """
+    def __init__(self, nic=None, nmethod=DHCP):
+        assert isinstance(nic, Nic), 'Invalid nic argument.  Must use a Nic object'
+        assert nmethod in (DHCP, STATIC), 'Invalid networking method argument'
+        self.nic = nic
+        self.nmethod = nmethod
+    
+    def _generate_config_data(self):
+        """ Generate the inet script with the information provided. 
+        Returns the data as a list"""
+        if self.nmethod is DHCP:
+            dhcpval = "yes"
+        else:
+            dhcpval = "no"
+        ret = [
+        "#!/bin/sh",
+        " This file is created by vasm",
+        " Avoid modifying it by hand",
+        "#",
+        "###################",
+        "#",
+        "## The settings",
+        "DEVICE='%s'"% self.nic.devname,
+        "DHCP='%s'"% dhcpval,
+        "IPADDR='%s'"%self.nic.ip_addr,
+        "NETMASK='%s'"% self.nic.netmask,
+        "GATEWAY=''",
+        "PROBE='no'",
+        " ",
+        "################## THE SCRIPT #########",
+        "# Source the standard networking script.",
+        ". /etc/rc.d/functions-network \"$@\""]
+        return ret
+
+
+class NetConfModel(object):
+    """ Global networking model. """
+    def __init__(self, host_file='/etc/hostname',
+        dns_file='/etc/resolve.conf',
+        hostname='vector.linux.vnet', nic_defs='/proc/net/dev'):
+        self.nic_defs = nic_defs
+        self.host_file = host_file
+        self.dns_file = dns_file
+        self.hostname = hostname
+
+    def listNetworkingDaemons(self):
+        """ Returns a list of known networking daemons available on 
+        the system.  list contents are NDaemon objects """
+        ret = []
+        # Define some known daemons in a dictionary where the key
+        # is the name of the daemon, and the key is another dictionary with
+        # a 'path', 'initscript', and 'service' keys.
+        DAEMONS = {'networkmanager':
+            {'path': '/usr/sbin/NetworkManager',
+                'initscript' : '/etc/rc.d/rc.networkmanager',
+                'service' : None},
+            'wicd' : {
+                'path': '/usr/sbin/wicd',
+                'initscript' : '/etc/rc.d/rc.wicd',
+                'service': None}}
+        for netapp in DAEMONS:
+            if os.path.exists(DAEMONS[netapp]['path']):
+                ndaemon = NDaemon(
+                    name = netapp,
+                    bin_path = DAEMONS[netapp]['path'],
+                    init_script = DAEMONS[netapp]['initscript'],
+                    service_script = DAEMONS[netapp]['service'])
+                ret.append(ndaemon)
+        return ret
+    
+    def useDaemon(self, daemon):
+        """ Configure the system to use the specified networking daemon """
+        options = self.lietNetworkingDaemons()
+        valid = False
+        for bin in options:
+            if bin.lower() == daemon.lower():
+                valid = True
+        if not valid:
+            raise MissingDaemonException(
+            "Specified daemon is not available on this system.")
+    
+    def listNetworkAdapters(self):
+        """ Return a list of Nic objects """
+        ret = []
+        for nic in interfaces():
+            if nic == 'lo':
+                continue
+            nicdata = ifaddresses(nic)
+            ip = nicdata[AF_INET][0]['addr']
+            broadcast = nicdata[AF_INET][0]['broadcast']
+            nmask = nicdata[AF_INET][0]['netmask']
+            macaddr = nicdata[AF_LINK][0]['addr']
+            _NIC = Nic(devname = nic,
+                netmask = nmask,
+                bcast = broadcast,
+                macaddr = macaddr,
+                ip_addr = ip)
+            ret.append(_NIC)
+        return ret

src/vasm/backend/SERVICES.py

     
     def list_all_services(self):
         return os.listdir(self.initdpath)
+    
+    def hasService(self, svcname):
+        """ Check if a service is available on the system. """
+        lst = self.list_all_services()
+        return svcname in lst
+    
+    def getServiceStatus(self, svcname, runlevel):
+        """ Check if svcname is enabled for runlevel.  Return True if svc is 
+        enabled for that runlevel, or False if it is disabled """
+        assert self.hasService(svcname) is True, 'No such service %s'% svcname
+        return self.get_service_runlevel_status(svcname, runlevel)
+        

src/vasm/backend/tests/__init__.py

-#!/usr/bin/env python
-
-""" Unit tests for the backend modules on vasm """

src/vasm/backend/tests/config.py

-#!/usr/bin/env python
-
-import os
-""" Some variables for the tests """
-backendpath = os.path.dirname(os.path.abspath(__file__))

src/vasm/backend/tests/jailedtest.sh

-#!/bin/bash
-
-#    This file is part of VASM.
-#
-#    VASM is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License v3 as published by
-#    the Free Software Foundation.
-#
-#    VASM is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License
-#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
-
-#    ro-chroot concept by Uelsk8s
-
-__author__="uelsk8s"
-# Modified by M0E-lnx
-
-TEST=$1
-CURDIR=$(pwd)
-TARGETDIR=/vasm
-TESTSDIR=${TARGETDIR}/vectorlinux/tests
-#echo $CURDIR
-#cd ../../../../../
-cd ../../
-CURDIR=$(pwd)
-#echo $CURDIR
-mkdir -p /dev/shm/CHROOT-RW /dev/shm/CHROOT
-#cp -ar vasm /dev/shm/CHROOT-RW/ || exit 1
-mkdir /dev/shm/CHROOT-RW/vasm
-cp * -ar /dev/shm/CHROOT-RW/vasm || exit 1
-mount -t aufs -o br=/dev/shm/CHROOT-RW=rw:/=ro,xino=/dev/shm/aufs.xino none /dev/shm/CHROOT
-mount -t proc none /dev/shm/CHROOT/proc
-mount -o bind /dev/ /dev/shm/CHROOT/dev
-#ls -la /dev/shm/CHROOT
-chroot /dev/shm/CHROOT python ${TESTSDIR}/${TEST}
-
-umount /dev/shm/CHROOT/dev
-umount /dev/shm/CHROOT/proc
-umount /dev/shm/CHROOT
-rm -rf /dev/shm/CHROOT-RW/vasm

src/vasm/backend/tests/test_BOOTMODE.py

-#!/usr/bin/env python
-
-#    This file is part of VASM.
-#
-#    VASM is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License v3 as published by
-#    the Free Software Foundation.
-#
-#    VASM is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License
-#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
-
-__author__ = "Moises Henriquez"
-__author_email__ = "moc.liamg@xnl.E0M"[::-1]
-
-
-import os
-import unittest
-import sys
-import shutil
-bepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-if not bepath in sys.path:
-    sys.path.append(bepath)
-import BOOTMODE
-
-
-class BootModeTest(unittest.TestCase):
-    def setUp(self):
-        self.file = "/tmp/inittab"
-        shutil.copy2("/etc/inittab", "/tmp/inittab")
-        self.model = BOOTMODE.InitTab(self.file)
-        self._original_data = []
-        with open(self.file) as file:
-            for line in file:
-                self._original_data.append(line)
-        
-    
-    def tearDown(self):
-        # remove the temp file
-        os.remove("/tmp/inittab")
-    
-    def test_methods(self):
-        """ Test to make sure the class has the right methods """
-        self.assertTrue(callable(self.model.getMode))
-        self.assertTrue(callable(self.model.setMode))
-
-    def test_getMode(self):
-        mode = self.model.getMode()
-        self.assertTrue(type(mode) == int)
-    
-    def test_setMode(self):
-        # copy the file to tmp
-        mode = 3
-        self.model.setMode(mode)
-        # make sure when we read it, it comes back the same as it went in
-        result = self.model.getMode()
-        self.assertEqual(mode, result)
-        
-        # Check that this method raises an exception if fed the wrong values
-        self.assertRaises(AssertionError, self.model.setMode, 0)
-        self.assertRaises(AssertionError, self.model.setMode, 6)
-
-if __name__ == "__main__":
-    unittest.main()

src/vasm/backend/tests/test_DATESET.py

-
-#!/usr/bin/env python
-# -*- encoding: utf-8 -*-
-
-#    This file is part of VASM.
-#
-#    VASM is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License v3 as published by
-#    the Free Software Foundation.
-#
-#    VASM is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License
-#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
-
-
-import unittest
-import os
-import sys
-bepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-if not bepath in sys.path:
-    sys.path.append(bepath)
-import DATESET
-
-class ClockTest(unittest.TestCase):
-    """ Test the functionality to set the hardware clock """
-    def setUp(self):
-        self.clock = DATESET.HWClock()
-        super(ClockTest, self).setUp()
-        self.dummyvalue = "localtime"
-
-    def test_setClock(self):
-        # This will except if something goes wrong
-        self.clock.set_value(self.dummyvalue)
-        gotval = self.clock.get_value()
-        return self.assertEqual(gotval, self.dummyvalue)
-
-    def test_invalid_values(self):
-        self.assertRaises(AssertionError,
-                          self.clock.set_value, "foo")
-        self.assertRaises(AssertionError,
-                          self.clock.set_value, "")
-        
-
-class TimeZoneTest(unittest.TestCase):
-    """ Test timezone setting and getting """
-    def setUp(self):
-        self.zone = DATESET.TimeZone()
-        super(TimeZoneTest, self).setUp()
-        self.zonesbase = "/usr/share/zoneinfo/"
-        self.tz = "US/Eastern"
-
-    def test_setEmtyZone(self):
-        self.assertRaises(AssertionError,
-                          self.zone.set_zone, "")
-        return self.assertRaises(AssertionError,
-                                 self.zone.set_zone, None)
-
-    def test_setzone(self):
-        ret = self.zone.set_zone(self.tz)
-        return self.assertTrue(ret)
-
-    def test_getzone(self):
-        # set the zone.
-        self.assertTrue(self.zone.set_zone(self.tz))
-        zone = self.zone.get_zone()
-        return self.assertEqual(zone, self.tz)
-
-    def test_verify_with_filesystem(self):
-        # we must set it again
-        self.assertTrue(self.zone.set_zone(self.tz))
-        rlink = os.readlink("/etc/localtime-copied-from")
-        return self.assertEqual(rlink, os.path.join(self.zonesbase, self.tz))
-
-
-class DateTimeTest(unittest.TestCase):
-    """ Test the functionality to set and get the system time """
-
-    def setUp(self):
-        super(DateTimeTest, self).setUp()
-        self.date_time = DATESET.DateTime()
-
-        # save current time for restoring it later
-        self.now = self.date_time._date_time
-        self.date = self.now.year, self.now.month, self.now.day
-        self.time = self.now.hour, self.now.minute, self.now.second
-
-    def tearDown(self):
-        super(DateTimeTest, self).tearDown()
-        dt = self.date_time
-        dt.year, dt.month, dt.day = self.date
-        dt.hour, dt.minute, dt.second = self.time
-        self.date_time.set_date_and_time()
-
-    def testSetDate(self):
-
-        # test day and month < 10
-        self.date_time.year += 1
-        self.date_time.month = 2
-        self.date_time.day = 2
-        self.date_time.set_date()
-        current_date = DATESET.DateTime()
-        self.assertEqual(current_date.year, self.date[0] + 1)
-        self.assertEqual(self.date_time.year, current_date.year)
-        self.assertEqual(self.date_time.month, current_date.month)
-        self.assertEqual(self.date_time.day, current_date.day)
-
-        # test day and month > 10
-        self.date_time.month = 12
-        self.date_time.day = 24
-        self.date_time.set_date()
-        current_date = DATESET.DateTime()
-        self.assertEqual(current_date.year, self.date[0] + 1)
-        self.assertEqual(self.date_time.year, current_date.year)
-        self.assertEqual(self.date_time.month, current_date.month)
-        self.assertEqual(self.date_time.day, current_date.day)
-
-    def testSetTime(self):
- 
-        self.date_time.hour += 1
-        self.date_time.minute += 1
-        self.date_time.second = 0
-        self.date_time.set_time()
-        current_time = DATESET.DateTime()
-        self.assertEqual(current_time.hour, self.time[0] + 1)
-        self.assertEqual(current_time.minute, self.time[1] + 1)
-        self.assertEqual(self.date_time.hour, current_time.hour)
-        self.assertEqual(self.date_time.minute, current_time.minute)
-        self.assertAlmostEqual(self.date_time.second, current_time.second)
-
-
-if __name__ == "__main__":
-    assert os.getuid() == 0, "You need to be root for running DateTime tests"
-    unittest.main()

src/vasm/backend/tests/test_FSTAB.py

-#!/usr/bin/env python
-
-#    This file is part of VASM.
-#
-#    VASM is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License v3 as published by
-#    the Free Software Foundation.
-#
-#    VASM is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License
-#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
-
-__author__ = "Moises Henriquez"
-__author_email__ = "moc.liamg@xnl.E0M"[::-1]
-
-import unittest
-import os
-import sys
-bepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-if not bepath in sys.path:
-    sys.path.append(bepath)
-import FSTAB
-from shutil import copy2
-
-class FstabTest(unittest.TestCase):
-    def setUp(self):
-        # create a copy of /etc/fstab so we can play with it
-        self.datapath = '/tmp/test_fstab'
-        copy2('/etc/fstab', self.datapath)
-        self.datamodel = FSTAB.FstabModel(self.datapath)
-        self.fake_entry = FSTAB.FstabEntry()
-        self.fake_entry.device = "/dev/sdz1"
-        self.fake_entry.mountpoint = "fake_mount_point"
-        self.fake_entry.filesystem = "ext2"
-        self.fake_entry.options = "defaults 1 0"
-        return
-
-    def test_check_for_entry(self):
-        # Check if an entry exists
-        # We have not yet added fake_entry, so this should return False
-        self.assertTrue(self.datamodel.hasEntry(self.fake_entry.device) is False)
-
-    def test_add_entry(self):
-        # Check if we can add an entry
-        self.datamodel.addEntry(self.fake_entry)
-        # now check if we have the entry there
-        self.assertTrue(self.datamodel.hasEntry(self.fake_entry.device))
-
-    def test_remove_entry(self):
-        # Check if we can remove an entry
-        self.datamodel.addEntry(self.fake_entry)
-        self.assertTrue(self.datamodel.hasEntry(self.fake_entry.device))
-        self.datamodel.removeEntry(self.fake_entry.device)
-        self.assertTrue(self.datamodel.hasEntry(self.fake_entry.device) is False)
-
-    def test_invalid_entry_argument(self):
-        # Make sure it raises an exception if we give it a string
-        self.assertRaises(AssertionError,
-                          self.datamodel.addEntry, 'foo')
-
-    def test_incomplete_entry_attributes(self):
-        # make sure we raise an exception when the attributes of the entry are not complete
-        entry = FSTAB.FstabEntry() # empty entry
-        self.assertRaises(AssertionError,
-                          self.datamodel.addEntry, entry)
-        
-    def tearDown(self):
-        """ Remove the file when we're done """
-        return os.remove(self.datapath)
-
-
-if __name__ == "__main__":
-    assert os.geteuid() == 0, "You must be root to run tests on /etc/fstab """
-    unittest.main()
-

src/vasm/backend/tests/test_LOGINMANAGERS.py

-#!/usr/bin/env python
-
-#    This file is part of VASM.
-#
-#    VASM is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License v3 as published by
-#    the Free Software Foundation.
-#
-#    VASM is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License
-#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
-
-__author__ = "Moises Henriquez"
-__author_email__ = "moc.liamg@xnl.E0M"[::-1]
-
-import sys
-import os
-bepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-if not bepath in sys.path:
-    sys.path.append(bepath)
-import LOGINMANAGERS as gestores
-import unittest
-import shutil
-
-class BootModeTest(unittest.TestCase):
-    def setUp(self):
-        self.file = "/tmp/rc.X"
-        shutil.copy2("/etc/rc.d/rc.X", "/tmp/rc.X")
-        self.model = gestores.LoginManagers(specfile=self.file)
-    
-    def tearDown(self):
-        # remove the temp file
-        os.remove(self.file)
-        
-    def test_getCurrent(self):
-        gestor = self.model.get_current()
-        self.assertTrue(type(gestor) == str)
-    
-    def test_setMode(self):
-        # copy the file to tmp
-        manager = "FOO"
-        res = self.model.set_manager("FOO")
-        read_man = self.model.get_current()
-        self.assertEqual(read_man, manager)
-    
-    def test_roundTest(self):
-        man = "BAR"
-        # set the mode
-        res = self.model.set_manager(man)
-        # read it to make sure it comes back the same
-        read = self.model.get_current()
-        self.assertEqual(read, man)
-    
-    def test_managers(self):
-        res = self.model.list_existing()
-        self.assertTrue(len(res) > 0)
-    
-    def test_descriptions(self):
-        manager = self.model.list_existing()[0].lower()
-        res = self.model._describe_manager(manager)
-        self.assertTrue(type(res), str)
-        
-        
-        
-        
-
-if __name__ == "__main__":
-    unittest.main()

src/vasm/backend/tests/test_SERVICES.py

-#!/usr/bin/env python
-
-#    This file is part of VASM.
-#
-#    VASM is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License v3 as published by
-#    the Free Software Foundation.
-#
-#    VASM is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License
-#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
-
-__author__ = "Moises Henriquez"
-__author_email__ = "moc.liamg@xnl.E0M"[::-1]
-
-import unittest
-import os
-import sys
-bepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-if not bepath in sys.path:
-    sys.path.append(bepath)
-import SERVICES as services
-
-class ServicesTests(unittest.TestCase):
-    def setUp(self):
-        self.datamodel = services.ServiceModel()
-        self.fake_service = self.datamodel.list_all_services()[0]
-        self.fake_runlevel = 4
-
-    def test_EnableService(self):
-        code, output = self.datamodel.enable_service(self.fake_service,
-                                                     self.fake_runlevel)
-        # subprocess will return > 0 if this fails
-        self.assertEqual(code, 0)
-        # this return True when service is enabled, False otherwise
-        # should be enabled now
-        val = self.datamodel.get_service_runlevel_status(self.fake_service,
-                                                         self.fake_runlevel)
-        self.assertTrue(val)
-
-    def test_DisableService(self):
-        code, output = self.datamodel.disable_service(self.fake_service,
-                                                      self.fake_runlevel)
-        # Subprocess will return > 0 if this fails
-        self.assertEqual(code, 0)
-        # Check the status of this service now.  Should be disabled
-        val = self.datamodel.get_service_runlevel_status(self.fake_service,
-                                                         self.fake_runlevel)
-        self.assertEqual(val, False)
-
-    def test_InvalidRunlevel_enable(self):
-        self.assertRaises(AssertionError,
-                          self.datamodel.enable_service,
-                          self.fake_service, 0)
-        self.assertRaises(AssertionError,
-                          self.datamodel.enable_service,
-            self.fake_service, 6)
-
-    def test_InvalidService_enable(self):
-        """ Try to enable an unknown service."""
-        return self.assertRaises(AssertionError,
-                          self.datamodel.enable_service,
-            "foo", 2)
-
-    def test_InvalidRunlevel_disable(self):
-        """ Try to disable services for an invalid runlevel """
-        self.assertRaises(AssertionError,
-                          self.datamodel.disable_service,
-            self.fake_service, 0)
-        self.assertRaises(AssertionError,
-                          self.datamodel.disable_service,
-            self.fake_service, 6)
-        return
-
-    def test_InvalidService_disable(self):
-        """ Try to disable an invalid service """
-        return self.assertRaises(AssertionError,
-                                 self.datamodel.disable_service,
-            "foo", 2)
-        
-
-if __name__ == '__main__':
-    assert os.geteuid() == 0, "You must be root to run tests on system services"
-    unittest.main()

src/vasm/backend/tests/test_SKEL.py

-#
-#    VASM is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License v3 as published by
-#    the Free Software Foundation.
-#
-#    VASM is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License
-#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
-
-import os
-import sys
-bepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-if not bepath in sys.path:
-    sys.path.append(bepath)
-import USERADMIN
-import SKEL
-import unittest
-
-__author__ = "Moises Henriquez"
-__author_email__ = "moc.liamg@xnl.E0M"[::-1]
-
-
-class TestSkel(unittest.TestCase):
-    def setUp(self):
-        # create a fake user account.
-        self.usermodel = USERADMIN.UserModel()
-        self._fake_user = USERADMIN.User(login='fidencio', new=True)
-        if self.usermodel.hasUser(self._fake_user.login):
-            self.usermodel.deleteUser(self._fake_user.login)
-        self._fake_user.realname = 'Fidencio Hdz'
-        self._fake_user.groups = ['sys', 'adm', 'slocate', 'netdev', 'power']
-        self._fake_user.password = 'secrepassword'
-        self.usermodel.addUser(self._fake_user)
-        
-        self.assertTrue(self.usermodel.hasUser('fidencio'))
-        self.SkelModel = SKEL.UserSkel('fidencio')
-        self.addCleanup(self._custom_cleanup)
-
-    def test_ResetInvalidSetting(self):
-        """ Make sure we raise an exception when we try to reset something that doesn't exist."""
-        return self.assertRaises(AssertionError,
-                                 self.SkelModel.reset_settings,'foo')
-
-    def test_ResetSettingsDir(self):
-        """ Test resetting a directory of settings """
-        d = None
-        for f in self.SkelModel.list_resettable_settings():
-            if os.path.isdir(os.path.join('/etc/skel', f)):
-                d = f
-                break
-        return self.assertTrue(self.SkelModel.reset_settings([d]))
-
-    def test_ResetSettingsFile(self):
-        """ Test resetting a settings file """
-        # get a file first
-        f = None
-        for s in self.SkelModel.list_resettable_settings():
-            if not os.path.isdir(os.path.join('/etc/skel', s)):
-                f = s
-                break
-        return self.assertTrue(self.SkelModel.reset_settings([f]))
-
-    def _custom_cleanup(self):
-        if self.usermodel.hasUser(self._fake_user.login):
-            self.usermodel.deleteUser(self._fake_user.login)
-
-    def tearDown(self):
-        # delete the created user
-        if self.usermodel.hasUser(self._fake_user.login):
-            self.usermodel.deleteUser(self._fake_user.login)
-        super(TestSkel, self).tearDown()
-
-
-if __name__ == '__main__':
-    assert os.geteuid != 0, "You must be root to perform SKEL tests because these are jailed tests."
-    unittest.main()

src/vasm/backend/tests/test_USERMANAGE.py

-#!/usr/bin/env python
-
-#    This file is part of VASM.
-#
-#    VASM is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License v3 as published by
-#    the Free Software Foundation.
-#
-#    VASM is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License
-#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.
-
-import os
-import sys
-import unittest
-bepath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-if not bepath in sys.path:
-    sys.path.append(bepath)
-import USERADMIN
-
-class Test(unittest.TestCase):
-    """ Subclass of jailedtests to test how we do when creating accounts """
-
-    @classmethod
-    def setUpClass(cls):
-        pass
-
-    @classmethod
-    def tearDownClass(cls):
-        pass
-
-    def tearDown(self):
-        if self.usermodel.hasUser(self.user.login):
-            self.usermodel.deleteUser(self.user.login)
-    
-    def setUp(self):
-        self.usermodel = USERADMIN.UserModel()
-        # create a dummy account
-        self.user = USERADMIN.User('fidencio', new=True)
-        self.user.fullname = 'Fidencio Hdz'
-        self.user.groups = ['sys', 'adm', 'slocate', 'power']
-        self.user.password = 'supersecretpassword'
-        self.addCleanup(self._cleanup)
-
-    def _cleanup(self):
-        if self.usermodel.hasUser(self.user.login):
-            self.usermodel.deleteUser(self.user.login)
-        return
-
-    def test_Invalid_user_object(self):
-        # Make sure we raise an exception when invalid user argument is given to addUser
-        self.assertRaises(AssertionError,
-                          self.usermodel.addUser, self.user.login)
-        return
-
-    def test_missing_login_attribute(self):
-        user = self.user
-        user.login = None
-        return self.assertRaises(USERADMIN.EmptyAttributeError,
-                                 self.usermodel.addUser, user)
-
-    def test_missing_passsword_attribute(self):
-        user = self.user
-        user.password = None
-        return self.assertRaises(USERADMIN.EmptyAttributeError,
-                                 self.usermodel.addUser, user)
-
-    def test_short_password_attribute(self):
-        user = self.user
-        user.password = 'foo'
-        return self.assertRaises(AssertionError,
-                                 self.usermodel.addUser, user)
-
-    def test_missing_groups_attribute(self):
-        user = self.user
-        user.groups = None
-        return self.assertRaises(USERADMIN.EmptyAttributeError,
-                                 self.usermodel.addUser, user)
-
-    def test_wrong_groups_attribute(self):
-        user = self.user
-        user.groups = "foo,bar"
-        return self.assertRaises(USERADMIN.EmptyAttributeError,
-                                 self.usermodel.addUser, user)
-    
-    def test_Delete_Nonexistant_User(self):
-        # Try to delete a user account that doesn't exist.  This should except.
-        return self.assertRaises(AssertionError,
-                                 self.usermodel.deleteUser, self.user)
-
-    def test_MakeUser(self):
-        # Create a new user account
-        self.usermodel.addUser(self.user)
-        self.assertTrue(self.usermodel.hasUser(self.user.login)), "User account was not successfully created."
-        # test to make sure the attributes of the created account match what we wanted.
-        return
-
-    def test_Add_Existing_user(self):
-        # Try to add a user that already exists.  This should except
-        self.test_MakeUser()
-        return self.assertRaises(AssertionError,
-                          self.usermodel.addUser, self.user)
-
-    def test_user_attributes(self):
-        # Test the user attributes, with the resulting user account
-        self.test_MakeUser()
-        euser = self.usermodel.getUser(self.user.login)
-        self.assertEqual(self.user.login, euser.login), "User login mismatch."
-        self.assertTrue(euser.uid > 1000), "User ID is in invalid range."
-        self.assertEqual(self.user.groups, euser.groups), "User groups mismatch."
-        self.assertEqual(self.user.fullname, euser.fullname), "User full name mismatch."
-    
-    def test_DeleteUser(self):
-        """ Testing user deletion capabilities ... """
-        self.test_MakeUser()
-        # make sure the user is created
-        self.assertTrue, self.usermodel.hasUser(self.user.login)
-        # delete the account
-        self.usermodel.deleteUser(self.user.login)
-        self.assertTrue(self.usermodel.hasUser(self.user.login) is False), "User account was not deleted."
-
-
-if __name__ =='__main__':
-    assert os.geteuid() == 0, "You must be root to run jailed tests."
-    unittest.main()