7040960 Missing usr/src/cmd/ai-webserver/export_profile.py in slim_source cause slim unit test failure.
authorWilliam Schumann <william.schumann@sun.com>
Tue, 10 May 2011 11:01:28 +0200
changeset 1116 29e34d65ceef
parent 1115 9c247606f767
child 1117 ae9a188dcfcc
7040960 Missing usr/src/cmd/ai-webserver/export_profile.py in slim_source cause slim unit test failure.
usr/src/cmd/ai-webserver/common_profile.py
usr/src/cmd/ai-webserver/export.py
usr/src/cmd/ai-webserver/test/test_ai_database.py
usr/src/cmd/ai-webserver/test/test_create_profile.py
usr/src/cmd/ai-webserver/test/test_delete_profile.py
usr/src/cmd/ai-webserver/test/test_export.py
usr/src/cmd/ai-webserver/test/test_export_profile.py
usr/src/cmd/ai-webserver/test/test_validate_profile.py
usr/src/cmd/ai-webserver/validate_profile.py
usr/src/tools/tests/slim_test
--- a/usr/src/cmd/ai-webserver/common_profile.py	Mon May 09 17:19:12 2011 -0600
+++ b/usr/src/cmd/ai-webserver/common_profile.py	Tue May 10 11:01:28 2011 +0200
@@ -241,12 +241,13 @@
     return columns
 
 
-def validate_profile_string(profile_str, image_dir, resolve_entities=True,
+def validate_profile_string(profile_str, image_dir=None, resolve_entities=True,
         dtd_validation=False, warn_if_dtd_missing=False):
     ''' Given the profile contained in a string variable, validate
     Args:
         profile_str - profile in string format
         image_dir - path of service image, used to locate service_bundle
+            if None, only unit test against local service_bundle(4)
         resolve_entities - if True, ask XML parser to resolve all entities
         dtd_validation - if True, validate against a DTD in the profile
         warn_if_dtd_missing - if True, raise an exception if the DTD not found
@@ -276,6 +277,11 @@
             print >> sys.stderr, _(
                 "Warning:  DOCTYPE %s specified instead of service_bundle(4). "
                 "The file might not be a profile.") % root.docinfo.system_url
+    if image_dir is None:  # unit testing only
+        err = validate_profile_external_dtd(profile_str)
+        if err:
+            raise etree.XMLSyntaxError(err, '', '', '')
+        return profile_str
     dtd_file = os.path.join(image_dir, 'auto_install', 'service_bundle.dtd.1')
     # if warning only on DTD missing, and DTD is indeed missing
     if root.docinfo.system_url is not None and warn_if_dtd_missing and \
--- a/usr/src/cmd/ai-webserver/export.py	Mon May 09 17:19:12 2011 -0600
+++ b/usr/src/cmd/ai-webserver/export.py	Tue May 10 11:01:28 2011 +0200
@@ -80,13 +80,6 @@
     except ValueError as err:
         parser.error(str(err))
 
-    try:
-        # get AI service directory, database name
-        options.svcdir, options.dbname, dummy = \
-            get_service_info(options.service_name)
-    except StandardError as err:
-        parser.error(str(err))
-
     if not len(options.mnames) and not len(options.pnames):
         parser.error(_("A manifest or profile name is required."))
 
@@ -134,7 +127,9 @@
     ''' Export a manifest or a profile.  Called from installadm.
     '''
     options = parse_options(cmd_options)
-
+    # get AI service directory, database name
+    options.svcdir, options.dbname, dummy = \
+            get_service_info(options.service_name)
     merrno = perrno = 0
     if len(options.mnames):
         merrno = do_export_manifest(options)
--- a/usr/src/cmd/ai-webserver/test/test_ai_database.py	Mon May 09 17:19:12 2011 -0600
+++ b/usr/src/cmd/ai-webserver/test/test_ai_database.py	Tue May 10 11:01:28 2011 +0200
@@ -19,7 +19,7 @@
 #
 # CDDL HEADER END
 #
-# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
 #
 
 '''
@@ -98,7 +98,8 @@
 
     # Disable unused-args message here as this is a dummy function.
     # pylint: disable-msg=W0613
-    def __call__(self, queue, onlyUsed=False, strip=False):
+    def __call__(self, queue, table=AIdb.MANIFESTS_TABLE, onlyUsed=False,
+                 strip=False):
         if strip:
             return self.crit_stripped
         else:
--- a/usr/src/cmd/ai-webserver/test/test_create_profile.py	Mon May 09 17:19:12 2011 -0600
+++ b/usr/src/cmd/ai-webserver/test/test_create_profile.py	Tue May 10 11:01:28 2011 +0200
@@ -34,9 +34,10 @@
 import os
 import tempfile
 import unittest
-import publish_manifest
-import create_profile
+
 import osol_install.auto_install.AI_database as AIdb
+import osol_install.auto_install.create_profile as create_profile
+import osol_install.auto_install.publish_manifest as publish_manifest
 import osol_install.libaiscf as smf
 
 
--- a/usr/src/cmd/ai-webserver/test/test_delete_profile.py	Mon May 09 17:19:12 2011 -0600
+++ b/usr/src/cmd/ai-webserver/test/test_delete_profile.py	Tue May 10 11:01:28 2011 +0200
@@ -34,9 +34,10 @@
 import unittest
 import os
 import os.path
-import delete_profile
+
 import osol_install.auto_install.AI_database as AIdb
 import osol_install.auto_install.common_profile as sc
+import osol_install.auto_install.delete_profile as delete_profile
 
 gettext.install("delete-profile-test")
 
--- a/usr/src/cmd/ai-webserver/test/test_export.py	Mon May 09 17:19:12 2011 -0600
+++ b/usr/src/cmd/ai-webserver/test/test_export.py	Tue May 10 11:01:28 2011 +0200
@@ -54,9 +54,16 @@
 
         myargs = ["-n", "-o", "/tmp/junk.xml"]
         self.assertRaises(SystemExit, export.parse_options, myargs)
-
         myargs = ["-n", "mysvc", "-o"]
         self.assertRaises(SystemExit, export.parse_options, myargs)
+        myargs = ["-n", "-p", "profile"]
+        self.assertRaises(SystemExit, export.parse_options, myargs)
+
+    def test_parse_multi_options(self):
+        '''Ensure multiple options processed'''
+        myargs = ["-n", "mysvc", "-p", "profile", "-p", "profile2"] 
+        options = export.parse_options(myargs)
+        self.assertEquals(options.pnames, ["profile", "profile2"])
 
 if __name__ == '__main__':
     unittest.main()
--- a/usr/src/cmd/ai-webserver/test/test_export_profile.py	Mon May 09 17:19:12 2011 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,162 +0,0 @@
-#!/usr/bin/python2.6
-#
-# CDDL HEADER START
-#
-# The contents of this file are subject to the terms of the
-# Common Development and Distribution License (the "License").
-# You may not use this file except in compliance with the License.
-#
-# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
-# or http://www.opensolaris.org/os/licensing.
-# See the License for the specific language governing permissions
-# and limitations under the License.
-#
-# When distributing Covered Code, include this CDDL HEADER in each
-# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
-# If applicable, add the following below this CDDL HEADER, with the
-# fields enclosed by brackets "[]" replaced with your own identifying
-# information: Portions Copyright [yyyy] [name of copyright owner]
-#
-# CDDL HEADER END
-#
-# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
-#
-
-'''
-To run these tests, see the instructions in usr/src/tools/tests/README.
-Remember that since the proto area is used for the PYTHONPATH, the gate
-must be rebuilt for these tests to pick up any changes in the tested code.
-
-'''
-
-import gettext
-import tempfile
-import unittest
-import os
-import os.path
-import export_profile
-import osol_install.auto_install.AI_database as AIdb
-
-gettext.install("export-profile-test")
-
-class MockDataBase(object):
-    '''Class for mock database '''
-    def __init__(self):
-        self.queue  = MockQueue()
-
-    def getQueue(self):
-        return self.queue
-
-class MockQueue(object):
-    '''Class for mock database '''
-    def __init__(self):
-        self.criteria = None
-
-    def put(self, query):
-        return
-
-class MockLog(object):
-    '''Class for mock log '''
-    def info(self, msg):
-        return
-    def debug(self, msg):
-        return
-
-class MockQuery(object):
-    '''Class for mock query '''
-    def __init__(self, name, file):
-        self.query = None
-        self.name = name
-        self.file = file
-
-    def __call__(self, query, commit=False):
-        self.query = query
-        return self
-
-    def waitAns(self):
-        return
-
-    def getResponse(self):
-        return [{'name': self.name, 'file': self.file}]
-
-class MockDataFiles(object):
-    '''Class for mock DataFiles'''
-    def __init__(self):
-        self.criteria = None
-        self.database = MockDataBase()
-
-class ExportProfile(unittest.TestCase):
-    '''Tests for export_profile'''
-
-    def setUp(self):
-        '''unit test set up
-
-        '''
-        self.aidb_DBrequest = AIdb.DBrequest
-        self.files = MockDataFiles()
-
-        prof = [
-                '<?xml version="1.0"?>',
-                '<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">',
-                '<service_bundle type="manifest" name="SUNWtime-slider">',
-                '<service name="system/filesystem/zfs/auto-snapshot"',
-                '	type="service"',
-                '	version="0.2.96">',
-                '        <property_group name="general" type="framework">',
-                '            <propval name="action_authorization" type="astring"',
-                '                value="solaris.smf.manage.zfs-auto-snapshot" />',
-                '            <propval name="value_authorization" type="astring"',
-                '                value="solaris.smf.manage.zfs-auto-snapshot" />',
-                '        </property_group>',
-                '</service>',
-                '</service_bundle>']
-        prof_str = ''
-        for i in prof:
-            prof_str += i + '\n'
-        (pfp, fname) = tempfile.mkstemp()
-        os.write(pfp, prof_str)
-        os.close(pfp)
-        self.mockquery = MockQuery(os.path.basename(fname), fname)
-        AIdb.DBrequest = self.mockquery
-
-    def tearDown(self):
-        '''unit test tear down
-        Functions originally saved in setUp are restored to their
-        original values.
-        '''
-        AIdb.DBrequest = self.aidb_DBrequest
-        os.unlink(self.mockquery.file)
-
-    def test_export(self):
-        export_profile.export_profile(self.mockquery.name,
-                self.files.database)
-
-class ParseOptions(unittest.TestCase):
-    '''Tests for parse_options. Some tests correctly output usage msg'''
-
-    def test_parse_no_options(self):
-        '''Ensure no options caught'''
-        self.assertRaises(SystemExit, export_profile.parse_options, []) 
-        myargs = ["mysvc"] 
-        self.assertRaises(SystemExit, export_profile.parse_options, myargs) 
-
-    def test_parse_multi_options(self):
-        '''Ensure multiple options processed'''
-        myargs = ["-n", "mysvc", "-p", "profile", "-p", "profile2"] 
-        options = export_profile.parse_options(myargs)
-        self.assertEquals(options.profile_name, ["profile", "profile2"])
-
-    def test_parse_invalid_options(self):
-        '''Ensure invalid option flagged'''
-        myargs = ["-n", "mysvc", "-p", "profile", "-u"] 
-        self.assertRaises(SystemExit, export_profile.parse_options, myargs) 
-
-    def test_parse_options_novalue(self):
-        '''Ensure options with missing value caught'''
-        myargs = ["-n", "-p", "profile"]
-        self.assertRaises(SystemExit, export_profile.parse_options, myargs)
-        myargs = ["-n", "mysvc", "-p"]
-        self.assertRaises(SystemExit, export_profile.parse_options, myargs)
-
-if __name__ == '__main__':
-    unittest.main()
--- a/usr/src/cmd/ai-webserver/test/test_validate_profile.py	Mon May 09 17:19:12 2011 -0600
+++ b/usr/src/cmd/ai-webserver/test/test_validate_profile.py	Tue May 10 11:01:28 2011 +0200
@@ -34,9 +34,9 @@
 import unittest
 import os
 import lxml.etree
-import validate_profile
+import osol_install.auto_install.AI_database as AIdb
 import osol_install.auto_install.common_profile as sc
-import osol_install.auto_install.AI_database as AIdb
+import osol_install.auto_install.validate_profile as validate_profile
 
 
 gettext.install("ai-test")
@@ -105,7 +105,7 @@
         prof = [
                 '<?xml version="1.0"?>',
                 '<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">',
-                '<service_bundle type="manifest" name="SUNWtime-slider">',
+                '<service_bundle type="profile" name="SUNWtime-slider">',
                 '<service name="system/filesystem/zfs/auto-snapshot"',
                 '	type="service"',
                 '	version="0.2.96">',
@@ -132,8 +132,8 @@
         os.write(tfp, prof_str)
         os.close(tfp)
         #these tests should fail for both string and file
-        self.assertRaises(lxml.etree.XMLSyntaxError, sc.validate_profile_string,
-                prof_str)
+        self.assertRaises(lxml.etree.XMLSyntaxError,
+                          sc.validate_profile_string, prof_str)
         self.assertFalse(validate_profile.validate_file(fname, fname))
         os.unlink(fname)
 
--- a/usr/src/cmd/ai-webserver/validate_profile.py	Mon May 09 17:19:12 2011 -0600
+++ b/usr/src/cmd/ai-webserver/validate_profile.py	Tue May 10 11:01:28 2011 +0200
@@ -120,7 +120,7 @@
     return isvalid
 
 
-def validate_file(profile_name, profile, image_dir):
+def validate_file(profile_name, profile, image_dir=None):
     '''validate a profile file, given the file path and profile name
     Args:
         profile_name - reference name of profile
--- a/usr/src/tools/tests/slim_test	Mon May 09 17:19:12 2011 -0600
+++ b/usr/src/tools/tests/slim_test	Tue May 10 11:01:28 2011 +0200
@@ -19,7 +19,7 @@
 #
 # CDDL HEADER END
 #
-# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
 #
 
 if [ -z "$SRC" -o -z "$ROOT" ]; then
@@ -30,6 +30,6 @@
 fi
 
 export PYTHONPATH=${ROOT}/usr/snadm/lib:${ROOT}/usr/lib/python2.6/vendor-packages/:\
-${ROOT}/usr/lib/installadm
+${ROOT}/usr/lib/installadm:${ROOT}/var/ai/image-server/cgi-bin
 
 nosetests -c ${SRC}/tools/tests/config.nose -w $SRC "$@"