From 7af5c38cdc0d54750948ad3ab3109ee5b4c0ddc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Tue, 24 Apr 2012 18:44:52 +0200
Subject: [PATCH] Simple alarm to cleanup Selenium Tester instances.

---
 .../promise_template_tool_configuration.xml   | 103 ++++++++++++++++++
 ...Alarm_destroySeleniumTesterKvmInstance.xml |  84 ++++++++++++++
 ...ption_requestDestructionSeleniumTester.xml |  82 ++++++++++++++
 master/bt5/vifib_slap/bt/revision             |   2 +-
 master/bt5/vifib_slap/bt/template_path_list   |   1 +
 5 files changed, 271 insertions(+), 1 deletion(-)
 create mode 100644 master/bt5/vifib_slap/PathTemplateItem/portal_alarms/promise_template_tool_configuration.xml
 create mode 100644 master/bt5/vifib_slap/SkinTemplateItem/portal_skins/vifib_slap/Alarm_destroySeleniumTesterKvmInstance.xml
 create mode 100644 master/bt5/vifib_slap/SkinTemplateItem/portal_skins/vifib_slap/HostingSubcription_requestDestructionSeleniumTester.xml

diff --git a/master/bt5/vifib_slap/PathTemplateItem/portal_alarms/promise_template_tool_configuration.xml b/master/bt5/vifib_slap/PathTemplateItem/portal_alarms/promise_template_tool_configuration.xml
new file mode 100644
index 000000000..2bbb08e7e
--- /dev/null
+++ b/master/bt5/vifib_slap/PathTemplateItem/portal_alarms/promise_template_tool_configuration.xml
@@ -0,0 +1,103 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="Alarm" module="erp5.portal_type"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>active_sense_method_id</string> </key>
+            <value> <string>Alarm_checkPromiseTemplateTool</string> </value>
+        </item>
+        <item>
+            <key> <string>alarm_notification_mode</string> </key>
+            <value>
+              <tuple>
+                <string>never</string>
+              </tuple>
+            </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>enabled</string> </key>
+            <value> <int>1</int> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>promise_template_tool_configuration</string> </value>
+        </item>
+        <item>
+            <key> <string>periodicity_day_frequency</string> </key>
+            <value> <int>1</int> </value>
+        </item>
+        <item>
+            <key> <string>periodicity_hour</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>periodicity_minute</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>periodicity_month</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>periodicity_month_day</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>periodicity_start_date</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="DateTime" module="DateTime.DateTime"/>
+                </klass>
+                <tuple>
+                  <none/>
+                </tuple>
+                <state>
+                  <tuple>
+                    <float>0.0</float>
+                    <string>GMT</string>
+                  </tuple>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>periodicity_week</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>portal_type</string> </key>
+            <value> <string>Alarm</string> </value>
+        </item>
+        <item>
+            <key> <string>solve_method_id</string> </key>
+            <value> <string>Alarm_installPromiseBt5</string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string>Check Template Tool Configuration</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/master/bt5/vifib_slap/SkinTemplateItem/portal_skins/vifib_slap/Alarm_destroySeleniumTesterKvmInstance.xml b/master/bt5/vifib_slap/SkinTemplateItem/portal_skins/vifib_slap/Alarm_destroySeleniumTesterKvmInstance.xml
new file mode 100644
index 000000000..8bd572478
--- /dev/null
+++ b/master/bt5/vifib_slap/SkinTemplateItem/portal_skins/vifib_slap/Alarm_destroySeleniumTesterKvmInstance.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>name_container</string> </key>
+                                <value> <string>container</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_context</string> </key>
+                                <value> <string>context</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_m_self</string> </key>
+                                <value> <string>script</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_body</string> </key>
+            <value> <string>from Products.ZSQLCatalog.SQLCatalog import NegatedQuery, Query\n
+\n
+portal = context.getPortalObject()\n
+person_reference = portal.restrictedTraverse(\'person_module/20120411-A56ED\').getReference()\n
+\n
+setup_service = portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceSetupResource())\n
+\n
+# XXX Owner column should not be used to fetch the list!\n
+# Data model of hosting subscription should be fixed to allow direct query\n
+portal.portal_catalog.searchAndActivate(\n
+  portal_type="Hosting Subscription",\n
+  owner=person_reference,\n
+  method_id=\'HostingSubcription_requestDestructionSeleniumTester\',\n
+  method_kw={\'tag\': tag},\n
+  activate_kw={\'tag\': tag},\n
+)\n
+\n
+context.activate(after_tag=tag).getId()\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>tag, fixit, params</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Alarm_destroySeleniumTesterKvmInstance</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/master/bt5/vifib_slap/SkinTemplateItem/portal_skins/vifib_slap/HostingSubcription_requestDestructionSeleniumTester.xml b/master/bt5/vifib_slap/SkinTemplateItem/portal_skins/vifib_slap/HostingSubcription_requestDestructionSeleniumTester.xml
new file mode 100644
index 000000000..a0737b9ec
--- /dev/null
+++ b/master/bt5/vifib_slap/SkinTemplateItem/portal_skins/vifib_slap/HostingSubcription_requestDestructionSeleniumTester.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>name_container</string> </key>
+                                <value> <string>container</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_context</string> </key>
+                                <value> <string>context</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_m_self</string> </key>
+                                <value> <string>script</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_body</string> </key>
+            <value> <string encoding="cdata"><![CDATA[
+
+from DateTime import DateTime\n
+portal = context.getPortalObject()\n
+hosting_subscription = context\n
+\n
+now = DateTime()\n
+\n
+if hosting_subscription.getAggregateRelatedValue(portal_type=\'Sale Order Line\').getParentValue().getDestinationSectionValue().getReference() == \'seleniumtester\' and \\\n
+  hosting_subscription.getModificationDate() < (now - 1):\n
+  if hosting_subscription.SoftwareInstance_getStatus() != \'Destroyed\':\n
+    software_instance = hosting_subscription.getPredecessorValue(portal_type=\'Software Instance\')\n
+    if software_instance is not None:\n
+      software_instance.requestDestroyComputerPartition(comment=\'Requested by clenaup alarm\', activate_kw={\'tag\': tag})\n
+
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>tag</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>HostingSubcription_requestDestructionSeleniumTester</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/master/bt5/vifib_slap/bt/revision b/master/bt5/vifib_slap/bt/revision
index 980f92ce8..5b3e043c5 100644
--- a/master/bt5/vifib_slap/bt/revision
+++ b/master/bt5/vifib_slap/bt/revision
@@ -1 +1 @@
-702
\ No newline at end of file
+703
\ No newline at end of file
diff --git a/master/bt5/vifib_slap/bt/template_path_list b/master/bt5/vifib_slap/bt/template_path_list
index 86b9e60ed..18e3e9dc0 100644
--- a/master/bt5/vifib_slap/bt/template_path_list
+++ b/master/bt5/vifib_slap/bt/template_path_list
@@ -1,6 +1,7 @@
 portal_alarms/confirm_ordered_sale_order
 portal_alarms/confirm_planned_sale_invoice_transaction
 portal_alarms/deliver_subscription_sale_packing_list
+portal_alarms/promise_template_tool_configuration
 portal_alarms/stop_confirmed_sale_invoice_transaction
 portal_alarms/vifib_cancel_destroy_partition
 portal_alarms/vifib_cancel_update_partition
-- 
2.30.9