java/code/src/com/redhat/rhn/manager/system/test/VirtualizationEntitlementsManagerTest.java
| 54 +++++++++-
schema/spacewalk/oracle/packages/rhn_entitlements.pkb
| 42 +++++++
2 files changed, 93 insertions(+), 3 deletions(-)
New commits:
commit dbbb162c7fd5ac64749a3dd2798f9b70da65fac8
Author: Partha Aji <paji(a)redhat.com>
Date: Wed Jul 7 20:19:08 2010 -0400
Made entitlement logic handle flex guests when the host is virt (un)entitled
diff --git
a/java/code/src/com/redhat/rhn/manager/system/test/VirtualizationEntitlementsManagerTest.java
b/java/code/src/com/redhat/rhn/manager/system/test/VirtualizationEntitlementsManagerTest.java
index 448a541..3591955 100644
---
a/java/code/src/com/redhat/rhn/manager/system/test/VirtualizationEntitlementsManagerTest.java
+++
b/java/code/src/com/redhat/rhn/manager/system/test/VirtualizationEntitlementsManagerTest.java
@@ -31,6 +31,7 @@ import com.redhat.rhn.domain.server.VirtualInstance;
import com.redhat.rhn.domain.server.test.HostBuilder;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.domain.user.UserFactory;
+import com.redhat.rhn.frontend.dto.ChannelFamilySystem;
import com.redhat.rhn.frontend.dto.ChannelFamilySystemGroup;
import com.redhat.rhn.manager.entitlement.EntitlementManager;
import com.redhat.rhn.manager.org.UpdateOrgSoftwareEntitlementsCommand;
@@ -58,7 +59,50 @@ public class VirtualizationEntitlementsManagerTest extends
RhnBaseTestCase {
User user = UserTestUtils.createUser(RandomStringUtils.randomAlphabetic(10),
org.getId());
user.addRole(RoleFactory.ORG_ADMIN);
+ UserFactory.save(user);
+ setupFlexGuestTest(user, false);
+ }
+
+
+ public void testListFlexGuestsOnVirtAddToHost() throws Exception {
+ Org org =
UserTestUtils.createNewOrgFull(RandomStringUtils.randomAlphabetic(10));
+ User user = UserTestUtils.createUser(RandomStringUtils.randomAlphabetic(10),
+ org.getId());
+ user.addRole(RoleFactory.ORG_ADMIN);
UserFactory.save(user);
+
+ setupFlexGuestTest(user, true);
+ List<ChannelFamilySystemGroup> l =
VirtualizationEntitlementsManager.getInstance().
+ listFlexGuests(user);
+ //NOW give Virt Entitlement to the Host
+ // And make sure flex is not being consumed
+ ChannelFamilySystemGroup g = l.get(0);
+ ChannelFamilySystem cfs = g.expand().get(0);
+ Server s = ServerFactory.lookupById(cfs.getId());
+ assertNotNull(s);
+ Server host = s.getVirtualInstance().getHostSystem();
+ Long hostId = host.getId();
+ assertNotNull(host);
+ SystemManager.entitleServer(host, EntitlementManager.VIRTUALIZATION);
+ HibernateFactory.getSession().clear();
+
+ l = VirtualizationEntitlementsManager.getInstance().
+ listFlexGuests(user);
+ assertTrue(l.isEmpty());
+
+
+ //NOW do the opposite remove the virt ent
+ //and ensure the guests are consuming flex
+ SystemManager.removeServerEntitlement(hostId,
EntitlementManager.VIRTUALIZATION);
+ HibernateFactory.getSession().clear();
+ l = VirtualizationEntitlementsManager.getInstance().
+ listFlexGuests(user);
+ assertTrue(!l.isEmpty());
+
+ }
+
+ public void setupFlexGuestTest(User user, boolean giveVirt) throws Exception {
+ Org org = user.getOrg();
long ents = 3;
int guestsToCreate = 6;
long flexEnts = guestsToCreate;
@@ -67,6 +111,13 @@ public class VirtualizationEntitlementsManagerTest extends
RhnBaseTestCase {
UpdateOrgSystemEntitlementsCommand cmd1 = new
UpdateOrgSystemEntitlementsCommand(
EntitlementManager.MANAGEMENT, org, sysEnts);
assertNull(cmd1.store());
+ if (giveVirt) {
+ UpdateOrgSystemEntitlementsCommand cmdVirt = new
+ UpdateOrgSystemEntitlementsCommand(
+ EntitlementManager.VIRTUALIZATION, org,
sysEnts);
+ assertNull(cmdVirt.store());
+ }
+
ChannelFamily rhelFamily = ChannelFamilyFactoryTest.createTestChannelFamily(
UserFactory.findRandomOrgAdmin(OrgFactory.getSatelliteOrg()),
@@ -97,7 +148,8 @@ public class VirtualizationEntitlementsManagerTest extends
RhnBaseTestCase {
assertEquals(1, l.size());
assertEquals(guestsToCreate, l.get(0).expand().size());
}
-
+
+
public void testNonVirtHostEligibleFlexGuests() throws Exception {
executeEligibleGuestTests(false);
diff --git a/schema/spacewalk/oracle/packages/rhn_entitlements.pkb
b/schema/spacewalk/oracle/packages/rhn_entitlements.pkb
index 8ea66da..8069cc9 100644
--- a/schema/spacewalk/oracle/packages/rhn_entitlements.pkb
+++ b/schema/spacewalk/oracle/packages/rhn_entitlements.pkb
@@ -579,14 +579,23 @@ is
order by sgm.modified desc
)
where rownum <= quantity_in;
-
+
org_id_val number;
max_members_val number;
max_flex_val number;
current_members_calc number;
sg_id number;
-
+ is_virt number := 0;
begin
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host',
'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
select org_id
into org_id_val
@@ -595,6 +604,35 @@ is
-- deal w/ channel entitlements first ...
for family in families loop
+ if is_virt = 0 then
+ -- if the host_server does not have virt
+ --- find all possible flex slots
+ -- and set each of the flex eligible guests to Y
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id in (
+ select virtual_system_id from (
+ select rownum, vi.virtual_system_id, max_members
+ from rhnServerFveCapable sfc
+ inner join rhnVirtualInstance vi on vi.virtual_system_id
= sfc.server_id
+ where vi.host_system_id = server_id_in
+ and sfc.channel_family_id = family.channel_family_id
+ order by vi.modified desc
+ )
+ where rownum <= max_members
+ );
+ else
+ -- if the host_server has virt
+ -- set all its flex guests to N
+ UPDATE rhnServerChannel sc set sc.is_fve = 'N'
+ where
+ sc.channel_id in (select cfm.channel_id from rhnChannelFamilyMembers
cfm
+ where cfm.CHANNEL_FAMILY_ID =
family.channel_family_id)
+ and sc.is_fve = 'Y'
+ and sc.server_id in
+ (select vi.virtual_system_id from rhnVirtualInstance vi
+ where vi.host_system_id = server_id_in);
+ end if;
+
-- get the current (physical) members of the family
current_members_calc :=
rhn_channel.channel_family_current_members(family.channel_family_id,
Show replies by date