java/code/src/com/redhat/rhn/common/db/datasource/xml/test_queries.xml | 16 +- java/code/src/com/redhat/rhn/domain/user/UserFactory.java | 12 + java/code/src/com/redhat/rhn/frontend/xmlrpc/test/SatScrubberTest.java | 74 +++++----- java/code/src/com/redhat/rhn/manager/user/UserManager.java | 16 -- 4 files changed, 72 insertions(+), 46 deletions(-)
New commits: commit a823d1955b0a45e66e83b165876291208e770394 Author: Partha Aji paji@redhat.com Date: Wed Jun 30 21:07:08 2010 -0400
Added a sat scrubber test that wipes out old test artifactsw
diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/test_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/test_queries.xml index c6a729c..5735de1 100644 --- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/test_queries.xml +++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/test_queries.xml @@ -456,12 +456,26 @@ SELECT * FROM time_series order by entry_time </query> </mode>
+<mode name="get_test_users"> + <query params=""> +SELECT id from web_customer where UPPER(name) like 'TEST%' + </query> +</mode> + + <mode name="get_test_orgs"> <query params=""> SELECT id from web_customer where UPPER(name) like 'TESTORG%' </query> </mode>
+<mode name="get_test_servers"> + <query params=""> +SELECT id from rhnServer where name like 'serverfactorytest%' + </query> +</mode> + + <mode name="select_in"> <query params=""> SELECT name FROM web_customer WHERE id IN (%s) @@ -492,6 +506,4 @@ SELECT name FROM web_customer WHERE id IN (%s) AND name = :name SELECT data FROM time_series WHERE data = :data </query> </mode> - - </datasource_modes> diff --git a/java/code/src/com/redhat/rhn/domain/user/UserFactory.java b/java/code/src/com/redhat/rhn/domain/user/UserFactory.java index 0c82636..82bca48 100644 --- a/java/code/src/com/redhat/rhn/domain/user/UserFactory.java +++ b/java/code/src/com/redhat/rhn/domain/user/UserFactory.java @@ -711,4 +711,16 @@ public class UserFactory extends HibernateFactory { return (List<User>)listObjectsByNamedQuery("User.findAllOrgAdmins", params); }
+ /** + * @param userId the user id + */ + public static void deleteUser(Long userId) { + CallableMode m = ModeFactory.getCallableMode("User_queries", + "delete_user"); + Map inParams = new HashMap(); + Map outParams = new HashMap(); + inParams.put("user_id", userId); + m.execute(inParams, outParams); + } + } diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/test/SatScrubberTest.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/test/SatScrubberTest.java index 9643bb5..da0c2d0 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/test/SatScrubberTest.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/test/SatScrubberTest.java @@ -22,7 +22,6 @@ import com.redhat.rhn.domain.channel.ChannelFactory; import com.redhat.rhn.domain.kickstart.KickstartData; import com.redhat.rhn.domain.kickstart.KickstartFactory; import com.redhat.rhn.domain.kickstart.KickstartableTree; -import com.redhat.rhn.domain.org.Org; import com.redhat.rhn.domain.org.OrgFactory; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.domain.user.UserFactory; @@ -30,7 +29,6 @@ import com.redhat.rhn.frontend.dto.kickstart.KickstartDto; import com.redhat.rhn.frontend.dto.kickstart.KickstartableTreeDto; import com.redhat.rhn.manager.channel.ChannelManager; import com.redhat.rhn.manager.kickstart.KickstartLister; -import com.redhat.rhn.manager.user.UserManager; import com.redhat.rhn.testing.RhnBaseTestCase; import com.redhat.rhn.testing.TestUtils;
@@ -52,7 +50,12 @@ public class SatScrubberTest extends RhnBaseTestCase { private static Logger log = Logger.getLogger(SatScrubberTest.class);
public void testNothing() throws Exception { - // Test nothing. + cleanupKickstarts(); + cleanupChannels(); + cleanupServers(); + cleanupUsers(); + cleanupOrgs(); + }
public void cleanupKickstarts() throws Exception { @@ -99,48 +102,35 @@ public class SatScrubberTest extends RhnBaseTestCase {
public void cleanupUsers() throws Exception { - orgAdmin = UserFactory.findRandomOrgAdmin(OrgFactory.getSatelliteOrg()); - List users = UserManager.usersInOrg(orgAdmin, null, Map.class); - for (int i = 0; i < users.size(); i++) { - Map row = (Map) users.get(i); - String login = (String) row.get("login"); - if (login.indexOf("test") > -1) { - User lookedup = UserFactory.lookupByLogin(login); - UserManager.deleteUser(orgAdmin, lookedup.getId()); + DataResult dr = TestUtils.runTestQuery("get_test_users", new HashMap()); + for (int i = 0; i < dr.size(); i++) { + Long uid = (Long) ((Map) dr.get(i)).get("id"); + try { + UserFactory.deleteUser(uid); + } + catch (Exception e) { + log.warn("Error deleting user: " + uid, e); } if (i % 100 == 0) { log.debug("Deleted [" + i + "] users"); commitAndCloseSession(); } + + } commitAndCloseSession(); }
public void cleanupServers() throws Exception { - - List orgs = OrgFactory.lookupAllOrgs(); + DataResult dr = TestUtils.runTestQuery("get_test_servers", new HashMap()); int numdeleted = 0; - for (int x = 0; x < orgs.size(); x++) { - Org org = (Org) orgs.get(x); - orgAdmin = UserFactory.findRandomOrgAdmin(org); - if (orgAdmin != null) { - List systems = UserManager.visibleSystemsAsMaps(orgAdmin); - for (int i = 0; i < systems.size(); i++) { - Long sid = (Long) ((Map) systems.get(i)).get("id"); - String name = (String) ((Map) systems.get(i)).get("name"); - if (name.startsWith("serverfactorytest")) { - CallableMode m = ModeFactory. - getCallableMode("System_queries", "delete_server"); - Map in = new HashMap(); - in.put("server_id", sid); - m.execute(in, new HashMap()); - numdeleted++; - } - if (i % 100 == 0) { - log.debug("Deleted [" + numdeleted + "] systems"); - commitAndCloseSession(); - } - } + for (int i = 0; i < dr.size(); i++) { + Long sid = (Long) ((Map) dr.get(i)).get("id"); + deleteServer(sid); + numdeleted++; + if (i % 100 == 0) { + log.debug("Deleted [" + numdeleted + "] systems"); + commitAndCloseSession(); } }
@@ -148,6 +138,20 @@ public class SatScrubberTest extends RhnBaseTestCase { log.debug("Done deleting [" + numdeleted + "] systems"); }
+ /** + * @param sid + */ + private void deleteServer(Long sid) { + CallableMode m = ModeFactory. + getCallableMode("System_queries", "delete_server"); + Map in = new HashMap(); + in.put("server_id", sid); + m.execute(in, new HashMap()); + } + + + + public void cleanupOrgs() throws Exception { // testOrg DataResult dr = TestUtils.runTestQuery("get_test_orgs", new HashMap()); @@ -159,7 +163,7 @@ public class SatScrubberTest extends RhnBaseTestCase { OrgFactory.deleteOrg(new Long(id.longValue())); } catch (Exception e) { - log.debug("Error deleting org: " + id); + log.warn("Error deleting org: " + id, e); } if (i % 10 == 0) { log.debug("Deleted [" + i + "] orgs"); diff --git a/java/code/src/com/redhat/rhn/manager/user/UserManager.java b/java/code/src/com/redhat/rhn/manager/user/UserManager.java index 3720d2e..7052d0b 100644 --- a/java/code/src/com/redhat/rhn/manager/user/UserManager.java +++ b/java/code/src/com/redhat/rhn/manager/user/UserManager.java @@ -37,6 +37,7 @@ import com.redhat.rhn.domain.user.UserServerPreference; import com.redhat.rhn.frontend.dto.SystemGroupOverview; import com.redhat.rhn.frontend.dto.SystemOverview; import com.redhat.rhn.frontend.dto.SystemSearchResult; +import com.redhat.rhn.frontend.dto.UserOverview; import com.redhat.rhn.frontend.listview.PageControl; import com.redhat.rhn.frontend.taglibs.list.decorators.PageSizeDecorator; import com.redhat.rhn.manager.BaseManager; @@ -461,12 +462,7 @@ public class UserManager extends BaseManager { } }
- CallableMode m = ModeFactory.getCallableMode("User_queries", - "delete_user"); - Map inParams = new HashMap(); - Map outParams = new HashMap(); - inParams.put("user_id", targetUid); - m.execute(inParams, outParams); + UserFactory.deleteUser(targetUid); }
/** @@ -563,7 +559,7 @@ public class UserManager extends BaseManager { * @param pc The details of which results to return. * @return A DataResult containing the specified number of users. */ - public static DataResult usersInOrg(User user, PageControl pc) { + public static DataResult <UserOverview> usersInOrg(User user, PageControl pc) { SelectMode m = ModeFactory.getMode("User_queries", "users_in_org"); return getUsersInOrg(user, pc, m); } @@ -576,7 +572,8 @@ public class UserManager extends BaseManager { * @param clazz The class you want the returned DataResult to contain. * @return A DataResult containing the specified number of users. */ - public static DataResult usersInOrg(User user, PageControl pc, Class clazz) { + public static DataResult usersInOrg(User user, + PageControl pc, Class clazz) { SelectMode m = ModeFactory.getMode("User_queries", "users_in_org", clazz); return getUsersInOrg(user, pc, m); } @@ -588,7 +585,8 @@ public class UserManager extends BaseManager { * @param m The select mode. * @return A list containing the specified number of users. */ - private static DataResult getUsersInOrg(User user, PageControl pc, SelectMode m) { + private static DataResult getUsersInOrg(User user, + PageControl pc, SelectMode m) { if (!user.hasRole(RoleFactory.ORG_ADMIN)) { //Throw an exception with a nice error message so the user //knows what went wrong.
spacewalk-commits@lists.fedorahosted.org