7037199 installadm delete-service should clean up after itself and removes profiles in /var/ai/profile
authorWilliam Schumann <william.schumann@sun.com>
Tue, 17 May 2011 14:58:21 +0200
changeset 1130 e4533da9b19c
parent 1129 e8fa7dfb2df2
child 1131 321737de165e
7037199 installadm delete-service should clean up after itself and removes profiles in /var/ai/profile
usr/src/cmd/ai-webserver/AI_database.py
usr/src/cmd/installadm/delete_service.py
--- a/usr/src/cmd/ai-webserver/AI_database.py	Tue May 17 06:57:19 2011 -0600
+++ b/usr/src/cmd/ai-webserver/AI_database.py	Tue May 17 14:58:21 2011 +0200
@@ -105,6 +105,12 @@
         self._ans = None
         self._committable = commit
 
+    def __repr__(self):
+        result =  ["DBrequest:_sql:%s" % self._sql]
+        result += ["          _ans:%s" % self._ans]
+        result += ["          _committable:%s" % self._committable]
+        return "\n".join(result)
+
     def needsCommit(self):
         ''' Use needsCommit() to determine if the query needs to
         be committed.
--- a/usr/src/cmd/installadm/delete_service.py	Tue May 17 06:57:19 2011 -0600
+++ b/usr/src/cmd/installadm/delete_service.py	Tue May 17 14:58:21 2011 +0200
@@ -35,6 +35,7 @@
 
 from optparse import OptionParser
 
+import osol_install.auto_install.AI_database as AIdb
 import osol_install.auto_install.installadm_common as com
 import osol_install.libaiscf as smf
 
@@ -736,6 +737,7 @@
     stop_service(service)
 
     # everything should be down, remove files
+    remove_profiles(service)
     remove_files(service, options.deleteImage)
 
     # check if this machine is a DHCP server
@@ -745,6 +747,28 @@
     remove_service(service)
 
 
+def remove_profiles(service):
+    ''' delete profile files from internal database
+    Arg: service - object of service to delete profile files for
+    Effects: all internal profile files for service are deleted
+    Exceptions: OSError logged only, considered non-critical
+    Note: database untouched - assumes that database file will be deleted
+    '''
+    svc_info = get_service_info(service.serviceName)
+    dbn = AIdb.DB(svc_info[1])
+    query = AIdb.DBrequest("SELECT file FROM " + AIdb.PROFILES_TABLE)
+    dbn.getQueue().put(query)
+    query.waitAns()
+    for row in iter(query.getResponse()):
+        filename = row['file']
+        try:
+            if os.path.exists(filename):
+                os.unlink(filename)
+        except OSError, emsg:
+            logging.warn(_("Could not delete profile %s: %s") %
+                         (filename, emsg))
+
+
 if __name__ == "__main__":
 
     # initialize gettext