update dist files and tests to enable unittest
authorGui Chen <gui.chen@intel.com>
Sun, 6 Jan 2013 02:36:53 +0000 (10:36 +0800)
committerGui Chen <gui.chen@intel.com>
Sun, 6 Jan 2013 09:43:58 +0000 (17:43 +0800)
Signed-off-by: Gui Chen <gui.chen@intel.com>
Makefile
debian/rules
packaging/mic.spec
tests/test_baseimager.py
tests/test_chroot.py
tests/test_configmgr.py
tests/test_pluginmgr.py

index 5165fd2..5bbf2f6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,6 @@ build:
 dist-common: man
        git archive --format=tar --prefix=$(PKGNAME)-$(TAGVER)/ $(TAG) | tar xpf -
        git show $(TAG) --oneline | head -1 > $(PKGNAME)-$(TAGVER)/commit-id
-       mkdir $(PKGNAME)-$(TAGVER)/doc; mv mic.1 $(PKGNAME)-$(TAGVER)/doc
        rm -rf $(PKGNAME)-$(TAGVER)/tests
 
 dist-bz2: dist-common
@@ -30,8 +29,8 @@ dist-gz: dist-common
        tar zcpf $(PKGNAME)-$(TAGVER).tar.gz $(PKGNAME)-$(TAGVER)
        rm -rf $(PKGNAME)-$(TAGVER)
 
-man: USAGE.rst
-       rst2man $< >mic.1
+man:
+       rst2man doc/man.rst > doc/mic.1
 
 install: build
        $(PYTHON) setup.py install
@@ -40,7 +39,7 @@ develop: build
        $(PYTHON) setup.py develop
 
 test:
-       cd tests/unittest/ && $(PYTHON) suite.py 
+       cd tests/ && $(PYTHON) suite.py 
 
 clean:
        rm -f *.tar.gz
index 5346591..fc55966 100755 (executable)
@@ -25,10 +25,7 @@ install: build
 
        # Installing package
        mkdir -p $(CURDIR)/debian/mic $(CURDIR)/debian/mic/usr/bin $(CURDIR)/debian/mic/usr/share/man/man1
-       install -m644 mic.1 $(CURDIR)/debian/mic/usr/share/man/man1
-       #make DESTDIR=$(CURDIR)/debian/mic installman
-       #make DESTDIR=$(CURDIR)/debian/micng installconf
-       #make DESTDIR=$(CURDIR)/debian/micng installsymlinks
+       install -m644 doc/mic.1 $(CURDIR)/debian/mic/usr/share/man/man1
        python setup.py install --root=$(CURDIR)/debian/mic
 
 binary-indep: build install
index b3a299e..53dc83c 100644 (file)
@@ -1,5 +1,5 @@
-%define is_tizen %(test -e /etc/tizen-release -o -e /etc/meego-release && echo 1 || echo 0)
 %{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
+
 Name:       mic
 Summary:    Image Creator for Linux Distributions
 Version:    0.15
@@ -27,26 +27,14 @@ Requires:   bzip2
 Requires:   squashfs-tools >= 4.0
 Requires:   qemu-arm-static
 Requires:   python-urlgrabber
-%if 0%{is_tizen} == 0
 Requires:   yum >= 3.2.24
-%endif
 %if 0%{?suse_version}
 Requires:   btrfsprogs
 %else
 Requires:   btrfs-progs
 %endif
 
-%if 0%{?fedora_version} || 0%{is_tizen} == 1
-Requires:   m2crypto
-%else
-%if 0%{?suse_version} == 1210
-Requires:   python-M2Crypto
-%else
-Requires:   python-m2crypto
-%endif
-%endif
-
-%if 0%{?fedora_version} > 13 || 0%{is_tizen} == 1
+%if 0%{?fedora_version} > 13
 Requires:   syslinux-extlinux
 %endif
 
@@ -83,26 +71,16 @@ rm -rf $RPM_BUILD_ROOT
 %{__python} setup.py install --root=$RPM_BUILD_ROOT -O1
 %endif
 
-# remove yum backend for tizen
-%if 0%{is_tizen} == 1
-rm -rf %{buildroot}/%{_prefix}/lib/%{name}/plugins/backend/yumpkgmgr.py
-rm -rf %{buildroot}/%{_sysconfdir}/%{name}/bootstrap.conf
-%endif
-
 # install man page
 mkdir -p %{buildroot}/%{_prefix}/share/man/man1
-install -m644 mic.1 %{buildroot}/%{_prefix}/share/man/man1
+install -m644 doc/mic.1 %{buildroot}/%{_prefix}/share/man/man1
 
 %files
 %defattr(-,root,root,-)
-%doc README.rst
-%doc doc/RELEASE_NOTES
+%doc doc/*
 %{_mandir}/man1/*
 %dir %{_sysconfdir}/%{name}
 %config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
-%if 0%{is_tizen} == 0
-%config %{_sysconfdir}/%{name}/bootstrap.conf
-%endif
 %{python_sitelib}/*
 %dir %{_prefix}/lib/%{name}
 %{_prefix}/lib/%{name}/*
index 6b91b0d..0348b36 100644 (file)
@@ -13,11 +13,12 @@ from mic import conf as configmgr
 from mic import msger
 from mic.imager import fs
 
-TEST_BASEIMGR_LOC = os.path.join(os.getcwd(), 'baseimgr_fixtures')
-KSCONF = os.path.join(os.getcwd(), 'baseimgr_fixtures', 'test.ks')
-KSBAK = os.path.join(os.getcwd(), 'baseimgr_fixtures', 'test.ks.bak')
-REPOURI = os.path.join(os.getcwd(), 'baseimgr_fixtures')
-CACHEDIR = os.path.join(os.getcwd(), 'baseimgr_fixtures', 'cache')
+CWD = os.path.dirname(__file__) or '.'
+TEST_BASEIMGR_LOC = os.path.join(CWD, 'baseimgr_fixtures')
+KSCONF = os.path.join(CWD, 'baseimgr_fixtures', 'test.ks')
+KSBAK = os.path.join(CWD, 'baseimgr_fixtures', 'test.ks.bak')
+REPOURI = os.path.join(CWD, 'baseimgr_fixtures')
+CACHEDIR = os.path.join(CWD, 'baseimgr_fixtures', 'cache')
 RPMLOCK_PATH = None
 
 def suite():
@@ -56,7 +57,7 @@ class BaseImgrTest(unittest.TestCase):
         
         for entry in p.communicate()[0].split('\n'):
             if entry.find(pattern) > 0:
-                real_mount_list.append(entry.split(' ')[0])
+                real_mount_list.append(entry.split(' ')[2])
         real_mount_list.sort()
         os.close(dev_null)
         return real_mount_list
@@ -102,6 +103,7 @@ class BaseImgrTest(unittest.TestCase):
             RPMLOCK_PATH = "%s/var/lib/rpm" % creator._instroot
         exp_mount_list = ['/sys', '/proc', '/proc/sys/fs/binfmt_misc', '/dev/pts']
         exp_mount_list.sort()
+        exp_mount_list = [os.path.join(creator._instroot, pth.lstrip('/')) for pth in exp_mount_list]
         real_mount_list = self.getMountList(creator._instroot)
         self.assertEqual(real_mount_list, exp_mount_list)
         
@@ -128,6 +130,7 @@ class BaseImgrTest(unittest.TestCase):
         real_pkglist = f.read()
         self.assertEqual(real_pkglist, '\n'.join(pkglist))
 
+if os.getuid == 0:
     def testBaseImagerZypp(self):
         self.BaseImager('zypp')
 
index 546e3ae..3563f14 100644 (file)
@@ -8,7 +8,8 @@ import StringIO
 import unittest
 from mic import chroot
 
-TEST_CHROOT_LOC = os.path.join(os.getcwd(), 'chroot_fixtures')
+CWD = os.path.dirname(__file__) or '.'
+TEST_CHROOT_LOC = os.path.join(CWD, 'chroot_fixtures')
 TEST_CHROOT_TAR = os.path.join(TEST_CHROOT_LOC, 'minchroot.tar.gz')
 TEST_CHROOT_DIR = os.path.join(TEST_CHROOT_LOC, 'minchroot')
 
@@ -31,6 +32,7 @@ class ChrootTest(unittest.TestCase):
         sys.stderr = self.stderr
         shutil.rmtree(TEST_CHROOT_DIR, ignore_errors=True)
 
+if os.getuid() == 0:
     def testChroot(self):
         try:
             chroot.chroot(TEST_CHROOT_DIR, None, 'exit')
index fcebc9f..c357426 100644 (file)
@@ -4,16 +4,17 @@ import os
 import sys
 import shutil
 import StringIO
+import unittest
 
 from mic import conf, msger
 from pykickstart.parser import KickstartParser
-import unittest2 as unittest
 
-SITECONF = os.path.join(os.getcwd(), 'configmgr_fixtures', 'mic.conf')
-KSCONF = os.path.join(os.getcwd(), 'configmgr_fixtures', 'test.ks')
-KSBAK = os.path.join(os.getcwd(), 'configmgr_fixtures', 'test.ks.bak')
-REPOURI = os.path.join(os.getcwd(), 'configmgr_fixtures', 'packages')
-CACHEDIR = os.path.join(os.getcwd(), 'configmgr_fixtures', 'cache')
+CWD = os.path.dirname(__file__) or '.'
+SITECONF = os.path.join(CWD, 'configmgr_fixtures', 'mic.conf')
+KSCONF = os.path.join(CWD, 'configmgr_fixtures', 'test.ks')
+KSBAK = os.path.join(CWD, 'configmgr_fixtures', 'test.ks.bak')
+REPOURI = os.path.join(CWD, 'configmgr_fixtures', 'packages')
+CACHEDIR = os.path.join(CWD, 'configmgr_fixtures', 'cache')
 
 def suite():
     return unittest.makeSuite(ConfigMgrTest)
index 5c207b6..6263ee9 100644 (file)
@@ -9,7 +9,8 @@ from mic import pluginbase
 from mic import msger
 import unittest
 
-TEST_PLUGINS_LOC = os.path.join(os.getcwd(), 'pluginmgr_fixtures')
+CWD = os.path.dirname(__file__) or '.'
+TEST_PLUGINS_LOC = os.path.join(CWD, 'pluginmgr_fixtures')
 
 def suite():
     return unittest.makeSuite(PluginMgrTest)
@@ -17,9 +18,9 @@ def suite():
 class PluginMgrTest(unittest.TestCase):
 
     def setUp(self):
-        self.defploc = plugin.DEFAULT_PLUGIN_LOCATION
-        plugin.DEFAULT_PLUGIN_LOCATION = TEST_PLUGINS_LOC
         self.plugin = plugin.PluginMgr()
+        self.defploc = self.plugin.plugin_dir
+        self.plugin.plugin_dir = TEST_PLUGINS_LOC
         self.stdout = sys.stdout
         self.stderr = sys.stderr
         sys.stdout = StringIO.StringIO()
@@ -28,16 +29,7 @@ class PluginMgrTest(unittest.TestCase):
     def tearDown(self):
         sys.stdout = self.stdout
         sys.stderr = self.stderr
-        #dirs = map(lambda pt: os.path.join(TEST_PLUGINS_LOC, pt), \
-        #    plugin.PLUGIN_TYPES) 
-        #pys = reduce(lambda p, q: p+q, map(lambda d: filter(
-        #    lambda x: x.endswith(".py"), os.listdir(d)),  dirs))
-        #for mod in pys:
-        #    if mod.strip('.py') in sys.modules: 
-        #        del sys.modules[mod.strip('.py')]
-        #self.plugin._intance = None
-        #self.plugin.plugin_dirs = {}
-        plugin.DEFAULT_PLUGIN_LOCATION = self.defploc
+        self.plugin.plugin_dir = self.defploc
 
     def testPluginDir(self):
         plugindir = {}