summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorZhang Qiang <qiang.z.zhang@intel.com>2011-12-16 18:54:59 +0800
committerZhang Qiang <qiang.z.zhang@intel.com>2011-12-16 18:54:59 +0800
commitffe98af4b1a0841489a84e1b459432d07251ddd8 (patch)
tree324e186037df3927c79ebf09767eefa2ba359abe /tests
parent1e5133f0aa9864c0592fe0525b85c82251767a7a (diff)
downloadmic-ffe98af4b1a0841489a84e1b459432d07251ddd8.tar.gz
mic-ffe98af4b1a0841489a84e1b459432d07251ddd8.tar.bz2
mic-ffe98af4b1a0841489a84e1b459432d07251ddd8.zip
Unit test support
currently, unit test can cover plugin manager, config manager, baseimage (yum/zypp). run 'make test' at top dir can run unit test cases. Signed-off-by: Zhang Qiang <qiang.z.zhang@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest/baseimgr_fixtures/i586/A-0.1-1.i586.rpmbin0 -> 1396 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/i586/ABC-0.1-1.i586.rpmbin0 -> 1404 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/i586/B-0.1-1.i586.rpmbin0 -> 1392 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/i586/D-0.1-1.i586.rpmbin0 -> 1460 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/i586/E-0.1-1.i586.rpmbin0 -> 1404 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/i586/G-0.1-1.i586.rpmbin0 -> 1396 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/i686/C-0.2-1.i686.rpmbin0 -> 1396 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/localpkgs/H-0.2-1.armv7hl.rpmbin0 -> 1228 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/localpkgs/H-0.2-1.i586.rpmbin0 -> 1396 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/noarch/F-0.1-1.noarch.rpmbin0 -> 1224 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/noarch/H-0.1-1.noarch.rpmbin0 -> 1224 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/repodata/4bb63d1039a6f0d3fd1e7035acff76e7015963cabab2751263c7a20f4ff1c668-group.xml.gzbin0 -> 316 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/repodata/ea95ecaccf9abc214715b1724188a3ecfcae1eb9b7855127938b39de83fbc303-patterns.xml.gzbin0 -> 350 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/repodata/filelists.xml.gzbin0 -> 699 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/repodata/other.xml.gzbin0 -> 697 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/repodata/primary.xml.gzbin0 -> 1372 bytes
-rw-r--r--tests/unittest/baseimgr_fixtures/repodata/repomd.xml40
-rw-r--r--tests/unittest/baseimgr_fixtures/test.ks14
-rw-r--r--tests/unittest/configmgr_fixtures/mic.conf9
-rw-r--r--tests/unittest/configmgr_fixtures/packages/repodata/filelists.sqlite.bz2bin0 -> 679 bytes
-rw-r--r--tests/unittest/configmgr_fixtures/packages/repodata/filelists.xml.gzbin0 -> 304 bytes
-rw-r--r--tests/unittest/configmgr_fixtures/packages/repodata/other.sqlite.bz2bin0 -> 644 bytes
-rw-r--r--tests/unittest/configmgr_fixtures/packages/repodata/other.xml.gzbin0 -> 299 bytes
-rw-r--r--tests/unittest/configmgr_fixtures/packages/repodata/primary.sqlite.bz2bin0 -> 1616 bytes
-rw-r--r--tests/unittest/configmgr_fixtures/packages/repodata/primary.xml.gzbin0 -> 654 bytes
-rw-r--r--tests/unittest/configmgr_fixtures/packages/repodata/repomd.xml55
-rw-r--r--tests/unittest/configmgr_fixtures/packages/test-0-1.i686.rpmbin0 -> 1400 bytes
-rw-r--r--tests/unittest/configmgr_fixtures/test.ks28
-rw-r--r--tests/unittest/pluginmgr_fixtures/backend/yumtest.py8
-rw-r--r--tests/unittest/pluginmgr_fixtures/backend/zypptest.py9
-rw-r--r--tests/unittest/pluginmgr_fixtures/imager/fs_test.py6
-rw-r--r--tests/unittest/pluginmgr_fixtures/imager/loop_test.py6
-rw-r--r--tests/unittest/suite.py16
-rw-r--r--tests/unittest/test_baseimager.py140
-rw-r--r--tests/unittest/test_configmgr.py74
-rw-r--r--tests/unittest/test_pluginmgr.py77
36 files changed, 482 insertions, 0 deletions
diff --git a/tests/unittest/baseimgr_fixtures/i586/A-0.1-1.i586.rpm b/tests/unittest/baseimgr_fixtures/i586/A-0.1-1.i586.rpm
new file mode 100644
index 0000000..b608485
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/i586/A-0.1-1.i586.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/i586/ABC-0.1-1.i586.rpm b/tests/unittest/baseimgr_fixtures/i586/ABC-0.1-1.i586.rpm
new file mode 100644
index 0000000..4c790d1
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/i586/ABC-0.1-1.i586.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/i586/B-0.1-1.i586.rpm b/tests/unittest/baseimgr_fixtures/i586/B-0.1-1.i586.rpm
new file mode 100644
index 0000000..3d693db
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/i586/B-0.1-1.i586.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/i586/D-0.1-1.i586.rpm b/tests/unittest/baseimgr_fixtures/i586/D-0.1-1.i586.rpm
new file mode 100644
index 0000000..0eb4310
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/i586/D-0.1-1.i586.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/i586/E-0.1-1.i586.rpm b/tests/unittest/baseimgr_fixtures/i586/E-0.1-1.i586.rpm
new file mode 100644
index 0000000..0c0a92d
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/i586/E-0.1-1.i586.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/i586/G-0.1-1.i586.rpm b/tests/unittest/baseimgr_fixtures/i586/G-0.1-1.i586.rpm
new file mode 100644
index 0000000..95a583a
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/i586/G-0.1-1.i586.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/i686/C-0.2-1.i686.rpm b/tests/unittest/baseimgr_fixtures/i686/C-0.2-1.i686.rpm
new file mode 100644
index 0000000..1235866
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/i686/C-0.2-1.i686.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/localpkgs/H-0.2-1.armv7hl.rpm b/tests/unittest/baseimgr_fixtures/localpkgs/H-0.2-1.armv7hl.rpm
new file mode 100644
index 0000000..7614cef
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/localpkgs/H-0.2-1.armv7hl.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/localpkgs/H-0.2-1.i586.rpm b/tests/unittest/baseimgr_fixtures/localpkgs/H-0.2-1.i586.rpm
new file mode 100644
index 0000000..896bd53
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/localpkgs/H-0.2-1.i586.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/noarch/F-0.1-1.noarch.rpm b/tests/unittest/baseimgr_fixtures/noarch/F-0.1-1.noarch.rpm
new file mode 100644
index 0000000..80e9138
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/noarch/F-0.1-1.noarch.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/noarch/H-0.1-1.noarch.rpm b/tests/unittest/baseimgr_fixtures/noarch/H-0.1-1.noarch.rpm
new file mode 100644
index 0000000..8940b59
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/noarch/H-0.1-1.noarch.rpm
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/repodata/4bb63d1039a6f0d3fd1e7035acff76e7015963cabab2751263c7a20f4ff1c668-group.xml.gz b/tests/unittest/baseimgr_fixtures/repodata/4bb63d1039a6f0d3fd1e7035acff76e7015963cabab2751263c7a20f4ff1c668-group.xml.gz
new file mode 100644
index 0000000..ec5cb9e
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/repodata/4bb63d1039a6f0d3fd1e7035acff76e7015963cabab2751263c7a20f4ff1c668-group.xml.gz
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/repodata/ea95ecaccf9abc214715b1724188a3ecfcae1eb9b7855127938b39de83fbc303-patterns.xml.gz b/tests/unittest/baseimgr_fixtures/repodata/ea95ecaccf9abc214715b1724188a3ecfcae1eb9b7855127938b39de83fbc303-patterns.xml.gz
new file mode 100644
index 0000000..ba21df6
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/repodata/ea95ecaccf9abc214715b1724188a3ecfcae1eb9b7855127938b39de83fbc303-patterns.xml.gz
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/repodata/filelists.xml.gz b/tests/unittest/baseimgr_fixtures/repodata/filelists.xml.gz
new file mode 100644
index 0000000..1c54c61
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/repodata/filelists.xml.gz
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/repodata/other.xml.gz b/tests/unittest/baseimgr_fixtures/repodata/other.xml.gz
new file mode 100644
index 0000000..bfb4320
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/repodata/other.xml.gz
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/repodata/primary.xml.gz b/tests/unittest/baseimgr_fixtures/repodata/primary.xml.gz
new file mode 100644
index 0000000..aaf0423
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/repodata/primary.xml.gz
Binary files differ
diff --git a/tests/unittest/baseimgr_fixtures/repodata/repomd.xml b/tests/unittest/baseimgr_fixtures/repodata/repomd.xml
new file mode 100644
index 0000000..dad3740
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/repodata/repomd.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" ?>
+<repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm">
+ <revision>1323679441</revision>
+ <data type="other">
+ <checksum type="sha256">b986688b812223a31fbe59f59229cdda5eb7010bdc1492c9a77d66b45dc51207</checksum>
+ <timestamp>1323679441</timestamp>
+ <size>697</size>
+ <open-size>1567</open-size>
+ <open-checksum type="sha256">da7a68cbd42c85411ecca4069f1d04d8e9fe27d12f0a912d837f68c5e15bdfc7</open-checksum>
+ <location href="repodata/other.xml.gz"/>
+ </data>
+ <data type="filelists">
+ <checksum type="sha256">8274d0eefe8cc49055ccd2e82743d37d91a2ebf1c1e4ff288aa5f3a8b3572194</checksum>
+ <timestamp>1323679441</timestamp>
+ <size>699</size>
+ <open-size>1562</open-size>
+ <open-checksum type="sha256">77977b787c2e5c5326752100c77a93a6573385b43061671e7091a0895b5aad53</open-checksum>
+ <location href="repodata/filelists.xml.gz"/>
+ </data>
+ <data type="primary">
+ <checksum type="sha256">cc428f16cb0ae3a3981c43bd2ab494fa12549459912b491d4b10664e95703860</checksum>
+ <timestamp>1323679441</timestamp>
+ <size>1372</size>
+ <open-size>9145</open-size>
+ <open-checksum type="sha256">b61cfc6373c10e02ab0bf256cfa30ca01b1295765c4d9f7ce1cf147c79f7cb26</open-checksum>
+ <location href="repodata/primary.xml.gz"/>
+ </data>
+ <data type="patterns">
+ <location href="repodata/ea95ecaccf9abc214715b1724188a3ecfcae1eb9b7855127938b39de83fbc303-patterns.xml.gz"/>
+ <checksum type="sha256">ea95ecaccf9abc214715b1724188a3ecfcae1eb9b7855127938b39de83fbc303</checksum>
+ <timestamp>1323679441.67</timestamp>
+ <open-checksum type="sha256">053b5757a184246546ddc61ee0533d755ccdd73799cd310042606da57f066897</open-checksum>
+ </data>
+ <data type="group">
+ <location href="repodata/4bb63d1039a6f0d3fd1e7035acff76e7015963cabab2751263c7a20f4ff1c668-group.xml.gz"/>
+ <checksum type="sha256">4bb63d1039a6f0d3fd1e7035acff76e7015963cabab2751263c7a20f4ff1c668</checksum>
+ <timestamp>1323679441.82</timestamp>
+ <open-checksum type="sha256">b830ae0d0a36c4c1044fcc7c87797d374053ed3909e6d84770704b3016c992c6</open-checksum>
+ </data>
+</repomd>
diff --git a/tests/unittest/baseimgr_fixtures/test.ks b/tests/unittest/baseimgr_fixtures/test.ks
new file mode 100644
index 0000000..aa0425f
--- /dev/null
+++ b/tests/unittest/baseimgr_fixtures/test.ks
@@ -0,0 +1,14 @@
+
+part / --size 3000 --ondisk sda --fstype=ext3
+
+repo --name=test --baseurl=$$$$$$
+
+%packages
+@base
+A
+EE
+A*
+*C
+H.noarch
+
+%end
diff --git a/tests/unittest/configmgr_fixtures/mic.conf b/tests/unittest/configmgr_fixtures/mic.conf
new file mode 100644
index 0000000..8418475
--- /dev/null
+++ b/tests/unittest/configmgr_fixtures/mic.conf
@@ -0,0 +1,9 @@
+[common]
+
+[create]
+local_pkgs_path=/opt/cache
+pkgmgr=yum
+
+[chroot]
+
+[convert]
diff --git a/tests/unittest/configmgr_fixtures/packages/repodata/filelists.sqlite.bz2 b/tests/unittest/configmgr_fixtures/packages/repodata/filelists.sqlite.bz2
new file mode 100644
index 0000000..0fbd0df
--- /dev/null
+++ b/tests/unittest/configmgr_fixtures/packages/repodata/filelists.sqlite.bz2
Binary files differ
diff --git a/tests/unittest/configmgr_fixtures/packages/repodata/filelists.xml.gz b/tests/unittest/configmgr_fixtures/packages/repodata/filelists.xml.gz
new file mode 100644
index 0000000..d4eec18
--- /dev/null
+++ b/tests/unittest/configmgr_fixtures/packages/repodata/filelists.xml.gz
Binary files differ
diff --git a/tests/unittest/configmgr_fixtures/packages/repodata/other.sqlite.bz2 b/tests/unittest/configmgr_fixtures/packages/repodata/other.sqlite.bz2
new file mode 100644
index 0000000..2054a8c
--- /dev/null
+++ b/tests/unittest/configmgr_fixtures/packages/repodata/other.sqlite.bz2
Binary files differ
diff --git a/tests/unittest/configmgr_fixtures/packages/repodata/other.xml.gz b/tests/unittest/configmgr_fixtures/packages/repodata/other.xml.gz
new file mode 100644
index 0000000..a180630
--- /dev/null
+++ b/tests/unittest/configmgr_fixtures/packages/repodata/other.xml.gz
Binary files differ
diff --git a/tests/unittest/configmgr_fixtures/packages/repodata/primary.sqlite.bz2 b/tests/unittest/configmgr_fixtures/packages/repodata/primary.sqlite.bz2
new file mode 100644
index 0000000..fe8e476
--- /dev/null
+++ b/tests/unittest/configmgr_fixtures/packages/repodata/primary.sqlite.bz2
Binary files differ
diff --git a/tests/unittest/configmgr_fixtures/packages/repodata/primary.xml.gz b/tests/unittest/configmgr_fixtures/packages/repodata/primary.xml.gz
new file mode 100644
index 0000000..51555e4
--- /dev/null
+++ b/tests/unittest/configmgr_fixtures/packages/repodata/primary.xml.gz
Binary files differ
diff --git a/tests/unittest/configmgr_fixtures/packages/repodata/repomd.xml b/tests/unittest/configmgr_fixtures/packages/repodata/repomd.xml
new file mode 100644
index 0000000..ba3baf7
--- /dev/null
+++ b/tests/unittest/configmgr_fixtures/packages/repodata/repomd.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm">
+ <revision>1323324513</revision>
+ <data type="other_db">
+ <location href="repodata/other.sqlite.bz2"/>
+ <checksum type="sha256">a764872097928532f9ff374d36ce56393c05ddc631f0b6d5c953fdc382db8b24</checksum>
+ <timestamp>1323324514.06</timestamp>
+ <size>644</size>
+ <open-size>6144</open-size>
+ <open-checksum type="sha256">70b849fade981be795f148b2144dde802bf13b9c97e80d42ddf43008480f4a51</open-checksum>
+ <database_version>10</database_version>
+ </data>
+ <data type="other">
+ <checksum type="sha256">d2f760614fc731dcefb65067a92e39d81d77de809f95059635a5455f18af36ac</checksum>
+ <timestamp>1323324513</timestamp>
+ <size>299</size>
+ <open-size>282</open-size>
+ <open-checksum type="sha256">0fc2b7f25d345a3720af2c1ac5b5624442af094ec1b27d572f3afef6c00bf49b</open-checksum>
+ <location href="repodata/other.xml.gz"/>
+ </data>
+ <data type="filelists_db">
+ <location href="repodata/filelists.sqlite.bz2"/>
+ <checksum type="sha256">a6a2911beef45b8872f16f90b86384f29c586850edc34842ba86e3bff83fa8d2</checksum>
+ <timestamp>1323324514.36</timestamp>
+ <size>679</size>
+ <open-size>7168</open-size>
+ <open-checksum type="sha256">0248529164242123addf80e0d1e5aea55ae8682d7e43df7dcfd16f7c7508f937</open-checksum>
+ <database_version>10</database_version>
+ </data>
+ <data type="filelists">
+ <checksum type="sha256">44a10b7c93db9ab466c02ce2afb5328376f63436c484147183f76475b45aca1e</checksum>
+ <timestamp>1323324513</timestamp>
+ <size>304</size>
+ <open-size>286</open-size>
+ <open-checksum type="sha256">1b4abfd7b5dcb0e9d323a3dbde9ceff48246c5bdb28619dea34bcd8a1919b0b8</open-checksum>
+ <location href="repodata/filelists.xml.gz"/>
+ </data>
+ <data type="primary_db">
+ <location href="repodata/primary.sqlite.bz2"/>
+ <checksum type="sha256">8708d817534323eb42163ce48a390468fbc051c18902ea280938481bfd9ec95d</checksum>
+ <timestamp>1323324515.01</timestamp>
+ <size>1616</size>
+ <open-size>21504</open-size>
+ <open-checksum type="sha256">1d475a2af9b29cda28eaace008cd130301e6a2e175735b0119e6e5bdbc16cd21</open-checksum>
+ <database_version>10</database_version>
+ </data>
+ <data type="primary">
+ <checksum type="sha256">6b8bd0db22f5cc42d5ab5ee8abdbee5c46b17342ecb04539f243e8820fa1459f</checksum>
+ <timestamp>1323324513</timestamp>
+ <size>654</size>
+ <open-size>1161</open-size>
+ <open-checksum type="sha256">de9b99406dc81ac5a5c7891453215441905ddff36c471f9b4b01c4f2c94e0983</open-checksum>
+ <location href="repodata/primary.xml.gz"/>
+ </data>
+</repomd>
diff --git a/tests/unittest/configmgr_fixtures/packages/test-0-1.i686.rpm b/tests/unittest/configmgr_fixtures/packages/test-0-1.i686.rpm
new file mode 100644
index 0000000..76d728e
--- /dev/null
+++ b/tests/unittest/configmgr_fixtures/packages/test-0-1.i686.rpm
Binary files differ
diff --git a/tests/unittest/configmgr_fixtures/test.ks b/tests/unittest/configmgr_fixtures/test.ks
new file mode 100644
index 0000000..6e15df8
--- /dev/null
+++ b/tests/unittest/configmgr_fixtures/test.ks
@@ -0,0 +1,28 @@
+#
+# Do not Edit! Generated by:
+# kickstarter.py
+#
+
+lang en_US.UTF-8
+keyboard us
+timezone --utc America/Los_Angeles
+part / --size 3000 --ondisk sda --fstype=ext3
+rootpw meego
+xconfig --startxonboot
+bootloader --timeout=0 --append="quiet"
+desktop --autologinuser=meego
+user --name meego --groups audio,video --password meego
+
+repo --name=test --baseurl=$$$$$$ --save --debuginfo --source --gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-meego
+
+%packages
+
+%end
+
+%post
+
+%end
+
+%post --nochroot
+
+%end
diff --git a/tests/unittest/pluginmgr_fixtures/backend/yumtest.py b/tests/unittest/pluginmgr_fixtures/backend/yumtest.py
new file mode 100644
index 0000000..61ba220
--- /dev/null
+++ b/tests/unittest/pluginmgr_fixtures/backend/yumtest.py
@@ -0,0 +1,8 @@
+#!/usr/bin/python -tt
+
+from mic.pluginbase import BackendPlugin
+class Yum(BackendPlugin):
+ name = 'yumtest'
+
+ def __init__(self):
+ pass
diff --git a/tests/unittest/pluginmgr_fixtures/backend/zypptest.py b/tests/unittest/pluginmgr_fixtures/backend/zypptest.py
new file mode 100644
index 0000000..6ebe1f3
--- /dev/null
+++ b/tests/unittest/pluginmgr_fixtures/backend/zypptest.py
@@ -0,0 +1,9 @@
+#!/usr/bin/python -tt
+
+from mic.pluginbase import BackendPlugin
+class Zypp(BackendPlugin):
+ name = 'zypptest'
+
+ def __init__(self, root = None, cache = None, arch = None):
+ pass
+
diff --git a/tests/unittest/pluginmgr_fixtures/imager/fs_test.py b/tests/unittest/pluginmgr_fixtures/imager/fs_test.py
new file mode 100644
index 0000000..ced1ce2
--- /dev/null
+++ b/tests/unittest/pluginmgr_fixtures/imager/fs_test.py
@@ -0,0 +1,6 @@
+#!/usr/bin/python -tt
+
+from mic.pluginbase import ImagerPlugin
+class FsPlugin(ImagerPlugin):
+ name = 'fstest'
+
diff --git a/tests/unittest/pluginmgr_fixtures/imager/loop_test.py b/tests/unittest/pluginmgr_fixtures/imager/loop_test.py
new file mode 100644
index 0000000..5fb515c
--- /dev/null
+++ b/tests/unittest/pluginmgr_fixtures/imager/loop_test.py
@@ -0,0 +1,6 @@
+#!/usr/bin/python -tt
+
+from mic.pluginbase import ImagerPlugin
+class LoopPlugin(ImagerPlugin):
+ name = 'looptest'
+
diff --git a/tests/unittest/suite.py b/tests/unittest/suite.py
new file mode 100644
index 0000000..d738d00
--- /dev/null
+++ b/tests/unittest/suite.py
@@ -0,0 +1,16 @@
+import os
+import sys
+import unittest
+import test_configmgr
+import test_pluginmgr
+import test_baseimager
+
+if os.getuid() != 0:
+ raise SystemExit("Root permission is needed")
+
+suite = unittest.TestSuite()
+suite.addTests(test_pluginmgr.suite())
+suite.addTests(test_configmgr.suite())
+suite.addTests(test_baseimager.suite())
+result = unittest.TextTestRunner(verbosity=2).run(suite)
+sys.exit(not result.wasSuccessful())
diff --git a/tests/unittest/test_baseimager.py b/tests/unittest/test_baseimager.py
new file mode 100644
index 0000000..6ea6c9a
--- /dev/null
+++ b/tests/unittest/test_baseimager.py
@@ -0,0 +1,140 @@
+#!/usr/bin/python
+
+import os
+import sys
+import rpm
+import glob
+import shutil
+import StringIO
+import subprocess
+import unittest
+from mic import plugin as pluginmgr
+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')
+RPMLOCK_PATH = None
+
+def suite():
+ return unittest.makeSuite(BaseImgrTest)
+
+class BaseImgrTest(unittest.TestCase):
+
+ arch = 'i686'
+ rootdir = "%s/rootdir" % os.getcwd()
+ expect_pkglist = ['A', 'ABC', 'C', 'D', 'E', 'F', 'G', 'H']
+
+ def setUp(self):
+ self.stdout = sys.stdout
+ self.stream = sys.stdout
+ msger.STREAM = StringIO.StringIO()
+ shutil.copy2(KSCONF, KSBAK)
+ with open(KSCONF, 'r') as f:
+ content = f.read()
+ content = content.replace('$$$$$$', "file://" + REPOURI)
+ with open(KSCONF, 'w') as f:
+ f.write(content)
+ msger.set_loglevel('quiet')
+
+ def tearDown(self):
+ sys.stdout = self.stdout
+ msger.STREAM = self.stream
+ shutil.copy2(KSBAK, KSCONF)
+ shutil.rmtree (self.rootdir, ignore_errors = True)
+ shutil.rmtree (CACHEDIR, ignore_errors = True)
+ os.unlink(KSBAK)
+
+ def getMountList(self, pattern):
+ real_mount_list = []
+ dev_null = os.open("/dev/null", os.O_WRONLY)
+ p = subprocess.Popen('mount', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+ for entry in p.communicate()[0].split('\n'):
+ if entry.find(pattern) > 0:
+ real_mount_list.append(entry.split(' ')[0])
+ real_mount_list.sort()
+ os.close(dev_null)
+ return real_mount_list
+
+ def getInsPkgList(self, rootdir):
+ installed_pkgs = []
+ ts = rpm.TransactionSet (rootdir)
+ hrs = ts.dbMatch()
+ for pkg in hrs:
+ installed_pkgs.append(pkg['name'])
+ installed_pkgs.sort()
+ ts.closeDB()
+
+ return installed_pkgs
+
+ def BaseImager(self, backend):
+ global RPMLOCK_PATH
+
+ cfgmgr = configmgr.configmgr
+ creatoropts = cfgmgr.create
+
+ creatoropts["cachedir"] = CACHEDIR
+ creatoropts["outdir"] = self.rootdir
+ creatoropts["arch"] = self.arch
+ creatoropts['pkgmgr'] = backend
+ cfgmgr._ksconf = KSCONF
+ pkgmgr = None
+ for (key, pcls) in pluginmgr.PluginMgr().get_plugins('backend').iteritems():
+ if key == creatoropts['pkgmgr']:
+ pkgmgr = pcls
+ break
+
+ creator = fs.FsImageCreator(creatoropts, pkgmgr)
+ creator._recording_pkgs.append('name')
+
+ creator.check_depend_tools()
+
+ # Test mount interface
+ creator.mount(None, creatoropts["cachedir"])
+ if RPMLOCK_PATH:
+ os.makedirs(RPMLOCK_PATH)
+ else:
+ RPMLOCK_PATH = "%s/var/lib/rpm" % creator._instroot
+ exp_mount_list = ['/sys', '/proc', '/proc/sys/fs/binfmt_misc', '/dev/pts', CACHEDIR]
+ exp_mount_list.sort()
+ real_mount_list = self.getMountList(creator._instroot)
+ self.assertEqual(real_mount_list, exp_mount_list)
+
+ # Test Install interface
+ creator.install()
+ installed_pkgs = self.getInsPkgList(creator._instroot)
+ self.assertEqual(installed_pkgs, self.expect_pkglist)
+
+ # Test umount interface
+ creator.unmount()
+ real_mount_list = self.getMountList(creator._instroot)
+ self.assertEqual(real_mount_list, [])
+ # Test Packaging interface
+ creator.package(creatoropts["outdir"])
+ installed_pkgs = self.getInsPkgList("%s/%s" % (self.rootdir, creator.name))
+ self.assertEqual(installed_pkgs, self.expect_pkglist)
+
+ creator.cleanup()
+ # Test recore_pkgs option
+ pkglist = ['A-0.1-1.i586.rpm', 'ABC-0.1-1.i586.rpm', 'C-0.2-1.i686.rpm',
+ 'D-0.1-1.i586.rpm', 'E-0.1-1.i586.rpm', 'F-0.1-1.noarch.rpm',
+ 'G-0.1-1.i586.rpm', 'H-0.1-1.noarch.rpm']
+ f = open ("%s/%s.packages" % (self.rootdir, creator.name))
+ real_pkglist = f.read()
+ self.assertEqual(real_pkglist, '\n'.join(pkglist))
+
+ def testBaseImagerZypp(self):
+ self.BaseImager('zypp')
+
+ def testBaseImagerYum(self):
+ self.BaseImager('yum')
+
+if __name__ == "__main__":
+ if os.getuid() != 0:
+ raise SystemExit("Root permission is needed")
+ unittest.main()
diff --git a/tests/unittest/test_configmgr.py b/tests/unittest/test_configmgr.py
new file mode 100644
index 0000000..fcebc9f
--- /dev/null
+++ b/tests/unittest/test_configmgr.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+import os
+import sys
+import shutil
+import StringIO
+
+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')
+
+def suite():
+ return unittest.makeSuite(ConfigMgrTest)
+
+class ConfigMgrTest(unittest.TestCase):
+
+ def setUp(self):
+ self.configmgr = conf.ConfigMgr(siteconf=SITECONF)
+ shutil.copy2(KSCONF, KSBAK)
+ with open(KSCONF, 'r') as f:
+ content = f.read()
+ content = content.replace('$$$$$$', "file://" + REPOURI)
+ with open(KSCONF, 'w') as f:
+ f.write(content)
+ if not os.path.exists(CACHEDIR):
+ os.makedirs(CACHEDIR)
+ self.configmgr.create['cachedir'] = CACHEDIR
+ self.level = msger.get_loglevel()
+ msger.set_loglevel('quiet')
+
+ def tearDown(self):
+ msger.set_loglevel(self.level)
+ shutil.copy2(KSBAK, KSCONF)
+ os.unlink(KSBAK)
+ shutil.rmtree(CACHEDIR, ignore_errors = True)
+
+# def testCommonSection(self):
+# self.assertEqual(self.configmgr.common['test'], 'test')
+
+ def testCreateSection(self):
+ #self.assertEqual(self.configmgr.create['local_pkgs_path'], '/opt/cache')
+ self.assertEqual(self.configmgr.create['pkgmgr'], 'yum')
+
+# def testChrootSection(self):
+# self.assertEqual(self.configmgr.chroot['test2'], 'test2')
+
+# def testConvertSection(self):
+# self.assertEqual(self.configmgr.convert['test3'], 'test3')
+
+ def testKickstartConfig(self):
+ cachedir = self.configmgr.create['cachedir']
+ repomd = [{'baseurl': 'file://%s' % REPOURI ,
+ 'cachedir': '%s' % cachedir,
+ 'comps': None,
+ 'name': 'test',
+ 'patterns': None,
+ 'primary': '%s/test/primary.sqlite' % cachedir,
+ 'proxies': None,
+ 'repokey': None,
+ 'repomd': '%s/test/repomd.xml' % cachedir}]
+ self.configmgr._ksconf = KSCONF
+ self.assertTrue(isinstance(self.configmgr.create['ks'], KickstartParser))
+ self.assertEqual(self.configmgr.create['name'], 'test')
+ self.assertDictEqual(repomd[0], self.configmgr.create['repomd'][0])
+ self.assertEqual(self.configmgr.create['arch'], 'i686')
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/unittest/test_pluginmgr.py b/tests/unittest/test_pluginmgr.py
new file mode 100644
index 0000000..5c207b6
--- /dev/null
+++ b/tests/unittest/test_pluginmgr.py
@@ -0,0 +1,77 @@
+#!/usr/bin/python
+
+import os
+import sys
+import glob
+import StringIO
+from mic import plugin
+from mic import pluginbase
+from mic import msger
+import unittest
+
+TEST_PLUGINS_LOC = os.path.join(os.getcwd(), 'pluginmgr_fixtures')
+
+def suite():
+ return unittest.makeSuite(PluginMgrTest)
+
+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.stdout = sys.stdout
+ self.stderr = sys.stderr
+ sys.stdout = StringIO.StringIO()
+ sys.stderr = StringIO.StringIO()
+
+ 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
+
+ def testPluginDir(self):
+ plugindir = {}
+ for pt in plugin.PLUGIN_TYPES:
+ plugindir[os.path.join(TEST_PLUGINS_LOC, pt)] = True
+ #self.assertEqual(self.plugin.plugin_dirs.keys(), plugindir.keys())
+ self.assertTrue(any([x in plugindir.keys() for x in self.plugin.plugin_dirs.keys()]))
+
+ def testNoExistedPluginDir(self):
+ noexistdir = "/xxxx/xxxx/xxxx/xxxx"
+ self.plugin._add_plugindir(noexistdir)
+ warn = "Warning: Plugin dir is not a directory or does not exist: " \
+ "%s\n" % noexistdir
+ self.assertEqual(sys.stderr.getvalue(), warn)
+
+ def testBackendPlugins(self):
+ expect = ['zypptest', 'yumtest']
+ expect.sort()
+ lst = []
+ for name, cls in self.plugin.get_plugins('backend').items():
+ lst.append(name)
+ lst.sort()
+ #self.assertEqual(lst, expect)
+ self.assertTrue(any([x in expect for x in lst]))
+
+ def testImagerPlugins(self):
+ expect = ['fstest', 'looptest']
+ expect.sort()
+ lst = []
+ for name, cls in self.plugin.get_plugins('imager').items():
+ lst.append(name)
+ lst.sort()
+ #self.assertEqual(lst, expect)
+ self.assertTrue(any([x in expect for x in lst]))
+
+if __name__ == "__main__":
+ unittest.main()